summaryrefslogtreecommitdiffstats
path: root/pykolab/xml/attendee.py
blob: 7beb1230d53808da7b06ddfd5c76872773fffbf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import kolabformat

from contact_reference import ContactReference

class Attendee(kolabformat.Attendee):
    participant_status_map = {
            "NEEDS-ACTION": kolabformat.PartNeedsAction,
            "ACCEPTED": kolabformat.PartAccepted,
            "DECLINED": kolabformat.PartDeclined,
            "TENTATIVE": kolabformat.PartTentative,
            "DELEGATED": kolabformat.PartDelegated,
            # Not yet implemented
            #"COMPLETED": ,
            #"IN-PROCESS": ,
        }

    role_map = {
            "REQ-PARTICIPANT": kolabformat.Required,
            "CHAIR": kolabformat.Chair,
            "OPTIONAL": kolabformat.Optional,
            "NONPARTICIPANT": kolabformat.NonParticipant,
        }

    rsvp_map = {
            "TRUE": True,
            "FALSE": False,
        }

    def __init__(self, email, name=None, rsvp=False, role=None, participant_status=None):
        self.email = email

        contactreference = ContactReference(email)

        if not name == None:
            contactreference.set_name(name)

        kolabformat.Attendee.__init__(self, contactreference)

        if isinstance(rsvp, bool):
            self.setRSVP(rsvp)
        else:
            if self.rsvp_map.has_key(rsvp):
                self.setRSVP(self.rsvp_map[rsvp])

        if not role == None:
            self.set_role(role)

        if not participant_status == None:
            self.set_participant_status(participant_status)

    def get_email(self):
        return self.email

    def get_name(self):
        return self.contact().name()

    def get_participant_status(self):
        return self.partStat()

    def set_participant_status(self, participant_status):
        if self.participant_status_map.has_key(participant_status):
            #print "Setting participant status for %r to %r" %(str(self), participant_status)
            self.setPartStat(self.participant_status_map[participant_status])

    def set_role(self, role):
        if self.role_map.has_key(role):
            self.setRole(self.role_map[role])

    def __str__(self):
        return self.email