Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Workshop.activity/WorkshopController.py
blob: 84b59992f4dc517027ec9c4c03f946191985c704 (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
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
"""
WorkshopController

This module handles user action from the workshop view

"""
import logging
from WorkshopModel import Tutorial
class WorkshopController():
    def __init__(self,view,model):
        self.view = view
        self.model = model

    def tutorial_query(self,widget,keyword):
        """
        Handles query from the view

        @param widget the widget that sent the query
        @param keyword the keyword for the query, empty to get all tutorials
        """
        self.model.query([keyword.get_text()])

    def sort_selection_changed(self,widget,data):
        """
        Handles selection changes in the sorting selection

        @param widget the widget that sent the query
        @param sort the property to use to sort tutorial
        """
        sorting = widget.get_active_text()
        self.view.change_sorting(sorting)
        

    def launch_tutorial(self,widget,tutorial):
        """
        Handles start tutorial action

        @param widget the widget that triggered the action
        @param tutorial the tutorial to launch
        """
        self.model.launch_tutorial(tutorial)

    def show_details(self,widget,tutorial):
        """
        show the details for a tutorial

        @param widget the widget that made the call
        @param tutorial the tutorial to 
        """
        self.view.display_detail(tutorial)

    def back_pressed(self,widget,data):
        """
        When in detail view, go back to general view

        @param widget the widget that made the call
        @param data not used
        """
        self.view.display_main_view()

    def rate_tutorial(self,tutorial,rating):
        """
        Change the rating for a tutorial

        @param tutorial The tutorial to rate
        @param rating The new rating
        """
        self.model.rate_tutorial(tutorial,rating)

    def edit_tutorial(self,widget,tutorial):
        """
        Edit the tutorial in the detail view

        @param widget the widget that made the call
        @param tutorial the tutorial to edit
        """
        self.model.edit_tutorial(tutorial)

    def update_tutorial(self,widget,tutorial):
        """
        Need to know what this do
        """
        pass

    def info_tutorial(self,widget,tutorial):
        """
        Edit the infos about the tutorial

        @param widget the widget that made the call
        @param tutorial the tutorial to edit
        """
        self.view.display_info_dialog(tutorial)
        
    def save_tutorial_info(self,tutorial):
        """
        Save the metadata of a tutorial
        
        @param tutorial The tutorial to update containing the new metadata
        """
        self.model.save_metadata(tutorial)

    def delete_tutorial(self,widget,tutorial):
        """
        Delete a tutorial

        @param widget the widget that made the call
        @param tutorial the tutorial to delete
        """
        self.model.delete_tutorial(tutorial)

    def publish_tutorial(self,widget,tutorial):
        """
        Publish a tutorial

        @param widget the widget that made the call
        @param tutorial the tutorial to publish
        """
        self.model.publish_tutorial(tutorial)

    def unpublish_tutorial(self,widget,tutorial):
        """
        Unpublish a tutorial

        @param widget the widget that made the call
        @param tutorial the tutorial to unpublish
        """
        self.model.unpublish_tutorial(tutorial)


    def get_categories(self):
        self.model.get_categories_for_workshop()
        
class StoreController():
    def __init__(self,view,model):
        self.view = view
        self.model = model
        self.last_call_search = None
        self.last_call_keyword = None
        self.last_call_cat = None
        
    def show_details(self,widget,tutorial):
        self.view.show_details(tutorial)
    
    def get_categories(self):
        self.last_call_search = False
        self.model.get_categories()
    
    def search_store(self,widget,data):
        cat = data["category"].get_active_text()
        keyword = data["keyword"].get_text()
        if cat is None or cat == "":
            cat = 'all'
        self.model.search_store(keyword,cat)
        self.last_call_search = True
        self.last_call_keyword = keyword
        self.last_call_cat = cat
        self.last_call_page = 1
        
    def get_tutorials_by_category(self,widget,category):
        self.model.get_tutorials_by_category(category)
        self.last_call_search = False
        self.last_call_cat = category
        self.last_call_page = 1
        
    def download_tutorial(self,widget,tutorial):
        self.model.download_tutorial(tutorial)
        
    def get_also_like(self):
        self.model.get_also_like()
    
    def get_popular(self):
        self.model.get_popular()
        
    def display_infos(self,widget,tutorial):
        self.view.display_infos(tutorial)
        
    def next_page(self,widget,data):
        self.last_call_page = self.last_call_page + 1
        if self.last_call_search:
            self.model.search_store(self.last_call_keyword,self.last_call_cat,page = self.last_call_page )
        else:
            self.model.get_tutorials_by_category(self.last_call_cat,page = self.last_call_page )        
            
    def prev_page(self,widget,data):
        self.last_call_page = self.last_call_page - 1
        if self.last_call_search:
            self.model.search_store(self.last_call_keyword,self.last_call_cat,page = self.last_call_page )
        else:
            self.model.get_tutorials_by_category(self.last_call_cat,page = self.last_call_page )        
        
    def back_pressed(self,widget,data):
        self.view.show_search_result()

    def rate_tutorial(self,tutorial,rating):
        """
        Change the rating for a tutorial

        @param tutorial The tutorial to rate
        @param rating The new rating
        """
        self.model.rate_tutorial(tutorial,rating)