source: indico/indico/MaKaC/webinterface/rh/contribMod.py @ 03f356

hello-world-walkthroughipv6v0.98-seriesv0.98.2v0.98.3v0.99v1.0v1.1
Last change on this file since 03f356 was 03f356, checked in by Jose Benito <jose.benito.gonzalez@…>, 16 months ago

[IMP] Search users popup in Contrib/Sub?.Control

  • Implemented new AJAX services to add/remove submitters.
  • Implemented new functionality to add/remove the submitter from pr.authors, co-authors, presenters
  • Deleted previous code
  • Implemented JS class to manage the list of submitters
  • Added option in ListOfUsersManager? class to select if we want to block or not the screen with each action
  • Property mode set to 100644
File size: 36.9 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
21import MaKaC.webinterface.locators as locators
22import MaKaC.webinterface.urlHandlers as urlHandlers
23import MaKaC.webinterface.materialFactories as materialFactories
24import MaKaC.webinterface.pages.contributions as contributions
25import MaKaC.conference as conference
26import MaKaC.user as user
27import MaKaC.domain as domain
28import MaKaC.webinterface.webFactoryRegistry as webFactoryRegistry
29from MaKaC.webinterface.rh.base import RHModificationBaseProtected
30from MaKaC.common.xmlGen import XMLGen
31from MaKaC.common.utils import parseDateTime
32from MaKaC.common import Config
33from MaKaC.webinterface.rh.conferenceBase import RHSubmitMaterialBase
34from MaKaC.webinterface.rh.base import RoomBookingDBMixin
35from MaKaC.PDFinterface.conference import ConfManagerContribToPDF
36from MaKaC.errors import FormValuesError
37from MaKaC.conference import SubContribParticipation
38from MaKaC.errors import MaKaCError
39from MaKaC.i18n import _
40from MaKaC.webinterface.pages.conferences import WPConferenceModificationClosed
41from MaKaC.webinterface.rh.materialDisplay import RHMaterialDisplayCommon
42from MaKaC.user import AvatarHolder
43
44class RHContribModifBase(RHModificationBaseProtected):
45    """ Base RH for contribution modification.
46        Sets the _target (the contribution) and the _conf (the conference)
47    """
48
49    def _checkParams(self, params):
50        l = locators.WebLocator()
51        l.setContribution(params)
52        self._target = l.getObject()
53        self._conf = self._target.getConference()
54
55    def getWebFactory(self):
56        wr = webFactoryRegistry.WebFactoryRegistry()
57        self._wf = wr.getFactory(self._target.getConference())
58        return self._wf
59
60class RCSessionCoordinator(object):
61    @staticmethod
62    def hasRights(request):
63        """ Returns true if the user is a Session Coordinator
64        """
65        if request._target.getSession() != None:
66            return request._target.getSession().canCoordinate(request.getAW(), "modifContribs")
67        else:
68            return False
69
70class RCContributionPaperReviewingStaff(object):
71
72    @staticmethod
73    def hasRights(request):
74        """ Returns true if the user is a PRM, or a Referee / Editor / Reviewer of the target contribution
75        """
76        user = request.getAW().getUser()
77        confPaperReview = request._target.getConference().getConfPaperReview()
78        paperReviewChoice = confPaperReview.getChoice()
79        reviewManager = request._target.getReviewManager()
80        return (confPaperReview.isPaperReviewManager(user) or \
81               (reviewManager.hasReferee() and reviewManager.isReferee(user)) or \
82               ((paperReviewChoice == 3 or paperReviewChoice == 4) and reviewManager.hasEditor() and reviewManager.isEditor(user)) or \
83               ((paperReviewChoice == 2 or paperReviewChoice == 4) and request._target.getReviewManager().isReviewer(user)))
84
85class RCContributionReferee(object):
86    @staticmethod
87    def hasRights(request):
88        """ Returns true if the user is a referee of the target contribution
89        """
90        user = request.getAW().getUser()
91        reviewManager = request._target.getReviewManager()
92        return reviewManager.hasReferee() and reviewManager.isReferee(user)
93
94class RCContributionEditor(object):
95    @staticmethod
96    def hasRights(request):
97        """ Returns true if the user is an editor of the target contribution
98        """
99
100        user = request.getAW().getUser()
101        reviewManager = request._target.getReviewManager()
102        return reviewManager.hasEditor() and reviewManager.isEditor(user)
103
104class RCContributionReviewer(object):
105    @staticmethod
106    def hasRights(request):
107        """ Returns true if the user is a reviewer of the target contribution
108        """
109        user = request.getAW().getUser()
110        reviewManager = request._target.getReviewManager()
111        return reviewManager.isReviewer(user)
112
113class RHContribModifBaseSpecialSesCoordRights(RHContribModifBase):
114    """ Base class for any RH where a Session Coordinator has the rights to perform the request
115    """
116
117    def _checkProtection(self):
118        if not RCSessionCoordinator.hasRights(self):
119            RHContribModifBase._checkProtection(self)
120
121class RHContribModifBaseReviewingStaffRights(RHContribModifBase):
122    """ Base class for any RH where a member of the Paper Reviewing staff
123        (a PRM, or a Referee / Editor / Reviewer of the target contribution)
124        has the rights to perform the request
125    """
126
127    def _checkProtection(self):
128        if not RCContributionPaperReviewingStaff.hasRights(self):
129            RHContribModifBase._checkProtection(self);
130
131class RHContribModifBaseSpecialSesCoordAndReviewingStaffRights(RHContribModifBase):
132    """ Base class for any RH where a member of the Paper Reviewing staff
133        (a PRM, or a Referee / Editor / Reviewer of the target contribution),
134        OR  a Session Coordinator has the rights to perform the request
135    """
136
137    def _checkProtection(self):
138        if not (RCSessionCoordinator.hasRights(self) or RCContributionPaperReviewingStaff.hasRights(self)):
139            RHContribModifBase._checkProtection(self);
140
141class RHContributionModification(RHContribModifBaseSpecialSesCoordAndReviewingStaffRights):
142    _uh = urlHandlers.UHContributionModification
143
144    def _checkParams(self, params):
145        RHContribModifBase._checkParams(self, params)
146        params["days"] = params.get("day", "all")
147        if params.get("day", None) is not None :
148            del params["day"]
149
150    def _process(self):
151        params = self._getRequestParams()
152        if self._target.getOwner().isClosed():
153            p = contributions.WPContributionModificationClosed(self, self._target)
154        else:
155            wf = self.getWebFactory()
156            if wf != None:
157                p = wf.getContributionModification(self, self._target)
158            else:
159                p = contributions.WPContributionModification(self, self._target)
160        return p.display(**params)
161
162class RHWithdraw(RHContribModifBaseSpecialSesCoordRights):
163    _uh=urlHandlers.UHContribModWithdraw
164
165    def _checkParams(self, params):
166        RHContribModifBase._checkParams(self, params)
167        self._action=""
168        self._comment=""
169        if params.has_key("REACTIVATE"):
170            self._action="REACTIVATE"
171        elif params.has_key("OK"):
172            self._action="WITHDRAW"
173            self._comment=params.get("comment", "")
174        elif params.has_key("CANCEL"):
175            self._action="CANCEL"
176
177    def _process(self):
178        url=urlHandlers.UHContributionModification.getURL(self._target)
179        if self._action=="REACTIVATE":
180            self._target.withdraw(self._getUser(), self._comment)
181            self._redirect(url)
182            return
183        elif self._action=="WITHDRAW":
184            self._target.withdraw(self._getUser(), self._comment)
185            self._redirect(url)
186            return
187        elif self._action=="CANCEL":
188            self._redirect(url)
189            return
190        p=contributions.WPModWithdraw(self, self._target)
191        return p.display()
192
193
194class RHContributionAC(RHContribModifBaseSpecialSesCoordRights):
195    _uh = urlHandlers.UHContribModifAC
196
197    def _checkParams(self, params):
198        RHContribModifBase._checkParams(self, params)
199        params["days"] = params.get("day", "all")
200        if params.get("day", None) is not None :
201            del params["day"]
202
203    def _process(self):
204        params = self._getRequestParams()
205        if self._target.getOwner().isClosed():
206            p = contributions.WPContributionModificationClosed(self, self._target)
207        else:
208            p = contributions.WPContribModifAC(self, self._target)
209            wf = self.getWebFactory()
210            if wf != None:
211                p = wf.getContribModifAC(self, self._target)
212        return p.display(**params)
213
214
215class RHContributionSC(RHContribModifBaseSpecialSesCoordAndReviewingStaffRights):
216    _uh = urlHandlers.UHContribModifSubCont
217
218    def _checkParams(self, params):
219        RHContribModifBase._checkParams(self, params)
220        params["days"] = params.get("day", "all")
221        if params.get("day", None) is not None :
222            del params["day"]
223
224    def _process(self):
225        params = self._getRequestParams()
226        p = contributions.WPContribModifSC(self, self._target)
227        wf = self.getWebFactory()
228        if wf != None:
229            p = wf.getContribModifSC(self, self._target)
230        return p.display(**params)
231
232class RHSubContribActions(RHContribModifBaseSpecialSesCoordRights):
233    _uh = urlHandlers.UHSubContribActions
234
235    def _checkParams(self, params):
236        RHContribModifBase._checkParams(self, params)
237        self._confirm = params.has_key("confirm")
238        self._scIds = self._normaliseListParam(params.get("selSubContribs", []))
239        self._action=None
240        if "cancel" in params:
241            return
242        self._action=[]
243        for id in self._scIds:
244            sc = self._target.getSubContributionById(id)
245            self._action.append(_ActionSubContribDelete(self, self._target, sc))
246        if params.has_key("oldpos") and params["oldpos"]!='':
247            self._action = _ActionSubContribMove(self, params['newpos'+params['oldpos']], params['oldpos'])
248
249    def _process(self):
250        if self._action is not None:
251            if isinstance(self._action, list):
252                for act in self._action:
253                    act.perform()
254            else:
255                self._action.perform()
256        self._redirect(urlHandlers.UHContribModifSubCont.getURL(self._target))
257
258class _ActionSubContribDelete:
259
260    def __init__(self, rh, target, sc):
261        self._rh = rh
262        self._target = target
263        self._sc = sc
264
265    def perform(self):
266        self._target.removeSubContribution(self._sc)
267
268class _ActionSubContribMove:
269
270    def __init__(self, rh, newpos, oldpos):
271        self._rh = rh
272        self._newpos = int(newpos)
273        self._oldpos = int(oldpos)
274
275    def perform(self):
276        scList = self._rh._target.getSubContributionList()
277        order = 0
278        movedsubcontrib = scList[self._oldpos]
279        del scList[self._oldpos]
280        scList.insert(self._newpos, movedsubcontrib)
281        self._rh._target.notifyModification()
282
283        #for sc in scList:
284        #    sc.setOrder(scList.index(sc))
285
286#-------------------------------------------------------------------------------------
287
288class RHContributionAddSC(RHContribModifBaseSpecialSesCoordRights):
289    _uh = urlHandlers.UHContribAddSubCont
290
291    def _process(self):
292        p = contributions.WPContribAddSC(self, self._target)
293        params = self._getRequestParams()
294
295        wf = self.getWebFactory()
296        if wf != None:
297            p = wf.getContribAddSC(self, self._target)
298
299        params["days"] = params.get("day", "all")
300        if params.get("day", None) is not None :
301            del params["day"]
302
303        return p.display(**params)
304
305
306#-------------------------------------------------------------------------------------
307
308class RHContributionCreateSC(RHContribModifBaseSpecialSesCoordRights):
309    _uh = urlHandlers.UHContribCreateSubCont
310
311    def _process(self):
312
313        params = self._getRequestParams()
314
315        from MaKaC.services.interface.rpc import json
316        presenters = json.decode(params.get("presenters", "[]"))
317
318        sc = self._target
319        """self._target - contribution owning new subcontribution"""
320
321        if ("ok" in params):
322            sc = self._target.newSubContribution()
323            sc.setTitle( params.get("title", "") )
324            sc.setDescription( params.get("description", "") )
325            sc.setKeywords( params.get("keywords", "") )
326            try:
327                durationHours = int(params.get("durationHours",""))
328            except ValueError:
329                raise FormValuesError(_("Please specify a valid hour format (0-23)."))
330            try:
331                durationMinutes = int(params.get("durationMinutes",""))
332            except ValueError:
333                raise FormValuesError(_("Please specify a valid minutes format (0-59)."))
334
335            sc.setDuration( durationHours, durationMinutes )
336            sc.setSpeakerText( params.get("speakers", "") )
337            sc.setParent(self._target)
338
339            for presenter in presenters:
340                try:
341                    if presenter["existing"]:
342                        # the avatar should exists
343                        ah = AvatarHolder()
344                        spk = conference.SubContribParticipation()
345                        spk.setDataFromAvatar(ah.getById(presenter["id"]))
346                except KeyError:
347                    # create new speaker
348                    spk = self._newSpeaker(presenter)
349                sc.newSpeaker(spk)
350
351            logInfo = sc.getLogInfo()
352            logInfo["subject"] = "Create new subcontribution: %s"%sc.getTitle()
353            self._target.getConference().getLogHandler().logAction(logInfo, "Timetable/SubContribution", self._getUser())
354            self._redirect(urlHandlers.UHContribModifSubCont.getURL(sc))
355        else:
356            self._redirect(urlHandlers.UHContribModifSubCont.getURL(sc))
357
358    def _newSpeaker(self, presenter):
359        spk = conference.SubContribParticipation()
360        spk.setTitle(presenter["title"])
361        spk.setFirstName(presenter["firstName"])
362        spk.setFamilyName(presenter["familyName"])
363        spk.setAffiliation(presenter["affiliation"])
364        spk.setEmail(presenter["email"])
365        spk.setAddress(presenter["address"])
366        spk.setPhone(presenter["phone"])
367        spk.setFax(presenter["fax"])
368        return spk
369
370#-------------------------------------------------------------------------------------
371
372
373#class RHContributionDeleteSC( RHContribModifBase ):
374#    _uh = urlHandlers.UHContriDeleteSubCont
375#
376#    def _checkParams( self, params ):
377#        RHContribModifBase._checkParams( self, params )
378#        self._confirm = params.has_key( "confirm" )
379#        self._cancel = params.has_key( "cancel" )
380#        self._scIds = self._normaliseListParam( params.get("selSubContribs", []) )
381
382#    def _process( self ):
383#        for id in self._scIds:
384#            sc = self._target.getSubContributionById( id )
385#            self._target.removeSubContribution( sc )
386#        self._redirect( urlHandlers.UHContribModifSubCont.getURL( self._target ) )
387
388
389class RHContributionUpSC(RHContribModifBaseSpecialSesCoordRights):
390    _uh = urlHandlers.UHContribUpSubCont
391
392    def _checkParams(self, params):
393        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
394        self._scId = params.get("subContId", "")
395
396    def _process(self):
397        sc = self._target.getSubContributionById(self._scId)
398        self._target.upSubContribution(sc)
399        self._redirect(urlHandlers.UHContribModifSubCont.getURL(self._target))
400
401
402class RHContributionDownSC(RHContribModifBaseSpecialSesCoordRights):
403    _uh = urlHandlers.UHContribDownSubCont
404
405    def _checkParams(self, params):
406        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
407        self._scId = params.get("subContId", "")
408
409    def _process(self):
410        sc = self._target.getSubContributionById(self._scId)
411        self._target.downSubContribution(sc)
412        self._redirect(urlHandlers.UHContribModifSubCont.getURL(self._target))
413
414
415class RHContributionTools(RHContribModifBaseSpecialSesCoordRights):
416    _uh = urlHandlers.UHContribModifTools
417
418    def _process(self):
419        if self._target.getOwner().isClosed():
420            p = contributions.WPContributionModificationClosed(self, self._target)
421        else:
422            p = contributions.WPContributionModifTools(self, self._target)
423            wf = self.getWebFactory()
424            if wf != None:
425                p = wf.getContributionModifTools(self, self._target)
426        return p.display()
427
428
429class RHContributionData( RoomBookingDBMixin, RHContribModifBaseSpecialSesCoordRights ):
430    _uh = urlHandlers.UHContributionDataModif
431
432    def _checkParams( self, params ):
433        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
434
435        self._evt = self._target
436
437    def _process(self):
438        if self._target.getOwner().isClosed():
439            p = contributions.WPContributionModificationClosed(self, self._target)
440        else:
441            p = contributions.WPEditData(self, self._target)
442            wf = self.getWebFactory()
443            if wf != None:
444                p = wf.getContributionEditData(self, self._target)
445        return p.display(**self._getRequestParams())
446
447
448class RHContributionModifData(RHContribModifBaseSpecialSesCoordRights):
449    _uh = urlHandlers.UHContributionDataModification
450
451    def _checkParams(self, params):
452        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
453        self._type=None
454        self._check = int(params.get("check", 1))
455        if params.has_key("type") and params["type"].strip()!="":
456            self._type=self._target.getConference().getContribTypeById(params["type"])
457        self._cancel = params.has_key("cancel")
458
459    def _process(self):
460        if not self._cancel:
461            params = self._getRequestParams()
462
463            if params.has_key("dateTime"):
464                dateTime = parseDateTime(params["dateTime"])
465                params["sYear"] = dateTime.year
466                params["sMonth"] = dateTime.month
467                params["sDay"] = dateTime.day
468                params["sHour"] = dateTime.hour
469                params["sMinute"] = dateTime.minute
470            else:
471                params["sYear"] = ""
472                params["sMonth"] = ""
473                params["sDay"] = ""
474                params["sHour"] = ""
475                params["sMinute"] = ""
476
477            if params.has_key("duration"):
478                params["durMins"] = params["duration"];
479            else:
480                params["durMins"] = ""
481            self._target.setValues(params)
482            self._target.setType(self._type)
483        self._redirect(urlHandlers.UHContributionModification.getURL(self._target))
484
485
486class RHSetTrack(RHContribModifBase):
487
488    def _checkParams(self, params):
489        RHContribModifBase._checkParams(self, params)
490        self._track=None
491        if params.has_key("selTrack") and params["selTrack"].strip() != "":
492            self._track = self._target.getConference().getTrackById(params["selTrack"])
493
494    def _process(self):
495        self._target.setTrack(self._track)
496        url=urlHandlers.UHContributionModification.getURL(self._target)
497        self._redirect(url)
498
499
500class RHSetSession(RHContribModifBase):
501
502    def _checkParams(self, params):
503        RHContribModifBase._checkParams(self, params)
504        self._session=None
505        if params.has_key("selSession") and params["selSession"].strip() != "":
506            self._session=self._target.getConference().getSessionById(params["selSession"])
507
508    def _process(self):
509        self._target.setSession(self._session)
510        url=urlHandlers.UHContributionModification.getURL(self._target)
511        self._redirect(url)
512
513class RHContribModifMaterialBrowse( RHContribModifBase, RHMaterialDisplayCommon ):
514    _uh = urlHandlers.UHContribModifMaterialBrowse
515
516    def _checkParams(self, params):
517        RHContribModifBase._checkParams(self, params)
518        self._contrib = self._target
519        materialId = params["materialId"]
520
521        self._material = self._target = self._contrib.getMaterialById(materialId)
522
523    def _process(self):
524        return RHMaterialDisplayCommon._process(self)
525
526    def _processManyMaterials( self ):
527        self._redirect( urlHandlers.UHContribModifMaterials.getURL( self._material ))
528
529
530class RHContributionAddMaterial(RHContribModifBaseSpecialSesCoordRights):
531    _uh = urlHandlers.UHContributionAddMaterial
532
533    def _checkParams(self, params):
534        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
535        typeMat = params.get("typeMaterial", "notype")
536        if typeMat=="notype" or typeMat.strip()=="":
537            raise FormValuesError("Please choose a material type")
538        self._mf = materialFactories.ContribMFRegistry().getById(typeMat)
539
540    def _process(self):
541        if self._mf:
542            if not self._mf.needsCreationPage():
543                m = RHContributionPerformAddMaterial.create(self._target, self._mf, self._getRequestParams())
544                self._redirect(urlHandlers.UHMaterialModification.getURL(m))
545                return
546        p = contributions.WPContribAddMaterial(self, self._target, self._mf)
547        wf = self.getWebFactory()
548        if wf != None:
549            p = wf.getContribAddMaterial(self, self._target, self._mf)
550        return p.display()
551
552
553class RHContributionPerformAddMaterial(RHContribModifBaseSpecialSesCoordRights):
554    _uh = urlHandlers.UHContributionPerformAddMaterial
555
556    def _checkParams(self, params):
557        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
558        typeMat = params.get("typeMaterial", "")
559        self._mf = materialFactories.ContribMFRegistry.getById(typeMat)
560
561    @staticmethod
562    def create(contrib, matFactory, matData):
563        if matFactory:
564            m = matFactory.create(contrib)
565        else:
566            m = conference.Material()
567            contrib.addMaterial(m)
568            m.setValues(matData)
569        return m
570
571    def _process(self):
572        m = self.create(self._target, self._mf, self._getRequestParams())
573        self._redirect(urlHandlers.UHMaterialModification.getURL(m))
574
575
576class RHContributionRemoveMaterials(RHContribModifBaseSpecialSesCoordRights):
577    _uh = urlHandlers.UHContributionRemoveMaterials
578
579    def _checkParams(self, params):
580        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
581        #typeMat = params.get( "typeMaterial", "" )
582        #self._mf = materialFactories.ConfMFRegistry().getById( typeMat )
583        self._materialIds = self._normaliseListParam(params.get("deleteMaterial", []))
584        self._materialIds = self._normaliseListParam( params.get("materialId", []) )
585        self._returnURL = params.get("returnURL","")
586
587    def _process(self):
588        for id in self._materialIds:
589            #Performing the deletion of special material types
590            f = materialFactories.ContribMFRegistry().getById(id)
591            if f:
592                f.remove(self._target)
593            else:
594                #Performs the deletion of additional material types
595                mat = self._target.getMaterialById( id )
596                self._target.removeMaterial( mat )
597        if self._returnURL != "":
598            url = self._returnURL
599        else:
600            url = urlHandlers.UHContribModifMaterials.getURL( self._target )
601        self._redirect( url )
602
603
604class RHMaterialsAdd(RHSubmitMaterialBase, RHContribModifBaseSpecialSesCoordRights):
605    _uh = urlHandlers.UHContribModifAddMaterials
606
607    def __init__(self, req):
608        RHContribModifBaseSpecialSesCoordRights.__init__(self, req)
609        RHSubmitMaterialBase.__init__(self)
610
611    def _checkParams(self, params):
612        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
613        RHSubmitMaterialBase._checkParams(self, params)
614
615    def _checkProtection(self):
616        material, _ = self._getMaterial(forceCreate = False)
617        if self._target.canUserSubmit(self._aw.getUser()) \
618            and (not material or material.getReviewingState() < 3):
619            self._loggedIn = True
620        elif not (RCContributionPaperReviewingStaff.hasRights(self) and not self._target.getReviewManager().getLastReview().isAuthorSubmitted()):
621            RHSubmitMaterialBase._checkProtection(self)
622        else:
623            self._loggedIn = True
624
625class RHContributionSelectManagers(RHContribModifBaseSpecialSesCoordRights):
626    _uh = urlHandlers.UHContributionSelectManagers
627
628    def _process(self):
629        p = contributions.WPContributionSelectManagers(self, self._target)
630        return p.display(**self._getRequestParams())
631
632
633class RHContributionAddManagers(RHContribModifBaseSpecialSesCoordRights):
634    _uh = urlHandlers.UHContributionAddManagers
635
636    def _process(self):
637        params = self._getRequestParams()
638        if "selectedPrincipals" in params and not "cancel" in params:
639            ph = user.PrincipalHolder()
640            for id in self._normaliseListParam(params["selectedPrincipals"]):
641                self._target.grantModification(ph.getById(id))
642        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
643
644
645class RHContributionRemoveManagers(RHContribModifBaseSpecialSesCoordRights):
646    _uh = urlHandlers.UHContributionRemoveManagers
647
648    def _process(self):
649        params = self._getRequestParams()
650        if ("selectedPrincipals" in params) and \
651            (len(params["selectedPrincipals"])!=0):
652            ph = user.PrincipalHolder()
653            for id in self._normaliseListParam(params["selectedPrincipals"]):
654                self._target.revokeModification(ph.getById(id))
655        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
656
657
658class RHContributionSetVisibility(RHContribModifBaseSpecialSesCoordRights):
659    _uh = urlHandlers.UHContributionSetVisibility
660
661    def _process(self):
662        params = self._getRequestParams()
663        if params.has_key("changeToPrivate"):
664            self._protect = 1
665        elif params.has_key("changeToInheriting"):
666            self._protect = 0
667        elif params.has_key("changeToPublic"):
668            self._protect = -1
669        self._target.setProtection(self._protect)
670        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
671
672
673class RHContributionSelectAllowed(RHContribModifBaseSpecialSesCoordRights):
674    _uh = urlHandlers.UHContributionSelectAllowed
675
676    def _process(self):
677        p = contributions.WPContributionSelectAllowed(self, self._target)
678        return p.display(**self._getRequestParams())
679
680
681class RHContributionAddAllowed(RHContribModifBaseSpecialSesCoordRights):
682    _uh = urlHandlers.UHContributionAddAllowed
683
684    def _process(self):
685        params = self._getRequestParams()
686        if "selectedPrincipals" in params and not "cancel" in params:
687            ph = user.PrincipalHolder()
688            for id in self._normaliseListParam(params["selectedPrincipals"]):
689                self._target.grantAccess(ph.getById(id))
690        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
691
692
693class RHContributionRemoveAllowed(RHContribModifBaseSpecialSesCoordRights):
694    _uh = urlHandlers.UHContributionRemoveAllowed
695
696    def _process(self):
697        params = self._getRequestParams()
698        if ("selectedPrincipals" in params) and \
699            (len(params["selectedPrincipals"])!=0):
700            ph = user.PrincipalHolder()
701            for id in self._normaliseListParam(params["selectedPrincipals"]):
702                self._target.revokeAccess(ph.getById(id))
703        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
704
705
706class RHContributionAddDomains(RHContribModifBaseSpecialSesCoordRights):
707    _uh = urlHandlers.UHContributionAddDomain
708
709    def _process(self):
710        params = self._getRequestParams()
711        if ("addDomain" in params) and (len(params["addDomain"])!=0):
712            dh = domain.DomainHolder()
713            for domId in self._normaliseListParam(params["addDomain"]):
714                self._target.requireDomain(dh.getById(domId))
715        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
716
717
718class RHContributionRemoveDomains(RHContribModifBaseSpecialSesCoordRights):
719    _uh = urlHandlers.UHContributionRemoveDomain
720
721    def _process(self):
722        params = self._getRequestParams()
723        if ("selectedDomain" in params) and (len(params["selectedDomain"])!=0):
724            dh = domain.DomainHolder()
725            for domId in self._normaliseListParam(params["selectedDomain"]):
726                self._target.freeDomain(dh.getById(domId))
727        #self._endRequest()
728        self._redirect(urlHandlers.UHContribModifAC.getURL(self._target))
729
730
731class RHContributionDeletion(RHContribModifBaseSpecialSesCoordRights):
732    _uh = urlHandlers.UHContributionDelete
733
734    def _checkParams(self, params):
735        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
736        self._cancel = False
737        if "cancel" in params:
738            self._cancel = True
739        self._confirmation = params.has_key("confirm")
740
741    def _perform(self):
742        conf = self._target.getConference()
743        self._target.getOwner().getSchedule().removeEntry(self._target.getSchEntry())
744        #self._target.getOwner().removeContribution(self._target)
745        self._target.delete()
746        #conf.removeContribution(self._target)
747
748    def _process(self):
749        if self._cancel:
750            self._redirect(urlHandlers.UHContribModifTools.getURL(self._target))
751        elif self._confirmation:
752            owner = self._target.getOwner()
753            self._perform()
754            if self._target.getSession():
755                self._redirect(urlHandlers.UHsessionModification.getURL(owner))
756            else:
757                self._redirect(urlHandlers.UHConferenceModification.getURL(owner))
758        else:
759            p = contributions.WPContributionDeletion(self, self._target)
760            return p.display()
761
762
763class RHContributionMove(RHContribModifBaseSpecialSesCoordRights):
764    _uh = urlHandlers.UHContributionMove
765
766    def _process(self):
767        p = contributions.WPcontribMove(self, self._target)
768        return p.display(**self._getRequestParams())
769
770
771class RHContributionPerformMove(RHContribModifBaseSpecialSesCoordRights):
772    _uh = urlHandlers.UHContributionPerformMove
773
774    def _checkParams(self, params):
775        RHContribModifBaseSpecialSesCoordRights._checkParams(self, params)
776        self._dest = params["Destination"]
777        if self._dest == "--no-sessions--":
778            raise MaKaCError( _("Undefined destination for the contribution."))
779
780    def _process(self):
781        conf = self._target.getConference()
782        if self._dest == 'CONF':
783            newOwner = conf
784        else:
785            newOwner = conf.getSessionById(self._dest)
786        self._moveContrib(newOwner)
787        self._redirect(urlHandlers.UHContribModifTools.getURL(self._target))
788
789        return "done"
790
791    def _moveContrib(self, newOwner):
792        owner = self._target.getOwner()
793        owner.removeContribution(self._target)
794        newOwner.addContribution(self._target)
795
796class RHContributionToXML(RHContributionModification):
797    _uh = urlHandlers.UHContribToXMLConfManager
798
799    def _process(self):
800        filename = "%s - contribution.xml"%self._target.getTitle()
801        x = XMLGen()
802        x.openTag("contribution")
803        x.writeTag("Id", self._target.getId())
804        x.writeTag("Title", self._target.getTitle())
805        x.writeTag("Description", self._target.getDescription())
806        afm = self._target.getConference().getAbstractMgr().getAbstractFieldsMgr()
807        for f in afm.getFields():
808            id = f.getId()
809            if f.isActive() and self._target.getField(id).strip() != "":
810                x.writeTag(f.getName().replace(" ","_"),self._target.getField(id))
811        x.writeTag("Conference", self._target.getConference().getTitle())
812        session = self._target.getSession()
813        if session!=None:
814            x.writeTag("Session", self._target.getSession().getTitle())
815        l = []
816        for au in self._target.getAuthorList():
817            if self._target.isPrimaryAuthor(au):
818                x.openTag("PrimaryAuthor")
819                x.writeTag("FirstName", au.getFirstName())
820                x.writeTag("FamilyName", au.getFamilyName())
821                x.writeTag("Email", au.getEmail())
822                x.writeTag("Affiliation", au.getAffiliation())
823                x.closeTag("PrimaryAuthor")
824            else:
825                l.append(au)
826
827        for au in l:
828            x.openTag("Co-Author")
829            x.writeTag("FirstName", au.getFirstName())
830            x.writeTag("FamilyName", au.getFamilyName())
831            x.writeTag("Email", au.getEmail())
832            x.writeTag("Affiliation", au.getAffiliation())
833            x.closeTag("Co-Author")
834
835        for au in self._target.getSpeakerList():
836            x.openTag("Speaker")
837            x.writeTag("FirstName", au.getFirstName ())
838            x.writeTag("FamilyName", au.getFamilyName())
839            x.writeTag("Email", au.getEmail())
840            x.writeTag("Affiliation", au.getAffiliation())
841            x.closeTag("Speaker")
842
843        #To change for the new contribution type system to:
844        typeName = ""
845        if self._target.getType():
846            typeName = self._target.getType().getName()
847        x.writeTag("ContributionType", typeName)
848
849        t = self._target.getTrack()
850        if t!=None:
851            x.writeTag("Track", t.getTitle())
852
853        x.closeTag("contribution")
854
855        data = x.getXml()
856
857        cfg = Config.getInstance()
858        mimetype = cfg.getFileTypeMimeType("XML")
859        self._req.content_type = """%s"""%(mimetype)
860        self._req.headers_out["Content-Length"] = "%s"%len(data)
861        self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename.replace("\r\n"," ")
862        return data
863
864
865class RHContributionToPDF(RHContributionModification):
866    _uh = urlHandlers.UHContribToPDFConfManager
867
868    def _process(self):
869        tz = self._target.getConference().getTimezone()
870        filename = "%s - Contribution.pdf"%self._target.getTitle()
871        pdf = ConfManagerContribToPDF(self._target.getConference(), self._target, tz=tz)
872        data = pdf.getPDFBin()
873        self._req.headers_out["Content-Length"] = "%s"%len(data)
874        cfg = Config.getInstance()
875        mimetype = cfg.getFileTypeMimeType("PDF")
876        self._req.content_type = """%s"""%(mimetype)
877        self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%filename.replace("\r\n"," ")
878        return data
879
880
881class RHMaterials(RHContribModifBaseSpecialSesCoordAndReviewingStaffRights):
882    _uh = urlHandlers.UHContribModifMaterials
883
884    def _checkProtection(self):
885        """ This disables people that are not conference managers or track coordinators to
886            delete files from a contribution.
887        """
888        RHContribModifBaseSpecialSesCoordAndReviewingStaffRights._checkProtection(self)
889        for key in self._paramsForCheckProtection.keys():
890            if key.find("delete")!=-1:
891                RHContribModifBaseSpecialSesCoordRights._checkProtection(self)
892
893    def _checkParams(self, params):
894        RHContribModifBaseSpecialSesCoordAndReviewingStaffRights._checkParams(self, params)
895        params["days"] = params.get("day", "all")
896        if params.get("day", None) is not None :
897            del params["day"]
898        # note from DavidMC: i wrote this long parameter name in order
899        # not to overwrite a possibly existing _params in a base class
900        # we need to store the params so that _checkProtection can know
901        # if the action is to upload a file, delete etc.
902        self._paramsForCheckProtection = params
903
904    def _process(self):
905        if self._target.getOwner().isClosed():
906            p = WPConferenceModificationClosed( self, self._target )
907            return p.display()
908
909        p = contributions.WPContributionModifMaterials( self, self._target )
910        return p.display(**self._getRequestParams())
911
912
913
914class RHContributionReportNumberEdit(RHContribModifBase):
915
916    def _checkParams(self, params):
917        RHContribModifBase._checkParams(self, params)
918        self._reportNumberSystem=params.get("reportNumberSystem","")
919
920    def _process(self):
921        if self._reportNumberSystem!="":
922            p=contributions.WPContributionReportNumberEdit(self,self._target, self._reportNumberSystem)
923            return p.display()
924        else:
925            self._redirect(urlHandlers.UHContributionModification.getURL( self._target ))
926
927class RHContributionReportNumberPerformEdit(RHContribModifBase):
928
929    def _checkParams(self, params):
930        RHContribModifBase._checkParams(self, params)
931        self._reportNumberSystem=params.get("reportNumberSystem","")
932        self._reportNumber=params.get("reportNumber","")
933
934    def _process(self):
935        if self._reportNumberSystem!="" and self._reportNumber!="":
936            self._target.getReportNumberHolder().addReportNumber(self._reportNumberSystem, self._reportNumber)
937        self._redirect("%s#reportNumber"%urlHandlers.UHContributionModification.getURL( self._target ))
938
939
940class RHContributionReportNumberRemove(RHContribModifBase):
941
942    def _checkParams(self, params):
943        RHContribModifBase._checkParams(self, params)
944        self._reportNumberIdsToBeDeleted=self._normaliseListParam( params.get("deleteReportNumber",[]))
945
946    def _process(self):
947        nbDeleted = 0
948        for id in self._reportNumberIdsToBeDeleted:
949            self._target.getReportNumberHolder().removeReportNumberById(int(id)-nbDeleted)
950            nbDeleted += 1
951        self._redirect("%s#reportNumber"%urlHandlers.UHContributionModification.getURL( self._target ))
952
953
954
Note: See TracBrowser for help on using the repository browser.