# HG changeset patch # User Paul Boddie # Date 1422630911 -3600 # Node ID 591c54d309fe7240d9e11ec95e1a1c8e43c0a79f # Parent 464a0f3f82754c37f8b45e04ffb985891271c65a Changed the record of all points to that of all slot intervals/divisions so that start and end time points can be used in form controls for new event creation. diff -r 464a0f3f8275 -r 591c54d309fe imip_manager.py --- a/imip_manager.py Fri Jan 30 16:13:25 2015 +0100 +++ b/imip_manager.py Fri Jan 30 16:15:11 2015 +0100 @@ -614,7 +614,7 @@ # Record the slots and all time points employed. groups.append(slots) - all_points.update([point for point, slot in slots]) + all_points.update([point for point, active in slots]) # Partition the groups into days. @@ -638,7 +638,17 @@ partitioned = {} for day, day_slots in partition_by_day(slots).items(): - columns = max(columns, max(map(lambda i: len(i[1]), day_slots))) + intervals = [] + last = None + + for point, active in day_slots: + columns = max(columns, len(active)) + if last: + intervals.append((last, point)) + last = point + + if last: + intervals.append((last, None)) if not days.has_key(day): days[day] = set() @@ -646,9 +656,11 @@ # Convert each partition to a mapping from points to active # periods. - day_slots = dict(day_slots) - partitioned[day] = day_slots - days[day].update(day_slots.keys()) + partitioned[day] = dict(day_slots) + + # Record the divisions or intervals within each day. + + days[day].update(intervals) if group_type != "request" or columns: group_columns.append(columns) @@ -715,7 +727,7 @@ # Produce a heading and time points for each day. - for day, points in all_days: + for day, intervals in all_days: page.thead() page.tr() page.th(class_="dayheading", colspan=all_columns+1) @@ -727,13 +739,13 @@ groups_for_day = [partitioned.get(day) for partitioned in partitioned_groups] page.tbody() - self.show_calendar_points(points, groups_for_day, partitioned_group_types, group_columns) + self.show_calendar_points(intervals, groups_for_day, partitioned_group_types, group_columns) page.tbody.close() - def show_calendar_points(self, points, groups, group_types, group_columns): + def show_calendar_points(self, intervals, groups, group_types, group_columns): """ - Show the time 'points' along with period information from the given + Show the time 'intervals' along with period information from the given 'groups', having the indicated 'group_types', each with the number of columns given by 'group_columns'. """ @@ -742,15 +754,15 @@ # Produce a row for each time point. - points = list(points) - points.sort() + intervals = list(intervals) + intervals.sort() - for point in points: + for point, endpoint in intervals: continuation = point == get_start_of_day(point) page.tr() page.th(class_="timeslot") - self._time_point(point) + self._time_point(point, endpoint) page.th.close() # Obtain slots for the time point from each group. @@ -764,7 +776,7 @@ if not active: page.td(class_="empty container", colspan=max(columns, 1)) - self._empty_slot(point) + self._empty_slot(point, endpoint) page.td.close() continue @@ -819,7 +831,7 @@ page.td.close() else: page.td(class_="empty container") - self._empty_slot(point) + self._empty_slot(point, endpoint) page.td.close() # Pad with empty columns. @@ -828,21 +840,26 @@ while i > 0: i -= 1 page.td(class_="empty container") - self._empty_slot(point) + self._empty_slot(point, endpoint) page.td.close() page.tr.close() - def _time_point(self, point): + def _time_point(self, point, endpoint): + page = self.page + value, identifier = self._slot_value_and_identifier(point, endpoint) + page.input(name="start", type="radio", value=value, id=identifier, class_="newevent") + page.label(self.format_time(point, "long"), class_="timepoint", for_=identifier) + + def _empty_slot(self, point, endpoint): page = self.page - pointstr = format_datetime(point) - page.input(name="start", type="radio", value=pointstr, id="start-%s" % pointstr, class_="newevent") - page.label(self.format_time(point, "long"), class_="timepoint", for_="start-%s" % pointstr) + value, identifier = self._slot_value_and_identifier(point, endpoint) + page.label("Make a new event in this period", class_="newevent popup", for_=identifier) - def _empty_slot(self, point): - page = self.page - pointstr = format_datetime(point) - page.label("Start a new event at this time", class_="newevent popup", for_="start-%s" % pointstr) + def _slot_value_and_identifier(self, point, endpoint): + value = "%s-%s" % tuple(map(format_datetime, [point, endpoint])) + identifier = "slot-%s" % value + return value, identifier def select_action(self):