1.1 --- a/imipweb/event.py Sat May 16 20:03:34 2015 +0200
1.2 +++ b/imipweb/event.py Sun May 17 00:14:36 2015 +0200
1.3 @@ -23,7 +23,7 @@
1.4 from imiptools.client import update_attendees, update_participation
1.5 from imiptools.data import get_uri, uri_dict, uri_values
1.6 from imiptools.dates import format_datetime, to_date, get_datetime, \
1.7 - get_datetime_item, get_period_item, \
1.8 + get_datetime_item, get_period_item, to_datetime, \
1.9 to_recurrence_start, to_timezone, to_utc_datetime
1.10 from imiptools.mail import Messenger
1.11 from imiptools.period import have_conflict
1.12 @@ -64,33 +64,35 @@
1.13 def is_organiser(self, obj):
1.14 return get_uri(obj.get_value("ORGANIZER")) == self.user
1.15
1.16 - def get_recurrence_key(self, period):
1.17 - return format_datetime(to_utc_datetime(period.get_start(), self.get_tzid()))
1.18 -
1.19 - def get_recurrence_keys(self, recurrenceids):
1.20 - return [to_recurrence_start(s, self.get_tzid()) for s in recurrenceids]
1.21 -
1.22 - def is_replaced(self, period, recurrenceid, recurrenceids):
1.23 - start_utc = self.get_recurrence_key(period)
1.24 - return not recurrenceid and recurrenceids and start_utc in self.get_recurrence_keys(recurrenceids) and "replaced" or ""
1.25 + def is_replaced(self, period, recurrenceids):
1.26 + for s in recurrenceids:
1.27 + dt = to_timezone(get_datetime(s), self.get_tzid())
1.28 + if to_datetime(period.get_start(), self.get_tzid()) == dt:
1.29 + return s
1.30 + return None
1.31
1.32 def is_affected(self, period, recurrenceid):
1.33 - start_utc = self.get_recurrence_key(period)
1.34 - return recurrenceid and start_utc == to_recurrence_start(recurrenceid, self.get_tzid()) and "affected" or ""
1.35 + if not recurrenceid:
1.36 + return None
1.37 + dt = to_timezone(get_datetime(recurrenceid), self.get_tzid())
1.38 + if to_datetime(period.get_start(), self.get_tzid()) == dt:
1.39 + return recurrenceid
1.40 + return None
1.41
1.42 # Request logic methods.
1.43
1.44 - def handle_request(self, uid, recurrenceid, obj):
1.45 + def handle_request(self, obj):
1.46
1.47 """
1.48 - Handle actions involving the given 'uid', 'recurrenceid', and 'obj' as
1.49 - the object's representation, returning an error if one occurred, or None
1.50 - if the request was successfully handled.
1.51 + Handle actions involving the given 'obj' as an object's representation,
1.52 + returning an error if one occurred, or None if the request was
1.53 + successfully handled.
1.54 """
1.55
1.56 # Handle a submitted form.
1.57
1.58 args = self.env.get_args()
1.59 + uid = obj.get_uid()
1.60
1.61 # Get the possible actions.
1.62
1.63 @@ -477,7 +479,7 @@
1.64
1.65 attendees = self.get_current_attendees(obj)
1.66 is_attendee = self.user in attendees
1.67 - is_request = (obj.get_value("UID"), obj.get_value("RECURRENCE-ID")) in self._get_requests()
1.68 + is_request = (obj.get_uid(), obj.get_recurrenceid()) in self._get_requests()
1.69 sequence = obj.get_value("SEQUENCE")
1.70
1.71 # Show appropriate options depending on the role of the user.
1.72 @@ -509,12 +511,12 @@
1.73 self._control("save", "submit", "Save without sending")
1.74 page.p.close()
1.75
1.76 - def show_object_on_page(self, uid, obj, errors=None):
1.77 + def show_object_on_page(self, obj, errors=None):
1.78
1.79 """
1.80 - Show the calendar object with the given 'uid' and representation 'obj'
1.81 - on the current page. If 'errors' is given, show a suitable message for
1.82 - the different errors provided.
1.83 + Show the calendar object with the representation 'obj' on the current
1.84 + page. If 'errors' is given, show a suitable message for the different
1.85 + errors provided.
1.86 """
1.87
1.88 page = self.page
1.89 @@ -522,6 +524,7 @@
1.90
1.91 self._control("editing", "hidden", "true")
1.92
1.93 + uid = obj.get_uid()
1.94 args = self.env.get_args()
1.95
1.96 # Obtain basic event information, generating any necessary editing controls.
1.97 @@ -538,9 +541,9 @@
1.98
1.99 # Obtain any separate recurrences for this event.
1.100
1.101 - recurrenceid = format_datetime(obj.get_utc_datetime("RECURRENCE-ID"))
1.102 + recurrenceid = obj.get_recurrenceid()
1.103 recurrenceids = self._get_recurrences(uid)
1.104 - replaced = self.is_replaced(p, recurrenceid, recurrenceids)
1.105 + replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
1.106
1.107 # Provide a summary of the object.
1.108
1.109 @@ -583,7 +586,7 @@
1.110
1.111 elif name == "DTSTART":
1.112 page.td(class_="objectvalue %s replaced" % field, rowspan=2)
1.113 - page.a("First occurrence replaced by a separate event", href=self.link_to(uid, self.get_recurrence_key(p)))
1.114 + page.a("First occurrence replaced by a separate event", href=self.link_to(uid, replaced))
1.115 page.td.close()
1.116
1.117 page.tr.close()
1.118 @@ -650,7 +653,7 @@
1.119 page.table.close()
1.120
1.121 self.show_recurrences(obj, errors)
1.122 - self.show_conflicting_events(uid, obj)
1.123 + self.show_conflicting_events(obj)
1.124 self.show_request_controls(obj)
1.125
1.126 page.form.close()
1.127 @@ -721,8 +724,8 @@
1.128
1.129 # Obtain any parent object if this object is a specific recurrence.
1.130
1.131 - uid = obj.get_value("UID")
1.132 - recurrenceid = format_datetime(obj.get_utc_datetime("RECURRENCE-ID"))
1.133 + uid = obj.get_uid()
1.134 + recurrenceid = obj.get_recurrenceid()
1.135
1.136 if recurrenceid:
1.137 parent = self._get_object(uid)
1.138 @@ -792,7 +795,7 @@
1.139 sequence = obj.get_value("SEQUENCE")
1.140
1.141 p = event_period_from_period(period)
1.142 - replaced = self.is_replaced(p, recurrenceid, recurrenceids)
1.143 + replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
1.144
1.145 # Isolate the controls from neighbouring tables.
1.146
1.147 @@ -838,15 +841,15 @@
1.148
1.149 page.div.close()
1.150
1.151 - def show_conflicting_events(self, uid, obj):
1.152 + def show_conflicting_events(self, obj):
1.153
1.154 """
1.155 - Show conflicting events for the object having the given 'uid' and
1.156 - representation 'obj'.
1.157 + Show conflicting events for the object having the representation 'obj'.
1.158 """
1.159
1.160 page = self.page
1.161 - recurrenceid = format_datetime(obj.get_utc_datetime("RECURRENCE-ID"))
1.162 + uid = obj.get_uid()
1.163 + recurrenceid = obj.get_recurrenceid()
1.164 recurrenceids = self._get_recurrences(uid)
1.165
1.166 # Obtain the user's timezone.
1.167 @@ -875,7 +878,7 @@
1.168 # Show any conflicts with periods of actual attendance.
1.169
1.170 for p in have_conflict(freebusy, periods, True):
1.171 - if self.is_replaced(p, recurrenceid, recurrenceids):
1.172 + if not recurrenceid and self.is_replaced(p, recurrenceids):
1.173 continue
1.174 if (p.uid != uid or (recurrenceid and p.recurrenceid) and p.recurrenceid != recurrenceid) and p.transp != "ORG":
1.175 conflicts.append(p)
1.176 @@ -901,8 +904,8 @@
1.177
1.178 # Provide details of any conflicting event.
1.179
1.180 - start = self.format_datetime(p.get_start(tzid), "long")
1.181 - end = self.format_datetime(p.get_end(tzid), "long")
1.182 + start = self.format_datetime(to_timezone(p.get_start(), tzid), "long")
1.183 + end = self.format_datetime(to_timezone(p.get_end(), tzid), "long")
1.184
1.185 page.tr()
1.186
1.187 @@ -1036,7 +1039,7 @@
1.188 ssn = self._simple_suffixed_name
1.189
1.190 p = event_period_from_period(period)
1.191 - replaced = self.is_replaced(p, recurrenceid, recurrenceids)
1.192 + replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
1.193
1.194 # Show controls for editing as organiser.
1.195
1.196 @@ -1091,11 +1094,11 @@
1.197 page = self.page
1.198
1.199 p = event_period_from_period(period)
1.200 - replaced = self.is_replaced(p, recurrenceid, recurrenceids)
1.201 + replaced = not recurrenceid and self.is_replaced(p, recurrenceids)
1.202
1.203 css = " ".join([
1.204 - replaced,
1.205 - self.is_affected(p, recurrenceid)
1.206 + replaced and "replaced" or "",
1.207 + self.is_affected(p, recurrenceid) and "affected" or ""
1.208 ])
1.209
1.210 formdate = show_start and p.get_form_start() or p.get_form_end()
1.211 @@ -1117,13 +1120,13 @@
1.212 if not obj:
1.213 return False
1.214
1.215 - errors = self.handle_request(uid, recurrenceid, obj)
1.216 + errors = self.handle_request(obj)
1.217
1.218 if not errors:
1.219 return True
1.220
1.221 self.new_page(title="Event")
1.222 - self.show_object_on_page(uid, obj, errors)
1.223 + self.show_object_on_page(obj, errors)
1.224
1.225 return True
1.226