Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/WorkshopModel.py
blob: ebc55799e7ace2086f387b1dee9d1816dedfcc66 (plain)
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
"""
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 = None

        if 'author' in self.__original_dict:
            self.__author = self.__original_dict['author']
        else:
            self.__author = None

        if 'rating' in self.__original_dict:
            self.__rating = 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 = None

    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)