1.1 --- a/imiptools/client.py Tue Dec 20 16:43:44 2016 +0100
1.2 +++ b/imiptools/client.py Tue Dec 20 23:21:56 2016 +0100
1.3 @@ -22,8 +22,9 @@
1.4 from datetime import datetime, timedelta
1.5 from imiptools import config
1.6 from imiptools.data import Object, check_delegation, get_address, get_uri, \
1.7 - get_window_end, is_new_object, make_freebusy, to_part, \
1.8 - uri_dict, uri_item, uri_items, uri_parts, uri_values
1.9 + get_window_end, is_new_object, make_freebusy, \
1.10 + make_uid, to_part, uri_dict, uri_item, uri_items, \
1.11 + uri_parts, uri_values
1.12 from imiptools.dates import check_permitted_values, format_datetime, get_default_timezone, \
1.13 get_duration, get_timestamp
1.14 from imiptools.i18n import get_translator
1.15 @@ -263,8 +264,7 @@
1.16
1.17 # Invent a unique identifier.
1.18
1.19 - utcnow = get_timestamp()
1.20 - uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user))
1.21 + uid = make_uid(self.user)
1.22
1.23 freebusy = freebusy or self.store.get_freebusy(self.user)
1.24
2.1 --- a/imiptools/data.py Tue Dec 20 16:43:44 2016 +0100
2.2 +++ b/imiptools/data.py Tue Dec 20 23:21:56 2016 +0100
2.3 @@ -27,8 +27,8 @@
2.4 get_datetime_tzid, \
2.5 get_duration, get_period, get_period_item, \
2.6 get_recurrence_start_point, \
2.7 - get_time, get_tzid, to_datetime, to_timezone, \
2.8 - to_utc_datetime
2.9 + get_time, get_timestamp, get_tzid, to_datetime, \
2.10 + to_timezone, to_utc_datetime
2.11 from imiptools.period import FreeBusyPeriod, Period, RecurringPeriod
2.12 from vCalendar import iterwrite, parse, ParseError, to_dict, to_node
2.13 from vRecurrence import get_parameters, get_rule
2.14 @@ -61,6 +61,10 @@
2.15 Then, the specific object must be presented as follows:
2.16
2.17 object = Object({"VEVENT" : event})
2.18 +
2.19 + A convienience function is also provided to initialise objects:
2.20 +
2.21 + object = new_object("VEVENT")
2.22 """
2.23
2.24 self.objtype, (self.details, self.attr) = fragment.items()[0]
2.25 @@ -119,8 +123,19 @@
2.26
2.27 # Structure access.
2.28
2.29 + def add(self, obj):
2.30 +
2.31 + "Add 'obj' to the structure."
2.32 +
2.33 + name = obj.objtype
2.34 + if not self.details.has_key(name):
2.35 + l = self.details[name] = []
2.36 + else:
2.37 + l = self.details[name]
2.38 + l.append((obj.details, obj.attr))
2.39 +
2.40 def copy(self):
2.41 - return Object(to_dict(self.to_node()))
2.42 + return Object(self.to_dict())
2.43
2.44 def get_items(self, name, all=True):
2.45 return get_items(self.details, name, all)
2.46 @@ -163,6 +178,9 @@
2.47
2.48 # Serialisation.
2.49
2.50 + def to_dict(self):
2.51 + return to_dict(self.to_node())
2.52 +
2.53 def to_node(self):
2.54 return to_node({self.objtype : [(self.details, self.attr)]})
2.55
2.56 @@ -714,6 +732,19 @@
2.57 finally:
2.58 out.close()
2.59
2.60 +def new_object(object_type):
2.61 +
2.62 + "Make a new object of the given 'object_type'."
2.63 +
2.64 + return Object({object_type : ({}, {})})
2.65 +
2.66 +def make_uid(user):
2.67 +
2.68 + "Return a unique identifier for a new object by the given 'user'."
2.69 +
2.70 + utcnow = get_timestamp()
2.71 + return "imip-agent-%s-%s" % (utcnow, get_address(user))
2.72 +
2.73 # Structure access functions.
2.74
2.75 def get_items(d, name, all=True):
3.1 --- a/imipweb/calendar.py Tue Dec 20 16:43:44 2016 +0100
3.2 +++ b/imipweb/calendar.py Tue Dec 20 23:21:56 2016 +0100
3.3 @@ -20,7 +20,8 @@
3.4 """
3.5
3.6 from datetime import datetime, timedelta
3.7 -from imiptools.data import get_address, get_uri, get_verbose_address, uri_parts
3.8 +from imiptools.data import get_address, get_uri, get_verbose_address, make_uid, \
3.9 + uri_parts
3.10 from imiptools.dates import format_datetime, get_date, get_datetime, \
3.11 get_datetime_item, get_end_of_day, get_start_of_day, \
3.12 get_start_of_next_day, get_timestamp, ends_on_same_day, \
3.13 @@ -118,8 +119,7 @@
3.14
3.15 # Invent a unique identifier.
3.16
3.17 - utcnow = get_timestamp()
3.18 - uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user))
3.19 + uid = make_uid(self.user)
3.20
3.21 # Create a calendar object and store it as a request.
3.22