paul@446 | 1 | #!/usr/bin/env python |
paul@446 | 2 | |
paul@446 | 3 | """ |
paul@446 | 4 | A Web interface to a calendar event. |
paul@446 | 5 | |
paul@1244 | 6 | Copyright (C) 2014, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> |
paul@446 | 7 | |
paul@446 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@446 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@446 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@446 | 11 | version. |
paul@446 | 12 | |
paul@446 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@446 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@446 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@446 | 16 | details. |
paul@446 | 17 | |
paul@446 | 18 | You should have received a copy of the GNU General Public License along with |
paul@446 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@446 | 20 | """ |
paul@446 | 21 | |
paul@838 | 22 | from imiptools.data import get_uri, get_verbose_address, uri_dict, uri_items, \ |
paul@838 | 23 | uri_parts, uri_values |
paul@777 | 24 | from imiptools.dates import format_datetime, to_timezone |
paul@446 | 25 | from imiptools.mail import Messenger |
paul@1244 | 26 | from imipweb.data import EventPeriod, event_period_from_period, \ |
paul@1245 | 27 | get_period_control_values, set_period_control_values, \ |
paul@1245 | 28 | PeriodError |
paul@765 | 29 | from imipweb.resource import DateTimeFormUtilities, FormUtilities, ResourceClientForObject |
paul@446 | 30 | |
paul@1008 | 31 | # Fake gettext method for strings to be translated later. |
paul@1008 | 32 | |
paul@1008 | 33 | _ = lambda s: s |
paul@1008 | 34 | |
paul@765 | 35 | class EventPageFragment(ResourceClientForObject, DateTimeFormUtilities, FormUtilities): |
paul@446 | 36 | |
paul@765 | 37 | "A resource presenting the details of an event." |
paul@765 | 38 | |
paul@765 | 39 | def __init__(self, resource=None): |
paul@756 | 40 | ResourceClientForObject.__init__(self, resource) |
paul@446 | 41 | |
paul@474 | 42 | # Various property values and labels. |
paul@474 | 43 | |
paul@474 | 44 | property_items = [ |
paul@1008 | 45 | ("SUMMARY", _("Summary")), |
paul@1008 | 46 | ("DTSTART", _("Start")), |
paul@1008 | 47 | ("DTEND", _("End")), |
paul@1008 | 48 | ("ORGANIZER", _("Organiser")), |
paul@1008 | 49 | ("ATTENDEE", _("Attendee")), |
paul@474 | 50 | ] |
paul@474 | 51 | |
paul@474 | 52 | partstat_items = [ |
paul@1008 | 53 | ("NEEDS-ACTION", _("Not confirmed")), |
paul@1008 | 54 | ("ACCEPTED", _("Attending")), |
paul@1008 | 55 | ("TENTATIVE", _("Tentatively attending")), |
paul@1008 | 56 | ("DECLINED", _("Not attending")), |
paul@1008 | 57 | ("DELEGATED", _("Delegated")), |
paul@1008 | 58 | (None, _("Not indicated")), |
paul@474 | 59 | ] |
paul@474 | 60 | |
paul@780 | 61 | def can_remove_recurrence(self, recurrence): |
paul@780 | 62 | |
paul@780 | 63 | """ |
paul@780 | 64 | Return whether the 'recurrence' can be removed from the current object |
paul@780 | 65 | without notification. |
paul@780 | 66 | """ |
paul@780 | 67 | |
paul@867 | 68 | return (self.can_edit_recurrence(recurrence) or not self.is_organiser()) and \ |
paul@854 | 69 | recurrence.origin != "RRULE" |
paul@784 | 70 | |
paul@784 | 71 | def can_edit_recurrence(self, recurrence): |
paul@784 | 72 | |
paul@784 | 73 | "Return whether 'recurrence' can be edited." |
paul@784 | 74 | |
paul@780 | 75 | return self.recurrence_is_new(recurrence) or not self.obj.is_shared() |
paul@780 | 76 | |
paul@780 | 77 | def recurrence_is_new(self, recurrence): |
paul@780 | 78 | |
paul@780 | 79 | "Return whether 'recurrence' is new to the current object." |
paul@780 | 80 | |
paul@780 | 81 | return recurrence not in self.get_stored_recurrences() |
paul@619 | 82 | |
paul@758 | 83 | def can_remove_attendee(self, attendee): |
paul@758 | 84 | |
paul@758 | 85 | """ |
paul@758 | 86 | Return whether 'attendee' can be removed from the current object without |
paul@758 | 87 | notification. |
paul@758 | 88 | """ |
paul@758 | 89 | |
paul@867 | 90 | return self.can_edit_attendee(attendee) or attendee == self.user and self.is_organiser() |
paul@758 | 91 | |
paul@758 | 92 | def can_edit_attendee(self, attendee): |
paul@758 | 93 | |
paul@758 | 94 | "Return whether 'attendee' can be edited by an organiser." |
paul@758 | 95 | |
paul@758 | 96 | return self.attendee_is_new(attendee) or not self.obj.is_shared() |
paul@758 | 97 | |
paul@758 | 98 | def attendee_is_new(self, attendee): |
paul@758 | 99 | |
paul@758 | 100 | "Return whether 'attendee' is new to the current object." |
paul@758 | 101 | |
paul@795 | 102 | return attendee not in uri_values(self.get_stored_attendees()) |
paul@758 | 103 | |
paul@765 | 104 | # Access to stored object information. |
paul@477 | 105 | |
paul@765 | 106 | def get_stored_attendees(self): |
paul@794 | 107 | return [get_verbose_address(value, attr) for value, attr in self.obj.get_items("ATTENDEE") or []] |
paul@477 | 108 | |
paul@765 | 109 | def get_stored_main_period(self): |
paul@477 | 110 | |
paul@765 | 111 | "Return the main event period for the current object." |
paul@477 | 112 | |
paul@879 | 113 | (dtstart, dtstart_attr), (dtend, dtend_attr) = self.obj.get_main_period_items() |
paul@765 | 114 | return EventPeriod(dtstart, dtend, self.get_tzid(), None, dtstart_attr, dtend_attr) |
paul@477 | 115 | |
paul@765 | 116 | def get_stored_recurrences(self): |
paul@765 | 117 | |
paul@765 | 118 | "Return recurrences computed using the current object." |
paul@485 | 119 | |
paul@868 | 120 | recurrenceids = self._get_recurrences(self.uid) |
paul@765 | 121 | recurrences = [] |
paul@765 | 122 | for period in self.get_periods(self.obj): |
paul@868 | 123 | period = event_period_from_period(period) |
paul@868 | 124 | period.replaced = period.is_replaced(recurrenceids) |
paul@765 | 125 | if period.origin != "DTSTART": |
paul@765 | 126 | recurrences.append(period) |
paul@765 | 127 | return recurrences |
paul@757 | 128 | |
paul@765 | 129 | # Access to current object information. |
paul@496 | 130 | |
paul@765 | 131 | def get_current_main_period(self): |
paul@765 | 132 | return self.get_stored_main_period() |
paul@757 | 133 | |
paul@765 | 134 | def get_current_recurrences(self): |
paul@765 | 135 | return self.get_stored_recurrences() |
paul@477 | 136 | |
paul@765 | 137 | def get_current_attendees(self): |
paul@765 | 138 | return self.get_stored_attendees() |
paul@477 | 139 | |
paul@446 | 140 | # Page fragment methods. |
paul@446 | 141 | |
paul@756 | 142 | def show_request_controls(self): |
paul@446 | 143 | |
paul@756 | 144 | "Show form controls for a request." |
paul@446 | 145 | |
paul@1005 | 146 | _ = self.get_translator() |
paul@1005 | 147 | |
paul@446 | 148 | page = self.page |
paul@446 | 149 | args = self.env.get_args() |
paul@446 | 150 | |
paul@794 | 151 | attendees = uri_values(self.get_current_attendees()) |
paul@446 | 152 | is_attendee = self.user in attendees |
paul@446 | 153 | |
paul@801 | 154 | if not self.obj.is_shared(): |
paul@1005 | 155 | page.p(_("This event has not been shared.")) |
paul@801 | 156 | |
paul@446 | 157 | # Show appropriate options depending on the role of the user. |
paul@446 | 158 | |
paul@756 | 159 | if is_attendee and not self.is_organiser(): |
paul@1005 | 160 | page.p(_("An action is required for this request:")) |
paul@446 | 161 | |
paul@446 | 162 | page.p() |
paul@1005 | 163 | self.control("reply", "submit", _("Send reply")) |
paul@446 | 164 | page.add(" ") |
paul@1005 | 165 | self.control("discard", "submit", _("Discard event")) |
paul@446 | 166 | page.add(" ") |
paul@1005 | 167 | self.control("ignore", "submit", _("Return to the calendar"), class_="ignore") |
paul@446 | 168 | page.p.close() |
paul@446 | 169 | |
paul@756 | 170 | if self.is_organiser(): |
paul@1005 | 171 | page.p(_("As organiser, you can perform the following:")) |
paul@446 | 172 | |
paul@512 | 173 | page.p() |
paul@1005 | 174 | self.control("create", "submit", _("Update event")) |
paul@512 | 175 | page.add(" ") |
paul@512 | 176 | |
paul@841 | 177 | if self._get_counters(self.uid, self.recurrenceid): |
paul@1005 | 178 | self.control("uncounter", "submit", _("Ignore counter-proposals")) |
paul@841 | 179 | page.add(" ") |
paul@841 | 180 | |
paul@818 | 181 | if self.obj.is_shared() and not self._is_request(): |
paul@1005 | 182 | self.control("cancel", "submit", _("Cancel event")) |
paul@446 | 183 | else: |
paul@1005 | 184 | self.control("discard", "submit", _("Discard event")) |
paul@512 | 185 | |
paul@512 | 186 | page.add(" ") |
paul@1005 | 187 | self.control("ignore", "submit", _("Return to the calendar"), class_="ignore") |
paul@841 | 188 | page.add(" ") |
paul@1005 | 189 | self.control("save", "submit", _("Save without sending")) |
paul@512 | 190 | page.p.close() |
paul@446 | 191 | |
paul@756 | 192 | def show_object_on_page(self, errors=None): |
paul@446 | 193 | |
paul@446 | 194 | """ |
paul@756 | 195 | Show the calendar object on the current page. If 'errors' is given, show |
paul@756 | 196 | a suitable message for the different errors provided. |
paul@446 | 197 | """ |
paul@446 | 198 | |
paul@1005 | 199 | _ = self.get_translator() |
paul@1005 | 200 | |
paul@446 | 201 | page = self.page |
paul@446 | 202 | page.form(method="POST") |
paul@1162 | 203 | self.validator() |
paul@446 | 204 | |
paul@595 | 205 | # Add a hidden control to help determine whether editing has already begun. |
paul@595 | 206 | |
paul@764 | 207 | self.control("editing", "hidden", "true") |
paul@446 | 208 | |
paul@446 | 209 | args = self.env.get_args() |
paul@446 | 210 | |
paul@487 | 211 | # Obtain basic event information, generating any necessary editing controls. |
paul@446 | 212 | |
paul@787 | 213 | attendees = self.get_current_attendees() |
paul@765 | 214 | period = self.get_current_main_period() |
paul@834 | 215 | stored_period = self.get_stored_main_period() |
paul@765 | 216 | self.show_object_datetime_controls(period) |
paul@446 | 217 | |
paul@487 | 218 | # Obtain any separate recurrences for this event. |
paul@487 | 219 | |
paul@868 | 220 | recurrenceids = self._get_recurrences(self.uid) |
paul@765 | 221 | replaced = not self.recurrenceid and period.is_replaced(recurrenceids) |
paul@834 | 222 | excluded = period == stored_period and period not in self.get_periods(self.obj) |
paul@487 | 223 | |
paul@446 | 224 | # Provide a summary of the object. |
paul@446 | 225 | |
paul@446 | 226 | page.table(class_="object", cellspacing=5, cellpadding=5) |
paul@446 | 227 | page.thead() |
paul@446 | 228 | page.tr() |
paul@1005 | 229 | page.th(_("Event"), class_="mainheading", colspan=3) |
paul@446 | 230 | page.tr.close() |
paul@446 | 231 | page.thead.close() |
paul@446 | 232 | page.tbody() |
paul@446 | 233 | |
paul@446 | 234 | for name, label in self.property_items: |
paul@446 | 235 | field = name.lower() |
paul@446 | 236 | |
paul@757 | 237 | items = uri_items(self.obj.get_items(name) or []) |
paul@446 | 238 | rowspan = len(items) |
paul@446 | 239 | |
paul@843 | 240 | # Adjust rowspan for add button rows. |
paul@843 | 241 | # Skip properties without items apart from attendee (where items |
paul@843 | 242 | # may be added) and the end datetime (which might be described by a |
paul@843 | 243 | # duration property). |
paul@843 | 244 | |
paul@843 | 245 | if name in "ATTENDEE": |
paul@843 | 246 | rowspan = len(attendees) + 1 |
paul@843 | 247 | elif name == "DTEND": |
paul@867 | 248 | rowspan = 2 |
paul@446 | 249 | elif not items: |
paul@446 | 250 | continue |
paul@446 | 251 | |
paul@446 | 252 | page.tr() |
paul@1008 | 253 | page.th(_(label), class_="objectheading %s%s" % (field, errors and field in errors and " error" or ""), rowspan=rowspan) |
paul@446 | 254 | |
paul@446 | 255 | # Handle datetimes specially. |
paul@446 | 256 | |
paul@843 | 257 | if name in ("DTSTART", "DTEND"): |
paul@784 | 258 | if not replaced and not excluded: |
paul@446 | 259 | |
paul@487 | 260 | # Obtain the datetime. |
paul@487 | 261 | |
paul@498 | 262 | is_start = name == "DTSTART" |
paul@446 | 263 | |
paul@487 | 264 | # Where no end datetime exists, use the start datetime as the |
paul@487 | 265 | # basis of any potential datetime specified if dt-control is |
paul@487 | 266 | # set. |
paul@487 | 267 | |
paul@765 | 268 | self.show_datetime_controls(is_start and period.get_form_start() or period.get_form_end(), is_start) |
paul@446 | 269 | |
paul@487 | 270 | elif name == "DTSTART": |
paul@784 | 271 | |
paul@784 | 272 | # Replaced occurrences link to their replacements. |
paul@784 | 273 | |
paul@784 | 274 | if replaced: |
paul@920 | 275 | page.td(class_="objectvalue %s replaced" % field, rowspan=2, colspan=2) |
paul@1005 | 276 | page.a(_("First occurrence replaced by a separate event"), href=self.link_to(self.uid, replaced)) |
paul@784 | 277 | page.td.close() |
paul@784 | 278 | |
paul@784 | 279 | # NOTE: Should provide a way of editing recurrences when the |
paul@784 | 280 | # NOTE: first occurrence is excluded, plus a way of |
paul@784 | 281 | # NOTE: reinstating the occurrence. |
paul@784 | 282 | |
paul@784 | 283 | elif excluded: |
paul@920 | 284 | page.td(class_="objectvalue %s excluded" % field, rowspan=2, colspan=2) |
paul@1005 | 285 | page.add(_("First occurrence excluded")) |
paul@784 | 286 | page.td.close() |
paul@446 | 287 | |
paul@446 | 288 | page.tr.close() |
paul@446 | 289 | |
paul@845 | 290 | # After the end datetime, show a control to add recurrences. |
paul@845 | 291 | |
paul@867 | 292 | if name == "DTEND": |
paul@845 | 293 | page.tr() |
paul@920 | 294 | page.td(colspan=2) |
paul@845 | 295 | self.control("recur-add", "submit", "add", id="recur-add", class_="add") |
paul@1005 | 296 | page.label(_("Add a recurrence"), for_="recur-add", class_="add") |
paul@845 | 297 | page.td.close() |
paul@845 | 298 | page.tr.close() |
paul@845 | 299 | |
paul@446 | 300 | # Handle the summary specially. |
paul@446 | 301 | |
paul@446 | 302 | elif name == "SUMMARY": |
paul@756 | 303 | value = args.get("summary", [self.obj.get_value(name)])[0] |
paul@446 | 304 | |
paul@920 | 305 | page.td(class_="objectvalue summary", colspan=2) |
paul@756 | 306 | if self.is_organiser(): |
paul@764 | 307 | self.control("summary", "text", value, size=80) |
paul@446 | 308 | else: |
paul@446 | 309 | page.add(value) |
paul@446 | 310 | page.td.close() |
paul@446 | 311 | page.tr.close() |
paul@446 | 312 | |
paul@473 | 313 | # Handle attendees specially. |
paul@473 | 314 | |
paul@473 | 315 | elif name == "ATTENDEE": |
paul@473 | 316 | attendee_map = dict(items) |
paul@473 | 317 | |
paul@473 | 318 | for i, value in enumerate(attendees): |
paul@1244 | 319 | if i: page.tr() |
paul@473 | 320 | |
paul@479 | 321 | # Obtain details of attendees to supply attributes. |
paul@473 | 322 | |
paul@794 | 323 | self.show_attendee(i, value, attendee_map.get(get_uri(value))) |
paul@473 | 324 | page.tr.close() |
paul@473 | 325 | |
paul@473 | 326 | # Allow more attendees to be specified. |
paul@473 | 327 | |
paul@1244 | 328 | if i: page.tr() |
paul@473 | 329 | |
paul@920 | 330 | page.td(colspan=2) |
paul@867 | 331 | self.control("add", "submit", "add", id="add", class_="add") |
paul@1005 | 332 | page.label(_("Add attendee"), for_="add", class_="add") |
paul@867 | 333 | page.td.close() |
paul@867 | 334 | page.tr.close() |
paul@473 | 335 | |
paul@473 | 336 | # Handle potentially many values of other kinds. |
paul@446 | 337 | |
paul@446 | 338 | else: |
paul@446 | 339 | for i, (value, attr) in enumerate(items): |
paul@1244 | 340 | if i: page.tr() |
paul@446 | 341 | |
paul@920 | 342 | page.td(class_="objectvalue %s" % field, colspan=2) |
paul@794 | 343 | if name == "ORGANIZER": |
paul@794 | 344 | page.add(get_verbose_address(value, attr)) |
paul@794 | 345 | else: |
paul@794 | 346 | page.add(value) |
paul@446 | 347 | page.td.close() |
paul@446 | 348 | page.tr.close() |
paul@446 | 349 | |
paul@446 | 350 | page.tbody.close() |
paul@446 | 351 | page.table.close() |
paul@446 | 352 | |
paul@756 | 353 | self.show_recurrences(errors) |
paul@766 | 354 | self.show_counters() |
paul@756 | 355 | self.show_conflicting_events() |
paul@756 | 356 | self.show_request_controls() |
paul@446 | 357 | |
paul@446 | 358 | page.form.close() |
paul@446 | 359 | |
paul@756 | 360 | def show_attendee(self, i, attendee, attendee_attr): |
paul@479 | 361 | |
paul@479 | 362 | """ |
paul@756 | 363 | For the current object, show the attendee in position 'i' with the given |
paul@756 | 364 | 'attendee' value, having 'attendee_attr' as any stored attributes. |
paul@479 | 365 | """ |
paul@479 | 366 | |
paul@1005 | 367 | _ = self.get_translator() |
paul@1005 | 368 | |
paul@479 | 369 | page = self.page |
paul@479 | 370 | args = self.env.get_args() |
paul@479 | 371 | |
paul@794 | 372 | attendee_uri = get_uri(attendee) |
paul@479 | 373 | partstat = attendee_attr and attendee_attr.get("PARTSTAT") |
paul@479 | 374 | |
paul@479 | 375 | page.td(class_="objectvalue") |
paul@479 | 376 | |
paul@479 | 377 | # Show a form control as organiser for new attendees. |
paul@479 | 378 | |
paul@867 | 379 | if self.can_edit_attendee(attendee_uri): |
paul@764 | 380 | self.control("attendee", "value", attendee, size="40") |
paul@479 | 381 | else: |
paul@764 | 382 | self.control("attendee", "hidden", attendee) |
paul@479 | 383 | page.add(attendee) |
paul@479 | 384 | page.add(" ") |
paul@479 | 385 | |
paul@479 | 386 | # Show participation status, editable for the current user. |
paul@479 | 387 | |
paul@1008 | 388 | partstat_items = [(key, _(partstat_label)) for (key, partstat_label) in self.partstat_items] |
paul@1008 | 389 | |
paul@794 | 390 | if attendee_uri == self.user: |
paul@1008 | 391 | self.menu("partstat", partstat, partstat_items, class_="partstat") |
paul@479 | 392 | |
paul@479 | 393 | # Allow the participation indicator to act as a submit |
paul@479 | 394 | # button in order to refresh the page and show a control for |
paul@479 | 395 | # the current user, if indicated. |
paul@479 | 396 | |
paul@794 | 397 | elif self.is_organiser() and self.attendee_is_new(attendee_uri): |
paul@764 | 398 | self.control("partstat-refresh", "submit", "refresh", id="partstat-%d" % i, class_="refresh") |
paul@1008 | 399 | page.label(dict(partstat_items).get(partstat, ""), for_="partstat-%s" % i, class_="partstat") |
paul@758 | 400 | |
paul@758 | 401 | # Otherwise, just show a label with the participation status. |
paul@758 | 402 | |
paul@479 | 403 | else: |
paul@1008 | 404 | page.span(dict(partstat_items).get(partstat, ""), class_="partstat") |
paul@479 | 405 | |
paul@920 | 406 | page.td.close() |
paul@920 | 407 | page.td() |
paul@920 | 408 | |
paul@479 | 409 | # Permit organisers to remove attendees. |
paul@479 | 410 | |
paul@854 | 411 | if self.can_remove_attendee(attendee_uri) or self.is_organiser(): |
paul@479 | 412 | |
paul@479 | 413 | # Permit the removal of newly-added attendees. |
paul@479 | 414 | |
paul@794 | 415 | remove_type = self.can_remove_attendee(attendee_uri) and "submit" or "checkbox" |
paul@764 | 416 | self.control("remove", remove_type, str(i), str(i) in args.get("remove", []), id="remove-%d" % i, class_="remove") |
paul@479 | 417 | |
paul@1005 | 418 | page.label(_("Remove"), for_="remove-%d" % i, class_="remove") |
paul@701 | 419 | page.label(for_="remove-%d" % i, class_="removed") |
paul@1005 | 420 | page.add(_("(Uninvited)")) |
paul@1005 | 421 | page.span(_("Re-invite"), class_="action") |
paul@701 | 422 | page.label.close() |
paul@479 | 423 | |
paul@479 | 424 | page.td.close() |
paul@479 | 425 | |
paul@756 | 426 | def show_recurrences(self, errors=None): |
paul@446 | 427 | |
paul@492 | 428 | """ |
paul@756 | 429 | Show recurrences for the current object. If 'errors' is given, show a |
paul@756 | 430 | suitable message for the different errors provided. |
paul@492 | 431 | """ |
paul@446 | 432 | |
paul@1005 | 433 | _ = self.get_translator() |
paul@1005 | 434 | |
paul@446 | 435 | page = self.page |
paul@446 | 436 | |
paul@446 | 437 | # Obtain any parent object if this object is a specific recurrence. |
paul@446 | 438 | |
paul@756 | 439 | if self.recurrenceid: |
paul@756 | 440 | parent = self.get_stored_object(self.uid, None) |
paul@489 | 441 | if not parent: |
paul@446 | 442 | return |
paul@446 | 443 | |
paul@489 | 444 | page.p() |
paul@1005 | 445 | page.a(_("This event modifies a recurring event."), href=self.link_to(self.uid)) |
paul@489 | 446 | page.p.close() |
paul@446 | 447 | |
paul@499 | 448 | # Obtain the periods associated with the event. |
paul@446 | 449 | |
paul@787 | 450 | recurrences = self.get_current_recurrences() |
paul@446 | 451 | |
paul@499 | 452 | if len(recurrences) < 1: |
paul@446 | 453 | return |
paul@446 | 454 | |
paul@1005 | 455 | page.p(_("This event occurs on the following occasions within the next %d days:") % self.get_window_size()) |
paul@499 | 456 | |
paul@867 | 457 | # Show each recurrence in a separate table. |
paul@446 | 458 | |
paul@867 | 459 | for index, period in enumerate(recurrences): |
paul@868 | 460 | self.show_recurrence(index, period, self.recurrenceid, errors) |
paul@446 | 461 | |
paul@868 | 462 | def show_recurrence(self, index, period, recurrenceid, errors=None): |
paul@519 | 463 | |
paul@519 | 464 | """ |
paul@756 | 465 | Show recurrence controls for a recurrence provided by the current object |
paul@756 | 466 | with the given 'index' position in the list of periods, the given |
paul@756 | 467 | 'period' details, where a 'recurrenceid' indicates any specific |
paul@868 | 468 | recurrence. |
paul@519 | 469 | |
paul@519 | 470 | If 'errors' is given, show a suitable message for the different errors |
paul@519 | 471 | provided. |
paul@519 | 472 | """ |
paul@519 | 473 | |
paul@1005 | 474 | _ = self.get_translator() |
paul@1005 | 475 | |
paul@519 | 476 | page = self.page |
paul@526 | 477 | args = self.env.get_args() |
paul@526 | 478 | |
paul@519 | 479 | # Isolate the controls from neighbouring tables. |
paul@519 | 480 | |
paul@519 | 481 | page.div() |
paul@519 | 482 | |
paul@519 | 483 | self.show_object_datetime_controls(period, index) |
paul@519 | 484 | |
paul@519 | 485 | page.table(cellspacing=5, cellpadding=5, class_="recurrence") |
paul@1005 | 486 | page.caption(period.origin == "RRULE" and _("Occurrence from rule") or _("Occurrence")) |
paul@519 | 487 | page.tbody() |
paul@519 | 488 | |
paul@519 | 489 | page.tr() |
paul@519 | 490 | error = errors and ("dtstart", index) in errors and " error" or "" |
paul@519 | 491 | page.th("Start", class_="objectheading start%s" % error) |
paul@868 | 492 | self.show_recurrence_controls(index, period, recurrenceid, True) |
paul@519 | 493 | page.tr.close() |
paul@519 | 494 | page.tr() |
paul@519 | 495 | error = errors and ("dtend", index) in errors and " error" or "" |
paul@519 | 496 | page.th("End", class_="objectheading end%s" % error) |
paul@868 | 497 | self.show_recurrence_controls(index, period, recurrenceid, False) |
paul@519 | 498 | page.tr.close() |
paul@519 | 499 | |
paul@526 | 500 | # Permit the removal of recurrences. |
paul@526 | 501 | |
paul@868 | 502 | if not period.replaced: |
paul@528 | 503 | page.tr() |
paul@528 | 504 | page.th("") |
paul@528 | 505 | page.td() |
paul@526 | 506 | |
paul@853 | 507 | # Attendees can instantly remove recurrences and thus produce a |
paul@853 | 508 | # counter-proposal. Organisers may need to unschedule recurrences |
paul@853 | 509 | # instead. |
paul@853 | 510 | |
paul@854 | 511 | remove_type = self.can_remove_recurrence(period) and "submit" or "checkbox" |
paul@784 | 512 | |
paul@764 | 513 | self.control("recur-remove", remove_type, str(index), |
paul@528 | 514 | str(index) in args.get("recur-remove", []), |
paul@528 | 515 | id="recur-remove-%d" % index, class_="remove") |
paul@526 | 516 | |
paul@1005 | 517 | page.label(_("Remove"), for_="recur-remove-%d" % index, class_="remove") |
paul@701 | 518 | page.label(for_="recur-remove-%d" % index, class_="removed") |
paul@1005 | 519 | page.add(_("(Removed)")) |
paul@1005 | 520 | page.span(_("Re-add"), class_="action") |
paul@701 | 521 | page.label.close() |
paul@526 | 522 | |
paul@528 | 523 | page.td.close() |
paul@528 | 524 | page.tr.close() |
paul@526 | 525 | |
paul@519 | 526 | page.tbody.close() |
paul@519 | 527 | page.table.close() |
paul@519 | 528 | |
paul@519 | 529 | page.div.close() |
paul@519 | 530 | |
paul@766 | 531 | def show_counters(self): |
paul@766 | 532 | |
paul@766 | 533 | "Show any counter-proposals for the current object." |
paul@766 | 534 | |
paul@1005 | 535 | _ = self.get_translator() |
paul@1005 | 536 | |
paul@766 | 537 | page = self.page |
paul@777 | 538 | query = self.env.get_query() |
paul@777 | 539 | counter = query.get("counter", [None])[0] |
paul@777 | 540 | |
paul@766 | 541 | attendees = self._get_counters(self.uid, self.recurrenceid) |
paul@766 | 542 | tzid = self.get_tzid() |
paul@766 | 543 | |
paul@766 | 544 | if not attendees: |
paul@766 | 545 | return |
paul@766 | 546 | |
paul@809 | 547 | attendees = self.get_verbose_attendees(attendees) |
paul@838 | 548 | current_attendees = [uri for (name, uri) in uri_parts(self.get_current_attendees())] |
paul@856 | 549 | current_periods = set(self.get_periods(self.obj)) |
paul@809 | 550 | |
paul@819 | 551 | # Get suggestions. Attendees are aggregated and reference the existing |
paul@819 | 552 | # attendees suggesting them. Periods are referenced by each existing |
paul@819 | 553 | # attendee. |
paul@819 | 554 | |
paul@819 | 555 | suggested_attendees = {} |
paul@819 | 556 | suggested_periods = {} |
paul@819 | 557 | |
paul@819 | 558 | for i, attendee in enumerate(attendees): |
paul@819 | 559 | attendee_uri = get_uri(attendee) |
paul@819 | 560 | obj = self.get_stored_object(self.uid, self.recurrenceid, "counters", attendee_uri) |
paul@819 | 561 | |
paul@819 | 562 | # Get suggested attendees. |
paul@819 | 563 | |
paul@819 | 564 | for suggested_uri, suggested_attr in uri_dict(obj.get_value_map("ATTENDEE")).items(): |
paul@838 | 565 | if suggested_uri == attendee_uri or suggested_uri in current_attendees: |
paul@819 | 566 | continue |
paul@819 | 567 | suggested = get_verbose_address(suggested_uri, suggested_attr) |
paul@819 | 568 | |
paul@819 | 569 | if not suggested_attendees.has_key(suggested): |
paul@819 | 570 | suggested_attendees[suggested] = [] |
paul@819 | 571 | suggested_attendees[suggested].append(attendee) |
paul@819 | 572 | |
paul@819 | 573 | # Get suggested periods. |
paul@819 | 574 | |
paul@837 | 575 | periods = self.get_periods(obj) |
paul@856 | 576 | if current_periods.symmetric_difference(periods): |
paul@837 | 577 | suggested_periods[attendee] = periods |
paul@819 | 578 | |
paul@819 | 579 | # Present the suggested attendees. |
paul@819 | 580 | |
paul@837 | 581 | if suggested_attendees: |
paul@1005 | 582 | page.p(_("The following attendees have been suggested for this event:")) |
paul@766 | 583 | |
paul@837 | 584 | page.table(cellspacing=5, cellpadding=5, class_="counters") |
paul@837 | 585 | page.thead() |
paul@837 | 586 | page.tr() |
paul@1005 | 587 | page.th(_("Attendee")) |
paul@1005 | 588 | page.th(_("Suggested by...")) |
paul@837 | 589 | page.tr.close() |
paul@837 | 590 | page.thead.close() |
paul@837 | 591 | page.tbody() |
paul@819 | 592 | |
paul@837 | 593 | suggested_attendees = list(suggested_attendees.items()) |
paul@837 | 594 | suggested_attendees.sort() |
paul@819 | 595 | |
paul@838 | 596 | for i, (suggested, attendees) in enumerate(suggested_attendees): |
paul@837 | 597 | page.tr() |
paul@837 | 598 | page.td(suggested) |
paul@837 | 599 | page.td(", ".join(attendees)) |
paul@838 | 600 | page.td() |
paul@838 | 601 | self.control("suggested-attendee", "hidden", suggested) |
paul@838 | 602 | self.control("add-suggested-attendee-%d" % i, "submit", "Add") |
paul@838 | 603 | page.td.close() |
paul@837 | 604 | page.tr.close() |
paul@819 | 605 | |
paul@837 | 606 | page.tbody.close() |
paul@837 | 607 | page.table.close() |
paul@819 | 608 | |
paul@819 | 609 | # Present the suggested periods. |
paul@819 | 610 | |
paul@837 | 611 | if suggested_periods: |
paul@1005 | 612 | page.p(_("The following periods have been suggested for this event:")) |
paul@819 | 613 | |
paul@837 | 614 | page.table(cellspacing=5, cellpadding=5, class_="counters") |
paul@837 | 615 | page.thead() |
paul@837 | 616 | page.tr() |
paul@1005 | 617 | page.th(_("Periods"), colspan=2) |
paul@1005 | 618 | page.th(_("Suggested by..."), rowspan=2) |
paul@837 | 619 | page.tr.close() |
paul@837 | 620 | page.tr() |
paul@1005 | 621 | page.th(_("Start")) |
paul@1005 | 622 | page.th(_("End")) |
paul@837 | 623 | page.tr.close() |
paul@837 | 624 | page.thead.close() |
paul@837 | 625 | page.tbody() |
paul@766 | 626 | |
paul@856 | 627 | recurrenceids = self._get_recurrences(self.uid) |
paul@856 | 628 | |
paul@837 | 629 | suggested_periods = list(suggested_periods.items()) |
paul@837 | 630 | suggested_periods.sort() |
paul@766 | 631 | |
paul@837 | 632 | for attendee, periods in suggested_periods: |
paul@837 | 633 | first = True |
paul@837 | 634 | for p in periods: |
paul@856 | 635 | replaced = not self.recurrenceid and p.is_replaced(recurrenceids) |
paul@837 | 636 | identifier = "%s-%s" % (format_datetime(p.get_start_point()), format_datetime(p.get_end_point())) |
paul@837 | 637 | css = identifier == counter and "selected" or "" |
paul@837 | 638 | |
paul@837 | 639 | page.tr(class_=css) |
paul@805 | 640 | |
paul@837 | 641 | start = self.format_datetime(to_timezone(p.get_start(), tzid), "long") |
paul@837 | 642 | end = self.format_datetime(to_timezone(p.get_end(), tzid), "long") |
paul@766 | 643 | |
paul@837 | 644 | # Show each period. |
paul@819 | 645 | |
paul@856 | 646 | css = replaced and "replaced" or "" |
paul@856 | 647 | page.td(start, class_=css) |
paul@856 | 648 | page.td(end, class_=css) |
paul@766 | 649 | |
paul@837 | 650 | # Show attendees and controls alongside the first period in each |
paul@837 | 651 | # attendee's collection. |
paul@819 | 652 | |
paul@837 | 653 | if first: |
paul@837 | 654 | page.td(attendee, rowspan=len(periods)) |
paul@837 | 655 | page.td(rowspan=len(periods)) |
paul@837 | 656 | self.control("accept-%d" % i, "submit", "Accept") |
paul@837 | 657 | self.control("decline-%d" % i, "submit", "Decline") |
paul@837 | 658 | self.control("counter", "hidden", attendee) |
paul@837 | 659 | page.td.close() |
paul@809 | 660 | |
paul@837 | 661 | page.tr.close() |
paul@837 | 662 | first = False |
paul@766 | 663 | |
paul@837 | 664 | page.tbody.close() |
paul@837 | 665 | page.table.close() |
paul@766 | 666 | |
paul@756 | 667 | def show_conflicting_events(self): |
paul@446 | 668 | |
paul@756 | 669 | "Show conflicting events for the current object." |
paul@446 | 670 | |
paul@1005 | 671 | _ = self.get_translator() |
paul@1005 | 672 | |
paul@446 | 673 | page = self.page |
paul@756 | 674 | recurrenceids = self._get_active_recurrences(self.uid) |
paul@446 | 675 | |
paul@446 | 676 | # Obtain the user's timezone. |
paul@446 | 677 | |
paul@446 | 678 | tzid = self.get_tzid() |
paul@756 | 679 | periods = self.get_periods(self.obj) |
paul@446 | 680 | |
paul@446 | 681 | # Indicate whether there are conflicting events. |
paul@446 | 682 | |
paul@844 | 683 | conflicts = set() |
paul@756 | 684 | attendee_map = uri_dict(self.obj.get_value_map("ATTENDEE")) |
paul@446 | 685 | |
paul@839 | 686 | for name, participant in uri_parts(self.get_current_attendees()): |
paul@484 | 687 | if participant == self.user: |
paul@484 | 688 | freebusy = self.store.get_freebusy(participant) |
paul@787 | 689 | elif participant: |
paul@787 | 690 | freebusy = self.store.get_freebusy_for_other(self.user, participant) |
paul@484 | 691 | else: |
paul@787 | 692 | continue |
paul@484 | 693 | |
paul@484 | 694 | if not freebusy: |
paul@484 | 695 | continue |
paul@446 | 696 | |
paul@446 | 697 | # Obtain any time zone details from the suggested event. |
paul@446 | 698 | |
paul@756 | 699 | _dtstart, attr = self.obj.get_item("DTSTART") |
paul@446 | 700 | tzid = attr.get("TZID", tzid) |
paul@446 | 701 | |
paul@484 | 702 | # Show any conflicts with periods of actual attendance. |
paul@446 | 703 | |
paul@611 | 704 | participant_attr = attendee_map.get(participant) |
paul@611 | 705 | partstat = participant_attr and participant_attr.get("PARTSTAT") |
paul@756 | 706 | recurrences = self.obj.get_recurrence_start_points(recurrenceids, tzid) |
paul@611 | 707 | |
paul@1062 | 708 | for p in freebusy.have_conflict(periods, True): |
paul@756 | 709 | if not self.recurrenceid and p.is_replaced(recurrences): |
paul@528 | 710 | continue |
paul@611 | 711 | |
paul@611 | 712 | if ( # Unidentified or different event |
paul@756 | 713 | (p.uid != self.uid or self.recurrenceid and p.recurrenceid and p.recurrenceid != self.recurrenceid) and |
paul@611 | 714 | # Different period or unclear participation with the same period |
paul@611 | 715 | (p not in periods or not partstat in ("ACCEPTED", "TENTATIVE")) and |
paul@611 | 716 | # Participant not limited to organising |
paul@611 | 717 | p.transp != "ORG" |
paul@611 | 718 | ): |
paul@611 | 719 | |
paul@844 | 720 | conflicts.add(p) |
paul@446 | 721 | |
paul@844 | 722 | conflicts = list(conflicts) |
paul@484 | 723 | conflicts.sort() |
paul@484 | 724 | |
paul@484 | 725 | # Show any conflicts with periods of actual attendance. |
paul@446 | 726 | |
paul@484 | 727 | if conflicts: |
paul@1005 | 728 | page.p(_("This event conflicts with others:")) |
paul@446 | 729 | |
paul@484 | 730 | page.table(cellspacing=5, cellpadding=5, class_="conflicts") |
paul@484 | 731 | page.thead() |
paul@484 | 732 | page.tr() |
paul@1005 | 733 | page.th(_("Event")) |
paul@1005 | 734 | page.th(_("Start")) |
paul@1005 | 735 | page.th(_("End")) |
paul@484 | 736 | page.tr.close() |
paul@484 | 737 | page.thead.close() |
paul@484 | 738 | page.tbody() |
paul@446 | 739 | |
paul@484 | 740 | for p in conflicts: |
paul@484 | 741 | |
paul@484 | 742 | # Provide details of any conflicting event. |
paul@446 | 743 | |
paul@535 | 744 | start = self.format_datetime(to_timezone(p.get_start(), tzid), "long") |
paul@535 | 745 | end = self.format_datetime(to_timezone(p.get_end(), tzid), "long") |
paul@446 | 746 | |
paul@484 | 747 | page.tr() |
paul@446 | 748 | |
paul@484 | 749 | # Show the event summary for the conflicting event. |
paul@446 | 750 | |
paul@484 | 751 | page.td() |
paul@484 | 752 | if p.summary: |
paul@488 | 753 | page.a(p.summary, href=self.link_to(p.uid, p.recurrenceid)) |
paul@484 | 754 | else: |
paul@1005 | 755 | page.add(_("(Unspecified event)")) |
paul@484 | 756 | page.td.close() |
paul@446 | 757 | |
paul@484 | 758 | page.td(start) |
paul@484 | 759 | page.td(end) |
paul@446 | 760 | |
paul@484 | 761 | page.tr.close() |
paul@446 | 762 | |
paul@484 | 763 | page.tbody.close() |
paul@484 | 764 | page.table.close() |
paul@446 | 765 | |
paul@765 | 766 | class EventPage(EventPageFragment): |
paul@765 | 767 | |
paul@765 | 768 | "A request handler for the event page." |
paul@765 | 769 | |
paul@765 | 770 | def __init__(self, resource=None, messenger=None): |
paul@807 | 771 | ResourceClientForObject.__init__(self, resource, messenger or Messenger()) |
paul@474 | 772 | |
paul@877 | 773 | def link_to(self, uid=None, recurrenceid=None): |
paul@877 | 774 | args = self.env.get_query() |
paul@877 | 775 | d = {} |
paul@877 | 776 | for name in ("start", "end"): |
paul@877 | 777 | if args.get(name): |
paul@877 | 778 | d[name] = args[name][0] |
paul@877 | 779 | return ResourceClientForObject.link_to(self, uid, recurrenceid, d) |
paul@877 | 780 | |
paul@765 | 781 | # Request logic methods. |
paul@765 | 782 | |
paul@765 | 783 | def is_initial_load(self): |
paul@765 | 784 | |
paul@765 | 785 | "Return whether the event is being loaded and shown for the first time." |
paul@765 | 786 | |
paul@765 | 787 | return not self.env.get_args().has_key("editing") |
paul@765 | 788 | |
paul@765 | 789 | def handle_request(self): |
paul@474 | 790 | |
paul@474 | 791 | """ |
paul@765 | 792 | Handle actions involving the current object, returning an error if one |
paul@765 | 793 | occurred, or None if the request was successfully handled. |
paul@474 | 794 | """ |
paul@474 | 795 | |
paul@765 | 796 | # Handle a submitted form. |
paul@498 | 797 | |
paul@474 | 798 | args = self.env.get_args() |
paul@765 | 799 | |
paul@765 | 800 | # Get the possible actions. |
paul@765 | 801 | |
paul@765 | 802 | reply = args.has_key("reply") |
paul@765 | 803 | discard = args.has_key("discard") |
paul@765 | 804 | create = args.has_key("create") |
paul@765 | 805 | cancel = args.has_key("cancel") |
paul@765 | 806 | ignore = args.has_key("ignore") |
paul@765 | 807 | save = args.has_key("save") |
paul@841 | 808 | uncounter = args.has_key("uncounter") |
paul@813 | 809 | accept = self.prefixed_args("accept-", int) |
paul@813 | 810 | decline = self.prefixed_args("decline-", int) |
paul@809 | 811 | |
paul@841 | 812 | have_action = reply or discard or create or cancel or ignore or save or accept or decline or uncounter |
paul@765 | 813 | |
paul@765 | 814 | if not have_action: |
paul@765 | 815 | return ["action"] |
paul@474 | 816 | |
paul@1162 | 817 | # Check the validation token. |
paul@1162 | 818 | |
paul@1162 | 819 | if not self.check_validation_token(): |
paul@1162 | 820 | return ["token"] |
paul@1162 | 821 | |
paul@765 | 822 | # If ignoring the object, return to the calendar. |
paul@474 | 823 | |
paul@765 | 824 | if ignore: |
paul@877 | 825 | self.redirect(self.link_to()) |
paul@765 | 826 | return None |
paul@765 | 827 | |
paul@765 | 828 | # Update the object. |
paul@474 | 829 | |
paul@765 | 830 | single_user = False |
paul@818 | 831 | changed = False |
paul@765 | 832 | |
paul@765 | 833 | if reply or create or cancel or save: |
paul@765 | 834 | |
paul@867 | 835 | # Update time periods (main and recurring). |
paul@765 | 836 | |
paul@867 | 837 | try: |
paul@867 | 838 | period = self.handle_main_period() |
paul@867 | 839 | except PeriodError, exc: |
paul@867 | 840 | return exc.args |
paul@474 | 841 | |
paul@867 | 842 | try: |
paul@867 | 843 | periods = self.handle_recurrence_periods() |
paul@867 | 844 | except PeriodError, exc: |
paul@867 | 845 | return exc.args |
paul@474 | 846 | |
paul@867 | 847 | # Set the periods in the object, first obtaining removed and |
paul@867 | 848 | # modified period information. |
paul@872 | 849 | # NOTE: Currently, rules are not updated. |
paul@765 | 850 | |
paul@867 | 851 | to_unschedule, to_exclude = self.get_removed_periods(periods) |
paul@867 | 852 | periods = set(periods) |
paul@878 | 853 | active_periods = [p for p in periods if not p.replaced] |
paul@765 | 854 | |
paul@867 | 855 | changed = self.obj.set_period(period) or changed |
paul@867 | 856 | changed = self.obj.set_periods(periods) or changed |
paul@878 | 857 | |
paul@878 | 858 | # Add and remove exceptions. |
paul@878 | 859 | |
paul@878 | 860 | changed = self.obj.update_exceptions(to_exclude, active_periods) or changed |
paul@868 | 861 | |
paul@868 | 862 | # Assert periods restored after cancellation. |
paul@868 | 863 | |
paul@878 | 864 | changed = self.revert_cancellations(active_periods) or changed |
paul@474 | 865 | |
paul@867 | 866 | # Organiser-only changes... |
paul@818 | 867 | |
paul@867 | 868 | if self.is_organiser(): |
paul@818 | 869 | |
paul@867 | 870 | # Update summary. |
paul@765 | 871 | |
paul@867 | 872 | if args.has_key("summary"): |
paul@867 | 873 | self.obj["SUMMARY"] = [(args["summary"][0], {})] |
paul@765 | 874 | |
paul@867 | 875 | # Obtain any new participants and those to be removed. |
paul@474 | 876 | |
paul@867 | 877 | attendees = self.get_attendees_from_page() |
paul@867 | 878 | removed = [attendees[int(i)] for i in args.get("remove", [])] |
paul@867 | 879 | added, to_cancel = self.update_attendees(attendees, removed) |
paul@927 | 880 | single_user = not attendees or uri_values(attendees) == [self.user] |
paul@867 | 881 | changed = added or changed |
paul@765 | 882 | |
paul@765 | 883 | # Update attendee participation for the current user. |
paul@474 | 884 | |
paul@765 | 885 | if args.has_key("partstat"): |
paul@818 | 886 | self.update_participation(args["partstat"][0]) |
paul@765 | 887 | |
paul@765 | 888 | # Process any action. |
paul@474 | 889 | |
paul@765 | 890 | invite = not save and create and not single_user |
paul@765 | 891 | save = save or create and single_user |
paul@474 | 892 | |
paul@765 | 893 | handled = True |
paul@474 | 894 | |
paul@765 | 895 | if reply or invite or cancel: |
paul@765 | 896 | |
paul@765 | 897 | # Process the object and remove it from the list of requests. |
paul@765 | 898 | |
paul@818 | 899 | if reply and self.process_received_request(changed): |
paul@917 | 900 | if self.has_indicated_attendance(): |
paul@917 | 901 | self.remove_request() |
paul@765 | 902 | |
paul@765 | 903 | elif self.is_organiser() and (invite or cancel): |
paul@765 | 904 | |
paul@765 | 905 | # Invitation, uninvitation and unscheduling... |
paul@765 | 906 | |
paul@807 | 907 | if self.process_created_request( |
paul@765 | 908 | invite and "REQUEST" or "CANCEL", to_cancel, to_unschedule): |
paul@765 | 909 | |
paul@813 | 910 | self.remove_request() |
paul@474 | 911 | |
paul@765 | 912 | # Save single user events. |
paul@765 | 913 | |
paul@765 | 914 | elif save: |
paul@765 | 915 | self.store.set_event(self.user, self.uid, self.recurrenceid, node=self.obj.to_node()) |
paul@765 | 916 | self.update_event_in_freebusy() |
paul@813 | 917 | self.remove_request() |
paul@474 | 918 | |
paul@765 | 919 | # Remove the request and the object. |
paul@474 | 920 | |
paul@765 | 921 | elif discard: |
paul@765 | 922 | self.remove_event_from_freebusy() |
paul@813 | 923 | self.remove_event() |
paul@813 | 924 | self.remove_request() |
paul@813 | 925 | |
paul@813 | 926 | # Update counter-proposal records synchronously instead of assuming |
paul@813 | 927 | # that the outgoing handler will have done so before the form is |
paul@813 | 928 | # refreshed. |
paul@813 | 929 | |
paul@813 | 930 | # Accept a counter-proposal and decline all others, sending a new |
paul@813 | 931 | # request to all attendees. |
paul@813 | 932 | |
paul@813 | 933 | elif accept: |
paul@474 | 934 | |
paul@813 | 935 | # Take the first accepted proposal, although there should be only |
paul@813 | 936 | # one anyway. |
paul@813 | 937 | |
paul@813 | 938 | for i in accept: |
paul@813 | 939 | attendee_uri = get_uri(args.get("counter", [])[i]) |
paul@813 | 940 | obj = self.get_stored_object(self.uid, self.recurrenceid, "counters", attendee_uri) |
paul@813 | 941 | self.obj.set_periods(self.get_periods(obj)) |
paul@872 | 942 | self.obj.set_rule(obj.get_item("RRULE")) |
paul@872 | 943 | self.obj.set_exceptions(obj.get_items("EXDATE")) |
paul@813 | 944 | break |
paul@813 | 945 | |
paul@813 | 946 | # Remove counter-proposals and issue a new invitation. |
paul@813 | 947 | |
paul@813 | 948 | attendees = uri_values(args.get("counter", [])) |
paul@813 | 949 | self.remove_counters(attendees) |
paul@813 | 950 | self.process_created_request("REQUEST") |
paul@813 | 951 | |
paul@813 | 952 | # Decline a counter-proposal individually. |
paul@811 | 953 | |
paul@811 | 954 | elif decline: |
paul@813 | 955 | for i in decline: |
paul@813 | 956 | attendee_uri = get_uri(args.get("counter", [])[i]) |
paul@813 | 957 | self.process_declined_counter(attendee_uri) |
paul@813 | 958 | self.remove_counter(attendee_uri) |
paul@811 | 959 | |
paul@811 | 960 | # Redirect to the event. |
paul@811 | 961 | |
paul@811 | 962 | self.redirect(self.env.get_url()) |
paul@811 | 963 | handled = False |
paul@811 | 964 | |
paul@841 | 965 | # Remove counter-proposals without acknowledging them. |
paul@841 | 966 | |
paul@841 | 967 | elif uncounter: |
paul@841 | 968 | self.store.remove_counters(self.user, self.uid, self.recurrenceid) |
paul@841 | 969 | self.remove_request() |
paul@841 | 970 | |
paul@841 | 971 | # Redirect to the event. |
paul@841 | 972 | |
paul@841 | 973 | self.redirect(self.env.get_url()) |
paul@841 | 974 | handled = False |
paul@841 | 975 | |
paul@474 | 976 | else: |
paul@765 | 977 | handled = False |
paul@765 | 978 | |
paul@765 | 979 | # Upon handling an action, redirect to the main page. |
paul@765 | 980 | |
paul@765 | 981 | if handled: |
paul@877 | 982 | self.redirect(self.link_to()) |
paul@765 | 983 | |
paul@765 | 984 | return None |
paul@765 | 985 | |
paul@765 | 986 | def handle_main_period(self): |
paul@765 | 987 | |
paul@765 | 988 | "Return period details for the main start/end period in an event." |
paul@765 | 989 | |
paul@765 | 990 | return self.get_main_period_from_page().as_event_period() |
paul@765 | 991 | |
paul@765 | 992 | def handle_recurrence_periods(self): |
paul@765 | 993 | |
paul@765 | 994 | "Return period details for the recurrences specified for an event." |
paul@765 | 995 | |
paul@867 | 996 | return [p.as_event_period(i) for i, p in enumerate(self.get_recurrences_from_page())] |
paul@765 | 997 | |
paul@765 | 998 | # Access to form-originating object information. |
paul@765 | 999 | |
paul@765 | 1000 | def get_main_period_from_page(self): |
paul@765 | 1001 | |
paul@765 | 1002 | "Return the main period defined in the event form." |
paul@765 | 1003 | |
paul@1244 | 1004 | period = get_period_control_values(self.env.get_args(), |
paul@1244 | 1005 | "dtstart", "dtend", |
paul@1244 | 1006 | "dtend-control", "dttimes-control", |
paul@1244 | 1007 | origin="DTSTART", |
paul@1244 | 1008 | tzid=self.get_tzid()) |
paul@785 | 1009 | |
paul@785 | 1010 | # Handle absent main period details. |
paul@785 | 1011 | |
paul@785 | 1012 | if not period.get_start(): |
paul@785 | 1013 | return self.get_stored_main_period() |
paul@785 | 1014 | else: |
paul@785 | 1015 | return period |
paul@474 | 1016 | |
paul@765 | 1017 | def get_recurrences_from_page(self): |
paul@765 | 1018 | |
paul@765 | 1019 | "Return the recurrences defined in the event form." |
paul@765 | 1020 | |
paul@1244 | 1021 | return get_period_control_values(self.env.get_args(), |
paul@1244 | 1022 | "dtstart-recur", "dtend-recur", |
paul@1244 | 1023 | "dtend-control-recur", "dttimes-control-recur", |
paul@1244 | 1024 | origin_name="recur-origin", replaced_name="recur-replaced", |
paul@1244 | 1025 | tzid=self.get_tzid()) |
paul@765 | 1026 | |
paul@787 | 1027 | def set_recurrences_in_page(self, recurrences): |
paul@787 | 1028 | |
paul@787 | 1029 | "Set the recurrences defined in the event form." |
paul@787 | 1030 | |
paul@1245 | 1031 | set_period_control_values(recurrences, self.env.get_args(), |
paul@1245 | 1032 | "dtstart-recur", "dtend-recur", |
paul@1245 | 1033 | "dtend-control-recur", "dttimes-control-recur", |
paul@1245 | 1034 | "recur-origin", "recur-replaced") |
paul@787 | 1035 | |
paul@783 | 1036 | def get_removed_periods(self, periods): |
paul@765 | 1037 | |
paul@783 | 1038 | """ |
paul@783 | 1039 | Return those from the recurrence 'periods' to remove upon updating an |
paul@784 | 1040 | event along with those to exclude in a tuple of the form (unscheduled, |
paul@784 | 1041 | excluded). |
paul@783 | 1042 | """ |
paul@765 | 1043 | |
paul@784 | 1044 | args = self.env.get_args() |
paul@765 | 1045 | to_unschedule = [] |
paul@784 | 1046 | to_exclude = [] |
paul@784 | 1047 | |
paul@765 | 1048 | for i in args.get("recur-remove", []): |
paul@784 | 1049 | try: |
paul@784 | 1050 | period = periods[int(i)] |
paul@784 | 1051 | except (IndexError, ValueError): |
paul@784 | 1052 | continue |
paul@784 | 1053 | |
paul@871 | 1054 | if not self.can_edit_recurrence(period) and self.is_organiser(): |
paul@784 | 1055 | to_unschedule.append(period) |
paul@784 | 1056 | else: |
paul@784 | 1057 | to_exclude.append(period) |
paul@784 | 1058 | |
paul@784 | 1059 | return to_unschedule, to_exclude |
paul@765 | 1060 | |
paul@765 | 1061 | def get_attendees_from_page(self): |
paul@474 | 1062 | |
paul@809 | 1063 | """ |
paul@809 | 1064 | Return attendees from the request, using any stored attributes to obtain |
paul@809 | 1065 | verbose details. |
paul@809 | 1066 | """ |
paul@809 | 1067 | |
paul@809 | 1068 | return self.get_verbose_attendees(self.env.get_args().get("attendee", [])) |
paul@474 | 1069 | |
paul@809 | 1070 | def get_verbose_attendees(self, attendees): |
paul@809 | 1071 | |
paul@809 | 1072 | """ |
paul@809 | 1073 | Use any stored attributes to obtain verbose details for the given |
paul@809 | 1074 | 'attendees'. |
paul@809 | 1075 | """ |
paul@809 | 1076 | |
paul@809 | 1077 | attendee_map = self.obj.get_value_map("ATTENDEE") |
paul@809 | 1078 | return [get_verbose_address(value, attendee_map.get(value)) for value in attendees] |
paul@765 | 1079 | |
paul@765 | 1080 | def update_attendees_from_page(self): |
paul@765 | 1081 | |
paul@765 | 1082 | "Add or remove attendees. This does not affect the stored object." |
paul@765 | 1083 | |
paul@765 | 1084 | args = self.env.get_args() |
paul@765 | 1085 | |
paul@765 | 1086 | attendees = self.get_attendees_from_page() |
paul@474 | 1087 | |
paul@765 | 1088 | if args.has_key("add"): |
paul@765 | 1089 | attendees.append("") |
paul@517 | 1090 | |
paul@838 | 1091 | # Add attendees suggested in counter-proposals. |
paul@838 | 1092 | |
paul@838 | 1093 | add_suggested = self.prefixed_args("add-suggested-attendee-", int) |
paul@838 | 1094 | |
paul@838 | 1095 | if add_suggested: |
paul@838 | 1096 | for i in add_suggested: |
paul@838 | 1097 | try: |
paul@838 | 1098 | suggested = args["suggested-attendee"][i] |
paul@838 | 1099 | except (IndexError, KeyError): |
paul@838 | 1100 | continue |
paul@838 | 1101 | if suggested not in attendees: |
paul@838 | 1102 | attendees.append(suggested) |
paul@838 | 1103 | |
paul@765 | 1104 | # Only actually remove attendees if the event is unsent, if the attendee |
paul@765 | 1105 | # is new, or if it is the current user being removed. |
paul@765 | 1106 | |
paul@765 | 1107 | if args.has_key("remove"): |
paul@765 | 1108 | still_to_remove = [] |
paul@795 | 1109 | correction = 0 |
paul@517 | 1110 | |
paul@765 | 1111 | for i in args["remove"]: |
paul@765 | 1112 | try: |
paul@795 | 1113 | i = int(i) - correction |
paul@795 | 1114 | attendee = attendees[i] |
paul@795 | 1115 | except (IndexError, ValueError): |
paul@765 | 1116 | continue |
paul@474 | 1117 | |
paul@795 | 1118 | if self.can_remove_attendee(get_uri(attendee)): |
paul@795 | 1119 | del attendees[i] |
paul@795 | 1120 | correction += 1 |
paul@765 | 1121 | else: |
paul@795 | 1122 | still_to_remove.append(str(i)) |
paul@474 | 1123 | |
paul@765 | 1124 | args["remove"] = still_to_remove |
paul@765 | 1125 | |
paul@787 | 1126 | args["attendee"] = attendees |
paul@765 | 1127 | return attendees |
paul@498 | 1128 | |
paul@780 | 1129 | def update_recurrences_from_page(self): |
paul@780 | 1130 | |
paul@780 | 1131 | "Add or remove recurrences. This does not affect the stored object." |
paul@780 | 1132 | |
paul@780 | 1133 | args = self.env.get_args() |
paul@780 | 1134 | |
paul@780 | 1135 | recurrences = self.get_recurrences_from_page() |
paul@780 | 1136 | |
paul@845 | 1137 | if args.has_key("recur-add"): |
paul@845 | 1138 | period = self.get_current_main_period().as_form_period() |
paul@845 | 1139 | period.origin = "RDATE" |
paul@845 | 1140 | recurrences.append(period) |
paul@780 | 1141 | |
paul@780 | 1142 | # Only actually remove recurrences if the event is unsent, or if the |
paul@784 | 1143 | # recurrence is new, but only for explicit recurrences. |
paul@780 | 1144 | |
paul@780 | 1145 | if args.has_key("recur-remove"): |
paul@780 | 1146 | still_to_remove = [] |
paul@795 | 1147 | correction = 0 |
paul@780 | 1148 | |
paul@780 | 1149 | for i in args["recur-remove"]: |
paul@780 | 1150 | try: |
paul@795 | 1151 | i = int(i) - correction |
paul@795 | 1152 | recurrence = recurrences[i] |
paul@795 | 1153 | except (IndexError, ValueError): |
paul@780 | 1154 | continue |
paul@780 | 1155 | |
paul@854 | 1156 | if self.can_remove_recurrence(recurrence): |
paul@795 | 1157 | del recurrences[i] |
paul@795 | 1158 | correction += 1 |
paul@780 | 1159 | else: |
paul@795 | 1160 | still_to_remove.append(str(i)) |
paul@780 | 1161 | |
paul@780 | 1162 | args["recur-remove"] = still_to_remove |
paul@780 | 1163 | |
paul@787 | 1164 | self.set_recurrences_in_page(recurrences) |
paul@780 | 1165 | return recurrences |
paul@780 | 1166 | |
paul@765 | 1167 | # Access to current object information. |
paul@765 | 1168 | |
paul@765 | 1169 | def get_current_main_period(self): |
paul@498 | 1170 | |
paul@498 | 1171 | """ |
paul@765 | 1172 | Return the currently active main period for the current object depending |
paul@765 | 1173 | on whether editing has begun or whether the object has just been loaded. |
paul@765 | 1174 | """ |
paul@498 | 1175 | |
paul@867 | 1176 | if self.is_initial_load(): |
paul@765 | 1177 | return self.get_stored_main_period() |
paul@765 | 1178 | else: |
paul@765 | 1179 | return self.get_main_period_from_page() |
paul@765 | 1180 | |
paul@765 | 1181 | def get_current_recurrences(self): |
paul@765 | 1182 | |
paul@765 | 1183 | """ |
paul@765 | 1184 | Return recurrences for the current object using the original object |
paul@765 | 1185 | details where no editing is in progress, using form data otherwise. |
paul@498 | 1186 | """ |
paul@498 | 1187 | |
paul@867 | 1188 | if self.is_initial_load(): |
paul@765 | 1189 | return self.get_stored_recurrences() |
paul@765 | 1190 | else: |
paul@765 | 1191 | return self.get_recurrences_from_page() |
paul@498 | 1192 | |
paul@780 | 1193 | def update_current_recurrences(self): |
paul@780 | 1194 | |
paul@780 | 1195 | "Return an updated collection of recurrences for the current object." |
paul@780 | 1196 | |
paul@867 | 1197 | if self.is_initial_load(): |
paul@780 | 1198 | return self.get_stored_recurrences() |
paul@780 | 1199 | else: |
paul@780 | 1200 | return self.update_recurrences_from_page() |
paul@780 | 1201 | |
paul@765 | 1202 | def get_current_attendees(self): |
paul@765 | 1203 | |
paul@765 | 1204 | """ |
paul@765 | 1205 | Return attendees for the current object depending on whether the object |
paul@765 | 1206 | has been edited or instead provides such information from its stored |
paul@765 | 1207 | form. |
paul@765 | 1208 | """ |
paul@499 | 1209 | |
paul@867 | 1210 | if self.is_initial_load(): |
paul@765 | 1211 | return self.get_stored_attendees() |
paul@765 | 1212 | else: |
paul@765 | 1213 | return self.get_attendees_from_page() |
paul@765 | 1214 | |
paul@765 | 1215 | def update_current_attendees(self): |
paul@498 | 1216 | |
paul@765 | 1217 | "Return an updated collection of attendees for the current object." |
paul@765 | 1218 | |
paul@867 | 1219 | if self.is_initial_load(): |
paul@765 | 1220 | return self.get_stored_attendees() |
paul@498 | 1221 | else: |
paul@765 | 1222 | return self.update_attendees_from_page() |
paul@474 | 1223 | |
paul@446 | 1224 | # Full page output methods. |
paul@446 | 1225 | |
paul@446 | 1226 | def show(self, path_info): |
paul@446 | 1227 | |
paul@446 | 1228 | "Show an object request using the given 'path_info' for the current user." |
paul@446 | 1229 | |
paul@763 | 1230 | uid, recurrenceid = self.get_identifiers(path_info) |
paul@763 | 1231 | obj = self.get_stored_object(uid, recurrenceid) |
paul@756 | 1232 | self.set_object(obj) |
paul@446 | 1233 | |
paul@446 | 1234 | if not obj: |
paul@446 | 1235 | return False |
paul@446 | 1236 | |
paul@756 | 1237 | errors = self.handle_request() |
paul@446 | 1238 | |
paul@492 | 1239 | if not errors: |
paul@446 | 1240 | return True |
paul@446 | 1241 | |
paul@787 | 1242 | self.update_current_attendees() |
paul@787 | 1243 | self.update_current_recurrences() |
paul@787 | 1244 | |
paul@1005 | 1245 | _ = self.get_translator() |
paul@1005 | 1246 | |
paul@1005 | 1247 | self.new_page(title=_("Event")) |
paul@756 | 1248 | self.show_object_on_page(errors) |
paul@446 | 1249 | |
paul@446 | 1250 | return True |
paul@446 | 1251 | |
paul@446 | 1252 | # vim: tabstop=4 expandtab shiftwidth=4 |