source: indico/indico/MaKaC/participant.py @ bdd862

burotelhello-world-walkthroughipv6new-webexv0.97-seriesv0.98-seriesv0.98.2v0.98.3v0.98b1v0.98b2v0.99v1.0v1.1
Last change on this file since bdd862 was bdd862, checked in by Pedro Ferreira <jose.pedro.ferreira@…>, 3 years ago

[VER] Removed CVS $Id lines

  • MaKaC dir;
  • XSL files
  • PO files
  • CSS files
  • POT file generation;
  • Python scripts for i18n;
  • Property mode set to 100644
File size: 39.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 persistent import Persistent
22from datetime import timedelta, datetime
23from MaKaC.common.timezoneUtils import nowutc
24import MaKaC.webinterface.urlHandlers as urlHandlers
25from MaKaC.user import Avatar
26from MaKaC.negotiations import Negotiator
27from MaKaC.webinterface.mail import GenericMailer
28from MaKaC.webinterface.mail import GenericNotification
29from MaKaC.common import utils
30import MaKaC.common.info as info
31from MaKaC.i18n import _
32
33class Participation(Persistent):
34   
35    def __init__(self, conference):
36        self._conference = conference
37        self._obligatory = False
38        self._addedInfo = False
39        self._allowedForApplying = False
40        self._autoAccept = False
41        self._participantList = {}
42        self._pendingParticipantList = {}
43        self._participantIdGenerator = 0
44        self._pendingIdGenerator = 0
45        self._dateNegotiation = None
46        self._displayParticipantList = True
47           
48    def clone(self, conference, options, eventManager=None):
49        newParticipation = conference.getParticipation()
50        newParticipation._obligatory = self._obligatory
51        newParticipation._allowedForApplying = self._allowedForApplying
52        if options.get("addedInfo", False) :
53            newParticipation._addedInfo = True
54        clonedStatuses = ["added", "excused", "refused"]
55        for p in self._participantList.values():
56            if p.getStatus() in clonedStatuses :
57                newParticipation.addParticipant(p.clone(conference), eventManager)
58        return newParticipation
59       
60    def getConference(self):
61        return self._conference
62       
63    def isObligatory(self):
64        return self._obligatory
65       
66    def setObligatory(self, responsibleUser = None):
67        self._obligatory = True
68        logData = {}
69        logData["subject"] = "Event set to MANDATORY"
70        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
71       
72    def setInobligatory(self, responsibleUser = None):
73        self._obligatory = False
74        logData = {}
75        logData["subject"] = "Event set to NON MANDATORY"
76        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
77       
78    def isAddedInfo(self):
79        return self._addedInfo
80       
81    def setAddedInfo(self, responsibleUser = None):
82        self._addedInfo = True
83        logData = {}
84        logData["subject"] = "Info about adding WILL be sent to participants"
85        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
86       
87    def setNoAddedInfo(self, responsibleUser = None):
88        self._addedInfo = False
89        logData = {}
90        logData["subject"] = "Info about adding WON'T be sent to participants"
91        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
92       
93    def isAllowedForApplying(self):
94        try :
95            if self._allowedForApplying :
96                pass
97        except AttributeError :
98            self._allowedForApplying = False
99        return self._allowedForApplying
100       
101    def setAllowedForApplying(self, responsibleUser=None):
102        self._allowedForApplying = True
103        logData = {}
104        logData["subject"] = "Applying for participation is ALLOWED"
105        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
106        self.notifyModification()
107       
108    def setNotAllowedForApplying(self, responsibleUser=None):
109        self._allowedForApplying = False
110        logData = {}
111        logData["subject"] = "Applying for participation is NOT ALLOWED"
112        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
113        self.notifyModification()
114   
115    def getAutoAccept(self):
116        try:
117            return self._autoAccept
118        except AttributeError :
119            self._autoAccept = False
120            return False
121       
122    def setAutoAccept(self, value, responsibleUser = None):
123        self._autoAccept = value
124        logData = {
125            "subject": "Auto accept of participation.",
126            "value": str(value)
127        }
128        self._conference.getLogHandler().logAction(logData, "participants", responsibleUser)
129        self.notifyModification()
130   
131    def alreadyParticipating(self, participant):
132        if participant is None : 
133            return -1
134        if participant.getConference().getId() != self.getConference().getId() :
135            return -1
136        if participant.getId() in self._participantList.keys() :
137            return 1
138        if participant.getEmail().strip() == "":
139            return 0
140        for p in self._participantList.values() :
141            pString = p.getEmail()
142            newString = participant.getEmail()
143            if pString == newString :
144                return 1
145        return 0
146               
147    def alreadyPending(self, pending):
148        if pending is None : 
149            return -1
150        if pending.getConference().getId() != self.getConference().getId() :
151            return -1
152        if pending.getId() in self._pendingParticipantList.keys() :
153            return 1
154        if pending.getEmail().strip() == "":
155            return -1
156        for p in self._pendingParticipantList.values() :
157            if p.getEmail() == pending.getEmail() :
158                return 1
159        return 0
160               
161    def getParticipantList(self):
162        participants = self._participantList.values()
163        participants.sort(utils.sortUsersByName)
164        return participants
165
166    def getParticipantListText(self):
167        text = []
168        for p in self.getParticipantList():
169            part = p.getName()
170            if not p.isPresent() and nowutc() > self._conference.getEndDate():
171                part += " (absent)"
172            text.append(part)
173        return "; ".join(text)
174   
175    def getPresentParticipantListText(self):
176        text = []
177        for p in self.getParticipantList():
178            if p.isPresent() or nowutc() < self._conference.getEndDate():
179                part = p.getName()
180                text.append(part)
181        return "; ".join(text)
182
183    def getParticipantById(self, participantId):
184        if participantId is not None :
185            return self._participantList.get(participantId, None)
186        else :
187            return None
188       
189    def getPendingParticipantList(self):
190        return self._pendingParticipantList
191       
192    def getPendingParticipantByKey(self, key):
193        if key is not None :
194            return self._pendingParticipantList.get(key, None)
195        else :
196            return None
197   
198    def prepareAddedInfo(self, participant, eventManager):
199        if participant is None :
200            return None
201        if eventManager is None :
202            return None
203           
204        data = {}
205        title = ""
206        familyName = ""
207        firstName = ""
208        refuse = ""
209       
210        refuseURL = urlHandlers.UHConfParticipantsRefusal.getURL( self._conference )
211        refuseURL.addParam("participantId","%d"%self._lastParticipantId())
212        eventURL = urlHandlers.UHConferenceDisplay.getURL( self._conference )
213       
214        toList = []
215        if participant.getAvatar() is not None :
216            toList.append(participant.getAvatar().getEmail())
217            data["toList"] = toList
218            title = participant.getAvatar().getTitle()
219            familyName = participant.getAvatar().getFamilyName()
220            firstName = participant.getAvatar().getFirstName()
221        else :
222            toList.append(participant.getEmail())
223            data["toList"] = toList
224            title = participant.getTitle()
225            familyName = participant.getFamilyName()
226            firstName = participant.getFamilyName()
227        if data["toList"] is None or len(data["toList"]) == 0 :
228            return None
229           
230        if title is None or title == "" :
231            title = firstName
232        if not self._obligatory :
233            refuse = _("""
234            If you are not interested in taking part in this event
235            or cannot participate due to any reason, please indicate your decline
236            to the event organisers at %s
237            """)%refuseURL
238        else :
239            refuse = _("""
240            Due to decision of the organisers, presence in the event
241            is obligatory for all participants.
242            """)
243               
244        data["fromAddr"] = eventManager.getEmail()
245        data["subject"] = _("Invitation to %s")%self._conference.getTitle()
246        data["body"] = _("""
247        Dear %s %s,
248           
249        you have been added to the list of '%s' participants.
250        Further information on this event are avaliable at %s.
251        %s
252        Looking forward to meeting you at %s
253        Your Indico
254        on behalf of %s %s
255        """)%(title, familyName, \
256             self._conference.getTitle(), \
257             eventURL, refuse, \
258             self._conference.getTitle(), \
259             eventManager.getFirstName(), eventManager.getFamilyName())
260       
261        return data
262       
263   
264    def addParticipant(self, participant, eventManager = None):
265       
266        # check if it's worth to add the participant
267        if participant.getConference().getId() != self._conference.getId() :
268            return False
269        self.removePendingParticipant(participant)
270        if not participant.setId(self._newParticipantId()):
271            return False
272        if self.alreadyParticipating(participant) != 0 :
273            return False
274        self._participantList["%d"%self._lastParticipantId()] = participant
275       
276        # remove him from the "pending" list
277        if participant in self._pendingParticipantList.values() :
278            for k in self._pendingParticipantList.keys() :
279                if self._pendingParticipantList[k] == participant :
280                    del self._pendingParticipantList[k]
281                    break
282               
283        logData = participant.getParticipantData()
284        logData["subject"] = _("New participant added : %s")%participant.getWholeName()
285        self._conference.getLogHandler().logAction(logData,"participants",eventManager)
286       
287        participant.setStatusAdded()
288       
289        # check if an e-mail should be sent...
290        if self._addedInfo :
291            # to notify the user of his/her addition
292            if eventManager is None :
293                return False
294            data = self.prepareAddedInfo(participant, eventManager)       
295            GenericMailer.sendAndLog(GenericNotification(data),self._conference,"participants")
296           
297        avatar = participant.getAvatar()   
298       
299        if avatar is None :
300            # or to encourage him/her to register at Indico
301            #self.sendEncouragementToCreateAccount(participant)
302                        pass
303        else:
304            # OK, if we have an avatar, let's keep things consistent
305            avatar.linkTo(self._conference,"participant")
306           
307        self.notifyModification()
308        return True
309       
310    def inviteParticipant(self, participant, eventManager):
311        if participant.getConference().getId() != self._conference.getId() :
312            return False
313        if not participant.setId(self._newParticipantId()):
314            return False
315        if eventManager is None :
316            return False
317        if self.alreadyParticipating(participant) != 0 :
318            return False
319        self._participantList["%d"%self._lastParticipantId()] = participant
320        logData = participant.getParticipantData()
321        logData["subject"] = _("New participant invited : %s")%participant.getWholeName()
322        self._conference.getLogHandler().logAction(logData,"participants",eventManager)
323        participant.setStatusInvited()
324        data = {}
325        title = ""
326        firstName = ""
327        familyName = ""
328        eventURL = urlHandlers.UHConferenceDisplay.getURL( self._conference )
329        actionURL = urlHandlers.UHConfParticipantsInvitation.getURL( self._conference )
330        actionURL.addParam("participantId","%d"%self._lastParticipantId())
331        toList = []
332        if participant.getAvatar() is not None :
333            toList.append(participant.getAvatar().getEmail())
334            data["toList"] = toList
335            title = participant.getAvatar().getTitle()
336            familyName = participant.getAvatar().getFamilyName()
337            firstName = participant.getAvatar().getFirstName()
338        else :
339            toList.append(participant.getEmail())
340            data["toList"] = toList
341            title = participant.getTitle()
342            familyName = participant.getFamilyName()
343            firstName = participant.getFamilyName()
344        locationName = locationAddress = ""
345        if self._conference.getLocation() is not None :
346            locationName = self._conference.getLocation().getName()
347            locationAddress = self._conference.getLocation().getAddress()
348        if data["toList"] is None or len(data["toList"]) == 0 :
349            return False
350        if title is None or title == "" :
351            title = firstName
352        data["fromAddr"] = eventManager.getEmail()
353        data["subject"] = _("Invitation to %s")%self._conference.getTitle()
354        data["body"] = _("""
355        Dear %s %s,
356       
357        %s %s, event manager of '%s' would like to invite you to take part in this event,
358        which will take place on %s in %s, %s. Further information on this event are
359        available at %s
360        You are kindly requested to accept or decline your participation in this event by
361        clicking on the link below :
362         %s
363       
364        Looking forward to meeting you at %s
365        Your Indico
366        on behalf of %s %s
367       
368        """)%(title, familyName, \
369             eventManager.getFirstName(), eventManager.getFamilyName(), \
370             self._conference.getTitle(), \
371             self._conference.getAdjustedStartDate(), \
372             locationName, locationAddress, \
373             eventURL, actionURL, \
374             self._conference.getTitle(), \
375             eventManager.getFirstName(), eventManager.getFamilyName())
376        GenericMailer.sendAndLog(GenericNotification(data),self._conference,"participants")
377        #if participant.getAvatar() is None :
378        #    self.sendEncouragementToCreateAccount(participant)
379        self.notifyModification()
380        return True
381       
382    def removeParticipant(self, participant, responsibleUser=None):
383        if participant is None:
384            return False
385                # If 'participant' is an object from Participant
386        if isinstance(participant, Participant):
387            # remove all entries with participant
388            for key, value in self._participantList.items():
389                if value == participant:
390                    del self._participantList[key]
391                # If 'participant' is a key
392        else:
393            key = participant
394            if key not in self._participantList:
395                return False
396            participant = self._participantList[key]
397            del self._participantList[key]
398       
399        logData = participant.getParticipantData()
400        logData["subject"] = _("Removed participant %s %s (%s)")%(participant.getFirstName(),participant.getFamilyName(),participant.getEmail())
401        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
402
403        avatar = participant.getAvatar()           
404        if avatar:           
405            avatar.unlinkTo(self._conference,"participant")
406               
407        self.notifyModification()
408        return True
409       
410    def setParticipantRefused(self, participantId):
411        return self._participantList[participantId].setStatusRefused()
412        self.notifyModification()
413       
414    def setParticipantExcused(self, participantId):
415        return self._participantList[participantId].setStatusExcused()
416        self.notifyModification()
417       
418    def setParticipantAccepted(self, participantId):
419        return self._participantList[participantId].setStatusAccepted()
420        self.notifyModification()
421       
422    def setParticipantRejected(self, participantId):
423        return self._participantList[participantId].setStatusRejected()
424        self.notifyModification()
425       
426    def addPendingParticipant(self, participant):
427        if participant.getConference().getId() != self._conference.getId() :
428            return False
429        if participant.getId() is not None :
430            return False
431        if self.alreadyParticipating(participant) != 0 :
432            return False
433        if self.getAutoAccept():
434            self.addParticipant(participant)
435        else:
436            self._pendingParticipantList["%d"%self._newPendingId()] = participant
437           
438            logData = participant.getParticipantData()
439            logData["subject"] = _("New pending participant : %s")%participant.getWholeName()
440            self._conference.getLogHandler().logAction(logData,"participants")
441           
442            participant.setStatusPending()
443                   
444            profileURL = urlHandlers.UHConfModifParticipantsPendingDetails.getURL(self._conference)
445            profileURL.addParam("pendingId", self._lastPendingId())
446                   
447            toList = []
448            creator=self._conference.getCreator()
449            if isinstance(creator, Avatar) :
450                toList.append(creator.getEmail())
451            for manager in self._conference.getAccessController().getModifierList() :
452                if isinstance(manager, Avatar) :
453                    toList.append(manager.getEmail())
454           
455            data = {}
456            data["toList"] = toList
457            data["fromAddr"] = info.HelperMaKaCInfo.getMaKaCInfoInstance().getSupportEmail()
458            data["subject"] = _("New pending participant for %s")%self._conference.getTitle()
459            data["body"] = _("""
460            Dear Event Manager,
461           
462            a new person is asking for participation in %s.
463            Personal profile of this pending participant is available at %s
464            Please take this candidature into consideration and accept or reject it
465           
466            Your Indico
467            """)%(self._conference.getTitle(), profileURL)
468           
469            GenericMailer.send(GenericNotification(data))
470            self.notifyModification()
471        return True
472       
473    def removePendingParticipant(self, participant, responsibleUser=None):
474        if participant is None:
475            return False
476        if isinstance(participant, Participant):
477            # remove all entries with participant
478            for key, value in self._pendingParticipantList.items():
479                if value == participant:
480                    del self._pendingParticipantList[key]
481        else:
482            key = participant
483            if key == "":
484                return False
485            participant = self._pendingParticipantList[key]
486            del self._pendingParticipantList[key]
487       
488        logData = participant.getParticipantData()
489        logData["subject"] = _("Pending participant removed : %s")%participant.getWholeName()
490        self._conference.getLogHandler().logAction(logData,"participants",responsibleUser)
491
492        self.notifyModification()
493        return True
494       
495    def setPendingDeclined(self, pendingId):
496        return self._pendingParticipantList[pendingId].setStatusDeclined()
497        self.notifyModification()
498       
499    def setPendingAdded(self, pendingId):
500        return self.addParticipant(self._pendingParticipantList[pendingId])
501        self.notifyModification()
502       
503    def prepareAskForExcuse(self, eventManager, toIdList):
504        if eventManager is None :
505            return None
506        if toIdList is None :
507            return None
508        if not self._obligatory :
509            return None
510       
511        if nowutc() < self._conference.getEndDate() :
512            return None
513       
514        toList = []
515        for id in toIdList :
516            p = self._participantList[id]
517            if not p.isPresent() :
518                toList.append(p.getEmail())
519        if len(toList) == 0 :
520            return None
521           
522        data = {}
523        data["toList"] = toList
524        data["fromAddr"] = eventManager.getEmail()
525        data["subject"] = _("Please excuse your absence to %s")%self._conference.getTitle()
526        data["body"] = _("""
527Dear Participant,
528       
529you were absent to %s, which was mandatory for you to attend.
530Therefore %s %s, the organiser of this event is kindly asking you to provide reasons
531for your absence, so that it could be excused - simply by replying to
532this email.
533       
534Your Indico
535on behalf of %s %s
536        """)%(self._conference.getTitle(), \
537        eventManager.getFirstName(), eventManager.getFamilyName(), \
538        eventManager.getFirstName(), eventManager.getFamilyName())
539       
540        return data
541       
542    def askForExcuse(self, eventManager, toIdList):
543        data = self.prepareAskForExcuse(eventManager,toIdList)
544        if data is None :
545            return False
546           
547        GenericMailer.sendAndLog(GenericNotification(data),self._conference,"participants",eventManager)
548        return True
549   
550    def sendSpecialEmail(self, participantsIdList, eventManager, data):
551        if participantsIdList is None :
552            return False
553        if eventManager is None :
554            return False
555        if len(participantsIdList) == 0:
556            return True
557        if data.get("subject",None) is None :
558            return False
559        if data.get("body",None) is None :
560            return False
561        data["fromAddr"] = eventManager.getEmail()
562       
563        toList = []
564        for id in participantsIdList :
565            participant = self._participantList.get(id,None)
566            if Participant is not None :
567                toList.append(p.getEmail())
568        data["toList"] = toList
569        GenericMailer.sendAndLog(GenericNotification(data),self._conference,"participants",eventManager)
570        return True
571   
572    def sendEncouragementToCreateAccount(self, participant):
573        if participant is None :
574            return False
575        if participant.getEmail() is None or participant.getEmail() == "" :
576            return None
577        data = {}
578        title = participant.getTitle()
579        if title is None or title == "" :
580            title = participant.getFirstName()
581       
582        createURL = urlHandlers.UHUserCreation.getURL()
583        data["fromAddr"] = info.HelperMaKaCInfo.getMaKaCInfoInstance().getNoReplyEmail(returnSupport=True)
584        toList = []
585        toList.append(participant.getEmail())
586        data["toList"] = toList
587        data["subject"] = _("Invitation to create an Indico account")
588        data["body"] = _("""
589        Dear %s %s,
590       
591        You have been added as a participant to '%s' and you have started to use
592        the Indico system. Most probably you are going to use it in the future,
593        participating in other events supported by Indico.
594        Therefore we strongly recommend that you create your personal Indico Account -
595        storing your personal data it will make your work with Indico easier and
596        allow you access more sophisticated features of the system.
597       
598        To proceed in creating your Indico Account simply click on the following
599        link : %s
600        Please use this email address when creating your account: %s
601
602        Your Indico
603        """)%(participant.getFirstName(), participant.getFamilyName(), \
604        self._conference.getTitle(), \
605        createURL, participant.getEmail())
606       
607        GenericMailer.sendAndLog(GenericNotification(data),self._conference,"participants")
608        return True
609   
610    def sendNegotiationInfo(self):
611        if self._dateNgotiation is None :
612            return False
613        if not self._dateNegotiation.isFinished() :
614            return False
615           
616        data = {}
617        data["fromAddr"] = info.HelperMaKaCInfo.getMaKaCInfoInstance().getNoReplyEmail(returnSupport=True)
618        if len(self._dateNegotiation.getSolutionList()) == 0:
619           
620            """ TODO: Prepate URLs..!! """
621       
622            settingURL = ">>must be prepared yet..!!<<"
623            data["subject"] = _("Negotiation algorithm finished - FAILED to find date")
624            toList = []
625            for manager in self._conference.getManagerList() :
626                if isinstance(manager, Avatar) :
627                    toList.append(manager.getEmail())
628            data["toList"] = toList
629            data["body"] = _("""
630            Dear Event Manager,
631           
632            negotiation algorithm has finished its work on finding the date for %s,
633            yet it didn't managed to find any solution satisfying all (or almost all)
634            given restrictions.
635            Setting the event's date is now up to you at %s
636           
637            Your Indico
638            """)%(self._conference.getTitle(), settingURL)
639           
640        elif not self.dateNegotiation.isAutomatic :
641            """ TODO: Prepate URLs..!! """
642       
643            choseURL = ">>must be prepared yet..!!<<"
644            data["subject"] = _("Negotiation algorithm finished - SUCCSEEDED")
645            toList = []
646            for manager in self._conference.getManagerList() :
647                if isinstance(manager, Avatar) :
648                    toList.append(manager.getEmail())
649            data["toList"] = toList
650            data["body"] = _("""
651            Dear Event Manager,
652           
653            negotiation algorithm has finished its work on finding the date for %s,
654            now you are kindly requested to choose the most siutable date from
655            the list of solution which is avaliable at %s
656           
657            Your Indico
658            """)%(self._conference.getTitle(), choseURL)
659           
660        else :
661            data["subject"] = _("Date of the %s setteled")%self._conference.getTitle()
662            toList = []
663            for p in self._participantList.valuess() :
664                toList.append(p.getEmail())
665            data["toList"] = toList
666            data["body"] = _("""
667            Dear Participant,
668           
669            negotiation algorithm has just set the date of the %s to :
670                start date : %s
671                end date   : %s
672               
673            Wishing you a pleasent and interesting time -
674            Your Indico
675            """)%(self._conference.getTitle(), \
676            self._conference.getAdjustedStartDate(), self._conference.getAdjustedEndDate())
677           
678        GenericMailer.send(GenericNotification(data))
679        return True
680   
681    def getPresentNumber(self):
682        counter = 0
683        for p in self._participantList.values() :
684            if p.isPresent() :
685                counter += 1
686        return counter
687   
688    def getAbsentNumber(self):
689        counter = 0
690        for p in self._participantList.values() :
691            if not p.isPresent() :
692                counter += 1
693        return counter
694   
695    def getExcusedNumber(self):
696        counter = 0
697        for p in self._participantList.values() :
698            if "excused" == p.getStatus() :
699                counter += 1
700        return counter
701   
702    def getInvitedNumber(self):
703        counter = 0
704        for p in self._participantList.values() :
705            if "invited" == p.getStatus() :
706                counter += 1
707        return counter
708   
709    def getRejectedNumber(self):
710        counter = 0
711        for p in self._participantList.values() :
712            if "rejected" == p.getStatus() :
713                counter += 1
714        return counter
715       
716    def getAddedNumber(self):
717        counter = 0
718        for p in self._participantList.values() :
719            if "added" == p.getStatus() :
720                counter += 1
721        return counter
722   
723    def getRefusedNumber(self):
724        counter = 0
725        for p in self._participantList.values() :
726            if "excused" == p.getStatus() :
727                counter += 1
728        return counter
729   
730    def getPendingNumber(self):
731        counter = 0
732        for part in self._pendingParticipantList.values():
733            if not part.getStatus() == "declined":
734                counter += 1
735        return counter
736   
737    def _newParticipantId(self):   
738        self._participantIdGenerator += 1
739        return self._participantIdGenerator
740
741    def _lastParticipantId(self):
742        return self._participantIdGenerator
743
744    def _newPendingId(self):   
745        self._pendingIdGenerator += 1
746        return self._pendingIdGenerator
747       
748    def _lastPendingId(self):
749        return self._pendingIdGenerator
750       
751    def displayParticipantList(self):
752        try :
753            if self._displayParticipantList :
754                pass
755        except AttributeError :
756            self._displayParticipantList = True
757        return self._displayParticipantList
758       
759    def participantListDisplay(self):
760        self.displayParticipantList()
761        self._displayParticipantList = True
762        self.notifyModification()
763       
764    def participantListHide(self):
765        self.displayParticipantList()
766        self._displayParticipantList = False 
767        self.notifyModification()       
768       
769    def notifyModification(self):
770        if self._conference != None:
771            self._conference.notifyModification()
772        self._p_changed=1
773       
774#---------------------------------------------------------------------------------
775
776class Participant (Persistent, Negotiator):
777    """
778        Class collecting data about person taking part in meeting / lecture
779    """   
780       
781    def __init__(self, conference, avatar=None):
782        Negotiator(avatar)
783        if avatar is not None :
784            self._id = None
785            self._avatar = avatar
786            self._firstName = avatar.getFirstName()
787            self._familyName = avatar.getFamilyName()
788            if self._firstName.strip() == "" and self._familyName.strip() == "":
789                self._firstName = "Undefined name"
790            self._title = avatar.getTitle()
791            self._address = avatar.getAddress()
792            self._affiliation = avatar.getAffiliation()
793            self._telephone = avatar.getTelephone()
794            self._fax = avatar.getFax()
795            self._email = avatar.getEmail()
796           
797            self._status = None
798            self._present = True
799            self._participation = None
800            if conference is not None :
801                self._participation = conference.getParticipation()
802        else : 
803            Negotiator(None)
804            self._id = None
805            self._avatar = None
806            self._firstName = ""
807            self._familyName = ""
808            self._title = ""
809            self._address = ""
810            self._affiliation = ""
811            self._telephone = ""
812            self._fax = ""
813            self._email = ""
814       
815            self._status = None
816            self._present = None
817            self._participation = None
818            if conference is not None:
819                self._participation = conference.getParticipation()
820       
821    def clone(self, conference):
822        newPart = Participant(conference)
823        newPart._avatar = self._avatar
824        newPart._firstName = self._firstName
825        newPart._familyName = self._familyName
826        newPart._title = self._title
827        newPart._address = self._address
828        newPart._affiliation = self._affiliation
829        newPart._telephone = self._telephone
830        newPart._fax = self._fax
831        newPart._email = self._email
832        newPart._status = None
833        newPart._present = True
834       
835        return newPart
836
837           
838    def getId(self):
839        return self._id
840       
841    def setId(self, id):
842        if self._id is not None :
843            return False
844        self._id = id
845        return True
846   
847    def getAvatar(self):
848        return self._avatar
849       
850    def getTitle(self):
851        return self._title
852       
853    def setTitle(self, title):
854        self._title = title
855   
856    def getFirstName(self):
857        return self._firstName
858   
859    def setFirstName(self, firstName):
860        self._firstName = firstName
861   
862    def getFamilyName(self):
863        return self._familyName
864       
865    def setFamilyName(self, familyName):
866        self._familyName = familyName
867   
868    def getWholeName(self):
869        return "%s %s %s"%(self._title,self._firstName,self._familyName)
870   
871    def getFullName(self):
872        return self.getWholeName()
873   
874    def getName(self):
875        return "%s %s"%(self.getFirstName(),self.getFamilyName())
876   
877    def getNegotiatorInfo(self):
878        return "%s %s %s"%(self._firstName,self._familyName,self._email)
879       
880    def getAddress(self):
881        return self._address
882       
883    def setAddress(self, address):
884        self._address = address
885       
886    def getAffiliation(self):
887        return self._affiliation
888       
889    def setAffiliation(self, affiliation):
890        self._affiliation = affiliation
891       
892    def getTelephone(self):
893        return self._telephone
894       
895    def setTelephone(self, telephone):
896        self._telephone = telephone
897       
898    def getFax(self):
899        return self._fax
900       
901    def setFax(self, fax):
902        self._fax = fax
903       
904    def getEmail(self):
905        return self._email
906   
907    def setEmail(self, email):
908        self._email = email
909   
910    def getParticipantData(self):
911        data = {}
912        data["Title"] = self.getTitle()
913        data["Family name"] = self.getFamilyName()
914        data["First name"] = self.getFirstName()
915        data["Affiliation"] = self.getAffiliation()
916        data["Address"] = self.getAddress()
917        data["Email"] = self.getEmail()
918        data["Phone"] = self.getTelephone()
919        data["Fax"] = self.getFax()
920        data["Participant status"] = self.getStatus()
921       
922        return data
923   
924    def isPresent(self):
925        return self._present
926   
927    def setPresent(self):
928        self._present = True
929       
930    def setAbsent(self):
931        self._present = False
932   
933    def getParticipation(self):
934        return self._participation
935       
936    def getConference(self):
937        return self._participation.getConference()
938       
939    def getStatus(self):
940        return self._status
941       
942    def setStatusAdded(self, responsibleUser=None):   
943        self._status = "added"
944        #if self._status is None or self._status == "pending" :
945        #    self._status = "added"
946        #   
947        #    logData = self.getParticipantData()
948        #    logData["subject"] = _("%s : status set to ADDED")%self.getWholeName()
949        #    self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
950       
951        logData = self.getParticipantData()
952        logData["subject"] = "%s : status set to ADDED"%self.getWholeName()
953        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
954   
955        return True
956   
957    def setStatusRefused(self, responsibleUser=None):
958        if self._status != "added" :
959            return False
960        self._status = "refused"
961       
962        logData = self.getParticipantData()
963        logData["subject"] = _("%s : status set to REFUSED")%self.getWholeName()
964        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
965       
966        return True
967       
968    def setStatusExcused(self, responsibleUser=None):
969        if self._status != "added" or self._present :
970            return False
971        self._status = "excused"
972       
973        logData = self.getParticipantData()
974        logData["subject"] = _("%s : status set to EXCUSED")%self.getWholeName()
975        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
976       
977        return True
978   
979    def setStatusInvited(self, responsibleUser=None):
980        if self._status is not None :
981            return False
982        self._status = "invited"
983       
984        logData = self.getParticipantData()
985        logData["subject"] = _("%s : status set to INVITED")%self.getWholeName()
986        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
987       
988        return True
989   
990    def setStatusAccepted(self, responsibleUser=None):
991        if self._status != "invited" :
992            return False
993        self._status = "accepted"
994
995        logData = self.getParticipantData()
996        logData["subject"] = _("%s : status set to ACCEPTED")%self.getWholeName()
997        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
998       
999        return True
1000   
1001    def setStatusRejected(self, responsibleUser=None):
1002        if self._status != "invited" :
1003            return False
1004        self._status = "rejected"
1005
1006        logData = self.getParticipantData()
1007        logData["subject"] = _("%s : status set to REJECTED")%self.getWholeName()
1008        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
1009       
1010        return True
1011   
1012    def setStatusPending(self, responsibleUser=None):
1013        if self._status is not None :
1014            return False
1015        self._status = "pending"
1016
1017        logData = self.getParticipantData()
1018        logData["subject"] = _("%s : status set to PENDING")%self.getWholeName()
1019        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
1020       
1021        return True
1022   
1023    def setStatusDeclined(self, responsibleUser=None, sendMail=True):
1024        if self._status != "pending" :
1025            return False
1026        self._status = "declined"
1027       
1028        logData = self.getParticipantData()
1029        logData["subject"] = _("%s : status set to DECLINED")%self.getWholeName()
1030        self.getConference().getLogHandler().logAction(logData,"participants",responsibleUser)
1031
1032        if sendMail:
1033            data = {}
1034            data["fromAddr"] = info.HelperMaKaCInfo.getMaKaCInfoInstance().getNoReplyEmail(returnSupport=True)
1035            confTitle = self._participation.getConference().getTitle()
1036            data["subject"] = _("Your application for attendance in %s declined")%confTitle
1037            toList = []
1038            toList.append(self._email)
1039            title = ""
1040            if self._title == "" or self._title is None :
1041                title = self._firstName
1042            else:
1043                title = self._title       
1044            data["toList"] = toList
1045            data["body"] = _("""
1046            Dear %s %s,
1047           
1048            your request to attend the %s has been declined by the event manager.
1049           
1050            Your Indico
1051            """)%(title, self._familyName, confTitle)
1052                       
1053            GenericMailer.sendAndLog(GenericNotification(data),self.getConference(),"participants",responsibleUser)
1054       
1055        return True
1056
1057   
1058#---------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.