1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
"""
WorkshopModel
This module is the model of the Workshop Activity
"""
from sugar.tutorius.vault import *
from sugar.tutorius.store import *
from dialogs import LoginDialog
class Login(object):
def __init__(self,proxy,login_view):
self.proxy = proxy
self.login_view = login_view
def __call__(self,f):
def wrapper(*args):
if self.proxy.get_session_id() == None:
self.login_view.run()
self.login_view.destroy()
f(*args)
return wrapper
class WorkshopModel():
store_proxy = StoreProxy("http://bobthebuilder.mine.nu/tutorius/en-US/tutorius")
login_view = LoginDialog()
def __init__(self,view):
self.view = view
self.login_view.set_model(self)
def login(self,username,password):
"""
Log a user in the store
@param username The username of the user
@param password The password of the user
@return True if login succeeded False otherwise
"""
return self.store_proxy.login(username,password)
def register(self,username,password,email):
"""
Register a new user to the store
@param username The username of the new user
@param password The password of the user
@param email The email of the user
@return True if user is registered, False otherwise
"""
return self.store_proxy.register_new_user({'nickname':username,'password':password,'email':email})
def query(self,keyword):
"""
Query the vault for tutorial that are linked with the keyword
Update the currently managed tutorials and notifies the view that the managed tutorials have changed
@param keyword the keyword for the query
"""
vault_return = Vault.query()
tutorial_list = []
for tuto in vault_return:
tutorial_list.append(Tutorial(tuto))
self.view.set_tutorial_list(tutorial_list)
def delete_tutorial(self,tutorial):
"""
Delete a tutorial and updated the currently managed tutorials
Notifies the view that the manages tutorials have changed
@param tutorial the tutorial to delete
"""
vault.deleteTutorial(tutorial.id)
def update_tutorial_infos(self,tutorial, new_infos):
"""
Updates the metadata on a tutorial and updates the currently managed tutorials
Notifies the view that the managed tutorials have changed
@param tutorial the tutorial to update
@param new_infos a dictionnary of the new informations i.e. {"title":"tut1","author":"Max Power"}
"""
pass
@Login(store_proxy,login_view)
def publish_tutorial(self,tutorial):
"""
Publishes a tutorial
Details to come
"""
if not tutorial.published_state:
binary = vault.get_tutorial_binary(tutorial.id)
@Login(store_proxy,login_view)
def unpublish_tutorial(self,tutorial):
"""
Unpublishes a tutorial
Details to come
"""
pass
def launch_tutorial(self,tutorial):
"""
Lauches a tutorial
@param tutorial The tutorial to launch
"""
pass
@Login(store_proxy,login_view)
def rate_tutorial(self,tutorial,rating):
"""
Rate the tutorial
@param tutorial The tutorial to rate
@param rating The new rating for the tutorial
"""
tutorial.rating = rating
self.view.refresh_content()
def edit_tutorial(self,tutorial):
"""
Edit a tutorial
@param tutorial The tutorial to edit
"""
pass
def save_metadata(self,tutorial):
"""
Save the metadata of a tutorial
@param tutorial The tutorial to udpate containing the new metadata
"""
self.view.refresh_content()
class Tutorial():
"""
Wrapper for tutorial metadata
"""
def __init__(self,metadata_dict):
self.__original_dict = metadata_dict
self.__update_dict = metadata_dict
if 'name' in self.__original_dict:
self.__name = self.__original_dict['name']
else:
self.__description = name
if 'description' in self.__original_dict:
self.__description = self.__original_dict['description']
else:
self.__description = ""
if 'author' in self.__original_dict:
self.__author = self.__original_dict['author']
else:
self.__author = ""
if 'rating' in self.__original_dict:
self.__rating = float(self.__original_dict['rating'])
else:
self.__rating = 0
if 'publish_state' in self.__original_dict:
#I'm sorry for this
temp = self.__original_dict['publish_state']
temp = temp.lower()
if temp == 'false':
self.__published_state = False
elif temp == 'true':
self.__published_state = True
else:
self.__published_state = None
else:
self.__published_state = None
if 'guid' in self.__original_dict:
self.__id = self.__original_dict['guid']
else:
self.__id = ""
def get_name(self):
return self.__name
def set_name(self,name):
self.__name = name
def get_description(self):
return self.__description
def set_description(self,description):
self.__description = description
self.__update_dict['Description'] = description
def get_author(self):
return self.__author
def set_author(self,author):
self.__author = author
self.__update_dict['Author'] = author
def get_rating(self):
return self.__rating
def set_rating(self,rating):
self.__rating = rating
self.__update_dict['Rating'] = rating
def get_published_state(self):
return self.__published_state
def set_published_state(self,published_state):
self.__published_state = published_state
self.__update_dict['PublishedState'] = published_state
def get_id(self):
return self.__id
def set_id(self,id):
self.__id = id
self.__update_dict['TutorialId'] = id
def get_updated_metadata(self):
return self.__update_dict
name = property(get_name,set_name)
description = property(get_description,set_description)
author = property(get_author,set_author)
rating = property(get_rating,set_rating)
published_state = property(get_published_state,set_published_state)
id = property(get_id,set_id)
updated_metadata = property(get_updated_metadata)
|