# HG changeset patch # User Paul Boddie # Date 1445355885 -7200 # Node ID 1dda608a1fb1745c53276db52e151b673b030e7b # Parent 8ee0c9bc2d142dac569ca272b404555e707aa799 Separated out period group calculation from the show method. Moved the calendar controls above the time navigation controls. Added a default view period. diff -r 8ee0c9bc2d14 -r 1dda608a1fb1 imiptools/dates.py --- a/imiptools/dates.py Tue Oct 20 17:42:58 2015 +0200 +++ b/imiptools/dates.py Tue Oct 20 17:44:45 2015 +0200 @@ -443,9 +443,22 @@ offset = offset or timedelta(0) return format_datetime(to_timezone(datetime.utcnow(), "UTC") + offset) +def get_date(offset=None): + + """ + Return the current date, offset by the given timedelta 'offset' if + specified. The returned date will not be positioned in any time zone. + """ + + offset = offset or timedelta(0) + return date.today() + offset + def get_time(offset=None): - "Return the current time." + """ + Return the current time, offset by the given timedelta 'offset' if + specified. The returned time will be in the UTC time zone. + """ offset = offset or timedelta(0) return to_timezone(datetime.utcnow(), "UTC") + offset diff -r 8ee0c9bc2d14 -r 1dda608a1fb1 imipweb/calendar.py --- a/imipweb/calendar.py Tue Oct 20 17:42:58 2015 +0200 +++ b/imipweb/calendar.py Tue Oct 20 17:44:45 2015 +0200 @@ -21,7 +21,7 @@ from datetime import datetime, timedelta from imiptools.data import get_address, get_uri, uri_parts -from imiptools.dates import format_datetime, get_datetime, \ +from imiptools.dates import format_datetime, get_date, get_datetime, \ get_datetime_item, get_end_of_day, get_start_of_day, \ get_start_of_next_day, get_timestamp, ends_on_same_day, \ to_timezone @@ -270,7 +270,7 @@ page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D") page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B") - page.p(class_="controls") + page.p(id_="calendar-controls", class_="controls") page.span("Select days or periods for a new event.") page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable") page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable") @@ -348,45 +348,17 @@ link_args["end"] = format_datetime(view_end) return link_args - # Full page output methods. - - def show(self): - - "Show the calendar for the current user." - - self.new_page(title="Calendar") - page = self.page - - if self.handle_newevent(): - return + def get_period_group_details(self, freebusy, participants, view_period): - freebusy = self.store.get_freebusy(self.user) - - if not freebusy: - page.p("No events scheduled.") - return - - participants = self.update_participants() - - # Form controls are used in various places on the calendar page. - - page.form(method="POST") - - self.show_requests_on_page() - self.show_participants_on_page(participants) + """ + Return details of periods in the given 'freebusy' collection and for the + collections of the given 'participants'. + """ # Obtain the user's timezone. tzid = self.get_tzid() - # Day view: start at the earliest known day and produce days until the - # latest known day, with expandable sections of empty days. - - view_start, view_end = self.get_time_navigation() - view_period = (view_start or view_end) and Period(view_start, view_end, self.get_tzid()) - - self.show_time_navigation(view_start, view_end) - # Requests are listed and linked to their tentative positions in the # calendar. Other participants are also shown. @@ -498,13 +470,59 @@ partitioned_group_types.append(group_type) partitioned_group_sources.append(group_source) + return days, partitioned_groups, partitioned_group_types, partitioned_group_sources, group_columns + + # Full page output methods. + + def show(self): + + "Show the calendar for the current user." + + self.new_page(title="Calendar") + page = self.page + + if self.handle_newevent(): + return + + freebusy = self.store.get_freebusy(self.user) + + if not freebusy: + page.p("No events scheduled.") + return + + participants = self.update_participants() + + # Form controls are used in various places on the calendar page. + + page.form(method="POST") + + self.show_requests_on_page() + self.show_participants_on_page(participants) + + # Day view: start at the earliest known day and produce days until the + # latest known day, with expandable sections of empty days. + + view_start, view_end = self.get_time_navigation() + + # Without any explicit limits, impose a reasonable view period. + + if not (view_start or view_end): + view_start = get_date() + view_end = get_date(timedelta(8)) + + view_period = (view_start or view_end) and Period(view_start, view_end, self.get_tzid()) + + (days, partitioned_groups, partitioned_group_types, partitioned_group_sources, group_columns) = \ + self.get_period_group_details(freebusy, participants, view_period) + # Add empty days. - add_empty_days(days, tzid, view_start, view_end) + add_empty_days(days, self.get_tzid(), view_start, view_end) # Show controls to change the calendar appearance. self.show_calendar_controls() + self.show_time_navigation(view_start, view_end) # Show the calendar itself.