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