summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-23 14:02:12 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-23 14:02:12 +0100
commitbd561b3e7b4e26d53d6882eb9d42c437f4c8bd60 (patch)
treebd2d5c69950f13dc83e2f5a1203652cb5a52136f
parent84992b37c15405a6276ced189a9de185c000a3da (diff)
downloadpykolab-bd561b3e7b4e26d53d6882eb9d42c437f4c8bd60.tar.gz
Add exception raising to attendee
-rw-r--r--pykolab/xml/attendee.py72
1 files changed, 63 insertions, 9 deletions
diff --git a/pykolab/xml/attendee.py b/pykolab/xml/attendee.py
index 7beb123..8d41c49 100644
--- a/pykolab/xml/attendee.py
+++ b/pykolab/xml/attendee.py
@@ -1,8 +1,16 @@
import kolabformat
+from pykolab.translate import _
+
from contact_reference import ContactReference
class Attendee(kolabformat.Attendee):
+ cutype_map = {
+ "INDIVIDUAL": kolabformat.CutypeIndividual,
+ "RESOURCE": kolabformat.CutypeResource,
+ "GROUP": kolabformat.CutypeGroup,
+ }
+
participant_status_map = {
"NEEDS-ACTION": kolabformat.PartNeedsAction,
"ACCEPTED": kolabformat.PartAccepted,
@@ -26,15 +34,24 @@ class Attendee(kolabformat.Attendee):
"FALSE": False,
}
- def __init__(self, email, name=None, rsvp=False, role=None, participant_status=None):
+ def __init__(
+ self,
+ email,
+ name=None,
+ rsvp=False,
+ role=None,
+ participant_status=None,
+ cutype=None
+ ):
+
self.email = email
- contactreference = ContactReference(email)
+ self.contactreference = ContactReference(email)
if not name == None:
- contactreference.set_name(name)
+ self.contactreference.set_name(name)
- kolabformat.Attendee.__init__(self, contactreference)
+ kolabformat.Attendee.__init__(self, self.contactreference)
if isinstance(rsvp, bool):
self.setRSVP(rsvp)
@@ -48,23 +65,60 @@ class Attendee(kolabformat.Attendee):
if not participant_status == None:
self.set_participant_status(participant_status)
+ if not cutype == None:
+ self.set_cutype(cutype)
+
def get_email(self):
- return self.email
+ return self.contactreference.get_email()
def get_name(self):
- return self.contact().name()
+ return self.contactreference.get_name()
def get_participant_status(self):
return self.partStat()
+ def set_cutype(self, cutype):
+ if cutype in self.cutype_map.keys():
+ self.setCutype(self.cutype_map[cutype])
+ elif cutype in self.cutype_map.values():
+ self.setCutype(cutype)
+ else:
+ raise InvalidAttendeeCutypeError, _("Invalid cutype %r") % (cutype)
+
+ def set_name(self, name):
+ self.contactreference.set_name(name)
+
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)
+ if participant_status in self.participant_status_map.keys():
self.setPartStat(self.participant_status_map[participant_status])
+ elif participant_status in self.participant_status_map.values():
+ self.setPartStat(participant_status)
+ else:
+ raise InvalidAttendeeParticipantStatusError, _("Invalid participant status %r") % (participant_status)
def set_role(self, role):
- if self.role_map.has_key(role):
+ if role in self.role_map.keys():
self.setRole(self.role_map[role])
+ elif role in self.role_map.values():
+ self.setRole(role)
+ else:
+ raise InvalidAttendeeRoleError, _("Invalid role %r") % (role)
def __str__(self):
return self.email
+
+class AttendeeIntegrityError(Exception):
+ def __init__(self, message):
+ Exception.__init__(self, message)
+
+class InvalidAttendeeCutypeError(Exception):
+ def __init__(self, message):
+ Exception.__init__(self, message)
+
+class InvalidAttendeeParticipantStatusError(Exception):
+ def __init__(self, message):
+ Exception.__init__(self, message)
+
+class InvalidAttendeeRoleError(Exception):
+ def __init__(self, message):
+ Exception.__init__(self, message)