source: indico/indico/MaKaC/webinterface/pages/collaboration.py @ 3f852f

hello-world-walkthroughipv6v0.98-seriesv0.98.2v0.98.3v0.99v1.0v1.1
Last change on this file since 3f852f was 3f852f, checked in by Pedro Ferreira <jose.pedro.ferreira@…>, 11 months ago

[IMP] Add connect button event display

  • Property mode set to 100644
File size: 19.0 KB
Line 
1# -*- coding: utf-8 -*-
2##
3##
4## This file is part of CDS Indico.
5## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
6##
7## CDS Indico is free software; you can redistribute it and/or
8## modify it under the terms of the GNU General Public License as
9## published by the Free Software Foundation; either version 2 of the
10## License, or (at your option) any later version.
11##
12## CDS Indico is distributed in the hope that it will be useful, but
13## WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15## General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
19## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20
21from datetime import timedelta
22from MaKaC.webinterface import wcomponents, urlHandlers
23from MaKaC.webinterface.pages.conferences import WPConferenceModifBase, \
24    WPConferenceDefaultDisplayBase
25from MaKaC.plugins.Collaboration.collaborationTools import CollaborationTools
26from MaKaC.common.timezoneUtils import nowutc, setAdjustedDate, DisplayTZ,\
27    minDatetime
28from MaKaC.common.utils import formatDateTime, parseDateTime
29from MaKaC.common.timezoneUtils import getAdjustedDate
30from MaKaC.i18n import _
31from MaKaC.webinterface.pages.main import WPMainBase
32from MaKaC.common.indexes import IndexesHolder
33from MaKaC.plugins.Collaboration.base import CollaborationException, WCSPageTemplateBase
34from MaKaC.common.fossilize import fossilize
35from MaKaC.fossils.user import IAvatarFossil
36from MaKaC.services.implementation.user import UserComparator
37from MaKaC.plugins.Collaboration.fossils import IIndexInformationFossil
38
39#from MaKaC.fossils.contribution import IContributionWithSpeakersMinimalFossil
40
41################################################### Server Wide pages #########################################
42
43class WPAdminCollaboration(WPMainBase):
44
45    def __init__(self, rh, queryParams):
46        WPMainBase.__init__(self, rh)
47        self._queryParams = queryParams
48        self._user = self._rh.getAW().getUser()
49        self._pluginsWithIndexing = CollaborationTools.pluginsWithIndexing() # list of names
50        self._buildExtraJS()
51
52    def getJSFiles(self):
53        return WPMainBase.getJSFiles(self) + self._includeJSPackage('Display') \
54            + self._includeJSPackage('Collaboration')
55
56    def _getHeader(self):
57        wc = wcomponents.WHeader(self._getAW())
58        return wc.getHTML({ "subArea": _("Video Services Administration"), \
59                             "loginURL": self._escapeChars(str(self.getLoginURL())), \
60                             "logoutURL": self._escapeChars(str(self.getLogoutURL())), \
61                             "tabControl": self._getTabControl() })
62
63    def _getBody(self, params):
64        return WAdminCollaboration(self._queryParams, self._pluginsWithIndexing, self._user).getHTML()
65
66    def _getNavigationDrawer(self):
67        return wcomponents.WSimpleNavigationDrawer("Video Services Admin", urlHandlers.UHAdminCollaboration.getURL)
68
69    def _buildExtraJS(self):
70        for plugin in self._pluginsWithIndexing:
71            extraJS = CollaborationTools.getExtraJS(None, plugin, self._user)
72            if extraJS:
73                self.addExtraJS(extraJS)
74
75class WAdminCollaboration(wcomponents.WTemplated):
76
77    def __init__(self, queryParams, pluginsWithIndexing, user):
78        wcomponents.WTemplated.__init__(self)
79        self._queryParams = queryParams
80        self._pluginsWithIndexing = pluginsWithIndexing # list of names
81        self._user = user
82
83    def getVars(self):
84        vars = wcomponents.WTemplated.getVars(self)
85
86        #dictionary where the keys are names of false "indexes" for the user, and the values are IndexInformation objects
87        indexes = CollaborationTools.getCollaborationPluginType().getOption("pluginsPerIndex").getValue()
88        vars["Indexes"] = indexes
89        vars["IndexInformation"] = fossilize(dict([(i.getName(), i) for i in indexes]), IIndexInformationFossil)
90        vars["InitialIndex"] = self._queryParams["indexName"]
91        vars["InitialViewBy"] = self._queryParams["viewBy"]
92        vars["InitialOrderBy"] = self._queryParams["orderBy"]
93        vars["InitialOnlyPending"] = self._queryParams["onlyPending"]
94        vars["InitialConferenceId"] = self._queryParams["conferenceId"]
95        vars["InitialCategoryId"] = self._queryParams["categoryId"]
96        vars["InitialSinceDate"] = self._queryParams["sinceDate"]
97        vars["InitialToDate"] = self._queryParams["toDate"]
98        vars["InitialFromDays"] = self._queryParams["fromDays"]
99        vars["InitialToDays"] = self._queryParams["toDays"]
100        vars["InitialFromTitle"] = self._queryParams["fromTitle"]
101        vars["InitialToTitle"] = self._queryParams["toTitle"]
102        vars["InitialResultsPerPage"] = self._queryParams["resultsPerPage"]
103        vars["InitialPage"] = self._queryParams["page"]
104        vars["BaseURL"] = urlHandlers.UHAdminCollaboration.getURL()
105
106        if self._queryParams["queryOnLoad"]:
107            ci = IndexesHolder().getById('collaboration')
108            tz = self._rh._getUser().getTimezone()
109            #####
110            minKey = None
111            maxKey = None
112            if self._queryParams['sinceDate']:
113                minKey = setAdjustedDate(parseDateTime(self._queryParams['sinceDate'].strip()), tz = self._tz)
114            if self._queryParams['toDate']:
115                maxKey = setAdjustedDate(parseDateTime(self._queryParams['toDate'].strip()), tz = self._tz)
116            if self._queryParams['fromTitle']:
117                minKey = self._queryParams['fromTitle'].strip()
118            if self._queryParams['toTitle']:
119                maxKey = self._queryParams['toTitle'].strip()
120            if self._queryParams['fromDays']:
121                try:
122                    fromDays = int(self._queryParams['fromDays'])
123                except ValueError, e:
124                    raise CollaborationException(_("Parameter 'fromDays' is not an integer"), inner = e)
125                midnight = nowutc().replace(hour=0, minute=0, second=0)
126                minKey = midnight - timedelta(days = fromDays)
127            if self._queryParams['toDays']:
128                try:
129                    toDays = int(self._queryParams['toDays'])
130                except ValueError, e:
131                    raise CollaborationException(_("Parameter 'toDays' is not an integer"), inner = e)
132                midnight_1 = nowutc().replace(hour=23, minute=59, second=59)
133                maxKey = midnight_1 + timedelta(days = toDays)
134
135            if self._queryParams["conferenceId"]:
136                conferenceId = self._queryParams["conferenceId"]
137            else:
138                conferenceId = None
139
140            if self._queryParams["categoryId"]:
141                categoryId = self._queryParams["categoryId"]
142            else:
143                categoryId = None
144
145            result = ci.getBookings(
146                        self._queryParams["indexName"],
147                        self._queryParams["viewBy"],
148                        self._queryParams["orderBy"],
149                        minKey,
150                        maxKey,
151                        tz = tz,
152                        onlyPending = self._queryParams["onlyPending"],
153                        conferenceId = conferenceId,
154                        categoryId = categoryId,
155                        pickle = True,
156                        dateFormat = '%a %d %b %Y',
157                        page = self._queryParams["page"],
158                        resultsPerPage = self._queryParams["resultsPerPage"],
159                        grouped= True)
160
161            vars["InitialBookings"] = result["results"]
162            vars["InitialNumberOfBookings"] = result["nBookings"]
163            vars["InitialTotalInIndex"] = result["totalInIndex"]
164            vars["InitialNumberOfPages"] = result["nPages"]
165
166        else:
167            vars["InitialBookings"] = None
168            vars["InitialNumberOfBookings"] = -1
169            vars["InitialTotalInIndex"] = -1
170            vars["InitialNumberOfPages"] = -1
171
172        jsCodes = {}
173        for plugin in self._pluginsWithIndexing:
174            templateClass = CollaborationTools.getTemplateClass(plugin.getId(),
175                                                                "WIndexing")
176            if templateClass:
177                jsCodes[plugin.getId()] = templateClass(None, plugin.getId(), self._user).getHTML()
178
179        vars["JSCodes"] = jsCodes
180
181        return vars
182
183
184################################################### Event Modif pages ###############################################
185
186class WPConfModifCSBase (WPConferenceModifBase):
187
188    _userData = ['favorite-user-list']
189
190    def __init__(self, rh, conf):
191        """ Constructor
192            The rh is expected to have the attributes _tabs, _activeTab, _tabPlugins (like for ex. RHConfModifCSBookings)
193        """
194        WPConferenceModifBase.__init__(self, rh, conf)
195        self._conf = conf
196        self._tabs = {} # list of Indico's Tab objects
197        self._tabNames = rh._tabs
198        self._activeTabName = rh._activeTabName
199        self.rh = rh
200        self._tabCtrl = wcomponents.TabControl()
201
202    def _createTabCtrl(self):
203
204        for tabName in self._tabNames:
205            isPlugin = False
206
207            for plugin in CollaborationTools.getPluginsByTab(tabName, self._conf, self.rh._getUser()):
208                isPlugin = True
209
210            if tabName != 'Managers' and not isPlugin:
211                from MaKaC.plugins.Collaboration.urlHandlers import UHCollaborationElectronicAgreement
212                url = UHCollaborationElectronicAgreement.getURL(self._conf)
213            elif tabName == 'Managers':
214                url = urlHandlers.UHConfModifCollaborationManagers.getURL(self._conf)
215            else:
216                url = urlHandlers.UHConfModifCollaboration.getURL(self._conf, secure = self.rh.use_https(), tab = tabName)
217            self._tabs[tabName] = self._tabCtrl.newTab(tabName, tabName, url)
218
219        self._setActiveTab()
220
221    def _setActiveTab(self):
222        self._tabs[self._activeTabName].setActive()
223
224    def _setActiveSideMenuItem(self):
225        self._videoServicesMenuItem.setActive()
226
227
228class WPConfModifCollaboration(WPConfModifCSBase):
229
230    def __init__(self, rh, conf):
231        """ Constructor
232            The rh is expected to have the attributes _tabs, _activeTabName, _tabPlugins (like RHConfModifCSBookings)
233        """
234        WPConfModifCSBase.__init__(self, rh, conf)
235        self._tabPlugins = rh._tabPlugins
236        self._buildExtraJS()
237
238    def getCSSFiles(self):
239        for plugin in self._tabPlugins:
240            return WPConfModifCSBase.getCSSFiles(self) + \
241                   ['Collaboration/%s/Style.css' % plugin.getId()]
242
243    def getJSFiles(self):
244        return WPMainBase.getJSFiles(self) + self._includeJSPackage("Display") + self._includeJSPackage('Collaboration') + self._includeJSPackage("Management")
245
246    ######### private methods ###############
247    def _buildExtraJS(self):
248        for plugin in self._tabPlugins:
249            extraJS = CollaborationTools.getExtraJS(self._conf, plugin, self._getAW().getUser())
250            if extraJS:
251                self.addExtraJS(extraJS)
252
253    ############## overloading methods #################
254
255    def _getPageContent(self, params):
256        if len(self._tabNames) > 0:
257            self._createTabCtrl()
258            wc = WConfModifCollaboration(self._conf, self._rh.getAW().getUser(), self._activeTabName, self._tabPlugins)
259            return wcomponents.WTabControl(self._tabCtrl, self._getAW()).getHTML(wc.getHTML({}))
260        else:
261            return _("No available plugins, or no active plugins")
262
263class WConfModifCollaboration(wcomponents.WTemplated):
264
265    def __init__(self, conference, user, activeTab, tabPlugins):
266        self._conf = conference
267        self._user = user
268        self._activeTab = activeTab
269        self._tabPlugins = tabPlugins
270
271    def getVars(self):
272        vars = wcomponents.WTemplated.getVars(self)
273
274        plugins = self._tabPlugins
275        singleBookingPlugins, multipleBookingPlugins = CollaborationTools.splitPluginsByAllowMultiple(plugins)
276        csBookingManager = self._conf.getCSBookingManager()
277
278        bookingsS = {}
279
280        for p in singleBookingPlugins:
281            bookingList = csBookingManager.getBookingList(filterByType = p.getId())
282            if len(bookingList) > 0:
283                bookingsS[p.getId()] = fossilize(bookingList[0]) #will use ICSBookingConfModifBaseFossil or inheriting fossil
284
285        bookingsM = fossilize(csBookingManager.getBookingList(
286            sorted = True,
287            notify = True,
288            filterByType = [p.getName() for p in multipleBookingPlugins])) #will use ICSBookingConfModifBaseFossil or inheriting fossil
289
290        vars["Conference"] = self._conf
291        vars["AllPlugins"] = plugins
292        vars["SingleBookingPlugins"] = singleBookingPlugins
293        vars["BookingsS"] = bookingsS
294        vars["MultipleBookingPlugins"] = multipleBookingPlugins
295        vars["BookingsM"] = bookingsM
296        vars["Tab"] = self._activeTab
297        vars["EventDate"] = formatDateTime(getAdjustedDate(nowutc(), self._conf))
298
299        from MaKaC.webinterface.rh.collaboration import RCCollaborationAdmin, RCCollaborationPluginAdmin, RCVideoServicesUser
300        vars["UserIsAdmin"] = RCCollaborationAdmin.hasRights(user = self._user) or RCCollaborationPluginAdmin.hasRights(user = self._user, plugins = self._tabPlugins)
301
302        hasCreatePermissions = {}
303        videoServSupport = {}
304        for plugin in plugins:
305            pname = plugin.getName()
306            hasCreatePermissions[pname] = RCVideoServicesUser.hasRights(user = self._user, pluginName = pname)
307            videoServSupport[pname] = plugin.getOption("contactSupport").getValue() if plugin.hasOption("contactSupport") else ""
308        vars["HasCreatePermissions"] = hasCreatePermissions
309        vars["VideoServiceSupport"] = videoServSupport
310
311
312
313
314        singleBookingForms = {}
315        multipleBookingForms = {}
316        jsCodes = {}
317        canBeNotified = {}
318
319        for plugin in singleBookingPlugins:
320            pluginId = plugin.getId()
321            templateClass = CollaborationTools.getTemplateClass(pluginId, "WNewBookingForm")
322            singleBookingForms[pluginId] = templateClass(self._conf, plugin.getId(), self._user).getHTML()
323
324        for plugin in multipleBookingPlugins:
325            pluginId = plugin.getId()
326            templateClass = CollaborationTools.getTemplateClass(pluginId, "WNewBookingForm")
327            newBookingFormHTML = templateClass(self._conf, plugin.getId(), self._user).getHTML()
328
329            advancedTabClass = CollaborationTools.getTemplateClass(pluginId, "WAdvancedTab")
330            if advancedTabClass:
331                advancedTabClassHTML = advancedTabClass(self._conf, plugin.getId(), self._user).getHTML()
332            else:
333                advancedTabClassHTML = WConfModifCollaborationDefaultAdvancedTab(self._conf, plugin, self._user).getHTML()
334            multipleBookingForms[pluginId] = (newBookingFormHTML, advancedTabClassHTML)
335
336        for plugin in plugins:
337            pluginId = plugin.getId()
338
339            templateClass = CollaborationTools.getTemplateClass(pluginId, "WMain")
340            jsCodes[pluginId] = templateClass(self._conf, plugin.getId(), self._user).getHTML()
341
342            bookingClass = CollaborationTools.getCSBookingClass(pluginId)
343            canBeNotified[pluginId] = bookingClass._canBeNotifiedOfEventDateChanges
344
345        vars["SingleBookingForms"] = singleBookingForms
346        vars["MultipleBookingForms"] = multipleBookingForms
347        vars["JSCodes"] = jsCodes
348        vars["CanBeNotified"] = canBeNotified
349
350        return vars
351
352class WAdvancedTabBase(WCSPageTemplateBase):
353
354    def getVars(self):
355        variables = WCSPageTemplateBase.getVars(self)
356
357        bookingClass = CollaborationTools.getCSBookingClass(self._pluginId)
358        variables["CanBeNotified"] = bookingClass._canBeNotifiedOfEventDateChanges
359
360        return variables
361
362class WConfModifCollaborationDefaultAdvancedTab(WAdvancedTabBase):
363
364    def _setTPLFile(self):
365        wcomponents.WTemplated._setTPLFile(self)
366
367
368class WPConfModifCollaborationProtection(WPConfModifCSBase):
369
370    def __init__(self, rh, conf):
371        """ Constructor
372            The rh is expected to have the attributes _tabs, _activeTab, _tabPlugins (like RHConfModifCSBookings)
373        """
374        WPConfModifCSBase.__init__(self, rh, conf)
375        self._user = rh._getUser()
376
377    def _getPageContent(self, params):
378        if len(self._tabNames) > 0:
379            self._createTabCtrl()
380            wc = WConfModifCollaborationProtection(self._conf, self._user)
381            return wcomponents.WTabControl(self._tabCtrl, self._getAW()).getHTML(wc.getHTML({}))
382        else:
383            return _("No available plugins, or no active plugins")
384
385class WConfModifCollaborationProtection(wcomponents.WTemplated):
386
387    def __init__(self, conference, user):
388        self._conf = conference
389        self._user = user
390
391    def getVars(self):
392        vars = wcomponents.WTemplated.getVars(self)
393        vars["Conference"] = self._conf
394        csbm = self._conf.getCSBookingManager()
395        vars["CSBM"] = csbm
396        allManagers = fossilize(csbm.getAllManagers(), IAvatarFossil)
397        vars["AllManagers"] = sorted(allManagers, cmp = UserComparator.cmpUsers)
398        return vars
399
400################################################### Event Display pages ###############################################
401class WPCollaborationDisplay(WPConferenceDefaultDisplayBase):
402
403
404    def getJSFiles(self):
405        return WPConferenceDefaultDisplayBase.getJSFiles(self) + self._includeJSPackage('Display') + self._includeJSPackage('Collaboration')
406
407    def _defineSectionMenu(self):
408        WPConferenceDefaultDisplayBase._defineSectionMenu(self)
409        self._sectionMenu.setCurrentItem(self._collaborationOpt)
410
411    def _getBody(self, params):
412
413        wc = WCollaborationDisplay(self._getAW(), self._conf)
414        return wc.getHTML()
415
416class WCollaborationDisplay(wcomponents.WTemplated):
417
418    def __init__(self, aw, conference):
419        wcomponents.WTemplated.__init__(self)
420        self._conf = conference
421        self._tz = DisplayTZ(aw, conference).getDisplayTZ()
422
423    def getVars(self):
424        vars = wcomponents.WTemplated.getVars(self)
425
426        csbm = self._conf.getCSBookingManager()
427        pluginNames = csbm.getEventDisplayPlugins()
428        bookings = csbm.getBookingList(filterByType = pluginNames, notify = True, onlyPublic = True)
429        bookings.sort(key = lambda b: b.getStartDate() or minDatetime())
430
431        ongoingBookings = []
432        scheduledBookings = {} #date, list of bookings
433
434        for b in bookings:
435            if b.isHappeningNow():
436                ongoingBookings.append(b)
437            if b.getStartDate() and b.getAdjustedStartDate('UTC') > nowutc():
438                scheduledBookings.setdefault(b.getAdjustedStartDate(self._tz).date(), []).append(b)
439
440        keys = scheduledBookings.keys()
441        keys.sort()
442        scheduledBookings = [(date, scheduledBookings[date]) for date in keys]
443
444        vars["OngoingBookings"] = ongoingBookings
445        vars["ScheduledBookings"] = scheduledBookings
446        vars["Timezone"] = self._tz
447        vars["conf"] = self._conf
448
449        return vars
Note: See TracBrowser for help on using the repository browser.