summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-03-04 13:25:37 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-03-04 13:25:37 +0100
commitb8e3042daddd8a77d97080ed61eb0f135817ce79 (patch)
tree9dae0f994e26915103ee5fd43ecf4e948eac12d7 /pykolab
parent4c572065c63e3bb830070ab71583e349cc109455 (diff)
parentdd711f06e4e56ecbc6808a992e84f2a5f8e1a746 (diff)
downloadpykolab-b8e3042daddd8a77d97080ed61eb0f135817ce79.tar.gz
Merge branch 'master' of ssh://git.kolabsys.com/git/pykolab
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/xml/attendee.py20
-rw-r--r--pykolab/xml/event.py272
-rw-r--r--pykolab/xml/utils.py78
3 files changed, 106 insertions, 264 deletions
diff --git a/pykolab/xml/attendee.py b/pykolab/xml/attendee.py
index 15f1c1a..68e9d9b 100644
--- a/pykolab/xml/attendee.py
+++ b/pykolab/xml/attendee.py
@@ -26,7 +26,7 @@ class Attendee(kolabformat.Attendee):
"REQ-PARTICIPANT": kolabformat.Required,
"CHAIR": kolabformat.Chair,
"OPTIONAL": kolabformat.Optional,
- "NONPARTICIPANT": kolabformat.NonParticipant,
+ "NON-PARTICIPANT": kolabformat.NonParticipant,
}
rsvp_map = {
@@ -41,7 +41,8 @@ class Attendee(kolabformat.Attendee):
rsvp=False,
role=None,
participant_status=None,
- cutype=None
+ cutype=None,
+ ical_params=None
):
self.email = email
@@ -62,12 +63,18 @@ class Attendee(kolabformat.Attendee):
if not role == None:
self.set_role(role)
- if not participant_status == None:
- self.set_participant_status(participant_status)
-
if not cutype == None:
self.set_cutype(cutype)
+ if ical_params and ical_params.has_key('DELEGATED-FROM'):
+ self.delegate_from(Attendee(str(ical_params['DELEGATED-FROM'])))
+
+ if ical_params and ical_params.has_key('DELEGATED-TO'):
+ self.delegate_to(Attendee(str(ical_params['DELEGATED-TO'])))
+
+ if not participant_status == None:
+ self.set_participant_status(participant_status)
+
def delegate_from(self, delegators):
crefs = []
@@ -160,6 +167,9 @@ class Attendee(kolabformat.Attendee):
else:
raise InvalidAttendeeRoleError, _("Invalid role %r") % (role)
+ def set_rsvp(self, rsvp):
+ self.setRSVP(rsvp)
+
def __str__(self):
return self.email
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 2dea819..70dfea2 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -10,6 +10,7 @@ import uuid
import pykolab
from pykolab import constants
from pykolab import utils
+from pykolab.xml import utils as xmlutils
from pykolab.translate import _
from attendee import Attendee
@@ -44,8 +45,8 @@ class Event(object):
self.uid = self.get_uid()
- def add_attendee(self, email, name=None, rsvp=False, role=None, participant_status=None, cutype="INDIVIDUAL"):
- attendee = Attendee(email, name, rsvp, role, participant_status, cutype)
+ 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)
@@ -68,33 +69,7 @@ class Event(object):
if not valid_datetime:
raise InvalidEventDateError, _("Event start needs datetime.date or datetime.datetime instance")
- (
- year,
- month,
- day,
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- )
- if hasattr(_datetime, 'hour'):
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
- _cdatetime = kolabformat.cDateTime(year, month, day, hour, minute, second)
- else:
- _cdatetime = kolabformat.cDateTime(year, month, day)
-
- if hasattr(_datetime, "tzinfo"):
- _cdatetime.setTimezone(_datetime.tzinfo.__str__())
-
- self.event.addExceptionDate(_cdatetime)
+ self.event.addExceptionDate(xmlutils.to_cdatetime(_datetime, True))
def as_string_itip(self, method="REQUEST"):
cal = icalendar.Calendar()
@@ -252,69 +227,16 @@ class Event(object):
return self.classification()
def get_created(self):
- _datetime = self.event.created()
-
- (
- year,
- month,
- day,
- hour,
- minute,
- second
- ) = (
- _datetime.year(),
- _datetime.month(),
- _datetime.day(),
- _datetime.hour(),
- _datetime.minute(),
- _datetime.second()
- )
-
try:
- result = datetime.datetime(year, month, day, hour, minute, second)
+ return xmlutils.from_cdatetime(self.event.created(), False)
except ValueError:
- result = datetime.datetime.now()
+ return datetime.datetime.now()
def get_description(self):
return self.event.description()
def get_end(self):
- _datetime = self.event.end()
-
- (
- year,
- month,
- day,
- ) = (
- _datetime.year(),
- _datetime.month(),
- _datetime.day(),
- )
-
- if not _datetime.hour() == None and not _datetime.hour() < 0:
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour(),
- _datetime.minute(),
- _datetime.second()
- )
-
- _timezone = _datetime.timezone()
-
- if _timezone == '':
- _timezone = pytz.utc
- elif _timezone == None:
- _timezone = pytz.utc
- else:
- _timezone = pytz.timezone(_timezone)
-
- if _datetime.hour() == None or _datetime.hour() < 0:
- return datetime.date(year, month, day)
- else:
- return datetime.datetime(year, month, day, hour, minute, second, tzinfo=_timezone)
+ return xmlutils.from_cdatetime(self.event.end(), True)
def get_exception_dates(self):
return self.event.exceptionDates()
@@ -447,25 +369,7 @@ class Event(object):
except:
self.__str__()
- _datetime = self.event.lastModified()
-
- (
- year,
- month,
- day,
- hour,
- minute,
- second
- ) = (
- _datetime.year(),
- _datetime.month(),
- _datetime.day(),
- _datetime.hour(),
- _datetime.minute(),
- _datetime.second()
- )
-
- return datetime.datetime(year, month, day, hour, minute, second)
+ return xmlutils.from_cdatetime(self.event.lastModified(), False)
def get_organizer(self):
organizer = self.event.organizer()
@@ -475,42 +379,7 @@ class Event(object):
return str(self.event.priority())
def get_start(self):
- _datetime = self.event.start()
-
- (
- year,
- month,
- day,
- ) = (
- _datetime.year(),
- _datetime.month(),
- _datetime.day(),
- )
-
- if not _datetime.hour() == None and not _datetime.hour() < 0:
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour(),
- _datetime.minute(),
- _datetime.second()
- )
-
- _timezone = _datetime.timezone()
-
- if _timezone == '':
- _timezone = pytz.utc
- elif _timezone == None:
- _timezone = pytz.utc
- else:
- _timezone = pytz.timezone(_timezone)
-
- if _datetime.hour() == None or _datetime.hour() < 0:
- return datetime.date(year, month, day)
- else:
- return datetime.datetime(year, month, day, hour, minute, second, tzinfo=_timezone)
+ return xmlutils.from_cdatetime(self.event.start(), True)
def get_status(self):
status = self.event.status()
@@ -552,49 +421,13 @@ class Event(object):
if _datetime == None:
_datetime = datetime.datetime.now()
- (
- year,
- month,
- day,
- hour,
- minute,
- second
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
-
- self.event.setCreated(
- kolabformat.cDateTime(year, month, day, hour, minute, second)
- )
+ self.event.setCreated(xmlutils.to_cdatetime(_datetime, False))
def set_description(self, description):
self.event.setDescription(description)
def set_dtstamp(self, _datetime):
- (
- year,
- month,
- day,
- hour,
- minute,
- second
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
-
- self.event.setLastModified(
- kolabformat.cDateTime(year, month, day, hour, minute, second)
- )
+ self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False))
def set_end(self, _datetime):
valid_datetime = False
@@ -611,33 +444,7 @@ class Event(object):
if not valid_datetime:
raise InvalidEventDateError, _("Event end needs datetime.date or datetime.datetime instance")
- (
- year,
- month,
- day,
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- )
- if hasattr(_datetime, 'hour'):
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
- _cdatetime = kolabformat.cDateTime(year, month, day, hour, minute, second)
- else:
- _cdatetime = kolabformat.cDateTime(year, month, day)
-
- if hasattr(_datetime, "tzinfo"):
- _cdatetime.setTimezone(_datetime.tzinfo.__str__())
-
- self.event.setEnd(_cdatetime)
+ self.event.setEnd(xmlutils.to_cdatetime(_datetime, True))
def set_exception_dates(self, _datetimes):
for _datetime in _datetimes:
@@ -701,7 +508,7 @@ class Event(object):
else:
cutype = kolabformat.CutypeIndividual
- self.add_attendee(address, name=name, rsvp=rsvp, role=role, participant_status=partstat, cutype=cutype)
+ att = self.add_attendee(address, name=name, rsvp=rsvp, role=role, participant_status=partstat, cutype=cutype, params=params)
def set_ical_dtend(self, dtend):
self.set_end(dtend)
@@ -762,29 +569,7 @@ class Event(object):
if not valid_datetime:
raise InvalidEventDateError, _("Event start needs datetime.date or datetime.datetime instance")
- (
- year,
- month,
- day,
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- )
- if hasattr(_datetime, 'hour'):
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
- else:
- (hour, minute, second) = (0,0,0)
-
- self.event.setLastModified(kolabformat.cDateTime(year, month, day, hour, minute, second))
+ self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False))
def set_location(self, location):
self.event.setLocation(location)
@@ -806,7 +591,6 @@ class Event(object):
self.event.setRecurrenceRule(recurrence)
def set_start(self, _datetime):
-
valid_datetime = False
if isinstance(_datetime, datetime.date):
valid_datetime = True
@@ -821,33 +605,7 @@ class Event(object):
if not valid_datetime:
raise InvalidEventDateError, _("Event start needs datetime.date or datetime.datetime instance")
- (
- year,
- month,
- day,
- ) = (
- _datetime.year,
- _datetime.month,
- _datetime.day,
- )
- if hasattr(_datetime, 'hour'):
- (
- hour,
- minute,
- second
- ) = (
- _datetime.hour,
- _datetime.minute,
- _datetime.second
- )
- _cdatetime = kolabformat.cDateTime(year, month, day, hour, minute, second)
- else:
- _cdatetime = kolabformat.cDateTime(year, month, day)
-
- if hasattr(_datetime, "tzinfo"):
- _cdatetime.setTimezone(_datetime.tzinfo.__str__())
-
- self.event.setStart(_cdatetime)
+ self.event.setStart(xmlutils.to_cdatetime(_datetime, True))
def set_status(self, status):
if status in self.status_map.keys():
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index 0959c80..c09da54 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -1,19 +1,93 @@
import datetime
import pytz
+import kolabformat
def to_dt(dt):
"""
Convert a naive date or datetime to a tz-aware datetime.
"""
- if type(dt) == 'datetime.date' or not hasattr(dt, 'hour'):
+ if isinstance(dt, datetime.date) or not hasattr(dt, 'hour'):
dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0)
else:
if dt.tzinfo == None:
return dt.replace(tzinfo=pytz.utc)
+
+ return dt
+
+
+def from_cdatetime(_cdatetime, with_timezone=True):
+ """
+ Convert from kolabformat.cDateTime to datetime.date(time)
+ """
+ (
+ year,
+ month,
+ day,
+ ) = (
+ _cdatetime.year(),
+ _cdatetime.month(),
+ _cdatetime.day(),
+ )
+
+ if _cdatetime.hour() == None or _cdatetime.hour() < 0:
+ return datetime.date(year, month, day)
+
+ (
+ hour,
+ minute,
+ second
+ ) = (
+ _cdatetime.hour(),
+ _cdatetime.minute(),
+ _cdatetime.second()
+ )
+
+ if with_timezone:
+ _timezone = _cdatetime.timezone()
+
+ if _timezone == '' or _timezone == None:
+ _timezone = pytz.utc
else:
+ _timezone = pytz.timezone(_timezone)
- return dt
+ return datetime.datetime(year, month, day, hour, minute, second, tzinfo=_timezone)
+
+ else:
+ return datetime.datetime(year, month, day, hour, minute, second)
+
+
+def to_cdatetime(_datetime, with_timezone=True):
+ """
+ Convert a datetime.dateime object into a kolabformat.cDateTime instance
+ """
+ (
+ year,
+ month,
+ day,
+ ) = (
+ _datetime.year,
+ _datetime.month,
+ _datetime.day,
+ )
+
+ if hasattr(_datetime, 'hour'):
+ (
+ hour,
+ minute,
+ second
+ ) = (
+ _datetime.hour,
+ _datetime.minute,
+ _datetime.second
+ )
+ _cdatetime = kolabformat.cDateTime(year, month, day, hour, minute, second)
+
+ else:
+ _cdatetime = kolabformat.cDateTime(year, month, day)
+ if with_timezone and hasattr(_datetime, "tzinfo"):
+ _cdatetime.setTimezone(_datetime.tzinfo.__str__())
+ return _cdatetime