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