1.1 --- a/macros/EventAggregator.py Sun Oct 31 22:08:00 2010 +0100
1.2 +++ b/macros/EventAggregator.py Sun Nov 07 23:56:44 2010 +0100
1.3 @@ -131,6 +131,11 @@
1.4 self.getQualifiedParameterName("mode"), mode or self.mode
1.5 )
1.6
1.7 + def getFullDateLabel(self, date):
1.8 + page = self.page
1.9 + request = page.request
1.10 + return EventAggregatorSupport.getFullDateLabel(request, date)
1.11 +
1.12 def getFullMonthLabel(self, year_month):
1.13 page = self.page
1.14 request = page.request
1.15 @@ -381,7 +386,39 @@
1.16
1.17 # Calendar layout methods.
1.18
1.19 - def writeDayNumbers(self, first_day, number_of_days, month, busy_dates):
1.20 + def writeMonthTableHeading(self, year_month):
1.21 + page = self.page
1.22 + fmt = page.formatter
1.23 +
1.24 + output = []
1.25 + output.append(fmt.table_row(on=1))
1.26 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"}))
1.27 +
1.28 + output.append(self.writeMonthHeading(year_month))
1.29 +
1.30 + output.append(fmt.table_cell(on=0))
1.31 + output.append(fmt.table_row(on=0))
1.32 +
1.33 + return "".join(output)
1.34 +
1.35 + def writeWeekdayHeadings(self):
1.36 + page = self.page
1.37 + request = page.request
1.38 + fmt = page.formatter
1.39 + _ = request.getText
1.40 +
1.41 + output = []
1.42 + output.append(fmt.table_row(on=1))
1.43 +
1.44 + for weekday in range(0, 7):
1.45 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"}))
1.46 + output.append(fmt.text(_(EventAggregatorSupport.getDayLabel(weekday))))
1.47 + output.append(fmt.table_cell(on=0))
1.48 +
1.49 + output.append(fmt.table_row(on=0))
1.50 + return "".join(output)
1.51 +
1.52 + def writeDayNumbers(self, first_day, number_of_days, month, coverage):
1.53 page = self.page
1.54 fmt = page.formatter
1.55
1.56 @@ -402,7 +439,7 @@
1.57 # Output normal days.
1.58
1.59 else:
1.60 - if date in busy_dates:
1.61 + if date in coverage:
1.62 output.append(fmt.table_cell(on=1,
1.63 attrs={"class" : "event-day-heading event-day-busy", "colspan" : "3"}))
1.64 else:
1.65 @@ -703,6 +740,25 @@
1.66 output.append(fmt.table_row(on=0))
1.67 return "".join(output)
1.68
1.69 + # Day layout methods.
1.70 +
1.71 + def writeDayHeading(self, date):
1.72 + page = self.page
1.73 + request = page.request
1.74 + fmt = page.formatter
1.75 + _ = request.getText
1.76 + full_date_label = self.getFullDateLabel(date)
1.77 +
1.78 + output = []
1.79 + output.append(fmt.table_row(on=1))
1.80 +
1.81 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading"}))
1.82 + output.append(fmt.text(full_date_label))
1.83 + output.append(fmt.table_cell(on=0))
1.84 +
1.85 + output.append(fmt.table_row(on=0))
1.86 + return "".join(output)
1.87 +
1.88 # HTML-related functions.
1.89
1.90 def getColour(s):
1.91 @@ -731,11 +787,16 @@
1.92 optional named arguments of the following forms:
1.93
1.94 start=YYYY-MM shows event details starting from the specified month
1.95 + start=YYYY-MM-DD shows event details starting from the specified day
1.96 start=current-N shows event details relative to the current month
1.97 + (or relative to the current day in "day" mode)
1.98 end=YYYY-MM shows event details ending at the specified month
1.99 + end=YYYY-MM-DD shows event details ending on the specified day
1.100 end=current+N shows event details relative to the current month
1.101 + (or relative to the current day in "day" mode)
1.102
1.103 mode=calendar shows a calendar view of events
1.104 + mode=day shows a calendar day view of events
1.105 mode=list shows a list of events by month
1.106 mode=table shows a table of events
1.107
1.108 @@ -782,11 +843,9 @@
1.109 for arg in parsed_args:
1.110 if arg.startswith("start="):
1.111 raw_calendar_start = arg[6:]
1.112 - calendar_start = EventAggregatorSupport.getParameterMonth(raw_calendar_start)
1.113
1.114 elif arg.startswith("end="):
1.115 raw_calendar_end = arg[4:]
1.116 - calendar_end = EventAggregatorSupport.getParameterMonth(raw_calendar_end)
1.117
1.118 elif arg.startswith("mode="):
1.119 mode = arg[5:]
1.120 @@ -808,16 +867,29 @@
1.121
1.122 # Find request parameters to override settings.
1.123
1.124 - if calendar_name is not None:
1.125 - calendar_start = EventAggregatorSupport.getFormMonth(request, calendar_name, "start") or calendar_start
1.126 - calendar_end = EventAggregatorSupport.getFormMonth(request, calendar_name, "end") or calendar_end
1.127 -
1.128 mode = EventAggregatorSupport.getQualifiedParameter(request, calendar_name, "mode", mode or "calendar")
1.129
1.130 - # Get the events.
1.131 + if mode == "day":
1.132 + get_date = EventAggregatorSupport.getParameterDate
1.133 + get_form_date = EventAggregatorSupport.getFormDate
1.134 + else:
1.135 + get_date = EventAggregatorSupport.getParameterMonth
1.136 + get_form_date = EventAggregatorSupport.getFormMonth
1.137 +
1.138 + # Determine the limits of the calendar.
1.139 +
1.140 + calendar_start = get_date(raw_calendar_start)
1.141 + calendar_end = get_date(raw_calendar_end)
1.142 +
1.143 + if calendar_name is not None:
1.144 + calendar_start = get_form_date(request, calendar_name, "start") or calendar_start
1.145 + calendar_end = get_form_date(request, calendar_name, "end") or calendar_end
1.146 +
1.147 + # Get the events according to the resolution of the calendar.
1.148
1.149 events, shown_events, all_shown_events, earliest, latest = \
1.150 - EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end)
1.151 + EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end,
1.152 + mode == "day" and "date" or "month")
1.153
1.154 # Get a concrete period of time.
1.155
1.156 @@ -919,7 +991,7 @@
1.157
1.158 output.append(fmt.table(on=0))
1.159
1.160 - # Output a list or calendar.
1.161 + # Output a list or month calendar.
1.162
1.163 elif mode in ("list", "calendar"):
1.164
1.165 @@ -942,27 +1014,14 @@
1.166
1.167 output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
1.168
1.169 - output.append(fmt.table_row(on=1))
1.170 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"}))
1.171 -
1.172 # Either write a month heading or produce links for navigable
1.173 # calendars.
1.174
1.175 - output.append(view.writeMonthHeading(month))
1.176 -
1.177 - output.append(fmt.table_cell(on=0))
1.178 - output.append(fmt.table_row(on=0))
1.179 + output.append(view.writeMonthTableHeading(month))
1.180
1.181 # Weekday headings.
1.182
1.183 - output.append(fmt.table_row(on=1))
1.184 -
1.185 - for weekday in range(0, 7):
1.186 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"}))
1.187 - output.append(fmt.text(_(EventAggregatorSupport.getDayLabel(weekday))))
1.188 - output.append(fmt.table_cell(on=0))
1.189 -
1.190 - output.append(fmt.table_row(on=0))
1.191 + output.append(view.writeWeekdayHeadings())
1.192
1.193 # Process the days of the month.
1.194
1.195 @@ -1087,6 +1146,25 @@
1.196 if mode == "list":
1.197 output.append(fmt.bullet_list(on=0))
1.198
1.199 + # Output a day view.
1.200 +
1.201 + elif mode == "day":
1.202 +
1.203 + # Visit all days in the requested range, or across known events.
1.204 +
1.205 + for date in first.days_until(last):
1.206 +
1.207 + output.append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"}))
1.208 +
1.209 + full_coverage, day_slots = EventAggregatorSupport.getCoverage(
1.210 + date, date, shown_events.get(date, []))
1.211 +
1.212 + output.append(self.writeDayHeading(date))
1.213 +
1.214 + # End of day.
1.215 +
1.216 + output.append(fmt.table(on=0))
1.217 +
1.218 # Output view controls.
1.219
1.220 output.append(fmt.div(on=1, css_class="event-controls"))