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