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@794 | 22 | from imiptools.data import get_uri, get_verbose_address, uri_dict, uri_items, uri_values |
paul@777 | 23 | from imiptools.dates import format_datetime, to_timezone |
paul@446 | 24 | from imiptools.mail import Messenger |
paul@529 | 25 | from imiptools.period import have_conflict |
paul@765 | 26 | from imipweb.data import EventPeriod, event_period_from_period, FormPeriod, PeriodError |
paul@601 | 27 | from imipweb.client import ManagerClient |
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@780 | 56 | def can_remove_recurrence(self, recurrence): |
paul@780 | 57 | |
paul@780 | 58 | """ |
paul@780 | 59 | Return whether the 'recurrence' can be removed from the current object |
paul@780 | 60 | without notification. |
paul@780 | 61 | """ |
paul@780 | 62 | |
paul@786 | 63 | return self.can_edit_recurrence(recurrence) and recurrence.origin != "RRULE" |
paul@784 | 64 | |
paul@784 | 65 | def can_edit_recurrence(self, recurrence): |
paul@784 | 66 | |
paul@784 | 67 | "Return whether 'recurrence' can be edited." |
paul@784 | 68 | |
paul@780 | 69 | return self.recurrence_is_new(recurrence) or not self.obj.is_shared() |
paul@780 | 70 | |
paul@780 | 71 | def recurrence_is_new(self, recurrence): |
paul@780 | 72 | |
paul@780 | 73 | "Return whether 'recurrence' is new to the current object." |
paul@780 | 74 | |
paul@780 | 75 | return recurrence not in self.get_stored_recurrences() |
paul@619 | 76 | |
paul@758 | 77 | def can_remove_attendee(self, attendee): |
paul@758 | 78 | |
paul@758 | 79 | """ |
paul@758 | 80 | Return whether 'attendee' can be removed from the current object without |
paul@758 | 81 | notification. |
paul@758 | 82 | """ |
paul@758 | 83 | |
paul@758 | 84 | return self.can_edit_attendee(attendee) or attendee == self.user |
paul@758 | 85 | |
paul@758 | 86 | def can_edit_attendee(self, attendee): |
paul@758 | 87 | |
paul@758 | 88 | "Return whether 'attendee' can be edited by an organiser." |
paul@758 | 89 | |
paul@758 | 90 | return self.attendee_is_new(attendee) or not self.obj.is_shared() |
paul@758 | 91 | |
paul@758 | 92 | def attendee_is_new(self, attendee): |
paul@758 | 93 | |
paul@758 | 94 | "Return whether 'attendee' is new to the current object." |
paul@758 | 95 | |
paul@795 | 96 | return attendee not in uri_values(self.get_stored_attendees()) |
paul@758 | 97 | |
paul@765 | 98 | # Access to stored object information. |
paul@477 | 99 | |
paul@780 | 100 | def is_organiser(self): |
paul@780 | 101 | return get_uri(self.obj.get_value("ORGANIZER")) == self.user |
paul@780 | 102 | |
paul@765 | 103 | def get_stored_attendees(self): |
paul@794 | 104 | return [get_verbose_address(value, attr) for value, attr in self.obj.get_items("ATTENDEE") or []] |
paul@477 | 105 | |
paul@765 | 106 | def get_stored_main_period(self): |
paul@477 | 107 | |
paul@765 | 108 | "Return the main event period for the current object." |
paul@477 | 109 | |
paul@765 | 110 | (dtstart, dtstart_attr), (dtend, dtend_attr) = self.obj.get_main_period_items(self.get_tzid()) |
paul@765 | 111 | return EventPeriod(dtstart, dtend, self.get_tzid(), None, dtstart_attr, dtend_attr) |
paul@477 | 112 | |
paul@765 | 113 | def get_stored_recurrences(self): |
paul@765 | 114 | |
paul@765 | 115 | "Return recurrences computed using the current object." |
paul@485 | 116 | |
paul@765 | 117 | recurrences = [] |
paul@765 | 118 | for period in self.get_periods(self.obj): |
paul@765 | 119 | if period.origin != "DTSTART": |
paul@765 | 120 | recurrences.append(period) |
paul@765 | 121 | return recurrences |
paul@757 | 122 | |
paul@765 | 123 | # Access to current object information. |
paul@496 | 124 | |
paul@765 | 125 | def get_current_main_period(self): |
paul@765 | 126 | return self.get_stored_main_period() |
paul@757 | 127 | |
paul@765 | 128 | def get_current_recurrences(self): |
paul@765 | 129 | return self.get_stored_recurrences() |
paul@477 | 130 | |
paul@765 | 131 | def get_current_attendees(self): |
paul@765 | 132 | return self.get_stored_attendees() |
paul@477 | 133 | |
paul@446 | 134 | # Page fragment methods. |
paul@446 | 135 | |
paul@756 | 136 | def show_request_controls(self): |
paul@446 | 137 | |
paul@756 | 138 | "Show form controls for a request." |
paul@446 | 139 | |
paul@446 | 140 | page = self.page |
paul@446 | 141 | args = self.env.get_args() |
paul@446 | 142 | |
paul@794 | 143 | attendees = uri_values(self.get_current_attendees()) |
paul@446 | 144 | is_attendee = self.user in attendees |
paul@756 | 145 | is_request = self._have_request(self.uid, self.recurrenceid) |
paul@446 | 146 | |
paul@801 | 147 | if not self.obj.is_shared(): |
paul@801 | 148 | page.p("This event has not been shared.") |
paul@801 | 149 | |
paul@446 | 150 | # Show appropriate options depending on the role of the user. |
paul@446 | 151 | |
paul@756 | 152 | if is_attendee and not self.is_organiser(): |
paul@446 | 153 | page.p("An action is required for this request:") |
paul@446 | 154 | |
paul@446 | 155 | page.p() |
paul@764 | 156 | self.control("reply", "submit", "Send reply") |
paul@446 | 157 | page.add(" ") |
paul@764 | 158 | self.control("discard", "submit", "Discard event") |
paul@446 | 159 | page.add(" ") |
paul@764 | 160 | self.control("ignore", "submit", "Do nothing for now") |
paul@446 | 161 | page.p.close() |
paul@446 | 162 | |
paul@756 | 163 | if self.is_organiser(): |
paul@446 | 164 | page.p("As organiser, you can perform the following:") |
paul@446 | 165 | |
paul@512 | 166 | page.p() |
paul@801 | 167 | self.control("create", "submit", "Update event") |
paul@512 | 168 | page.add(" ") |
paul@512 | 169 | |
paul@756 | 170 | if self.obj.is_shared() and not is_request: |
paul@764 | 171 | self.control("cancel", "submit", "Cancel event") |
paul@446 | 172 | else: |
paul@764 | 173 | self.control("discard", "submit", "Discard event") |
paul@512 | 174 | |
paul@512 | 175 | page.add(" ") |
paul@764 | 176 | self.control("save", "submit", "Save without sending") |
paul@512 | 177 | page.p.close() |
paul@446 | 178 | |
paul@756 | 179 | def show_object_on_page(self, errors=None): |
paul@446 | 180 | |
paul@446 | 181 | """ |
paul@756 | 182 | Show the calendar object on the current page. If 'errors' is given, show |
paul@756 | 183 | a suitable message for the different errors provided. |
paul@446 | 184 | """ |
paul@446 | 185 | |
paul@446 | 186 | page = self.page |
paul@446 | 187 | page.form(method="POST") |
paul@446 | 188 | |
paul@595 | 189 | # Add a hidden control to help determine whether editing has already begun. |
paul@595 | 190 | |
paul@764 | 191 | self.control("editing", "hidden", "true") |
paul@446 | 192 | |
paul@446 | 193 | args = self.env.get_args() |
paul@446 | 194 | |
paul@487 | 195 | # Obtain basic event information, generating any necessary editing controls. |
paul@446 | 196 | |
paul@787 | 197 | attendees = self.get_current_attendees() |
paul@765 | 198 | period = self.get_current_main_period() |
paul@765 | 199 | self.show_object_datetime_controls(period) |
paul@446 | 200 | |
paul@487 | 201 | # Obtain any separate recurrences for this event. |
paul@487 | 202 | |
paul@756 | 203 | recurrenceids = self._get_active_recurrences(self.uid) |
paul@765 | 204 | replaced = not self.recurrenceid and period.is_replaced(recurrenceids) |
paul@784 | 205 | excluded = period not in self.get_periods(self.obj) |
paul@487 | 206 | |
paul@446 | 207 | # Provide a summary of the object. |
paul@446 | 208 | |
paul@446 | 209 | page.table(class_="object", cellspacing=5, cellpadding=5) |
paul@446 | 210 | page.thead() |
paul@446 | 211 | page.tr() |
paul@446 | 212 | page.th("Event", class_="mainheading", colspan=2) |
paul@446 | 213 | page.tr.close() |
paul@446 | 214 | page.thead.close() |
paul@446 | 215 | page.tbody() |
paul@446 | 216 | |
paul@446 | 217 | for name, label in self.property_items: |
paul@446 | 218 | field = name.lower() |
paul@446 | 219 | |
paul@757 | 220 | items = uri_items(self.obj.get_items(name) or []) |
paul@446 | 221 | rowspan = len(items) |
paul@446 | 222 | |
paul@446 | 223 | if name == "ATTENDEE": |
paul@473 | 224 | rowspan = len(attendees) + 1 # for the add button |
paul@446 | 225 | elif not items: |
paul@446 | 226 | continue |
paul@446 | 227 | |
paul@446 | 228 | page.tr() |
paul@492 | 229 | page.th(label, class_="objectheading %s%s" % (field, errors and field in errors and " error" or ""), rowspan=rowspan) |
paul@446 | 230 | |
paul@446 | 231 | # Handle datetimes specially. |
paul@446 | 232 | |
paul@446 | 233 | if name in ["DTSTART", "DTEND"]: |
paul@784 | 234 | if not replaced and not excluded: |
paul@446 | 235 | |
paul@487 | 236 | # Obtain the datetime. |
paul@487 | 237 | |
paul@498 | 238 | is_start = name == "DTSTART" |
paul@446 | 239 | |
paul@487 | 240 | # Where no end datetime exists, use the start datetime as the |
paul@487 | 241 | # basis of any potential datetime specified if dt-control is |
paul@487 | 242 | # set. |
paul@487 | 243 | |
paul@765 | 244 | self.show_datetime_controls(is_start and period.get_form_start() or period.get_form_end(), is_start) |
paul@446 | 245 | |
paul@487 | 246 | elif name == "DTSTART": |
paul@784 | 247 | |
paul@784 | 248 | # Replaced occurrences link to their replacements. |
paul@784 | 249 | |
paul@784 | 250 | if replaced: |
paul@784 | 251 | page.td(class_="objectvalue %s replaced" % field, rowspan=2) |
paul@784 | 252 | page.a("First occurrence replaced by a separate event", href=self.link_to(self.uid, replaced)) |
paul@784 | 253 | page.td.close() |
paul@784 | 254 | |
paul@784 | 255 | # NOTE: Should provide a way of editing recurrences when the |
paul@784 | 256 | # NOTE: first occurrence is excluded, plus a way of |
paul@784 | 257 | # NOTE: reinstating the occurrence. |
paul@784 | 258 | |
paul@784 | 259 | elif excluded: |
paul@784 | 260 | page.td(class_="objectvalue %s excluded" % field, rowspan=2) |
paul@784 | 261 | page.add("First occurrence excluded") |
paul@784 | 262 | page.td.close() |
paul@446 | 263 | |
paul@446 | 264 | page.tr.close() |
paul@446 | 265 | |
paul@446 | 266 | # Handle the summary specially. |
paul@446 | 267 | |
paul@446 | 268 | elif name == "SUMMARY": |
paul@756 | 269 | value = args.get("summary", [self.obj.get_value(name)])[0] |
paul@446 | 270 | |
paul@490 | 271 | page.td(class_="objectvalue summary") |
paul@756 | 272 | if self.is_organiser(): |
paul@764 | 273 | self.control("summary", "text", value, size=80) |
paul@446 | 274 | else: |
paul@446 | 275 | page.add(value) |
paul@446 | 276 | page.td.close() |
paul@446 | 277 | page.tr.close() |
paul@446 | 278 | |
paul@473 | 279 | # Handle attendees specially. |
paul@473 | 280 | |
paul@473 | 281 | elif name == "ATTENDEE": |
paul@473 | 282 | attendee_map = dict(items) |
paul@473 | 283 | first = True |
paul@473 | 284 | |
paul@473 | 285 | for i, value in enumerate(attendees): |
paul@473 | 286 | if not first: |
paul@473 | 287 | page.tr() |
paul@473 | 288 | else: |
paul@473 | 289 | first = False |
paul@473 | 290 | |
paul@479 | 291 | # Obtain details of attendees to supply attributes. |
paul@473 | 292 | |
paul@794 | 293 | self.show_attendee(i, value, attendee_map.get(get_uri(value))) |
paul@473 | 294 | page.tr.close() |
paul@473 | 295 | |
paul@473 | 296 | # Allow more attendees to be specified. |
paul@473 | 297 | |
paul@756 | 298 | if self.is_organiser(): |
paul@473 | 299 | if not first: |
paul@473 | 300 | page.tr() |
paul@473 | 301 | |
paul@473 | 302 | page.td() |
paul@764 | 303 | self.control("add", "submit", "add", id="add", class_="add") |
paul@496 | 304 | page.label("Add attendee", for_="add", class_="add") |
paul@473 | 305 | page.td.close() |
paul@473 | 306 | page.tr.close() |
paul@473 | 307 | |
paul@473 | 308 | # Handle potentially many values of other kinds. |
paul@446 | 309 | |
paul@446 | 310 | else: |
paul@446 | 311 | first = True |
paul@446 | 312 | |
paul@446 | 313 | for i, (value, attr) in enumerate(items): |
paul@446 | 314 | if not first: |
paul@446 | 315 | page.tr() |
paul@446 | 316 | else: |
paul@446 | 317 | first = False |
paul@446 | 318 | |
paul@490 | 319 | page.td(class_="objectvalue %s" % field) |
paul@794 | 320 | if name == "ORGANIZER": |
paul@794 | 321 | page.add(get_verbose_address(value, attr)) |
paul@794 | 322 | else: |
paul@794 | 323 | page.add(value) |
paul@446 | 324 | page.td.close() |
paul@446 | 325 | page.tr.close() |
paul@446 | 326 | |
paul@446 | 327 | page.tbody.close() |
paul@446 | 328 | page.table.close() |
paul@446 | 329 | |
paul@756 | 330 | self.show_recurrences(errors) |
paul@766 | 331 | self.show_counters() |
paul@756 | 332 | self.show_conflicting_events() |
paul@756 | 333 | self.show_request_controls() |
paul@446 | 334 | |
paul@446 | 335 | page.form.close() |
paul@446 | 336 | |
paul@756 | 337 | def show_attendee(self, i, attendee, attendee_attr): |
paul@479 | 338 | |
paul@479 | 339 | """ |
paul@756 | 340 | For the current object, show the attendee in position 'i' with the given |
paul@756 | 341 | 'attendee' value, having 'attendee_attr' as any stored attributes. |
paul@479 | 342 | """ |
paul@479 | 343 | |
paul@479 | 344 | page = self.page |
paul@479 | 345 | args = self.env.get_args() |
paul@479 | 346 | |
paul@794 | 347 | attendee_uri = get_uri(attendee) |
paul@479 | 348 | partstat = attendee_attr and attendee_attr.get("PARTSTAT") |
paul@479 | 349 | |
paul@479 | 350 | page.td(class_="objectvalue") |
paul@479 | 351 | |
paul@479 | 352 | # Show a form control as organiser for new attendees. |
paul@479 | 353 | |
paul@794 | 354 | if self.is_organiser() and self.can_edit_attendee(attendee_uri): |
paul@764 | 355 | self.control("attendee", "value", attendee, size="40") |
paul@479 | 356 | else: |
paul@764 | 357 | self.control("attendee", "hidden", attendee) |
paul@479 | 358 | page.add(attendee) |
paul@479 | 359 | page.add(" ") |
paul@479 | 360 | |
paul@479 | 361 | # Show participation status, editable for the current user. |
paul@479 | 362 | |
paul@794 | 363 | if attendee_uri == self.user: |
paul@764 | 364 | self.menu("partstat", partstat, self.partstat_items, "partstat") |
paul@479 | 365 | |
paul@479 | 366 | # Allow the participation indicator to act as a submit |
paul@479 | 367 | # button in order to refresh the page and show a control for |
paul@479 | 368 | # the current user, if indicated. |
paul@479 | 369 | |
paul@794 | 370 | elif self.is_organiser() and self.attendee_is_new(attendee_uri): |
paul@764 | 371 | self.control("partstat-refresh", "submit", "refresh", id="partstat-%d" % i, class_="refresh") |
paul@479 | 372 | page.label(dict(self.partstat_items).get(partstat, ""), for_="partstat-%s" % i, class_="partstat") |
paul@758 | 373 | |
paul@758 | 374 | # Otherwise, just show a label with the participation status. |
paul@758 | 375 | |
paul@479 | 376 | else: |
paul@479 | 377 | page.span(dict(self.partstat_items).get(partstat, ""), class_="partstat") |
paul@479 | 378 | |
paul@479 | 379 | # Permit organisers to remove attendees. |
paul@479 | 380 | |
paul@756 | 381 | if self.is_organiser(): |
paul@479 | 382 | |
paul@479 | 383 | # Permit the removal of newly-added attendees. |
paul@479 | 384 | |
paul@794 | 385 | remove_type = self.can_remove_attendee(attendee_uri) and "submit" or "checkbox" |
paul@764 | 386 | self.control("remove", remove_type, str(i), str(i) in args.get("remove", []), id="remove-%d" % i, class_="remove") |
paul@479 | 387 | |
paul@479 | 388 | page.label("Remove", for_="remove-%d" % i, class_="remove") |
paul@701 | 389 | page.label(for_="remove-%d" % i, class_="removed") |
paul@701 | 390 | page.add("(Uninvited)") |
paul@701 | 391 | page.span("Re-invite", class_="action") |
paul@701 | 392 | page.label.close() |
paul@479 | 393 | |
paul@479 | 394 | page.td.close() |
paul@479 | 395 | |
paul@756 | 396 | def show_recurrences(self, errors=None): |
paul@446 | 397 | |
paul@492 | 398 | """ |
paul@756 | 399 | Show recurrences for the current object. If 'errors' is given, show a |
paul@756 | 400 | suitable message for the different errors provided. |
paul@492 | 401 | """ |
paul@446 | 402 | |
paul@446 | 403 | page = self.page |
paul@446 | 404 | |
paul@446 | 405 | # Obtain any parent object if this object is a specific recurrence. |
paul@446 | 406 | |
paul@756 | 407 | if self.recurrenceid: |
paul@756 | 408 | parent = self.get_stored_object(self.uid, None) |
paul@489 | 409 | if not parent: |
paul@446 | 410 | return |
paul@446 | 411 | |
paul@489 | 412 | page.p() |
paul@756 | 413 | page.a("This event modifies a recurring event.", href=self.link_to(self.uid)) |
paul@489 | 414 | page.p.close() |
paul@446 | 415 | |
paul@499 | 416 | # Obtain the periods associated with the event. |
paul@595 | 417 | # NOTE: Add a control to add recurrences here. |
paul@446 | 418 | |
paul@787 | 419 | recurrences = self.get_current_recurrences() |
paul@446 | 420 | |
paul@499 | 421 | if len(recurrences) < 1: |
paul@446 | 422 | return |
paul@446 | 423 | |
paul@756 | 424 | recurrenceids = self._get_recurrences(self.uid) |
paul@446 | 425 | |
paul@499 | 426 | page.p("This event occurs on the following occasions within the next %d days:" % self.get_window_size()) |
paul@499 | 427 | |
paul@446 | 428 | # Show each recurrence in a separate table if editable. |
paul@446 | 429 | |
paul@756 | 430 | if self.is_organiser() and recurrences: |
paul@446 | 431 | |
paul@519 | 432 | for index, period in enumerate(recurrences): |
paul@756 | 433 | self.show_recurrence(index, period, self.recurrenceid, recurrenceids, errors) |
paul@446 | 434 | |
paul@446 | 435 | # Otherwise, use a compact single table. |
paul@446 | 436 | |
paul@499 | 437 | else: |
paul@499 | 438 | page.table(cellspacing=5, cellpadding=5, class_="recurrence") |
paul@499 | 439 | page.caption("Occurrences") |
paul@499 | 440 | page.thead() |
paul@499 | 441 | page.tr() |
paul@499 | 442 | page.th("Start", class_="objectheading start") |
paul@499 | 443 | page.th("End", class_="objectheading end") |
paul@499 | 444 | page.tr.close() |
paul@499 | 445 | page.thead.close() |
paul@499 | 446 | page.tbody() |
paul@446 | 447 | |
paul@519 | 448 | for index, period in enumerate(recurrences): |
paul@499 | 449 | page.tr() |
paul@756 | 450 | self.show_recurrence_label(period, self.recurrenceid, recurrenceids, True) |
paul@756 | 451 | self.show_recurrence_label(period, self.recurrenceid, recurrenceids, False) |
paul@499 | 452 | page.tr.close() |
paul@446 | 453 | |
paul@499 | 454 | page.tbody.close() |
paul@499 | 455 | page.table.close() |
paul@446 | 456 | |
paul@756 | 457 | def show_recurrence(self, index, period, recurrenceid, recurrenceids, errors=None): |
paul@519 | 458 | |
paul@519 | 459 | """ |
paul@756 | 460 | Show recurrence controls for a recurrence provided by the current object |
paul@756 | 461 | with the given 'index' position in the list of periods, the given |
paul@756 | 462 | 'period' details, where a 'recurrenceid' indicates any specific |
paul@756 | 463 | recurrence, and where 'recurrenceids' indicates all known additional |
paul@756 | 464 | recurrences for the object. |
paul@519 | 465 | |
paul@519 | 466 | If 'errors' is given, show a suitable message for the different errors |
paul@519 | 467 | provided. |
paul@519 | 468 | """ |
paul@519 | 469 | |
paul@519 | 470 | page = self.page |
paul@526 | 471 | args = self.env.get_args() |
paul@526 | 472 | |
paul@528 | 473 | p = event_period_from_period(period) |
paul@633 | 474 | replaced = not recurrenceid and p.is_replaced(recurrenceids) |
paul@528 | 475 | |
paul@519 | 476 | # Isolate the controls from neighbouring tables. |
paul@519 | 477 | |
paul@519 | 478 | page.div() |
paul@519 | 479 | |
paul@519 | 480 | self.show_object_datetime_controls(period, index) |
paul@519 | 481 | |
paul@519 | 482 | page.table(cellspacing=5, cellpadding=5, class_="recurrence") |
paul@519 | 483 | page.caption(period.origin == "RRULE" and "Occurrence from rule" or "Occurrence") |
paul@519 | 484 | page.tbody() |
paul@519 | 485 | |
paul@519 | 486 | page.tr() |
paul@519 | 487 | error = errors and ("dtstart", index) in errors and " error" or "" |
paul@519 | 488 | page.th("Start", class_="objectheading start%s" % error) |
paul@756 | 489 | self.show_recurrence_controls(index, period, recurrenceid, recurrenceids, True) |
paul@519 | 490 | page.tr.close() |
paul@519 | 491 | page.tr() |
paul@519 | 492 | error = errors and ("dtend", index) in errors and " error" or "" |
paul@519 | 493 | page.th("End", class_="objectheading end%s" % error) |
paul@756 | 494 | self.show_recurrence_controls(index, period, recurrenceid, recurrenceids, False) |
paul@519 | 495 | page.tr.close() |
paul@519 | 496 | |
paul@526 | 497 | # Permit the removal of recurrences. |
paul@526 | 498 | |
paul@528 | 499 | if not replaced: |
paul@528 | 500 | page.tr() |
paul@528 | 501 | page.th("") |
paul@528 | 502 | page.td() |
paul@526 | 503 | |
paul@784 | 504 | remove_type = self.can_remove_recurrence(period) and "submit" or "checkbox" |
paul@784 | 505 | |
paul@764 | 506 | self.control("recur-remove", remove_type, str(index), |
paul@528 | 507 | str(index) in args.get("recur-remove", []), |
paul@528 | 508 | id="recur-remove-%d" % index, class_="remove") |
paul@526 | 509 | |
paul@528 | 510 | page.label("Remove", for_="recur-remove-%d" % index, class_="remove") |
paul@701 | 511 | page.label(for_="recur-remove-%d" % index, class_="removed") |
paul@701 | 512 | page.add("(Removed)") |
paul@701 | 513 | page.span("Re-add", class_="action") |
paul@701 | 514 | page.label.close() |
paul@526 | 515 | |
paul@528 | 516 | page.td.close() |
paul@528 | 517 | page.tr.close() |
paul@526 | 518 | |
paul@519 | 519 | page.tbody.close() |
paul@519 | 520 | page.table.close() |
paul@519 | 521 | |
paul@519 | 522 | page.div.close() |
paul@519 | 523 | |
paul@766 | 524 | def show_counters(self): |
paul@766 | 525 | |
paul@766 | 526 | "Show any counter-proposals for the current object." |
paul@766 | 527 | |
paul@766 | 528 | page = self.page |
paul@777 | 529 | query = self.env.get_query() |
paul@777 | 530 | counter = query.get("counter", [None])[0] |
paul@777 | 531 | |
paul@766 | 532 | attendees = self._get_counters(self.uid, self.recurrenceid) |
paul@766 | 533 | tzid = self.get_tzid() |
paul@766 | 534 | |
paul@766 | 535 | if not attendees: |
paul@766 | 536 | return |
paul@766 | 537 | |
paul@766 | 538 | page.p("The following counter-proposals have been received for this event:") |
paul@766 | 539 | |
paul@766 | 540 | page.table(cellspacing=5, cellpadding=5, class_="counters") |
paul@766 | 541 | page.thead() |
paul@766 | 542 | page.tr() |
paul@766 | 543 | page.th("Attendee", rowspan=2) |
paul@766 | 544 | page.th("Periods", colspan=2) |
paul@766 | 545 | page.tr.close() |
paul@766 | 546 | page.tr() |
paul@766 | 547 | page.th("Start") |
paul@766 | 548 | page.th("End") |
paul@766 | 549 | page.tr.close() |
paul@766 | 550 | page.thead.close() |
paul@766 | 551 | page.tbody() |
paul@766 | 552 | |
paul@766 | 553 | for attendee in attendees: |
paul@766 | 554 | obj = self.get_stored_object(self.uid, self.recurrenceid, "counters", attendee) |
paul@766 | 555 | periods = self.get_periods(obj) |
paul@766 | 556 | |
paul@766 | 557 | first = True |
paul@766 | 558 | for p in periods: |
paul@777 | 559 | identifier = "%s-%s" % (format_datetime(p.get_start_point()), format_datetime(p.get_end_point())) |
paul@777 | 560 | css = identifier == counter and "selected" or "" |
paul@777 | 561 | |
paul@805 | 562 | page.tr(class_=css) |
paul@805 | 563 | |
paul@777 | 564 | if first: |
paul@805 | 565 | page.td(attendee, rowspan=len(periods)) |
paul@777 | 566 | first = False |
paul@766 | 567 | |
paul@766 | 568 | start = self.format_datetime(to_timezone(p.get_start(), tzid), "long") |
paul@766 | 569 | end = self.format_datetime(to_timezone(p.get_end(), tzid), "long") |
paul@766 | 570 | |
paul@766 | 571 | page.td(start) |
paul@766 | 572 | page.td(end) |
paul@766 | 573 | |
paul@766 | 574 | page.tr.close() |
paul@766 | 575 | |
paul@766 | 576 | page.tbody.close() |
paul@766 | 577 | page.table.close() |
paul@766 | 578 | |
paul@756 | 579 | def show_conflicting_events(self): |
paul@446 | 580 | |
paul@756 | 581 | "Show conflicting events for the current object." |
paul@446 | 582 | |
paul@446 | 583 | page = self.page |
paul@756 | 584 | recurrenceids = self._get_active_recurrences(self.uid) |
paul@446 | 585 | |
paul@446 | 586 | # Obtain the user's timezone. |
paul@446 | 587 | |
paul@446 | 588 | tzid = self.get_tzid() |
paul@756 | 589 | periods = self.get_periods(self.obj) |
paul@446 | 590 | |
paul@446 | 591 | # Indicate whether there are conflicting events. |
paul@446 | 592 | |
paul@484 | 593 | conflicts = [] |
paul@756 | 594 | attendee_map = uri_dict(self.obj.get_value_map("ATTENDEE")) |
paul@446 | 595 | |
paul@756 | 596 | for participant in self.get_current_attendees(): |
paul@484 | 597 | if participant == self.user: |
paul@484 | 598 | freebusy = self.store.get_freebusy(participant) |
paul@787 | 599 | elif participant: |
paul@787 | 600 | freebusy = self.store.get_freebusy_for_other(self.user, participant) |
paul@484 | 601 | else: |
paul@787 | 602 | continue |
paul@484 | 603 | |
paul@484 | 604 | if not freebusy: |
paul@484 | 605 | continue |
paul@446 | 606 | |
paul@446 | 607 | # Obtain any time zone details from the suggested event. |
paul@446 | 608 | |
paul@756 | 609 | _dtstart, attr = self.obj.get_item("DTSTART") |
paul@446 | 610 | tzid = attr.get("TZID", tzid) |
paul@446 | 611 | |
paul@484 | 612 | # Show any conflicts with periods of actual attendance. |
paul@446 | 613 | |
paul@611 | 614 | participant_attr = attendee_map.get(participant) |
paul@611 | 615 | partstat = participant_attr and participant_attr.get("PARTSTAT") |
paul@756 | 616 | recurrences = self.obj.get_recurrence_start_points(recurrenceids, tzid) |
paul@611 | 617 | |
paul@484 | 618 | for p in have_conflict(freebusy, periods, True): |
paul@756 | 619 | if not self.recurrenceid and p.is_replaced(recurrences): |
paul@528 | 620 | continue |
paul@611 | 621 | |
paul@611 | 622 | if ( # Unidentified or different event |
paul@756 | 623 | (p.uid != self.uid or self.recurrenceid and p.recurrenceid and p.recurrenceid != self.recurrenceid) and |
paul@611 | 624 | # Different period or unclear participation with the same period |
paul@611 | 625 | (p not in periods or not partstat in ("ACCEPTED", "TENTATIVE")) and |
paul@611 | 626 | # Participant not limited to organising |
paul@611 | 627 | p.transp != "ORG" |
paul@611 | 628 | ): |
paul@611 | 629 | |
paul@484 | 630 | conflicts.append(p) |
paul@446 | 631 | |
paul@484 | 632 | conflicts.sort() |
paul@484 | 633 | |
paul@484 | 634 | # Show any conflicts with periods of actual attendance. |
paul@446 | 635 | |
paul@484 | 636 | if conflicts: |
paul@484 | 637 | page.p("This event conflicts with others:") |
paul@446 | 638 | |
paul@484 | 639 | page.table(cellspacing=5, cellpadding=5, class_="conflicts") |
paul@484 | 640 | page.thead() |
paul@484 | 641 | page.tr() |
paul@484 | 642 | page.th("Event") |
paul@484 | 643 | page.th("Start") |
paul@484 | 644 | page.th("End") |
paul@484 | 645 | page.tr.close() |
paul@484 | 646 | page.thead.close() |
paul@484 | 647 | page.tbody() |
paul@446 | 648 | |
paul@484 | 649 | for p in conflicts: |
paul@484 | 650 | |
paul@484 | 651 | # Provide details of any conflicting event. |
paul@446 | 652 | |
paul@535 | 653 | start = self.format_datetime(to_timezone(p.get_start(), tzid), "long") |
paul@535 | 654 | end = self.format_datetime(to_timezone(p.get_end(), tzid), "long") |
paul@446 | 655 | |
paul@484 | 656 | page.tr() |
paul@446 | 657 | |
paul@484 | 658 | # Show the event summary for the conflicting event. |
paul@446 | 659 | |
paul@484 | 660 | page.td() |
paul@484 | 661 | if p.summary: |
paul@488 | 662 | page.a(p.summary, href=self.link_to(p.uid, p.recurrenceid)) |
paul@484 | 663 | else: |
paul@484 | 664 | page.add("(Unspecified event)") |
paul@484 | 665 | page.td.close() |
paul@446 | 666 | |
paul@484 | 667 | page.td(start) |
paul@484 | 668 | page.td(end) |
paul@446 | 669 | |
paul@484 | 670 | page.tr.close() |
paul@446 | 671 | |
paul@484 | 672 | page.tbody.close() |
paul@484 | 673 | page.table.close() |
paul@446 | 674 | |
paul@765 | 675 | class EventPage(EventPageFragment): |
paul@765 | 676 | |
paul@765 | 677 | "A request handler for the event page." |
paul@765 | 678 | |
paul@765 | 679 | def __init__(self, resource=None, messenger=None): |
paul@765 | 680 | ResourceClientForObject.__init__(self, resource) |
paul@765 | 681 | self.messenger = messenger or Messenger() |
paul@474 | 682 | |
paul@765 | 683 | # Request logic methods. |
paul@765 | 684 | |
paul@765 | 685 | def is_initial_load(self): |
paul@765 | 686 | |
paul@765 | 687 | "Return whether the event is being loaded and shown for the first time." |
paul@765 | 688 | |
paul@765 | 689 | return not self.env.get_args().has_key("editing") |
paul@765 | 690 | |
paul@765 | 691 | def handle_request(self): |
paul@474 | 692 | |
paul@474 | 693 | """ |
paul@765 | 694 | Handle actions involving the current object, returning an error if one |
paul@765 | 695 | occurred, or None if the request was successfully handled. |
paul@474 | 696 | """ |
paul@474 | 697 | |
paul@765 | 698 | # Handle a submitted form. |
paul@498 | 699 | |
paul@474 | 700 | args = self.env.get_args() |
paul@765 | 701 | |
paul@765 | 702 | # Get the possible actions. |
paul@765 | 703 | |
paul@765 | 704 | reply = args.has_key("reply") |
paul@765 | 705 | discard = args.has_key("discard") |
paul@765 | 706 | create = args.has_key("create") |
paul@765 | 707 | cancel = args.has_key("cancel") |
paul@765 | 708 | ignore = args.has_key("ignore") |
paul@765 | 709 | save = args.has_key("save") |
paul@474 | 710 | |
paul@765 | 711 | have_action = reply or discard or create or cancel or ignore or save |
paul@765 | 712 | |
paul@765 | 713 | if not have_action: |
paul@765 | 714 | return ["action"] |
paul@474 | 715 | |
paul@765 | 716 | # If ignoring the object, return to the calendar. |
paul@474 | 717 | |
paul@765 | 718 | if ignore: |
paul@765 | 719 | self.redirect(self.env.get_path()) |
paul@765 | 720 | return None |
paul@765 | 721 | |
paul@765 | 722 | # Update the object. |
paul@474 | 723 | |
paul@765 | 724 | single_user = False |
paul@765 | 725 | |
paul@765 | 726 | if reply or create or cancel or save: |
paul@765 | 727 | |
paul@765 | 728 | # Update principal event details if organiser. |
paul@765 | 729 | |
paul@765 | 730 | if self.is_organiser(): |
paul@765 | 731 | |
paul@765 | 732 | # Update time periods (main and recurring). |
paul@474 | 733 | |
paul@765 | 734 | try: |
paul@765 | 735 | period = self.handle_main_period() |
paul@765 | 736 | except PeriodError, exc: |
paul@765 | 737 | return exc.args |
paul@474 | 738 | |
paul@765 | 739 | try: |
paul@765 | 740 | periods = self.handle_recurrence_periods() |
paul@765 | 741 | except PeriodError, exc: |
paul@765 | 742 | return exc.args |
paul@765 | 743 | |
paul@765 | 744 | # Set the periods in the object, first obtaining removed and |
paul@765 | 745 | # modified period information. |
paul@765 | 746 | |
paul@784 | 747 | to_unschedule, to_exclude = self.get_removed_periods(periods) |
paul@765 | 748 | |
paul@765 | 749 | self.obj.set_period(period) |
paul@765 | 750 | self.obj.set_periods(periods) |
paul@784 | 751 | self.obj.update_exceptions(to_exclude) |
paul@474 | 752 | |
paul@765 | 753 | # Update summary. |
paul@765 | 754 | |
paul@765 | 755 | if args.has_key("summary"): |
paul@765 | 756 | self.obj["SUMMARY"] = [(args["summary"][0], {})] |
paul@765 | 757 | |
paul@765 | 758 | # Obtain any participants and those to be removed. |
paul@474 | 759 | |
paul@794 | 760 | attendees = map(lambda s: s and get_uri(s), self.get_attendees_from_page()) |
paul@765 | 761 | removed = [attendees[int(i)] for i in args.get("remove", [])] |
paul@765 | 762 | to_cancel = self.update_attendees(self.obj, attendees, removed) |
paul@765 | 763 | single_user = not attendees or attendees == [self.user] |
paul@765 | 764 | |
paul@765 | 765 | # Update attendee participation for the current user. |
paul@474 | 766 | |
paul@765 | 767 | if args.has_key("partstat"): |
paul@765 | 768 | self.update_participation(self.obj, args["partstat"][0]) |
paul@765 | 769 | |
paul@765 | 770 | # Process any action. |
paul@474 | 771 | |
paul@765 | 772 | invite = not save and create and not single_user |
paul@765 | 773 | save = save or create and single_user |
paul@474 | 774 | |
paul@765 | 775 | handled = True |
paul@474 | 776 | |
paul@765 | 777 | if reply or invite or cancel: |
paul@765 | 778 | |
paul@765 | 779 | client = ManagerClient(self.obj, self.user, self.messenger) |
paul@474 | 780 | |
paul@765 | 781 | # Process the object and remove it from the list of requests. |
paul@765 | 782 | |
paul@765 | 783 | if reply and client.process_received_request(): |
paul@765 | 784 | self.remove_request(self.uid, self.recurrenceid) |
paul@765 | 785 | |
paul@765 | 786 | elif self.is_organiser() and (invite or cancel): |
paul@765 | 787 | |
paul@765 | 788 | # Invitation, uninvitation and unscheduling... |
paul@765 | 789 | |
paul@765 | 790 | if client.process_created_request( |
paul@765 | 791 | invite and "REQUEST" or "CANCEL", to_cancel, to_unschedule): |
paul@765 | 792 | |
paul@765 | 793 | self.remove_request(self.uid, self.recurrenceid) |
paul@474 | 794 | |
paul@765 | 795 | # Save single user events. |
paul@765 | 796 | |
paul@765 | 797 | elif save: |
paul@765 | 798 | self.store.set_event(self.user, self.uid, self.recurrenceid, node=self.obj.to_node()) |
paul@765 | 799 | self.update_event_in_freebusy() |
paul@765 | 800 | self.remove_request(self.uid, self.recurrenceid) |
paul@474 | 801 | |
paul@765 | 802 | # Remove the request and the object. |
paul@474 | 803 | |
paul@765 | 804 | elif discard: |
paul@765 | 805 | self.remove_event_from_freebusy() |
paul@765 | 806 | self.remove_event(self.uid, self.recurrenceid) |
paul@765 | 807 | self.remove_request(self.uid, self.recurrenceid) |
paul@474 | 808 | |
paul@474 | 809 | else: |
paul@765 | 810 | handled = False |
paul@765 | 811 | |
paul@765 | 812 | # Upon handling an action, redirect to the main page. |
paul@765 | 813 | |
paul@765 | 814 | if handled: |
paul@765 | 815 | self.redirect(self.env.get_path()) |
paul@765 | 816 | |
paul@765 | 817 | return None |
paul@765 | 818 | |
paul@765 | 819 | def handle_main_period(self): |
paul@765 | 820 | |
paul@765 | 821 | "Return period details for the main start/end period in an event." |
paul@765 | 822 | |
paul@765 | 823 | return self.get_main_period_from_page().as_event_period() |
paul@765 | 824 | |
paul@765 | 825 | def handle_recurrence_periods(self): |
paul@765 | 826 | |
paul@765 | 827 | "Return period details for the recurrences specified for an event." |
paul@765 | 828 | |
paul@765 | 829 | return [p.as_event_period(i) for i, p in enumerate(self.get_recurrences_from_page())] |
paul@765 | 830 | |
paul@765 | 831 | # Access to form-originating object information. |
paul@765 | 832 | |
paul@765 | 833 | def get_main_period_from_page(self): |
paul@765 | 834 | |
paul@765 | 835 | "Return the main period defined in the event form." |
paul@765 | 836 | |
paul@765 | 837 | args = self.env.get_args() |
paul@765 | 838 | |
paul@765 | 839 | dtend_enabled = args.get("dtend-control", [None])[0] |
paul@765 | 840 | dttimes_enabled = args.get("dttimes-control", [None])[0] |
paul@765 | 841 | start = self.get_date_control_values("dtstart") |
paul@765 | 842 | end = self.get_date_control_values("dtend") |
paul@765 | 843 | |
paul@785 | 844 | period = FormPeriod(start, end, dtend_enabled, dttimes_enabled, self.get_tzid()) |
paul@785 | 845 | |
paul@785 | 846 | # Handle absent main period details. |
paul@785 | 847 | |
paul@785 | 848 | if not period.get_start(): |
paul@785 | 849 | return self.get_stored_main_period() |
paul@785 | 850 | else: |
paul@785 | 851 | return period |
paul@474 | 852 | |
paul@765 | 853 | def get_recurrences_from_page(self): |
paul@765 | 854 | |
paul@765 | 855 | "Return the recurrences defined in the event form." |
paul@765 | 856 | |
paul@765 | 857 | args = self.env.get_args() |
paul@765 | 858 | |
paul@765 | 859 | all_dtend_enabled = args.get("dtend-control-recur", []) |
paul@765 | 860 | all_dttimes_enabled = args.get("dttimes-control-recur", []) |
paul@765 | 861 | all_starts = self.get_date_control_values("dtstart-recur", multiple=True) |
paul@765 | 862 | all_ends = self.get_date_control_values("dtend-recur", multiple=True, tzid_name="dtstart-recur") |
paul@765 | 863 | all_origins = args.get("recur-origin", []) |
paul@765 | 864 | |
paul@765 | 865 | periods = [] |
paul@765 | 866 | |
paul@765 | 867 | for index, (start, end, dtend_enabled, dttimes_enabled, origin) in \ |
paul@765 | 868 | enumerate(map(None, all_starts, all_ends, all_dtend_enabled, all_dttimes_enabled, all_origins)): |
paul@765 | 869 | |
paul@765 | 870 | dtend_enabled = str(index) in all_dtend_enabled |
paul@765 | 871 | dttimes_enabled = str(index) in all_dttimes_enabled |
paul@765 | 872 | period = FormPeriod(start, end, dtend_enabled, dttimes_enabled, self.get_tzid(), origin) |
paul@765 | 873 | periods.append(period) |
paul@765 | 874 | |
paul@765 | 875 | return periods |
paul@765 | 876 | |
paul@787 | 877 | def set_recurrences_in_page(self, recurrences): |
paul@787 | 878 | |
paul@787 | 879 | "Set the recurrences defined in the event form." |
paul@787 | 880 | |
paul@787 | 881 | args = self.env.get_args() |
paul@787 | 882 | |
paul@787 | 883 | args["dtend-control-recur"] = [] |
paul@787 | 884 | args["dttimes-control-recur"] = [] |
paul@787 | 885 | args["recur-origin"] = [] |
paul@787 | 886 | |
paul@787 | 887 | all_starts = [] |
paul@787 | 888 | all_ends = [] |
paul@787 | 889 | |
paul@787 | 890 | for index, period in enumerate(recurrences): |
paul@787 | 891 | if period.end_enabled: |
paul@787 | 892 | args["dtend-control-recur"].append(str(index)) |
paul@787 | 893 | if period.times_enabled: |
paul@787 | 894 | args["dttimes-control-recur"].append(str(index)) |
paul@787 | 895 | args["recur-origin"].append(period.origin or "") |
paul@787 | 896 | |
paul@787 | 897 | all_starts.append(period.get_form_start()) |
paul@787 | 898 | all_ends.append(period.get_form_end()) |
paul@787 | 899 | |
paul@787 | 900 | self.set_date_control_values("dtstart-recur", all_starts) |
paul@787 | 901 | self.set_date_control_values("dtend-recur", all_ends, tzid_name="dtstart-recur") |
paul@787 | 902 | |
paul@783 | 903 | def get_removed_periods(self, periods): |
paul@765 | 904 | |
paul@783 | 905 | """ |
paul@783 | 906 | Return those from the recurrence 'periods' to remove upon updating an |
paul@784 | 907 | event along with those to exclude in a tuple of the form (unscheduled, |
paul@784 | 908 | excluded). |
paul@783 | 909 | """ |
paul@765 | 910 | |
paul@784 | 911 | args = self.env.get_args() |
paul@765 | 912 | to_unschedule = [] |
paul@784 | 913 | to_exclude = [] |
paul@784 | 914 | |
paul@765 | 915 | for i in args.get("recur-remove", []): |
paul@784 | 916 | try: |
paul@784 | 917 | period = periods[int(i)] |
paul@784 | 918 | except (IndexError, ValueError): |
paul@784 | 919 | continue |
paul@784 | 920 | |
paul@784 | 921 | if not self.can_edit_recurrence(period): |
paul@784 | 922 | to_unschedule.append(period) |
paul@784 | 923 | else: |
paul@784 | 924 | to_exclude.append(period) |
paul@784 | 925 | |
paul@784 | 926 | return to_unschedule, to_exclude |
paul@765 | 927 | |
paul@765 | 928 | def get_attendees_from_page(self): |
paul@474 | 929 | |
paul@794 | 930 | "Return attendees from the request." |
paul@474 | 931 | |
paul@794 | 932 | return self.env.get_args().get("attendee", []) |
paul@765 | 933 | |
paul@765 | 934 | def update_attendees_from_page(self): |
paul@765 | 935 | |
paul@765 | 936 | "Add or remove attendees. This does not affect the stored object." |
paul@765 | 937 | |
paul@765 | 938 | args = self.env.get_args() |
paul@765 | 939 | |
paul@765 | 940 | attendees = self.get_attendees_from_page() |
paul@474 | 941 | |
paul@765 | 942 | if args.has_key("add"): |
paul@765 | 943 | attendees.append("") |
paul@517 | 944 | |
paul@765 | 945 | # Only actually remove attendees if the event is unsent, if the attendee |
paul@765 | 946 | # is new, or if it is the current user being removed. |
paul@765 | 947 | |
paul@765 | 948 | if args.has_key("remove"): |
paul@765 | 949 | still_to_remove = [] |
paul@795 | 950 | correction = 0 |
paul@517 | 951 | |
paul@765 | 952 | for i in args["remove"]: |
paul@765 | 953 | try: |
paul@795 | 954 | i = int(i) - correction |
paul@795 | 955 | attendee = attendees[i] |
paul@795 | 956 | except (IndexError, ValueError): |
paul@765 | 957 | continue |
paul@474 | 958 | |
paul@795 | 959 | if self.can_remove_attendee(get_uri(attendee)): |
paul@795 | 960 | del attendees[i] |
paul@795 | 961 | correction += 1 |
paul@765 | 962 | else: |
paul@795 | 963 | still_to_remove.append(str(i)) |
paul@474 | 964 | |
paul@765 | 965 | args["remove"] = still_to_remove |
paul@765 | 966 | |
paul@787 | 967 | args["attendee"] = attendees |
paul@765 | 968 | return attendees |
paul@498 | 969 | |
paul@780 | 970 | def update_recurrences_from_page(self): |
paul@780 | 971 | |
paul@780 | 972 | "Add or remove recurrences. This does not affect the stored object." |
paul@780 | 973 | |
paul@780 | 974 | args = self.env.get_args() |
paul@780 | 975 | |
paul@780 | 976 | recurrences = self.get_recurrences_from_page() |
paul@780 | 977 | |
paul@780 | 978 | # NOTE: Addition of recurrences to be supported. |
paul@780 | 979 | |
paul@780 | 980 | # Only actually remove recurrences if the event is unsent, or if the |
paul@784 | 981 | # recurrence is new, but only for explicit recurrences. |
paul@780 | 982 | |
paul@780 | 983 | if args.has_key("recur-remove"): |
paul@780 | 984 | still_to_remove = [] |
paul@795 | 985 | correction = 0 |
paul@780 | 986 | |
paul@780 | 987 | for i in args["recur-remove"]: |
paul@780 | 988 | try: |
paul@795 | 989 | i = int(i) - correction |
paul@795 | 990 | recurrence = recurrences[i] |
paul@795 | 991 | except (IndexError, ValueError): |
paul@780 | 992 | continue |
paul@780 | 993 | |
paul@780 | 994 | if self.can_remove_recurrence(recurrence): |
paul@795 | 995 | del recurrences[i] |
paul@795 | 996 | correction += 1 |
paul@780 | 997 | else: |
paul@795 | 998 | still_to_remove.append(str(i)) |
paul@780 | 999 | |
paul@780 | 1000 | args["recur-remove"] = still_to_remove |
paul@780 | 1001 | |
paul@787 | 1002 | self.set_recurrences_in_page(recurrences) |
paul@780 | 1003 | return recurrences |
paul@780 | 1004 | |
paul@765 | 1005 | # Access to current object information. |
paul@765 | 1006 | |
paul@765 | 1007 | def get_current_main_period(self): |
paul@498 | 1008 | |
paul@498 | 1009 | """ |
paul@765 | 1010 | Return the currently active main period for the current object depending |
paul@765 | 1011 | on whether editing has begun or whether the object has just been loaded. |
paul@765 | 1012 | """ |
paul@498 | 1013 | |
paul@765 | 1014 | if self.is_initial_load() or not self.is_organiser(): |
paul@765 | 1015 | return self.get_stored_main_period() |
paul@765 | 1016 | else: |
paul@765 | 1017 | return self.get_main_period_from_page() |
paul@765 | 1018 | |
paul@765 | 1019 | def get_current_recurrences(self): |
paul@765 | 1020 | |
paul@765 | 1021 | """ |
paul@765 | 1022 | Return recurrences for the current object using the original object |
paul@765 | 1023 | details where no editing is in progress, using form data otherwise. |
paul@498 | 1024 | """ |
paul@498 | 1025 | |
paul@765 | 1026 | if self.is_initial_load() or not self.is_organiser(): |
paul@765 | 1027 | return self.get_stored_recurrences() |
paul@765 | 1028 | else: |
paul@765 | 1029 | return self.get_recurrences_from_page() |
paul@498 | 1030 | |
paul@780 | 1031 | def update_current_recurrences(self): |
paul@780 | 1032 | |
paul@780 | 1033 | "Return an updated collection of recurrences for the current object." |
paul@780 | 1034 | |
paul@780 | 1035 | if self.is_initial_load() or not self.is_organiser(): |
paul@780 | 1036 | return self.get_stored_recurrences() |
paul@780 | 1037 | else: |
paul@780 | 1038 | return self.update_recurrences_from_page() |
paul@780 | 1039 | |
paul@765 | 1040 | def get_current_attendees(self): |
paul@765 | 1041 | |
paul@765 | 1042 | """ |
paul@765 | 1043 | Return attendees for the current object depending on whether the object |
paul@765 | 1044 | has been edited or instead provides such information from its stored |
paul@765 | 1045 | form. |
paul@765 | 1046 | """ |
paul@499 | 1047 | |
paul@765 | 1048 | if self.is_initial_load() or not self.is_organiser(): |
paul@765 | 1049 | return self.get_stored_attendees() |
paul@765 | 1050 | else: |
paul@765 | 1051 | return self.get_attendees_from_page() |
paul@765 | 1052 | |
paul@765 | 1053 | def update_current_attendees(self): |
paul@498 | 1054 | |
paul@765 | 1055 | "Return an updated collection of attendees for the current object." |
paul@765 | 1056 | |
paul@765 | 1057 | if self.is_initial_load() or not self.is_organiser(): |
paul@765 | 1058 | return self.get_stored_attendees() |
paul@498 | 1059 | else: |
paul@765 | 1060 | return self.update_attendees_from_page() |
paul@474 | 1061 | |
paul@446 | 1062 | # Full page output methods. |
paul@446 | 1063 | |
paul@446 | 1064 | def show(self, path_info): |
paul@446 | 1065 | |
paul@446 | 1066 | "Show an object request using the given 'path_info' for the current user." |
paul@446 | 1067 | |
paul@763 | 1068 | uid, recurrenceid = self.get_identifiers(path_info) |
paul@763 | 1069 | obj = self.get_stored_object(uid, recurrenceid) |
paul@756 | 1070 | self.set_object(obj) |
paul@446 | 1071 | |
paul@446 | 1072 | if not obj: |
paul@446 | 1073 | return False |
paul@446 | 1074 | |
paul@756 | 1075 | errors = self.handle_request() |
paul@446 | 1076 | |
paul@492 | 1077 | if not errors: |
paul@446 | 1078 | return True |
paul@446 | 1079 | |
paul@787 | 1080 | self.update_current_attendees() |
paul@787 | 1081 | self.update_current_recurrences() |
paul@787 | 1082 | |
paul@446 | 1083 | self.new_page(title="Event") |
paul@756 | 1084 | self.show_object_on_page(errors) |
paul@446 | 1085 | |
paul@446 | 1086 | return True |
paul@446 | 1087 | |
paul@446 | 1088 | # vim: tabstop=4 expandtab shiftwidth=4 |