summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-02-17 09:43:42 +0100
committerThomas Bruederli <bruederli@kolabsys.com>2015-02-17 09:43:42 +0100
commite25e91e5c23621c53e1c0034cf5d3c42e939363e (patch)
tree5079352a25e9825c7281b5833bb237f02fccfa39
parent28cff75a01981c596051129e7b7f5f3a14781d62 (diff)
downloadpykolab-e25e91e5c23621c53e1c0034cf5d3c42e939363e.tar.gz
Add utility methods to update attendees with propagation to recurrence exceptions
-rw-r--r--pykolab/xml/event.py42
-rw-r--r--tests/unit/test-003-event.py24
2 files changed, 62 insertions, 4 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index a054053..325cbc5 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -150,10 +150,14 @@ class Event(object):
exception._load_attendees()
self._exceptions.append(exception)
- def add_attendee(self, email, name=None, rsvp=False, role=None, participant_status=None, cutype="INDIVIDUAL", params=None):
- attendee = Attendee(email, name, rsvp, role, participant_status, cutype, params)
- self._attendees.append(attendee)
- self.event.setAttendees(self._attendees)
+ def add_attendee(self, email_or_attendee, name=None, rsvp=False, role=None, participant_status=None, cutype="INDIVIDUAL", params=None):
+ if isinstance(email_or_attendee, Attendee):
+ attendee = email_or_attendee
+ else:
+ attendee = Attendee(email_or_attendee, name, rsvp, role, participant_status, cutype, params)
+
+ # apply update to self and all exceptions
+ self.update_attendees([attendee])
def add_category(self, category):
self._categories.append(ustr(category))
@@ -695,6 +699,14 @@ class Event(object):
def get_transparency(self):
return self.event.transparency()
+ def set_attendees(self, _attendees):
+ self._attendees = _attendees
+ self.event.setAttendees(self._attendees)
+
+ # apply update to all exceptions
+ for exception in self._exceptions:
+ exception.merge_attendee_data(_attendees)
+
def set_attendee_participant_status(self, attendee, status, rsvp=None):
"""
Set the participant status of an attendee to status.
@@ -709,6 +721,28 @@ class Event(object):
if rsvp is not None:
attendee.set_rsvp(rsvp)
+ # apply update to self and all exceptions
+ self.update_attendees([attendee])
+
+ def update_attendees(self, _attendees):
+ self.merge_attendee_data(_attendees)
+
+ for exception in self._exceptions:
+ exception.merge_attendee_data(_attendees)
+
+ def merge_attendee_data(self, _attendees):
+ for attendee in _attendees:
+ found = False
+
+ for candidate in self._attendees:
+ if candidate.get_email() == attendee.get_email():
+ candidate.copy_from(attendee)
+ found = True
+ break
+
+ if not found:
+ self._attendees.append(attendee)
+
self.event.setAttendees(self._attendees)
def set_classification(self, classification):
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 042d56a..1d0ad10 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -404,6 +404,13 @@ class TestEventXML(unittest.TestCase):
def test_009_invalid_participant_status(self):
self.assertRaises(InvalidAttendeeParticipantStatusError, self.event.set_attendee_participant_status, "jane@doe.org", "INVALID")
+ def test_009_update_attendees(self):
+ jane = self.event.get_attendee("jane@doe.org")
+ jane.set_name("Jane (GI) Doe")
+ self.event.update_attendees([jane])
+ self.assertEqual(len(self.event.get_attendees()), 2)
+ self.assertEqual(self.event.get_attendee("jane@doe.org").get_name(), "Jane (GI) Doe")
+
def test_010_datetime_from_string(self):
self.assertRaises(InvalidEventDateError, self.event.set_start, "2012-05-23 11:58:00")
@@ -842,6 +849,23 @@ END:VEVENT
self.assertEqual(property_to_string('attach', data['attach'][0]), "noname.1395223627.5555")
+ def test_027_merge_attendee_data(self):
+ event = event_from_string(xml_event)
+
+ jane = event.get_attendee("jane@example.org")
+ jane.set_participant_status('TENTATIVE')
+ jack = Attendee("jack@example.org", name="Jack", role='OPT-PARTICIPANT')
+
+ # update jane + add jack
+ event.update_attendees([jane,jack])
+ self.assertEqual(len(event.get_attendees()), 3)
+ self.assertEqual(event.get_attendee("jane@example.org").get_participant_status(), kolabformat.PartTentative)
+
+ exception = event.get_exceptions()[0]
+ self.assertEqual(len(exception.get_attendees()), 2)
+ self.assertEqual(event.get_attendee("jane@example.org").get_participant_status(), kolabformat.PartTentative)
+ self.assertEqual(event.get_attendee("jack@example.org").get_name(), "Jack")
+
def _find_prop_in_list(self, diff, name):
for prop in diff:
if prop['property'] == name: