summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-08-21 07:14:10 -0400
committerThomas Bruederli <bruederli@kolabsys.com>2014-08-21 07:14:10 -0400
commitc5978eb22295fea9a09066dc177a5d167c58fb2c (patch)
treedab5a544a81dfb3a9a2a6dda34fd5a43fdb88b80
parentb87c86a62e3157de9ee17917783f74dc3b0d756c (diff)
downloadpykolab-c5978eb22295fea9a09066dc177a5d167c58fb2c.tar.gz
Make sure created and last-modified dates are saved in UTC; add folder type property to groupware objects
-rw-r--r--pykolab/xml/contact.py2
-rw-r--r--pykolab/xml/event.py14
-rw-r--r--pykolab/xml/todo.py1
-rw-r--r--pykolab/xml/utils.py13
4 files changed, 23 insertions, 7 deletions
diff --git a/pykolab/xml/contact.py b/pykolab/xml/contact.py
index 9a2c103..97987d9 100644
--- a/pykolab/xml/contact.py
+++ b/pykolab/xml/contact.py
@@ -1,6 +1,8 @@
import kolabformat
class Contact(kolabformat.Contact):
+ type = 'contact'
+
def __init__(self, *args, **kw):
kolabformat.Contact.__init__(self, *args, **kw)
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 34f857a..24b026e 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -43,6 +43,8 @@ def event_from_message(message):
class Event(object):
+ type = 'event'
+
status_map = {
"TENTATIVE": kolabformat.StatusTentative,
"CONFIRMED": kolabformat.StatusConfirmed,
@@ -612,9 +614,9 @@ class Event(object):
def set_created(self, _datetime=None):
if _datetime == None:
- _datetime = datetime.datetime.now()
+ _datetime = datetime.datetime.utcnow()
- self.event.setCreated(xmlutils.to_cdatetime(_datetime, False))
+ self.event.setCreated(xmlutils.to_cdatetime(_datetime, False, True))
def set_description(self, description):
self.event.setDescription(str(description))
@@ -624,7 +626,7 @@ class Event(object):
self.event.setComment(str(comment))
def set_dtstamp(self, _datetime):
- self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False))
+ self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False, True))
def set_end(self, _datetime):
valid_datetime = False
@@ -771,12 +773,12 @@ class Event(object):
if _datetime == None:
valid_datetime = True
- _datetime = datetime.datetime.now()
+ _datetime = datetime.datetime.utcnow()
if not valid_datetime:
raise InvalidEventDateError, _("Event start needs datetime.date or datetime.datetime instance")
- self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False))
+ self.event.setLastModified(xmlutils.to_cdatetime(_datetime, False, True))
def set_location(self, location):
self.event.setLocation(str(location))
@@ -938,7 +940,7 @@ class Event(object):
msg['Date'] = formatdate(localtime=True)
msg.add_header('X-Kolab-MIME-Version', '3.0')
- msg.add_header('X-Kolab-Type', 'application/x-vnd.kolab.event')
+ msg.add_header('X-Kolab-Type', 'application/x-vnd.kolab.' + self.type)
text = utils.multiline_message("""
This is a Kolab Groupware object. To view this object you
diff --git a/pykolab/xml/todo.py b/pykolab/xml/todo.py
index 28a7b4d..b04b233 100644
--- a/pykolab/xml/todo.py
+++ b/pykolab/xml/todo.py
@@ -34,6 +34,7 @@ def todo_from_message(message):
# FIXME: extend a generic pykolab.xml.Xcal class instead of Event
class Todo(Event):
+ type = 'task'
def __init__(self, from_ical="", from_string=""):
self._attendees = []
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index bcaa480..aa05e11 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -62,10 +62,18 @@ def from_cdatetime(_cdatetime, with_timezone=True):
return datetime.datetime(year, month, day, hour, minute, second)
-def to_cdatetime(_datetime, with_timezone=True):
+def to_cdatetime(_datetime, with_timezone=True, as_utc=False):
"""
Convert a datetime.dateime object into a kolabformat.cDateTime instance
"""
+ # convert date into UTC timezone
+ if as_utc and hasattr(_datetime, "tzinfo"):
+ if _datetime.tzinfo is not None:
+ _datetime = _datetime.astimezone(pytz.utc)
+ else:
+ datetime = _datetime.replace(tzinfo=pytz.utc)
+ with_timezone = False
+
(
year,
month,
@@ -97,4 +105,7 @@ def to_cdatetime(_datetime, with_timezone=True):
else:
_cdatetime.setTimezone(_datetime.tzinfo.__str__())
+ if as_utc:
+ _cdatetime.setUTC(True)
+
return _cdatetime