Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/WorkshopModel.py
diff options
context:
space:
mode:
Diffstat (limited to 'Workshop.activity/WorkshopModel.py')
-rw-r--r--Workshop.activity/WorkshopModel.py162
1 files changed, 162 insertions, 0 deletions
diff --git a/Workshop.activity/WorkshopModel.py b/Workshop.activity/WorkshopModel.py
new file mode 100644
index 0000000..159263d
--- /dev/null
+++ b/Workshop.activity/WorkshopModel.py
@@ -0,0 +1,162 @@
+"""
+WorkshopModel
+
+This module is the model of the Workshop Activity
+"""
+
+from sugar.tutorius.vault import *
+
+class WorkshopModel():
+ def __init__(self,view):
+ self.view = view
+
+ 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
+ """
+## t1 = Tutorial({'name':'tuto 1',"description":"This is the description","rating":5})
+## t2 = Tutorial({'name':'tuto 2',"description":"This is the description of another","rating":4})
+## t3 = Tutorial({'name':'tuto 3',"description":"This is the description oh the last","rating":3})
+## t4 = Tutorial({'name':'tuto 4',"description":"This is the description oh the last","rating":1})
+## t5 = Tutorial({'name':'tuto 5',"description":"This is the description oh the last","rating":1})
+## t6 = Tutorial({'name':'tuto 6',"description":"This is the description oh the last","rating":1})
+## t7 = Tutorial({'name':'tuto 7',"description":"This is the description oh the last","rating":1})
+## tutorial_list = [t1,t2,t3,t4,t5,t6,t7]
+
+ 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
+ """
+ pass
+
+ def update_tutorial_infos(self,tutorial, new_infos):
+ """
+ Updates the metadata on a tutorial and updates the currently managed tutorials
+ Notifies the view tha 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
+
+ def publish_tutorial(self,tutorial):
+ """
+ Publishes a tutorial
+
+ Details to come
+ """
+ pass
+
+ def unpublish_tutorial(self,tutorial):
+ """
+ Unpublishes a tutorial
+
+ Details to come
+ """
+ pass
+
+
+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:
+ self.__published_state = self.__original_dict['publish_state']
+ 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)
+
+