1 #!/usr/bin/env python 2 3 """ 4 A Web interface to an event calendar. 5 6 Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 from datetime import datetime 23 from imiptools.data import get_address, get_uri, uri_parts 24 from imiptools.dates import format_datetime, get_datetime, \ 25 get_datetime_item, get_end_of_day, get_start_of_day, \ 26 get_start_of_next_day, get_timestamp, ends_on_same_day, \ 27 to_timezone 28 from imiptools.period import add_day_start_points, add_empty_days, add_slots, \ 29 get_scale, get_slots, get_spans, partition_by_day, Point 30 from imipweb.resource import ResourceClient 31 32 class CalendarPage(ResourceClient): 33 34 "A request handler for the calendar page." 35 36 # Request logic methods. 37 38 def handle_newevent(self): 39 40 """ 41 Handle any new event operation, creating a new event and redirecting to 42 the event page for further activity. 43 """ 44 45 # Handle a submitted form. 46 47 args = self.env.get_args() 48 49 for key in args.keys(): 50 if key.startswith("newevent-"): 51 i = key[len("newevent-"):] 52 break 53 else: 54 return 55 56 # Create a new event using the available information. 57 58 slots = args.get("slot", []) 59 participants = args.get("participants", []) 60 summary = args.get("summary-%s" % i, [None])[0] 61 62 if not slots: 63 return 64 65 # Obtain the user's timezone. 66 67 tzid = self.get_tzid() 68 69 # Coalesce the selected slots. 70 71 slots.sort() 72 coalesced = [] 73 last = None 74 75 for slot in slots: 76 start, end = (slot.split("-", 1) + [None])[:2] 77 start = get_datetime(start, {"TZID" : tzid}) 78 end = end and get_datetime(end, {"TZID" : tzid}) or get_start_of_next_day(start, tzid) 79 80 if last: 81 last_start, last_end = last 82 83 # Merge adjacent dates and datetimes. 84 85 if start == last_end or \ 86 not isinstance(start, datetime) and \ 87 get_start_of_day(last_end, tzid) == get_start_of_day(start, tzid): 88 89 last = last_start, end 90 continue 91 92 # Handle datetimes within dates. 93 # Datetime periods are within single days and are therefore 94 # discarded. 95 96 elif not isinstance(last_start, datetime) and \ 97 get_start_of_day(start, tzid) == get_start_of_day(last_start, tzid): 98 99 continue 100 101 # Add separate dates and datetimes. 102 103 else: 104 coalesced.append(last) 105 106 last = start, end 107 108 if last: 109 coalesced.append(last) 110 111 # Invent a unique identifier. 112 113 utcnow = get_timestamp() 114 uid = "imip-agent-%s-%s" % (utcnow, get_address(self.user)) 115 116 # Create a calendar object and store it as a request. 117 118 record = [] 119 rwrite = record.append 120 121 # Define a single occurrence if only one coalesced slot exists. 122 123 start, end = coalesced[0] 124 start_value, start_attr = get_datetime_item(start, tzid) 125 end_value, end_attr = get_datetime_item(end, tzid) 126 user_attr = self.get_user_attributes() 127 128 rwrite(("UID", {}, uid)) 129 rwrite(("SUMMARY", {}, summary or ("New event at %s" % utcnow))) 130 rwrite(("DTSTAMP", {}, utcnow)) 131 rwrite(("DTSTART", start_attr, start_value)) 132 rwrite(("DTEND", end_attr, end_value)) 133 rwrite(("ORGANIZER", user_attr, self.user)) 134 135 cn_participants = uri_parts(filter(None, participants)) 136 participants = [] 137 138 for cn, participant in cn_participants: 139 d = {"RSVP" : "TRUE", "PARTSTAT" : "NEEDS-ACTION"} 140 if cn: 141 d["CN"] = cn 142 rwrite(("ATTENDEE", d, participant)) 143 participants.append(participant) 144 145 if self.user not in participants: 146 d = {"PARTSTAT" : "ACCEPTED"} 147 d.update(user_attr) 148 rwrite(("ATTENDEE", d, self.user)) 149 150 # Define additional occurrences if many slots are defined. 151 152 rdates = [] 153 154 for start, end in coalesced[1:]: 155 start_value, start_attr = get_datetime_item(start, tzid) 156 end_value, end_attr = get_datetime_item(end, tzid) 157 rdates.append("%s/%s" % (start_value, end_value)) 158 159 if rdates: 160 rwrite(("RDATE", {"VALUE" : "PERIOD", "TZID" : tzid}, rdates)) 161 162 node = ("VEVENT", {}, record) 163 164 self.store.set_event(self.user, uid, None, node=node) 165 self.store.queue_request(self.user, uid) 166 167 # Redirect to the object (or the first of the objects), where instead of 168 # attendee controls, there will be organiser controls. 169 170 self.redirect(self.link_to(uid)) 171 172 # Page fragment methods. 173 174 def show_requests_on_page(self): 175 176 "Show requests for the current user." 177 178 page = self.page 179 180 # NOTE: This list could be more informative, but it is envisaged that 181 # NOTE: the requests would be visited directly anyway. 182 183 requests = self._get_requests() 184 185 page.div(id="pending-requests") 186 187 if requests: 188 page.p("Pending requests:") 189 190 page.ul() 191 192 for uid, recurrenceid, request_type in requests: 193 obj = self._get_object(uid, recurrenceid) 194 if obj: 195 page.li() 196 page.a(obj.get_value("SUMMARY"), href="#request-%s-%s" % (uid, recurrenceid or "")) 197 page.li.close() 198 199 page.ul.close() 200 201 else: 202 page.p("There are no pending requests.") 203 204 page.div.close() 205 206 def show_participants_on_page(self): 207 208 "Show participants for scheduling purposes." 209 210 page = self.page 211 args = self.env.get_args() 212 participants = args.get("participants", []) 213 214 try: 215 for name, value in args.items(): 216 if name.startswith("remove-participant-"): 217 i = int(name[len("remove-participant-"):]) 218 del participants[i] 219 break 220 except ValueError: 221 pass 222 223 # Trim empty participants. 224 225 while participants and not participants[-1].strip(): 226 participants.pop() 227 228 # Show any specified participants together with controls to remove and 229 # add participants. 230 231 page.div(id="participants") 232 233 page.p("Participants for scheduling:") 234 235 for i, participant in enumerate(participants): 236 page.p() 237 page.input(name="participants", type="text", value=participant) 238 page.input(name="remove-participant-%d" % i, type="submit", value="Remove") 239 page.p.close() 240 241 page.p() 242 page.input(name="participants", type="text") 243 page.input(name="add-participant", type="submit", value="Add") 244 page.p.close() 245 246 page.div.close() 247 248 return participants 249 250 # Full page output methods. 251 252 def show(self): 253 254 "Show the calendar for the current user." 255 256 self.new_page(title="Calendar") 257 page = self.page 258 259 handled = self.handle_newevent() 260 freebusy = self.store.get_freebusy(self.user) 261 262 if not freebusy: 263 page.p("No events scheduled.") 264 return 265 266 # Form controls are used in various places on the calendar page. 267 268 page.form(method="POST") 269 270 self.show_requests_on_page() 271 participants = self.show_participants_on_page() 272 273 # Obtain the user's timezone. 274 275 tzid = self.get_tzid() 276 277 # Day view: start at the earliest known day and produce days until the 278 # latest known day, perhaps with expandable sections of empty days. 279 280 # Month view: start at the earliest known month and produce months until 281 # the latest known month, perhaps with expandable sections of empty 282 # months. 283 284 # Details of users to invite to new events could be superimposed on the 285 # calendar. 286 287 # Requests are listed and linked to their tentative positions in the 288 # calendar. Other participants are also shown. 289 290 request_summary = self._get_request_summary() 291 292 period_groups = [request_summary, freebusy] 293 period_group_types = ["request", "freebusy"] 294 period_group_sources = ["Pending requests", "Your schedule"] 295 296 for i, participant in enumerate(participants): 297 period_groups.append(self.store.get_freebusy_for_other(self.user, get_uri(participant))) 298 period_group_types.append("freebusy-part%d" % i) 299 period_group_sources.append(participant) 300 301 groups = [] 302 group_columns = [] 303 group_types = period_group_types 304 group_sources = period_group_sources 305 all_points = set() 306 307 # Obtain time point information for each group of periods. 308 309 for periods in period_groups: 310 311 # Get the time scale with start and end points. 312 313 scale = get_scale(periods, tzid) 314 315 # Get the time slots for the periods. 316 # Time slots are collections of Point objects with lists of active 317 # periods. 318 319 slots = get_slots(scale) 320 321 # Add start of day time points for multi-day periods. 322 323 add_day_start_points(slots, tzid) 324 325 # Record the slots and all time points employed. 326 327 groups.append(slots) 328 all_points.update([point for point, active in slots]) 329 330 # Partition the groups into days. 331 332 days = {} 333 partitioned_groups = [] 334 partitioned_group_types = [] 335 partitioned_group_sources = [] 336 337 for slots, group_type, group_source in zip(groups, group_types, group_sources): 338 339 # Propagate time points to all groups of time slots. 340 341 add_slots(slots, all_points) 342 343 # Count the number of columns employed by the group. 344 345 columns = 0 346 347 # Partition the time slots by day. 348 349 partitioned = {} 350 351 for day, day_slots in partition_by_day(slots).items(): 352 353 # Construct a list of time intervals within the day. 354 355 intervals = [] 356 357 # Convert each partition to a mapping from points to active 358 # periods. 359 360 partitioned[day] = day_points = {} 361 362 last = None 363 364 for point, active in day_slots: 365 columns = max(columns, len(active)) 366 day_points[point] = active 367 368 if last: 369 intervals.append((last, point)) 370 371 last = point 372 373 if last: 374 intervals.append((last, None)) 375 376 if not days.has_key(day): 377 days[day] = set() 378 379 # Record the divisions or intervals within each day. 380 381 days[day].update(intervals) 382 383 # Only include the requests column if it provides objects. 384 385 if group_type != "request" or columns: 386 group_columns.append(columns) 387 partitioned_groups.append(partitioned) 388 partitioned_group_types.append(group_type) 389 partitioned_group_sources.append(group_source) 390 391 # Add empty days. 392 393 add_empty_days(days, tzid) 394 395 page.p("Select days or periods for a new event.") 396 397 # Show controls for hiding empty days and busy slots. 398 # The positioning of the control, paragraph and table are important here. 399 400 page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D") 401 page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B") 402 403 page.p(class_="controls") 404 page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable") 405 page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable") 406 page.label("Show empty days", for_="showdays", class_="showdays disable") 407 page.label("Hide empty days", for_="showdays", class_="showdays enable") 408 page.input(name="reset", type="submit", value="Clear selections", id="reset") 409 page.label("Clear selections", for_="reset", class_="reset newevent-with-periods") 410 page.p.close() 411 412 # Show the calendar itself. 413 414 self.show_calendar_days(days, partitioned_groups, partitioned_group_types, partitioned_group_sources, group_columns) 415 416 # End the form region. 417 418 page.form.close() 419 420 # More page fragment methods. 421 422 def show_calendar_day_controls(self, day): 423 424 "Show controls for the given 'day' in the calendar." 425 426 page = self.page 427 daystr, dayid = self._day_value_and_identifier(day) 428 429 # Generate a dynamic stylesheet to allow day selections to colour 430 # specific days. 431 # NOTE: The style details need to be coordinated with the static 432 # NOTE: stylesheet. 433 434 page.style(type="text/css") 435 436 page.add("""\ 437 input.newevent.selector#%s:checked ~ table#region-%s label.day, 438 input.newevent.selector#%s:checked ~ table#region-%s label.timepoint { 439 background-color: #5f4; 440 text-decoration: underline; 441 } 442 """ % (dayid, dayid, dayid, dayid)) 443 444 page.style.close() 445 446 # Generate controls to select days. 447 448 slots = self.env.get_args().get("slot", []) 449 value, identifier = self._day_value_and_identifier(day) 450 self._slot_selector(value, identifier, slots) 451 452 def show_calendar_interval_controls(self, day, intervals): 453 454 "Show controls for the intervals provided by 'day' and 'intervals'." 455 456 page = self.page 457 daystr, dayid = self._day_value_and_identifier(day) 458 459 # Generate a dynamic stylesheet to allow day selections to colour 460 # specific days. 461 # NOTE: The style details need to be coordinated with the static 462 # NOTE: stylesheet. 463 464 l = [] 465 466 for point, endpoint in intervals: 467 timestr, timeid = self._slot_value_and_identifier(point, endpoint) 468 l.append("""\ 469 input.newevent.selector#%s:checked ~ table#region-%s th#region-%s""" % (timeid, dayid, timeid)) 470 471 page.style(type="text/css") 472 473 page.add(",\n".join(l)) 474 page.add(""" { 475 background-color: #5f4; 476 text-decoration: underline; 477 } 478 """) 479 480 page.style.close() 481 482 # Generate controls to select time periods. 483 484 slots = self.env.get_args().get("slot", []) 485 last = None 486 487 # Produce controls for the intervals/slots. Where instants in time are 488 # encountered, they are merged with the following slots, permitting the 489 # selection of contiguous time periods. However, the identifiers 490 # employed by controls corresponding to merged periods will encode the 491 # instant so that labels may reference them conveniently. 492 493 intervals = list(intervals) 494 intervals.sort() 495 496 for point, endpoint in intervals: 497 498 # Merge any previous slot with this one, producing a control. 499 500 if last: 501 _value, identifier = self._slot_value_and_identifier(last, last) 502 value, _identifier = self._slot_value_and_identifier(last, endpoint) 503 self._slot_selector(value, identifier, slots) 504 505 # If representing an instant, hold the slot for merging. 506 507 if endpoint and point.point == endpoint.point: 508 last = point 509 510 # If not representing an instant, produce a control. 511 512 else: 513 value, identifier = self._slot_value_and_identifier(point, endpoint) 514 self._slot_selector(value, identifier, slots) 515 last = None 516 517 # Produce a control for any unmerged slot. 518 519 if last: 520 _value, identifier = self._slot_value_and_identifier(last, last) 521 value, _identifier = self._slot_value_and_identifier(last, endpoint) 522 self._slot_selector(value, identifier, slots) 523 524 def show_calendar_participant_headings(self, group_types, group_sources, group_columns): 525 526 """ 527 Show headings for the participants and other scheduling contributors, 528 defined by 'group_types', 'group_sources' and 'group_columns'. 529 """ 530 531 page = self.page 532 533 page.colgroup(span=1, id="columns-timeslot") 534 535 for group_type, columns in zip(group_types, group_columns): 536 page.colgroup(span=max(columns, 1), id="columns-%s" % group_type) 537 538 page.thead() 539 page.tr() 540 page.th("", class_="emptyheading") 541 542 for group_type, source, columns in zip(group_types, group_sources, group_columns): 543 page.th(source, 544 class_=(group_type == "request" and "requestheading" or "participantheading"), 545 colspan=max(columns, 1)) 546 547 page.tr.close() 548 page.thead.close() 549 550 def show_calendar_days(self, days, partitioned_groups, partitioned_group_types, 551 partitioned_group_sources, group_columns): 552 553 """ 554 Show calendar days, defined by a collection of 'days', the contributing 555 period information as 'partitioned_groups' (partitioned by day), the 556 'partitioned_group_types' indicating the kind of contribution involved, 557 the 'partitioned_group_sources' indicating the origin of each group, and 558 the 'group_columns' defining the number of columns in each group. 559 """ 560 561 page = self.page 562 563 # Determine the number of columns required. Where participants provide 564 # no columns for events, one still needs to be provided for the 565 # participant itself. 566 567 all_columns = sum([max(columns, 1) for columns in group_columns]) 568 569 # Determine the days providing time slots. 570 571 all_days = days.items() 572 all_days.sort() 573 574 # Produce a heading and time points for each day. 575 576 i = 0 577 578 for day, intervals in all_days: 579 groups_for_day = [partitioned.get(day) for partitioned in partitioned_groups] 580 is_empty = True 581 582 for slots in groups_for_day: 583 if not slots: 584 continue 585 586 for active in slots.values(): 587 if active: 588 is_empty = False 589 break 590 591 daystr, dayid = self._day_value_and_identifier(day) 592 593 # Put calendar tables within elements for quicker CSS selection. 594 595 page.div(class_="calendar") 596 597 # Show the controls permitting day selection as well as the controls 598 # configuring the new event display. 599 600 self.show_calendar_day_controls(day) 601 self.show_calendar_interval_controls(day, intervals) 602 603 # Show an actual table containing the day information. 604 605 page.table(cellspacing=5, cellpadding=5, class_="calendar %s" % (is_empty and " empty" or ""), id="region-%s" % dayid) 606 607 page.caption(class_="dayheading container separator") 608 self._day_heading(day) 609 page.caption.close() 610 611 self.show_calendar_participant_headings(partitioned_group_types, partitioned_group_sources, group_columns) 612 613 page.tbody(class_="points") 614 self.show_calendar_points(intervals, groups_for_day, partitioned_group_types, group_columns) 615 page.tbody.close() 616 617 page.table.close() 618 619 # Show a button for scheduling a new event. 620 621 page.p(class_="newevent-with-periods") 622 page.label("Summary:") 623 page.input(name="summary-%d" % i, type="text") 624 page.input(name="newevent-%d" % i, type="submit", value="New event", accesskey="N") 625 page.p.close() 626 627 page.div.close() 628 629 i += 1 630 631 def show_calendar_points(self, intervals, groups, group_types, group_columns): 632 633 """ 634 Show the time 'intervals' along with period information from the given 635 'groups', having the indicated 'group_types', each with the number of 636 columns given by 'group_columns'. 637 """ 638 639 page = self.page 640 641 # Obtain the user's timezone. 642 643 tzid = self.get_tzid() 644 645 # Produce a row for each interval. 646 647 intervals = list(intervals) 648 intervals.sort() 649 650 for point, endpoint in intervals: 651 continuation = point.point == get_start_of_day(point.point, tzid) 652 653 # Some rows contain no period details and are marked as such. 654 655 have_active = False 656 have_active_request = False 657 658 for slots, group_type in zip(groups, group_types): 659 if slots and slots.get(point): 660 if group_type == "request": 661 have_active_request = True 662 else: 663 have_active = True 664 665 # Emit properties of the time interval, where post-instant intervals 666 # are also treated as busy. 667 668 css = " ".join([ 669 "slot", 670 (have_active or point.indicator == Point.REPEATED) and "busy" or \ 671 have_active_request and "suggested" or "empty", 672 continuation and "daystart" or "" 673 ]) 674 675 page.tr(class_=css) 676 677 # Produce a time interval heading, spanning two rows if this point 678 # represents an instant. 679 680 if point.indicator == Point.PRINCIPAL: 681 timestr, timeid = self._slot_value_and_identifier(point, endpoint) 682 page.th(class_="timeslot", id="region-%s" % timeid, 683 rowspan=(endpoint and point.point == endpoint.point and 2 or 1)) 684 self._time_point(point, endpoint) 685 page.th.close() 686 687 # Obtain slots for the time point from each group. 688 689 for columns, slots, group_type in zip(group_columns, groups, group_types): 690 active = slots and slots.get(point) 691 692 # Where no periods exist for the given time interval, generate 693 # an empty cell. Where a participant provides no periods at all, 694 # the colspan is adjusted to be 1, not 0. 695 696 if not active: 697 self._empty_slot(point, endpoint, max(columns, 1)) 698 continue 699 700 slots = slots.items() 701 slots.sort() 702 spans = get_spans(slots) 703 704 empty = 0 705 706 # Show a column for each active period. 707 708 for p in active: 709 710 # The period can be None, meaning an empty column. 711 712 if p: 713 714 # Flush empty slots preceding this one. 715 716 if empty: 717 self._empty_slot(point, endpoint, empty) 718 empty = 0 719 720 key = p.get_key() 721 span = spans[key] 722 723 # Produce a table cell only at the start of the period 724 # or when continued at the start of a day. 725 # Points defining the ends of instant events should 726 # never define the start of new events. 727 728 if point.indicator == Point.PRINCIPAL and (point.point == p.get_start() or continuation): 729 730 has_continued = continuation and point.point != p.get_start() 731 will_continue = not ends_on_same_day(point.point, p.get_end(), tzid) 732 is_organiser = p.organiser == self.user 733 734 css = " ".join([ 735 "event", 736 has_continued and "continued" or "", 737 will_continue and "continues" or "", 738 p.transp == "ORG" and "only-organising" or is_organiser and "organising" or "attending", 739 self._have_request(p.uid, p.recurrenceid, "COUNTER", True) and "counter" or "", 740 ]) 741 742 # Only anchor the first cell of events. 743 # Need to only anchor the first period for a recurring 744 # event. 745 746 html_id = "%s-%s-%s" % (group_type, p.uid, p.recurrenceid or "") 747 748 if point.point == p.get_start() and html_id not in self.html_ids: 749 page.td(class_=css, rowspan=span, id=html_id) 750 self.html_ids.add(html_id) 751 else: 752 page.td(class_=css, rowspan=span) 753 754 # Only link to events if they are not being updated 755 # by requests. 756 757 if not p.summary or \ 758 group_type != "request" and self._have_request(p.uid, p.recurrenceid, None, True): 759 760 page.span(p.summary or "(Participant is busy)") 761 762 # Link to requests and events (including ones for 763 # which counter-proposals exist). 764 765 elif group_type == "request" and self._have_request(p.uid, p.recurrenceid, "COUNTER", True): 766 page.a(p.summary, href=self.link_to(p.uid, p.recurrenceid, 767 {"counter" : self._period_identifier(p)})) 768 769 else: 770 page.a(p.summary, href=self.link_to(p.uid, p.recurrenceid)) 771 772 page.td.close() 773 else: 774 empty += 1 775 776 # Pad with empty columns. 777 778 empty = columns - len(active) 779 780 if empty: 781 self._empty_slot(point, endpoint, empty) 782 783 page.tr.close() 784 785 def _day_heading(self, day): 786 787 """ 788 Generate a heading for 'day' of the following form: 789 790 <label class="day" for="day-20150203">Tuesday, 3 February 2015</label> 791 """ 792 793 page = self.page 794 value, identifier = self._day_value_and_identifier(day) 795 page.label(self.format_date(day, "full"), class_="day", for_=identifier) 796 797 def _time_point(self, point, endpoint): 798 799 """ 800 Generate headings for the 'point' to 'endpoint' period of the following 801 form: 802 803 <label class="timepoint" for="slot-20150203T090000-20150203T100000">09:00:00 CET</label> 804 <span class="endpoint">10:00:00 CET</span> 805 """ 806 807 page = self.page 808 tzid = self.get_tzid() 809 value, identifier = self._slot_value_and_identifier(point, endpoint) 810 page.label(self.format_time(point.point, "long"), class_="timepoint", for_=identifier) 811 page.span(self.format_time(endpoint and endpoint.point or get_end_of_day(point.point, tzid), "long"), class_="endpoint") 812 813 def _slot_selector(self, value, identifier, slots): 814 815 """ 816 Provide a timeslot control having the given 'value', employing the 817 indicated HTML 'identifier', and using the given 'slots' collection 818 to select any control whose 'value' is in this collection, unless the 819 "reset" request parameter has been asserted. 820 """ 821 822 reset = self.env.get_args().has_key("reset") 823 page = self.page 824 if not reset and value in slots: 825 page.input(name="slot", type="checkbox", value=value, id=identifier, class_="newevent selector", checked="checked") 826 else: 827 page.input(name="slot", type="checkbox", value=value, id=identifier, class_="newevent selector") 828 829 def _empty_slot(self, point, endpoint, colspan): 830 831 """ 832 Show an empty slot cell for the given 'point' and 'endpoint', with the 833 given 'colspan' configuring the cell's appearance. 834 """ 835 836 page = self.page 837 page.td(class_="empty%s" % (point.indicator == Point.PRINCIPAL and " container" or ""), colspan=colspan) 838 if point.indicator == Point.PRINCIPAL: 839 value, identifier = self._slot_value_and_identifier(point, endpoint) 840 page.label("Select/deselect period", class_="newevent popup", for_=identifier) 841 page.td.close() 842 843 def _day_value_and_identifier(self, day): 844 845 "Return a day value and HTML identifier for the given 'day'." 846 847 value = format_datetime(day) 848 identifier = "day-%s" % value 849 return value, identifier 850 851 def _slot_value_and_identifier(self, point, endpoint): 852 853 """ 854 Return a slot value and HTML identifier for the given 'point' and 855 'endpoint'. 856 """ 857 858 value = "%s-%s" % (format_datetime(point.point), endpoint and format_datetime(endpoint.point) or "") 859 identifier = "slot-%s" % value 860 return value, identifier 861 862 def _period_identifier(self, period): 863 return "%s-%s" % (format_datetime(period.get_start()), format_datetime(period.get_end())) 864 865 # vim: tabstop=4 expandtab shiftwidth=4