1.1 --- a/imiptools/dates.py Tue Oct 20 17:42:58 2015 +0200
1.2 +++ b/imiptools/dates.py Tue Oct 20 17:44:45 2015 +0200
1.3 @@ -443,9 +443,22 @@
1.4 offset = offset or timedelta(0)
1.5 return format_datetime(to_timezone(datetime.utcnow(), "UTC") + offset)
1.6
1.7 +def get_date(offset=None):
1.8 +
1.9 + """
1.10 + Return the current date, offset by the given timedelta 'offset' if
1.11 + specified. The returned date will not be positioned in any time zone.
1.12 + """
1.13 +
1.14 + offset = offset or timedelta(0)
1.15 + return date.today() + offset
1.16 +
1.17 def get_time(offset=None):
1.18
1.19 - "Return the current time."
1.20 + """
1.21 + Return the current time, offset by the given timedelta 'offset' if
1.22 + specified. The returned time will be in the UTC time zone.
1.23 + """
1.24
1.25 offset = offset or timedelta(0)
1.26 return to_timezone(datetime.utcnow(), "UTC") + offset
2.1 --- a/imipweb/calendar.py Tue Oct 20 17:42:58 2015 +0200
2.2 +++ b/imipweb/calendar.py Tue Oct 20 17:44:45 2015 +0200
2.3 @@ -21,7 +21,7 @@
2.4
2.5 from datetime import datetime, timedelta
2.6 from imiptools.data import get_address, get_uri, uri_parts
2.7 -from imiptools.dates import format_datetime, get_datetime, \
2.8 +from imiptools.dates import format_datetime, get_date, get_datetime, \
2.9 get_datetime_item, get_end_of_day, get_start_of_day, \
2.10 get_start_of_next_day, get_timestamp, ends_on_same_day, \
2.11 to_timezone
2.12 @@ -270,7 +270,7 @@
2.13 page.input(name="showdays", type="checkbox", value="show", id="showdays", accesskey="D")
2.14 page.input(name="hidebusy", type="checkbox", value="hide", id="hidebusy", accesskey="B")
2.15
2.16 - page.p(class_="controls")
2.17 + page.p(id_="calendar-controls", class_="controls")
2.18 page.span("Select days or periods for a new event.")
2.19 page.label("Hide busy time periods", for_="hidebusy", class_="hidebusy enable")
2.20 page.label("Show busy time periods", for_="hidebusy", class_="hidebusy disable")
2.21 @@ -348,45 +348,17 @@
2.22 link_args["end"] = format_datetime(view_end)
2.23 return link_args
2.24
2.25 - # Full page output methods.
2.26 -
2.27 - def show(self):
2.28 -
2.29 - "Show the calendar for the current user."
2.30 -
2.31 - self.new_page(title="Calendar")
2.32 - page = self.page
2.33 -
2.34 - if self.handle_newevent():
2.35 - return
2.36 + def get_period_group_details(self, freebusy, participants, view_period):
2.37
2.38 - freebusy = self.store.get_freebusy(self.user)
2.39 -
2.40 - if not freebusy:
2.41 - page.p("No events scheduled.")
2.42 - return
2.43 -
2.44 - participants = self.update_participants()
2.45 -
2.46 - # Form controls are used in various places on the calendar page.
2.47 -
2.48 - page.form(method="POST")
2.49 -
2.50 - self.show_requests_on_page()
2.51 - self.show_participants_on_page(participants)
2.52 + """
2.53 + Return details of periods in the given 'freebusy' collection and for the
2.54 + collections of the given 'participants'.
2.55 + """
2.56
2.57 # Obtain the user's timezone.
2.58
2.59 tzid = self.get_tzid()
2.60
2.61 - # Day view: start at the earliest known day and produce days until the
2.62 - # latest known day, with expandable sections of empty days.
2.63 -
2.64 - view_start, view_end = self.get_time_navigation()
2.65 - view_period = (view_start or view_end) and Period(view_start, view_end, self.get_tzid())
2.66 -
2.67 - self.show_time_navigation(view_start, view_end)
2.68 -
2.69 # Requests are listed and linked to their tentative positions in the
2.70 # calendar. Other participants are also shown.
2.71
2.72 @@ -498,13 +470,59 @@
2.73 partitioned_group_types.append(group_type)
2.74 partitioned_group_sources.append(group_source)
2.75
2.76 + return days, partitioned_groups, partitioned_group_types, partitioned_group_sources, group_columns
2.77 +
2.78 + # Full page output methods.
2.79 +
2.80 + def show(self):
2.81 +
2.82 + "Show the calendar for the current user."
2.83 +
2.84 + self.new_page(title="Calendar")
2.85 + page = self.page
2.86 +
2.87 + if self.handle_newevent():
2.88 + return
2.89 +
2.90 + freebusy = self.store.get_freebusy(self.user)
2.91 +
2.92 + if not freebusy:
2.93 + page.p("No events scheduled.")
2.94 + return
2.95 +
2.96 + participants = self.update_participants()
2.97 +
2.98 + # Form controls are used in various places on the calendar page.
2.99 +
2.100 + page.form(method="POST")
2.101 +
2.102 + self.show_requests_on_page()
2.103 + self.show_participants_on_page(participants)
2.104 +
2.105 + # Day view: start at the earliest known day and produce days until the
2.106 + # latest known day, with expandable sections of empty days.
2.107 +
2.108 + view_start, view_end = self.get_time_navigation()
2.109 +
2.110 + # Without any explicit limits, impose a reasonable view period.
2.111 +
2.112 + if not (view_start or view_end):
2.113 + view_start = get_date()
2.114 + view_end = get_date(timedelta(8))
2.115 +
2.116 + view_period = (view_start or view_end) and Period(view_start, view_end, self.get_tzid())
2.117 +
2.118 + (days, partitioned_groups, partitioned_group_types, partitioned_group_sources, group_columns) = \
2.119 + self.get_period_group_details(freebusy, participants, view_period)
2.120 +
2.121 # Add empty days.
2.122
2.123 - add_empty_days(days, tzid, view_start, view_end)
2.124 + add_empty_days(days, self.get_tzid(), view_start, view_end)
2.125
2.126 # Show controls to change the calendar appearance.
2.127
2.128 self.show_calendar_controls()
2.129 + self.show_time_navigation(view_start, view_end)
2.130
2.131 # Show the calendar itself.
2.132