paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - EventAggregator Macro |
paul@0 | 4 | |
paul@126 | 5 | @copyright: 2008, 2009, 2010, 2011 by Paul Boddie <paul@boddie.org.uk> |
paul@0 | 6 | @copyright: 2000-2004 Juergen Hermann <jh@web.de>, |
paul@0 | 7 | 2005-2008 MoinMoin:ThomasWaldmann. |
paul@0 | 8 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@0 | 9 | """ |
paul@0 | 10 | |
paul@10 | 11 | from MoinMoin import wikiutil |
paul@10 | 12 | import EventAggregatorSupport |
paul@0 | 13 | import calendar |
paul@0 | 14 | |
paul@27 | 15 | linkToPage = EventAggregatorSupport.linkToPage |
paul@27 | 16 | |
paul@0 | 17 | Dependencies = ['pages'] |
paul@0 | 18 | |
paul@37 | 19 | # Abstractions. |
paul@37 | 20 | |
paul@37 | 21 | class View: |
paul@37 | 22 | |
paul@37 | 23 | "A view of the event calendar." |
paul@37 | 24 | |
paul@76 | 25 | def __init__(self, page, calendar_name, raw_calendar_start, raw_calendar_end, |
paul@128 | 26 | original_calendar_start, original_calendar_end, calendar_start, calendar_end, |
paul@128 | 27 | first, last, category_names, template_name, parent_name, mode, name_usage): |
paul@37 | 28 | |
paul@37 | 29 | """ |
paul@37 | 30 | Initialise the view with the current 'page', a 'calendar_name' (which |
paul@76 | 31 | may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which |
paul@76 | 32 | are the actual start and end values provided by the request), the |
paul@128 | 33 | calculated 'original_calendar_start' and 'original_calendar_end' (which |
paul@128 | 34 | are the result of calculating the calendar's limits from the raw start |
paul@128 | 35 | and end values), and the requested, calculated 'calendar_start' and |
paul@128 | 36 | 'calendar_end' (which may involve different start and end values due to |
paul@128 | 37 | navigation in the user interface), along with the 'first' and 'last' |
paul@128 | 38 | months of event coverage. |
paul@57 | 39 | |
paul@57 | 40 | The additional 'category_names', 'template_name', 'parent_name' and |
paul@57 | 41 | 'mode' parameters are used to configure the links employed by the view. |
paul@120 | 42 | |
paul@120 | 43 | The 'name_usage' parameter controls how names are shown on calendar mode |
paul@126 | 44 | events, such as how often labels are repeated. |
paul@37 | 45 | """ |
paul@37 | 46 | |
paul@37 | 47 | self.page = page |
paul@37 | 48 | self.calendar_name = calendar_name |
paul@76 | 49 | self.raw_calendar_start = raw_calendar_start |
paul@76 | 50 | self.raw_calendar_end = raw_calendar_end |
paul@128 | 51 | self.original_calendar_start = original_calendar_start |
paul@128 | 52 | self.original_calendar_end = original_calendar_end |
paul@57 | 53 | self.calendar_start = calendar_start |
paul@57 | 54 | self.calendar_end = calendar_end |
paul@57 | 55 | self.template_name = template_name |
paul@57 | 56 | self.parent_name = parent_name |
paul@57 | 57 | self.mode = mode |
paul@120 | 58 | self.name_usage = name_usage |
paul@57 | 59 | |
paul@57 | 60 | self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names]) |
paul@37 | 61 | |
paul@37 | 62 | if self.calendar_name is not None: |
paul@37 | 63 | |
paul@37 | 64 | # Store the view parameters. |
paul@37 | 65 | |
paul@67 | 66 | self.number_of_months = (last - first).months() + 1 |
paul@37 | 67 | |
paul@67 | 68 | self.previous_month_start = first.previous_month() |
paul@67 | 69 | self.next_month_start = first.next_month() |
paul@67 | 70 | self.previous_month_end = last.previous_month() |
paul@67 | 71 | self.next_month_end = last.next_month() |
paul@37 | 72 | |
paul@67 | 73 | self.previous_set_start = first.month_update(-self.number_of_months) |
paul@67 | 74 | self.next_set_start = first.month_update(self.number_of_months) |
paul@67 | 75 | self.previous_set_end = last.month_update(-self.number_of_months) |
paul@67 | 76 | self.next_set_end = last.month_update(self.number_of_months) |
paul@37 | 77 | |
paul@58 | 78 | def getQualifiedParameterName(self, argname): |
paul@119 | 79 | |
paul@119 | 80 | "Return the 'argname' qualified using the calendar name." |
paul@119 | 81 | |
paul@58 | 82 | return EventAggregatorSupport.getQualifiedParameterName(self.calendar_name, argname) |
paul@58 | 83 | |
paul@123 | 84 | def getDateQueryString(self, argname, date, prefix=1): |
paul@119 | 85 | |
paul@119 | 86 | """ |
paul@119 | 87 | Return a query string fragment for the given 'argname', referring to the |
paul@119 | 88 | month given by the specified 'year_month' object, appropriate for this |
paul@119 | 89 | calendar. |
paul@119 | 90 | |
paul@119 | 91 | If 'prefix' is specified and set to a false value, the parameters in the |
paul@119 | 92 | query string will not be calendar-specific, but could be used with the |
paul@119 | 93 | summary action. |
paul@119 | 94 | """ |
paul@119 | 95 | |
paul@123 | 96 | suffixes = ["year", "month", "day"] |
paul@123 | 97 | |
paul@123 | 98 | if date is not None: |
paul@123 | 99 | args = [] |
paul@123 | 100 | for suffix, value in zip(suffixes, date.as_tuple()): |
paul@123 | 101 | suffixed_argname = "%s-%s" % (argname, suffix) |
paul@123 | 102 | if prefix: |
paul@123 | 103 | suffixed_argname = self.getQualifiedParameterName(suffixed_argname) |
paul@123 | 104 | args.append("%s=%s" % (suffixed_argname, value)) |
paul@123 | 105 | return "&".join(args) |
paul@114 | 106 | else: |
paul@114 | 107 | return "" |
paul@114 | 108 | |
paul@123 | 109 | def getRawDateQueryString(self, argname, date, prefix=1): |
paul@119 | 110 | |
paul@119 | 111 | """ |
paul@119 | 112 | Return a query string fragment for the given 'argname', referring to the |
paul@123 | 113 | date given by the specified 'date' value, appropriate for this |
paul@119 | 114 | calendar. |
paul@119 | 115 | |
paul@119 | 116 | If 'prefix' is specified and set to a false value, the parameters in the |
paul@119 | 117 | query string will not be calendar-specific, but could be used with the |
paul@119 | 118 | summary action. |
paul@119 | 119 | """ |
paul@119 | 120 | |
paul@123 | 121 | if date is not None: |
paul@57 | 122 | if prefix: |
paul@58 | 123 | argname = self.getQualifiedParameterName(argname) |
paul@123 | 124 | return "%s=%s" % (argname, date) |
paul@37 | 125 | else: |
paul@37 | 126 | return "" |
paul@37 | 127 | |
paul@57 | 128 | def getNavigationLink(self, start, end, mode=None): |
paul@119 | 129 | |
paul@119 | 130 | """ |
paul@119 | 131 | Return a query string fragment for navigation to a view showing months |
paul@119 | 132 | from 'start' to 'end' inclusive, with the optional 'mode' indicating the |
paul@119 | 133 | view style. |
paul@119 | 134 | """ |
paul@119 | 135 | |
paul@58 | 136 | return "%s&%s&%s=%s" % ( |
paul@123 | 137 | self.getRawDateQueryString("start", start), |
paul@123 | 138 | self.getRawDateQueryString("end", end), |
paul@58 | 139 | self.getQualifiedParameterName("mode"), mode or self.mode |
paul@57 | 140 | ) |
paul@57 | 141 | |
paul@122 | 142 | def getFullDateLabel(self, date): |
paul@122 | 143 | page = self.page |
paul@122 | 144 | request = page.request |
paul@122 | 145 | return EventAggregatorSupport.getFullDateLabel(request, date) |
paul@122 | 146 | |
paul@114 | 147 | def getFullMonthLabel(self, year_month): |
paul@114 | 148 | page = self.page |
paul@114 | 149 | request = page.request |
paul@114 | 150 | return EventAggregatorSupport.getFullMonthLabel(request, year_month) |
paul@114 | 151 | |
paul@57 | 152 | def writeDownloadControls(self): |
paul@57 | 153 | page = self.page |
paul@57 | 154 | request = page.request |
paul@57 | 155 | fmt = page.formatter |
paul@57 | 156 | _ = request.getText |
paul@57 | 157 | |
paul@57 | 158 | output = [] |
paul@57 | 159 | |
paul@57 | 160 | # Generate the links. |
paul@57 | 161 | |
paul@128 | 162 | download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&%s" % ( |
paul@128 | 163 | self.parent_name or "", |
paul@128 | 164 | self.mode == "day" and "date" or "month", |
paul@128 | 165 | self.category_name_parameters |
paul@74 | 166 | ) |
paul@112 | 167 | download_all_link = download_dialogue_link + "&doit=1" |
paul@57 | 168 | download_link = download_all_link + ("&%s&%s" % ( |
paul@123 | 169 | self.getDateQueryString("start", self.calendar_start, prefix=0), |
paul@123 | 170 | self.getDateQueryString("end", self.calendar_end, prefix=0) |
paul@57 | 171 | )) |
paul@112 | 172 | |
paul@112 | 173 | # Subscription links just explicitly select the RSS format. |
paul@112 | 174 | |
paul@112 | 175 | subscribe_dialogue_link = download_dialogue_link + "&format=RSS" |
paul@57 | 176 | subscribe_all_link = download_all_link + "&format=RSS" |
paul@57 | 177 | subscribe_link = download_link + "&format=RSS" |
paul@57 | 178 | |
paul@76 | 179 | # Adjust the "download all" and "subscribe all" links if the calendar |
paul@76 | 180 | # has an inherent period associated with it. |
paul@76 | 181 | |
paul@76 | 182 | period_limits = [] |
paul@76 | 183 | |
paul@76 | 184 | if self.raw_calendar_start: |
paul@76 | 185 | period_limits.append("&%s" % |
paul@123 | 186 | self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0) |
paul@76 | 187 | ) |
paul@76 | 188 | if self.raw_calendar_end: |
paul@76 | 189 | period_limits.append("&%s" % |
paul@123 | 190 | self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0) |
paul@76 | 191 | ) |
paul@76 | 192 | |
paul@76 | 193 | period_limits = "".join(period_limits) |
paul@76 | 194 | |
paul@112 | 195 | download_dialogue_link += period_limits |
paul@76 | 196 | download_all_link += period_limits |
paul@112 | 197 | subscribe_dialogue_link += period_limits |
paul@76 | 198 | subscribe_all_link += period_limits |
paul@76 | 199 | |
paul@112 | 200 | # Pop-up descriptions of the downloadable calendars. |
paul@112 | 201 | |
paul@126 | 202 | get_label = self.mode == "day" and self.getFullDateLabel or self.getFullMonthLabel |
paul@126 | 203 | |
paul@114 | 204 | calendar_period = "%s - %s" % ( |
paul@126 | 205 | get_label(self.calendar_start), |
paul@126 | 206 | get_label(self.calendar_end) |
paul@114 | 207 | ) |
paul@128 | 208 | original_calendar_period = "%s - %s" % ( |
paul@128 | 209 | get_label(self.original_calendar_start), |
paul@128 | 210 | get_label(self.original_calendar_end) |
paul@128 | 211 | ) |
paul@112 | 212 | raw_calendar_period = "%s - %s" % (self.raw_calendar_start, self.raw_calendar_end) |
paul@112 | 213 | |
paul@57 | 214 | # Write the controls. |
paul@57 | 215 | |
paul@114 | 216 | # Download controls. |
paul@114 | 217 | |
paul@57 | 218 | output.append(fmt.div(on=1, css_class="event-download-controls")) |
paul@57 | 219 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 220 | output.append(linkToPage(request, page, _("Download this view"), download_link)) |
paul@112 | 221 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 222 | output.append(fmt.text(calendar_period)) |
paul@112 | 223 | output.append(fmt.span(on=0)) |
paul@57 | 224 | output.append(fmt.span(on=0)) |
paul@114 | 225 | |
paul@57 | 226 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 227 | output.append(linkToPage(request, page, _("Download this calendar"), download_all_link)) |
paul@112 | 228 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@114 | 229 | output.append(fmt.span(on=1, css_class="event-download-period")) |
paul@128 | 230 | output.append(fmt.text(original_calendar_period)) |
paul@114 | 231 | output.append(fmt.span(on=0)) |
paul@114 | 232 | output.append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@112 | 233 | output.append(fmt.text(raw_calendar_period)) |
paul@112 | 234 | output.append(fmt.span(on=0)) |
paul@112 | 235 | output.append(fmt.span(on=0)) |
paul@114 | 236 | output.append(fmt.span(on=0)) |
paul@114 | 237 | |
paul@112 | 238 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@112 | 239 | output.append(linkToPage(request, page, _("Download..."), download_dialogue_link)) |
paul@112 | 240 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 241 | output.append(fmt.text(_("Edit download options"))) |
paul@112 | 242 | output.append(fmt.span(on=0)) |
paul@57 | 243 | output.append(fmt.span(on=0)) |
paul@114 | 244 | |
paul@114 | 245 | # Subscription controls. |
paul@114 | 246 | |
paul@57 | 247 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 248 | output.append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link)) |
paul@112 | 249 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 250 | output.append(fmt.text(calendar_period)) |
paul@112 | 251 | output.append(fmt.span(on=0)) |
paul@57 | 252 | output.append(fmt.span(on=0)) |
paul@114 | 253 | |
paul@57 | 254 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 255 | output.append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link)) |
paul@112 | 256 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@114 | 257 | output.append(fmt.span(on=1, css_class="event-download-period")) |
paul@128 | 258 | output.append(fmt.text(original_calendar_period)) |
paul@114 | 259 | output.append(fmt.span(on=0)) |
paul@114 | 260 | output.append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@112 | 261 | output.append(fmt.text(raw_calendar_period)) |
paul@112 | 262 | output.append(fmt.span(on=0)) |
paul@112 | 263 | output.append(fmt.span(on=0)) |
paul@114 | 264 | output.append(fmt.span(on=0)) |
paul@114 | 265 | |
paul@112 | 266 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@112 | 267 | output.append(linkToPage(request, page, _("Subscribe..."), subscribe_dialogue_link)) |
paul@112 | 268 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 269 | output.append(fmt.text(_("Edit subscription options"))) |
paul@112 | 270 | output.append(fmt.span(on=0)) |
paul@57 | 271 | output.append(fmt.span(on=0)) |
paul@57 | 272 | output.append(fmt.div(on=0)) |
paul@57 | 273 | |
paul@57 | 274 | return "".join(output) |
paul@57 | 275 | |
paul@57 | 276 | def writeViewControls(self): |
paul@57 | 277 | page = self.page |
paul@57 | 278 | request = page.request |
paul@57 | 279 | fmt = page.formatter |
paul@57 | 280 | _ = request.getText |
paul@57 | 281 | |
paul@57 | 282 | output = [] |
paul@57 | 283 | |
paul@57 | 284 | calendar_link = self.getNavigationLink( |
paul@57 | 285 | self.calendar_start, self.calendar_end, "calendar" |
paul@57 | 286 | ) |
paul@57 | 287 | list_link = self.getNavigationLink( |
paul@57 | 288 | self.calendar_start, self.calendar_end, "list" |
paul@57 | 289 | ) |
paul@57 | 290 | table_link = self.getNavigationLink( |
paul@57 | 291 | self.calendar_start, self.calendar_end, "table" |
paul@57 | 292 | ) |
paul@57 | 293 | |
paul@57 | 294 | # Write the controls. |
paul@57 | 295 | |
paul@57 | 296 | output.append(fmt.div(on=1, css_class="event-view-controls")) |
paul@57 | 297 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@57 | 298 | output.append(linkToPage(request, page, _("View as calendar"), calendar_link)) |
paul@57 | 299 | output.append(fmt.span(on=0)) |
paul@57 | 300 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@57 | 301 | output.append(linkToPage(request, page, _("View as list"), list_link)) |
paul@57 | 302 | output.append(fmt.span(on=0)) |
paul@57 | 303 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@57 | 304 | output.append(linkToPage(request, page, _("View as table"), table_link)) |
paul@57 | 305 | output.append(fmt.span(on=0)) |
paul@57 | 306 | output.append(fmt.div(on=0)) |
paul@57 | 307 | |
paul@57 | 308 | return "".join(output) |
paul@57 | 309 | |
paul@67 | 310 | def writeMonthHeading(self, year_month): |
paul@37 | 311 | page = self.page |
paul@37 | 312 | request = page.request |
paul@37 | 313 | fmt = page.formatter |
paul@37 | 314 | _ = request.getText |
paul@116 | 315 | full_month_label = self.getFullMonthLabel(year_month) |
paul@37 | 316 | |
paul@37 | 317 | output = [] |
paul@37 | 318 | |
paul@37 | 319 | # Prepare navigation links. |
paul@37 | 320 | |
paul@37 | 321 | if self.calendar_name is not None: |
paul@37 | 322 | calendar_name = self.calendar_name |
paul@37 | 323 | |
paul@37 | 324 | # Links to the previous set of months and to a calendar shifted |
paul@37 | 325 | # back one month. |
paul@37 | 326 | |
paul@57 | 327 | previous_set_link = self.getNavigationLink( |
paul@57 | 328 | self.previous_set_start, self.previous_set_end |
paul@37 | 329 | ) |
paul@57 | 330 | previous_month_link = self.getNavigationLink( |
paul@57 | 331 | self.previous_month_start, self.previous_month_end |
paul@37 | 332 | ) |
paul@37 | 333 | |
paul@37 | 334 | # Links to the next set of months and to a calendar shifted |
paul@37 | 335 | # forward one month. |
paul@37 | 336 | |
paul@57 | 337 | next_set_link = self.getNavigationLink( |
paul@57 | 338 | self.next_set_start, self.next_set_end |
paul@37 | 339 | ) |
paul@57 | 340 | next_month_link = self.getNavigationLink( |
paul@57 | 341 | self.next_month_start, self.next_month_end |
paul@37 | 342 | ) |
paul@37 | 343 | |
paul@37 | 344 | # A link leading to this month being at the top of the calendar. |
paul@37 | 345 | |
paul@67 | 346 | end_month = year_month.month_update(self.number_of_months - 1) |
paul@37 | 347 | |
paul@67 | 348 | month_link = self.getNavigationLink(year_month, end_month) |
paul@37 | 349 | |
paul@37 | 350 | output.append(fmt.span(on=1, css_class="previous-month")) |
paul@37 | 351 | output.append(linkToPage(request, page, "<<", previous_set_link)) |
paul@37 | 352 | output.append(fmt.text(" ")) |
paul@37 | 353 | output.append(linkToPage(request, page, "<", previous_month_link)) |
paul@37 | 354 | output.append(fmt.span(on=0)) |
paul@37 | 355 | |
paul@37 | 356 | output.append(fmt.span(on=1, css_class="next-month")) |
paul@37 | 357 | output.append(linkToPage(request, page, ">", next_month_link)) |
paul@37 | 358 | output.append(fmt.text(" ")) |
paul@37 | 359 | output.append(linkToPage(request, page, ">>", next_set_link)) |
paul@37 | 360 | output.append(fmt.span(on=0)) |
paul@37 | 361 | |
paul@37 | 362 | output.append(linkToPage(request, page, full_month_label, month_link)) |
paul@37 | 363 | |
paul@37 | 364 | else: |
paul@37 | 365 | output.append(fmt.span(on=1)) |
paul@114 | 366 | output.append(fmt.text(full_month_label)) |
paul@37 | 367 | output.append(fmt.span(on=0)) |
paul@37 | 368 | |
paul@37 | 369 | return "".join(output) |
paul@37 | 370 | |
paul@67 | 371 | def writeDayNumberLinked(self, date): |
paul@57 | 372 | page = self.page |
paul@57 | 373 | request = page.request |
paul@57 | 374 | fmt = page.formatter |
paul@57 | 375 | _ = request.getText |
paul@57 | 376 | |
paul@67 | 377 | year, month, day = date.as_tuple() |
paul@57 | 378 | output = [] |
paul@57 | 379 | |
paul@58 | 380 | # Prepare navigation details for the calendar shown with the new event |
paul@58 | 381 | # form. |
paul@58 | 382 | |
paul@58 | 383 | navigation_link = self.getNavigationLink( |
paul@58 | 384 | self.calendar_start, self.calendar_end, self.mode |
paul@58 | 385 | ) |
paul@58 | 386 | |
paul@58 | 387 | # Prepare the link to the new event form, incorporating the above |
paul@58 | 388 | # calendar parameters. |
paul@58 | 389 | |
paul@57 | 390 | new_event_link = "action=EventAggregatorNewEvent&start-day=%d&start-month=%d&start-year=%d" \ |
paul@58 | 391 | "&%s&template=%s&parent=%s&%s" % ( |
paul@58 | 392 | day, month, year, self.category_name_parameters, self.template_name, self.parent_name or "", |
paul@58 | 393 | navigation_link) |
paul@57 | 394 | |
paul@57 | 395 | output.append(fmt.div(on=1)) |
paul@57 | 396 | output.append(fmt.span(on=1, css_class="event-day-number")) |
paul@57 | 397 | output.append(linkToPage(request, page, unicode(day), new_event_link)) |
paul@57 | 398 | output.append(fmt.span(on=0)) |
paul@57 | 399 | output.append(fmt.div(on=0)) |
paul@57 | 400 | |
paul@57 | 401 | return "".join(output) |
paul@57 | 402 | |
paul@126 | 403 | # Common layout methods. |
paul@126 | 404 | |
paul@126 | 405 | def getEventStyle(self, colour_seed): |
paul@126 | 406 | |
paul@126 | 407 | "Generate colour style information using the given 'colour_seed'." |
paul@126 | 408 | |
paul@126 | 409 | bg = getColour(colour_seed) |
paul@126 | 410 | fg = getBlackOrWhite(bg) |
paul@126 | 411 | return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg) |
paul@126 | 412 | |
paul@126 | 413 | def writeEventSummaryBox(self, event): |
paul@126 | 414 | |
paul@126 | 415 | "Return an event summary box linking to the given 'event'." |
paul@126 | 416 | |
paul@126 | 417 | page = self.page |
paul@126 | 418 | request = page.request |
paul@126 | 419 | fmt = page.formatter |
paul@126 | 420 | |
paul@126 | 421 | output = [] |
paul@126 | 422 | |
paul@126 | 423 | event_page = event.getPage() |
paul@126 | 424 | event_details = event.getDetails() |
paul@126 | 425 | event_summary = event.getSummary(self.parent_name) |
paul@126 | 426 | |
paul@126 | 427 | is_ambiguous = event_details["start"].ambiguous() or event_details["end"].ambiguous() |
paul@126 | 428 | style = self.getEventStyle(event_summary) |
paul@126 | 429 | |
paul@126 | 430 | # The event box contains the summary, alongside |
paul@126 | 431 | # other elements. |
paul@126 | 432 | |
paul@126 | 433 | output.append(fmt.div(on=1, css_class="event-summary-box")) |
paul@126 | 434 | output.append(fmt.div(on=1, css_class="event-summary", style=style)) |
paul@126 | 435 | |
paul@126 | 436 | if is_ambiguous: |
paul@126 | 437 | output.append(fmt.icon("/!\\")) |
paul@126 | 438 | |
paul@126 | 439 | output.append(event_page.linkToPage(request, event_summary)) |
paul@126 | 440 | output.append(fmt.div(on=0)) |
paul@126 | 441 | |
paul@126 | 442 | # Add a pop-up element for long summaries. |
paul@126 | 443 | |
paul@126 | 444 | output.append(fmt.div(on=1, css_class="event-summary-popup", style=style)) |
paul@126 | 445 | |
paul@126 | 446 | if is_ambiguous: |
paul@126 | 447 | output.append(fmt.icon("/!\\")) |
paul@126 | 448 | |
paul@126 | 449 | output.append(event_page.linkToPage(request, event_summary)) |
paul@126 | 450 | output.append(fmt.div(on=0)) |
paul@126 | 451 | |
paul@126 | 452 | output.append(fmt.div(on=0)) |
paul@126 | 453 | |
paul@126 | 454 | return "".join(output) |
paul@126 | 455 | |
paul@120 | 456 | # Calendar layout methods. |
paul@120 | 457 | |
paul@122 | 458 | def writeMonthTableHeading(self, year_month): |
paul@122 | 459 | page = self.page |
paul@122 | 460 | fmt = page.formatter |
paul@122 | 461 | |
paul@122 | 462 | output = [] |
paul@122 | 463 | output.append(fmt.table_row(on=1)) |
paul@122 | 464 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"})) |
paul@122 | 465 | |
paul@122 | 466 | output.append(self.writeMonthHeading(year_month)) |
paul@122 | 467 | |
paul@122 | 468 | output.append(fmt.table_cell(on=0)) |
paul@122 | 469 | output.append(fmt.table_row(on=0)) |
paul@122 | 470 | |
paul@122 | 471 | return "".join(output) |
paul@122 | 472 | |
paul@122 | 473 | def writeWeekdayHeadings(self): |
paul@122 | 474 | page = self.page |
paul@122 | 475 | request = page.request |
paul@122 | 476 | fmt = page.formatter |
paul@122 | 477 | _ = request.getText |
paul@122 | 478 | |
paul@122 | 479 | output = [] |
paul@122 | 480 | output.append(fmt.table_row(on=1)) |
paul@122 | 481 | |
paul@122 | 482 | for weekday in range(0, 7): |
paul@122 | 483 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"})) |
paul@122 | 484 | output.append(fmt.text(_(EventAggregatorSupport.getDayLabel(weekday)))) |
paul@122 | 485 | output.append(fmt.table_cell(on=0)) |
paul@122 | 486 | |
paul@122 | 487 | output.append(fmt.table_row(on=0)) |
paul@122 | 488 | return "".join(output) |
paul@122 | 489 | |
paul@122 | 490 | def writeDayNumbers(self, first_day, number_of_days, month, coverage): |
paul@120 | 491 | page = self.page |
paul@120 | 492 | fmt = page.formatter |
paul@120 | 493 | |
paul@120 | 494 | output = [] |
paul@120 | 495 | output.append(fmt.table_row(on=1)) |
paul@120 | 496 | |
paul@120 | 497 | for weekday in range(0, 7): |
paul@120 | 498 | day = first_day + weekday |
paul@120 | 499 | date = month.as_date(day) |
paul@120 | 500 | |
paul@120 | 501 | # Output out-of-month days. |
paul@120 | 502 | |
paul@120 | 503 | if day < 1 or day > number_of_days: |
paul@120 | 504 | output.append(fmt.table_cell(on=1, |
paul@120 | 505 | attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"})) |
paul@120 | 506 | output.append(fmt.table_cell(on=0)) |
paul@120 | 507 | |
paul@120 | 508 | # Output normal days. |
paul@120 | 509 | |
paul@120 | 510 | else: |
paul@122 | 511 | if date in coverage: |
paul@120 | 512 | output.append(fmt.table_cell(on=1, |
paul@120 | 513 | attrs={"class" : "event-day-heading event-day-busy", "colspan" : "3"})) |
paul@120 | 514 | else: |
paul@120 | 515 | output.append(fmt.table_cell(on=1, |
paul@120 | 516 | attrs={"class" : "event-day-heading event-day-empty", "colspan" : "3"})) |
paul@120 | 517 | |
paul@120 | 518 | # Output the day number, making a link to a new event |
paul@120 | 519 | # action. |
paul@120 | 520 | |
paul@120 | 521 | output.append(self.writeDayNumberLinked(date)) |
paul@120 | 522 | |
paul@120 | 523 | # End of day. |
paul@120 | 524 | |
paul@120 | 525 | output.append(fmt.table_cell(on=0)) |
paul@120 | 526 | |
paul@120 | 527 | # End of day numbers. |
paul@120 | 528 | |
paul@120 | 529 | output.append(fmt.table_row(on=0)) |
paul@120 | 530 | return "".join(output) |
paul@120 | 531 | |
paul@120 | 532 | def writeEmptyWeek(self, first_day, number_of_days): |
paul@120 | 533 | page = self.page |
paul@120 | 534 | fmt = page.formatter |
paul@120 | 535 | |
paul@120 | 536 | output = [] |
paul@120 | 537 | output.append(fmt.table_row(on=1)) |
paul@120 | 538 | |
paul@120 | 539 | for weekday in range(0, 7): |
paul@120 | 540 | day = first_day + weekday |
paul@120 | 541 | |
paul@120 | 542 | # Output out-of-month days. |
paul@120 | 543 | |
paul@120 | 544 | if day < 1 or day > number_of_days: |
paul@120 | 545 | output.append(fmt.table_cell(on=1, |
paul@120 | 546 | attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"})) |
paul@120 | 547 | output.append(fmt.table_cell(on=0)) |
paul@120 | 548 | |
paul@120 | 549 | # Output empty days. |
paul@120 | 550 | |
paul@120 | 551 | else: |
paul@120 | 552 | output.append(fmt.table_cell(on=1, |
paul@120 | 553 | attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"})) |
paul@120 | 554 | |
paul@120 | 555 | output.append(fmt.table_row(on=0)) |
paul@120 | 556 | return "".join(output) |
paul@120 | 557 | |
paul@120 | 558 | def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots): |
paul@120 | 559 | output = [] |
paul@120 | 560 | |
paul@120 | 561 | locations = week_slots.keys() |
paul@120 | 562 | locations.sort(EventAggregatorSupport.sort_none_first) |
paul@120 | 563 | |
paul@120 | 564 | # Visit each slot corresponding to a location (or no location). |
paul@120 | 565 | |
paul@120 | 566 | for location in locations: |
paul@120 | 567 | |
paul@120 | 568 | # Visit each coverage span, presenting the events in the span. |
paul@120 | 569 | |
paul@123 | 570 | for events in week_slots[location]: |
paul@120 | 571 | |
paul@120 | 572 | # Output each set. |
paul@120 | 573 | |
paul@123 | 574 | output.append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events)) |
paul@120 | 575 | |
paul@120 | 576 | # Add a spacer. |
paul@120 | 577 | |
paul@123 | 578 | output.append(self.writeWeekSpacer(first_day, number_of_days)) |
paul@120 | 579 | |
paul@120 | 580 | return "".join(output) |
paul@120 | 581 | |
paul@123 | 582 | def writeWeekSlot(self, first_day, number_of_days, month, week_end, events): |
paul@120 | 583 | page = self.page |
paul@120 | 584 | request = page.request |
paul@120 | 585 | fmt = page.formatter |
paul@120 | 586 | |
paul@120 | 587 | output = [] |
paul@120 | 588 | output.append(fmt.table_row(on=1)) |
paul@120 | 589 | |
paul@120 | 590 | # Then, output day details. |
paul@120 | 591 | |
paul@120 | 592 | for weekday in range(0, 7): |
paul@120 | 593 | day = first_day + weekday |
paul@120 | 594 | date = month.as_date(day) |
paul@120 | 595 | |
paul@120 | 596 | # Skip out-of-month days. |
paul@120 | 597 | |
paul@120 | 598 | if day < 1 or day > number_of_days: |
paul@120 | 599 | output.append(fmt.table_cell(on=1, |
paul@120 | 600 | attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"})) |
paul@120 | 601 | output.append(fmt.table_cell(on=0)) |
paul@120 | 602 | continue |
paul@120 | 603 | |
paul@120 | 604 | # Output the day. |
paul@120 | 605 | |
paul@123 | 606 | if date not in events: |
paul@120 | 607 | output.append(fmt.table_cell(on=1, |
paul@120 | 608 | attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"})) |
paul@120 | 609 | |
paul@120 | 610 | # Get event details for the current day. |
paul@120 | 611 | |
paul@120 | 612 | for event in events: |
paul@120 | 613 | event_page = event.getPage() |
paul@120 | 614 | event_details = event.getDetails() |
paul@120 | 615 | |
paul@123 | 616 | if date not in event: |
paul@120 | 617 | continue |
paul@120 | 618 | |
paul@120 | 619 | # Get basic properties of the event. |
paul@120 | 620 | |
paul@120 | 621 | starts_today = event_details["start"] == date |
paul@120 | 622 | ends_today = event_details["end"] == date |
paul@120 | 623 | event_summary = event.getSummary(self.parent_name) |
paul@120 | 624 | |
paul@126 | 625 | style = self.getEventStyle(event_summary) |
paul@120 | 626 | |
paul@120 | 627 | # Determine if the event name should be shown. |
paul@120 | 628 | |
paul@120 | 629 | start_of_period = starts_today or weekday == 0 or day == 1 |
paul@120 | 630 | |
paul@120 | 631 | if self.name_usage == "daily" or start_of_period: |
paul@120 | 632 | hide_text = 0 |
paul@120 | 633 | else: |
paul@120 | 634 | hide_text = 1 |
paul@120 | 635 | |
paul@120 | 636 | # Output start of day gap and determine whether |
paul@120 | 637 | # any event content should be explicitly output |
paul@120 | 638 | # for this day. |
paul@120 | 639 | |
paul@120 | 640 | if starts_today: |
paul@120 | 641 | |
paul@120 | 642 | # Single day events... |
paul@120 | 643 | |
paul@120 | 644 | if ends_today: |
paul@120 | 645 | colspan = 3 |
paul@120 | 646 | event_day_type = "event-day-single" |
paul@120 | 647 | |
paul@120 | 648 | # Events starting today... |
paul@120 | 649 | |
paul@120 | 650 | else: |
paul@120 | 651 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap"})) |
paul@120 | 652 | output.append(fmt.table_cell(on=0)) |
paul@120 | 653 | |
paul@120 | 654 | # Calculate the span of this cell. |
paul@120 | 655 | # Events whose names appear on every day... |
paul@120 | 656 | |
paul@120 | 657 | if self.name_usage == "daily": |
paul@120 | 658 | colspan = 2 |
paul@120 | 659 | event_day_type = "event-day-starting" |
paul@120 | 660 | |
paul@120 | 661 | # Events whose names appear once per week... |
paul@120 | 662 | |
paul@120 | 663 | else: |
paul@120 | 664 | if event_details["end"] <= week_end: |
paul@120 | 665 | event_length = event_details["end"].day() - day + 1 |
paul@120 | 666 | colspan = (event_length - 2) * 3 + 4 |
paul@120 | 667 | else: |
paul@120 | 668 | event_length = week_end.day() - day + 1 |
paul@120 | 669 | colspan = (event_length - 1) * 3 + 2 |
paul@120 | 670 | |
paul@120 | 671 | event_day_type = "event-day-multiple" |
paul@120 | 672 | |
paul@120 | 673 | # Events continuing from a previous week... |
paul@120 | 674 | |
paul@120 | 675 | elif start_of_period: |
paul@120 | 676 | |
paul@120 | 677 | # End of continuing event... |
paul@120 | 678 | |
paul@120 | 679 | if ends_today: |
paul@120 | 680 | colspan = 2 |
paul@120 | 681 | event_day_type = "event-day-ending" |
paul@120 | 682 | |
paul@120 | 683 | # Events continuing for at least one more day... |
paul@120 | 684 | |
paul@120 | 685 | else: |
paul@120 | 686 | |
paul@120 | 687 | # Calculate the span of this cell. |
paul@120 | 688 | # Events whose names appear on every day... |
paul@120 | 689 | |
paul@120 | 690 | if self.name_usage == "daily": |
paul@120 | 691 | colspan = 3 |
paul@120 | 692 | event_day_type = "event-day-full" |
paul@120 | 693 | |
paul@120 | 694 | # Events whose names appear once per week... |
paul@120 | 695 | |
paul@120 | 696 | else: |
paul@120 | 697 | if event_details["end"] <= week_end: |
paul@120 | 698 | event_length = event_details["end"].day() - day + 1 |
paul@120 | 699 | colspan = (event_length - 1) * 3 + 2 |
paul@120 | 700 | else: |
paul@120 | 701 | event_length = week_end.day() - day + 1 |
paul@120 | 702 | colspan = event_length * 3 |
paul@120 | 703 | |
paul@120 | 704 | event_day_type = "event-day-multiple" |
paul@120 | 705 | |
paul@120 | 706 | # Continuing events whose names appear on every day... |
paul@120 | 707 | |
paul@120 | 708 | elif self.name_usage == "daily": |
paul@120 | 709 | if ends_today: |
paul@120 | 710 | colspan = 2 |
paul@120 | 711 | event_day_type = "event-day-ending" |
paul@120 | 712 | else: |
paul@120 | 713 | colspan = 3 |
paul@120 | 714 | event_day_type = "event-day-full" |
paul@120 | 715 | |
paul@120 | 716 | # Continuing events whose names appear once per week... |
paul@120 | 717 | |
paul@120 | 718 | else: |
paul@120 | 719 | colspan = None |
paul@120 | 720 | |
paul@120 | 721 | # Output the main content only if it is not |
paul@120 | 722 | # continuing from a previous day. |
paul@120 | 723 | |
paul@120 | 724 | if colspan is not None: |
paul@120 | 725 | |
paul@120 | 726 | # Colour the cell for continuing events. |
paul@120 | 727 | |
paul@120 | 728 | attrs={ |
paul@120 | 729 | "class" : "event-day-content event-day-busy %s" % event_day_type, |
paul@120 | 730 | "colspan" : str(colspan) |
paul@120 | 731 | } |
paul@120 | 732 | |
paul@120 | 733 | if not (starts_today and ends_today): |
paul@120 | 734 | attrs["style"] = style |
paul@120 | 735 | |
paul@120 | 736 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@120 | 737 | |
paul@120 | 738 | # Output the event. |
paul@120 | 739 | |
paul@120 | 740 | if starts_today and ends_today or not hide_text: |
paul@126 | 741 | output.append(self.writeEventSummaryBox(event)) |
paul@120 | 742 | |
paul@126 | 743 | output.append(fmt.table_cell(on=0)) |
paul@120 | 744 | |
paul@120 | 745 | # Output end of day gap. |
paul@120 | 746 | |
paul@120 | 747 | if ends_today and not starts_today: |
paul@120 | 748 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap"})) |
paul@120 | 749 | output.append(fmt.table_cell(on=0)) |
paul@120 | 750 | |
paul@120 | 751 | # End of set. |
paul@120 | 752 | |
paul@120 | 753 | output.append(fmt.table_row(on=0)) |
paul@120 | 754 | return "".join(output) |
paul@120 | 755 | |
paul@123 | 756 | def writeWeekSpacer(self, first_day, number_of_days): |
paul@120 | 757 | page = self.page |
paul@120 | 758 | fmt = page.formatter |
paul@120 | 759 | |
paul@120 | 760 | output = [] |
paul@120 | 761 | output.append(fmt.table_row(on=1)) |
paul@120 | 762 | |
paul@120 | 763 | for weekday in range(0, 7): |
paul@120 | 764 | day = first_day + weekday |
paul@120 | 765 | css_classes = "event-day-spacer" |
paul@120 | 766 | |
paul@120 | 767 | # Skip out-of-month days. |
paul@120 | 768 | |
paul@120 | 769 | if day < 1 or day > number_of_days: |
paul@120 | 770 | css_classes += " event-day-excluded" |
paul@120 | 771 | |
paul@120 | 772 | output.append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"})) |
paul@120 | 773 | output.append(fmt.table_cell(on=0)) |
paul@120 | 774 | |
paul@120 | 775 | output.append(fmt.table_row(on=0)) |
paul@120 | 776 | return "".join(output) |
paul@120 | 777 | |
paul@122 | 778 | # Day layout methods. |
paul@122 | 779 | |
paul@126 | 780 | def writeDayHeading(self, date, colspan=1): |
paul@122 | 781 | page = self.page |
paul@122 | 782 | request = page.request |
paul@122 | 783 | fmt = page.formatter |
paul@122 | 784 | _ = request.getText |
paul@122 | 785 | full_date_label = self.getFullDateLabel(date) |
paul@122 | 786 | |
paul@122 | 787 | output = [] |
paul@122 | 788 | output.append(fmt.table_row(on=1)) |
paul@122 | 789 | |
paul@126 | 790 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : str(colspan)})) |
paul@122 | 791 | output.append(fmt.text(full_date_label)) |
paul@122 | 792 | output.append(fmt.table_cell(on=0)) |
paul@122 | 793 | |
paul@122 | 794 | output.append(fmt.table_row(on=0)) |
paul@122 | 795 | return "".join(output) |
paul@122 | 796 | |
paul@123 | 797 | def writeEmptyDay(self, date): |
paul@123 | 798 | page = self.page |
paul@123 | 799 | fmt = page.formatter |
paul@123 | 800 | |
paul@123 | 801 | output = [] |
paul@123 | 802 | output.append(fmt.table_row(on=1)) |
paul@123 | 803 | |
paul@123 | 804 | output.append(fmt.table_cell(on=1, |
paul@123 | 805 | attrs={"class" : "event-day-content event-day-empty"})) |
paul@123 | 806 | |
paul@123 | 807 | output.append(fmt.table_row(on=0)) |
paul@123 | 808 | return "".join(output) |
paul@123 | 809 | |
paul@123 | 810 | def writeDaySlots(self, date, full_coverage, day_slots): |
paul@123 | 811 | page = self.page |
paul@123 | 812 | fmt = page.formatter |
paul@123 | 813 | |
paul@123 | 814 | output = [] |
paul@123 | 815 | |
paul@123 | 816 | locations = day_slots.keys() |
paul@123 | 817 | locations.sort(EventAggregatorSupport.sort_none_first) |
paul@123 | 818 | |
paul@123 | 819 | # Traverse the time scale of the full coverage, visiting each slot to |
paul@123 | 820 | # determine whether it provides content for each period. |
paul@123 | 821 | |
paul@123 | 822 | scale = EventAggregatorSupport.getCoverageScale(full_coverage) |
paul@128 | 823 | |
paul@128 | 824 | # Define a mapping of events to rowspans. |
paul@128 | 825 | |
paul@128 | 826 | rowspans = {} |
paul@128 | 827 | |
paul@128 | 828 | # Populate each period with event details, recording how many periods |
paul@128 | 829 | # each event populates. |
paul@128 | 830 | |
paul@128 | 831 | day_rows = [] |
paul@123 | 832 | |
paul@123 | 833 | for period in scale: |
paul@126 | 834 | |
paul@126 | 835 | # Ignore timespans before this day. |
paul@126 | 836 | |
paul@128 | 837 | if period != date: |
paul@126 | 838 | continue |
paul@126 | 839 | |
paul@128 | 840 | # Visit each slot corresponding to a location (or no location). |
paul@128 | 841 | |
paul@128 | 842 | day_row = [] |
paul@128 | 843 | |
paul@128 | 844 | for location in locations: |
paul@128 | 845 | |
paul@128 | 846 | # Visit each coverage span, presenting the events in the span. |
paul@128 | 847 | |
paul@128 | 848 | for events in day_slots[location]: |
paul@128 | 849 | event = self.getActiveEvent(period, events) |
paul@128 | 850 | if event is not None: |
paul@128 | 851 | if not rowspans.has_key(event): |
paul@128 | 852 | rowspans[event] = 1 |
paul@128 | 853 | else: |
paul@128 | 854 | rowspans[event] += 1 |
paul@128 | 855 | day_row.append((location, event)) |
paul@128 | 856 | |
paul@128 | 857 | day_rows.append((period, day_row)) |
paul@128 | 858 | |
paul@128 | 859 | # Output the periods with event details. |
paul@128 | 860 | |
paul@128 | 861 | period = None |
paul@128 | 862 | events_written = set() |
paul@128 | 863 | |
paul@128 | 864 | for period, day_row in day_rows: |
paul@128 | 865 | |
paul@126 | 866 | # Write an empty heading for the start of the day where the first |
paul@126 | 867 | # applicable timespan starts before this day. |
paul@123 | 868 | |
paul@126 | 869 | if period.start < date: |
paul@126 | 870 | output.append(fmt.table_row(on=1)) |
paul@126 | 871 | output.append(self.writeDayScaleHeading("")) |
paul@126 | 872 | |
paul@126 | 873 | # Otherwise, write a heading describing the time. |
paul@126 | 874 | |
paul@126 | 875 | else: |
paul@126 | 876 | output.append(fmt.table_row(on=1)) |
paul@128 | 877 | output.append(self.writeDayScaleHeading(period.start.time_string())) |
paul@123 | 878 | |
paul@123 | 879 | # Visit each slot corresponding to a location (or no location). |
paul@123 | 880 | |
paul@128 | 881 | for location, event in day_row: |
paul@123 | 882 | |
paul@128 | 883 | # Add a spacer. |
paul@126 | 884 | |
paul@128 | 885 | output.append(self.writeDaySpacer()) |
paul@123 | 886 | |
paul@128 | 887 | # Output each location slot's contribution. |
paul@123 | 888 | |
paul@128 | 889 | if event is None or event not in events_written: |
paul@128 | 890 | output.append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event])) |
paul@128 | 891 | if event is not None: |
paul@128 | 892 | events_written.add(event) |
paul@123 | 893 | |
paul@123 | 894 | output.append(fmt.table_row(on=0)) |
paul@123 | 895 | |
paul@126 | 896 | # Write a final time heading if the last period ends in the current day. |
paul@126 | 897 | |
paul@126 | 898 | if period is not None: |
paul@126 | 899 | if period.end == date: |
paul@126 | 900 | output.append(fmt.table_row(on=1)) |
paul@128 | 901 | output.append(self.writeDayScaleHeading(period.end.time_string())) |
paul@126 | 902 | |
paul@128 | 903 | for slot in day_row: |
paul@128 | 904 | output.append(self.writeDaySpacer()) |
paul@128 | 905 | output.append(self.writeEmptyDaySlot()) |
paul@126 | 906 | |
paul@126 | 907 | output.append(fmt.table_row(on=0)) |
paul@126 | 908 | |
paul@126 | 909 | return "".join(output) |
paul@126 | 910 | |
paul@126 | 911 | def writeDayScaleHeading(self, heading): |
paul@126 | 912 | page = self.page |
paul@126 | 913 | fmt = page.formatter |
paul@126 | 914 | |
paul@126 | 915 | output = [] |
paul@126 | 916 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"})) |
paul@126 | 917 | output.append(fmt.text(heading)) |
paul@126 | 918 | output.append(fmt.table_cell(on=0)) |
paul@126 | 919 | |
paul@123 | 920 | return "".join(output) |
paul@123 | 921 | |
paul@128 | 922 | def getActiveEvent(self, period, events): |
paul@128 | 923 | for event in events: |
paul@128 | 924 | if period not in event: |
paul@128 | 925 | continue |
paul@128 | 926 | return event |
paul@128 | 927 | else: |
paul@128 | 928 | return None |
paul@128 | 929 | |
paul@128 | 930 | def writeDaySlot(self, period, event, rowspan): |
paul@126 | 931 | page = self.page |
paul@126 | 932 | fmt = page.formatter |
paul@126 | 933 | |
paul@126 | 934 | output = [] |
paul@126 | 935 | |
paul@128 | 936 | if event is not None: |
paul@126 | 937 | event_summary = event.getSummary(self.parent_name) |
paul@126 | 938 | style = self.getEventStyle(event_summary) |
paul@126 | 939 | |
paul@126 | 940 | output.append(fmt.table_cell(on=1, attrs={ |
paul@126 | 941 | "class" : "event-timespan-content event-timespan-busy", |
paul@128 | 942 | "style" : style, |
paul@128 | 943 | "rowspan" : str(rowspan) |
paul@128 | 944 | })) |
paul@126 | 945 | output.append(self.writeEventSummaryBox(event)) |
paul@126 | 946 | output.append(fmt.table_cell(on=0)) |
paul@126 | 947 | else: |
paul@126 | 948 | output.append(self.writeEmptyDaySlot()) |
paul@126 | 949 | |
paul@126 | 950 | return "".join(output) |
paul@126 | 951 | |
paul@126 | 952 | def writeEmptyDaySlot(self): |
paul@126 | 953 | page = self.page |
paul@126 | 954 | fmt = page.formatter |
paul@126 | 955 | |
paul@126 | 956 | output = [] |
paul@126 | 957 | |
paul@126 | 958 | output.append(fmt.table_cell(on=1, |
paul@126 | 959 | attrs={"class" : "event-timespan-content event-timespan-empty"})) |
paul@126 | 960 | output.append(fmt.table_cell(on=0)) |
paul@126 | 961 | |
paul@126 | 962 | return "".join(output) |
paul@126 | 963 | |
paul@126 | 964 | def writeDaySpacer(self): |
paul@126 | 965 | page = self.page |
paul@126 | 966 | fmt = page.formatter |
paul@126 | 967 | |
paul@126 | 968 | output = [] |
paul@126 | 969 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-timespan-spacer"})) |
paul@126 | 970 | output.append(fmt.table_cell(on=0)) |
paul@126 | 971 | return "".join(output) |
paul@123 | 972 | |
paul@10 | 973 | # HTML-related functions. |
paul@2 | 974 | |
paul@2 | 975 | def getColour(s): |
paul@2 | 976 | colour = [0, 0, 0] |
paul@2 | 977 | digit = 0 |
paul@2 | 978 | for c in s: |
paul@2 | 979 | colour[digit] += ord(c) |
paul@2 | 980 | colour[digit] = colour[digit] % 256 |
paul@2 | 981 | digit += 1 |
paul@2 | 982 | digit = digit % 3 |
paul@2 | 983 | return tuple(colour) |
paul@2 | 984 | |
paul@2 | 985 | def getBlackOrWhite(colour): |
paul@2 | 986 | if sum(colour) / 3.0 > 127: |
paul@2 | 987 | return (0, 0, 0) |
paul@2 | 988 | else: |
paul@2 | 989 | return (255, 255, 255) |
paul@2 | 990 | |
paul@11 | 991 | # Macro functions. |
paul@11 | 992 | |
paul@0 | 993 | def execute(macro, args): |
paul@0 | 994 | |
paul@0 | 995 | """ |
paul@0 | 996 | Execute the 'macro' with the given 'args': an optional list of selected |
paul@0 | 997 | category names (categories whose pages are to be shown), together with |
paul@5 | 998 | optional named arguments of the following forms: |
paul@5 | 999 | |
paul@5 | 1000 | start=YYYY-MM shows event details starting from the specified month |
paul@122 | 1001 | start=YYYY-MM-DD shows event details starting from the specified day |
paul@13 | 1002 | start=current-N shows event details relative to the current month |
paul@122 | 1003 | (or relative to the current day in "day" mode) |
paul@5 | 1004 | end=YYYY-MM shows event details ending at the specified month |
paul@122 | 1005 | end=YYYY-MM-DD shows event details ending on the specified day |
paul@13 | 1006 | end=current+N shows event details relative to the current month |
paul@122 | 1007 | (or relative to the current day in "day" mode) |
paul@5 | 1008 | |
paul@5 | 1009 | mode=calendar shows a calendar view of events |
paul@122 | 1010 | mode=day shows a calendar day view of events |
paul@5 | 1011 | mode=list shows a list of events by month |
paul@121 | 1012 | mode=table shows a table of events |
paul@5 | 1013 | |
paul@5 | 1014 | names=daily shows the name of an event on every day of that event |
paul@5 | 1015 | names=weekly shows the name of an event once per week |
paul@11 | 1016 | |
paul@11 | 1017 | calendar=NAME uses the given NAME to provide request parameters which |
paul@11 | 1018 | can be used to control the calendar view |
paul@55 | 1019 | |
paul@55 | 1020 | template=PAGE uses the given PAGE as the default template for new |
paul@55 | 1021 | events (or the default template from the configuration |
paul@55 | 1022 | if not specified) |
paul@55 | 1023 | |
paul@55 | 1024 | parent=PAGE uses the given PAGE as the parent of any new event page |
paul@0 | 1025 | """ |
paul@0 | 1026 | |
paul@0 | 1027 | request = macro.request |
paul@0 | 1028 | fmt = macro.formatter |
paul@0 | 1029 | page = fmt.page |
paul@0 | 1030 | _ = request.getText |
paul@0 | 1031 | |
paul@0 | 1032 | # Interpret the arguments. |
paul@0 | 1033 | |
paul@0 | 1034 | try: |
paul@0 | 1035 | parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] |
paul@0 | 1036 | except AttributeError: |
paul@0 | 1037 | parsed_args = args.split(",") |
paul@0 | 1038 | |
paul@0 | 1039 | parsed_args = [arg for arg in parsed_args if arg] |
paul@0 | 1040 | |
paul@0 | 1041 | # Get special arguments. |
paul@0 | 1042 | |
paul@0 | 1043 | category_names = [] |
paul@76 | 1044 | raw_calendar_start = None |
paul@76 | 1045 | raw_calendar_end = None |
paul@0 | 1046 | calendar_start = None |
paul@0 | 1047 | calendar_end = None |
paul@57 | 1048 | mode = None |
paul@35 | 1049 | name_usage = "weekly" |
paul@11 | 1050 | calendar_name = None |
paul@55 | 1051 | template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") |
paul@55 | 1052 | parent_name = None |
paul@0 | 1053 | |
paul@0 | 1054 | for arg in parsed_args: |
paul@0 | 1055 | if arg.startswith("start="): |
paul@76 | 1056 | raw_calendar_start = arg[6:] |
paul@11 | 1057 | |
paul@0 | 1058 | elif arg.startswith("end="): |
paul@76 | 1059 | raw_calendar_end = arg[4:] |
paul@11 | 1060 | |
paul@0 | 1061 | elif arg.startswith("mode="): |
paul@0 | 1062 | mode = arg[5:] |
paul@11 | 1063 | |
paul@5 | 1064 | elif arg.startswith("names="): |
paul@5 | 1065 | name_usage = arg[6:] |
paul@11 | 1066 | |
paul@11 | 1067 | elif arg.startswith("calendar="): |
paul@11 | 1068 | calendar_name = arg[9:] |
paul@11 | 1069 | |
paul@55 | 1070 | elif arg.startswith("template="): |
paul@55 | 1071 | template_name = arg[9:] |
paul@55 | 1072 | |
paul@55 | 1073 | elif arg.startswith("parent="): |
paul@55 | 1074 | parent_name = arg[7:] |
paul@55 | 1075 | |
paul@0 | 1076 | else: |
paul@0 | 1077 | category_names.append(arg) |
paul@0 | 1078 | |
paul@11 | 1079 | # Find request parameters to override settings. |
paul@11 | 1080 | |
paul@58 | 1081 | mode = EventAggregatorSupport.getQualifiedParameter(request, calendar_name, "mode", mode or "calendar") |
paul@55 | 1082 | |
paul@126 | 1083 | # Different modes require different levels of precision. |
paul@126 | 1084 | |
paul@122 | 1085 | if mode == "day": |
paul@122 | 1086 | get_date = EventAggregatorSupport.getParameterDate |
paul@122 | 1087 | get_form_date = EventAggregatorSupport.getFormDate |
paul@122 | 1088 | else: |
paul@122 | 1089 | get_date = EventAggregatorSupport.getParameterMonth |
paul@122 | 1090 | get_form_date = EventAggregatorSupport.getFormMonth |
paul@122 | 1091 | |
paul@122 | 1092 | # Determine the limits of the calendar. |
paul@122 | 1093 | |
paul@128 | 1094 | original_calendar_start = calendar_start = get_date(raw_calendar_start) |
paul@128 | 1095 | original_calendar_end = calendar_end = get_date(raw_calendar_end) |
paul@122 | 1096 | |
paul@122 | 1097 | if calendar_name is not None: |
paul@122 | 1098 | calendar_start = get_form_date(request, calendar_name, "start") or calendar_start |
paul@122 | 1099 | calendar_end = get_form_date(request, calendar_name, "end") or calendar_end |
paul@122 | 1100 | |
paul@122 | 1101 | # Get the events according to the resolution of the calendar. |
paul@11 | 1102 | |
paul@10 | 1103 | events, shown_events, all_shown_events, earliest, latest = \ |
paul@122 | 1104 | EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end, |
paul@122 | 1105 | mode == "day" and "date" or "month") |
paul@2 | 1106 | |
paul@13 | 1107 | # Get a concrete period of time. |
paul@13 | 1108 | |
paul@13 | 1109 | first, last = EventAggregatorSupport.getConcretePeriod(calendar_start, calendar_end, earliest, latest) |
paul@13 | 1110 | |
paul@37 | 1111 | # Define a view of the calendar, retaining useful navigational information. |
paul@13 | 1112 | |
paul@128 | 1113 | view = View(page, calendar_name, raw_calendar_start, raw_calendar_end, |
paul@128 | 1114 | original_calendar_start, original_calendar_end, calendar_start, calendar_end, |
paul@120 | 1115 | first, last, category_names, template_name, parent_name, mode, name_usage) |
paul@13 | 1116 | |
paul@0 | 1117 | # Make a calendar. |
paul@0 | 1118 | |
paul@0 | 1119 | output = [] |
paul@0 | 1120 | |
paul@26 | 1121 | # Output download controls. |
paul@26 | 1122 | |
paul@26 | 1123 | output.append(fmt.div(on=1, css_class="event-controls")) |
paul@57 | 1124 | output.append(view.writeDownloadControls()) |
paul@26 | 1125 | output.append(fmt.div(on=0)) |
paul@26 | 1126 | |
paul@61 | 1127 | # Output a table. |
paul@51 | 1128 | |
paul@61 | 1129 | if mode == "table": |
paul@0 | 1130 | |
paul@61 | 1131 | # Start of table view output. |
paul@51 | 1132 | |
paul@51 | 1133 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-table"})) |
paul@51 | 1134 | |
paul@51 | 1135 | output.append(fmt.table_row(on=1)) |
paul@51 | 1136 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@51 | 1137 | output.append(fmt.text(_("Event dates"))) |
paul@51 | 1138 | output.append(fmt.table_cell(on=0)) |
paul@51 | 1139 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@51 | 1140 | output.append(fmt.text(_("Event location"))) |
paul@51 | 1141 | output.append(fmt.table_cell(on=0)) |
paul@51 | 1142 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@51 | 1143 | output.append(fmt.text(_("Event details"))) |
paul@51 | 1144 | output.append(fmt.table_cell(on=0)) |
paul@51 | 1145 | output.append(fmt.table_row(on=0)) |
paul@51 | 1146 | |
paul@61 | 1147 | # Get the events in order. |
paul@0 | 1148 | |
paul@61 | 1149 | ordered_events = EventAggregatorSupport.getOrderedEvents(all_shown_events) |
paul@0 | 1150 | |
paul@61 | 1151 | # Show the events in order. |
paul@2 | 1152 | |
paul@69 | 1153 | for event in ordered_events: |
paul@69 | 1154 | event_page = event.getPage() |
paul@69 | 1155 | event_summary = event.getSummary(parent_name) |
paul@69 | 1156 | event_details = event.getDetails() |
paul@0 | 1157 | |
paul@61 | 1158 | # Prepare CSS classes with category-related styling. |
paul@11 | 1159 | |
paul@61 | 1160 | css_classes = ["event-table-details"] |
paul@61 | 1161 | |
paul@61 | 1162 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@11 | 1163 | |
paul@61 | 1164 | # Filter the category text to avoid illegal characters. |
paul@11 | 1165 | |
paul@61 | 1166 | css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic))) |
paul@0 | 1167 | |
paul@61 | 1168 | attrs = {"class" : " ".join(css_classes)} |
paul@0 | 1169 | |
paul@2 | 1170 | output.append(fmt.table_row(on=1)) |
paul@0 | 1171 | |
paul@61 | 1172 | # Start and end dates. |
paul@61 | 1173 | |
paul@61 | 1174 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@61 | 1175 | output.append(fmt.span(on=1)) |
paul@67 | 1176 | output.append(fmt.text(str(event_details["start"]))) |
paul@61 | 1177 | output.append(fmt.span(on=0)) |
paul@61 | 1178 | |
paul@61 | 1179 | if event_details["start"] != event_details["end"]: |
paul@61 | 1180 | output.append(fmt.text(" - ")) |
paul@61 | 1181 | output.append(fmt.span(on=1)) |
paul@67 | 1182 | output.append(fmt.text(str(event_details["end"]))) |
paul@61 | 1183 | output.append(fmt.span(on=0)) |
paul@61 | 1184 | |
paul@61 | 1185 | output.append(fmt.table_cell(on=0)) |
paul@61 | 1186 | |
paul@61 | 1187 | # Location. |
paul@61 | 1188 | |
paul@61 | 1189 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@61 | 1190 | |
paul@61 | 1191 | if event_details.has_key("location"): |
paul@61 | 1192 | output.append(fmt.text(event_details["location"])) |
paul@61 | 1193 | |
paul@61 | 1194 | output.append(fmt.table_cell(on=0)) |
paul@61 | 1195 | |
paul@61 | 1196 | # Link to the page using the summary. |
paul@61 | 1197 | |
paul@61 | 1198 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@67 | 1199 | output.append(event_page.linkToPage(request, event_summary)) |
paul@61 | 1200 | output.append(fmt.table_cell(on=0)) |
paul@2 | 1201 | |
paul@2 | 1202 | output.append(fmt.table_row(on=0)) |
paul@2 | 1203 | |
paul@61 | 1204 | # End of table view output. |
paul@61 | 1205 | |
paul@61 | 1206 | output.append(fmt.table(on=0)) |
paul@2 | 1207 | |
paul@122 | 1208 | # Output a list or month calendar. |
paul@61 | 1209 | |
paul@61 | 1210 | elif mode in ("list", "calendar"): |
paul@0 | 1211 | |
paul@61 | 1212 | # Output top-level information. |
paul@61 | 1213 | |
paul@61 | 1214 | # Start of list view output. |
paul@2 | 1215 | |
paul@61 | 1216 | if mode == "list": |
paul@61 | 1217 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"})) |
paul@61 | 1218 | |
paul@61 | 1219 | # Visit all months in the requested range, or across known events. |
paul@61 | 1220 | |
paul@67 | 1221 | for month in first.months_until(last): |
paul@2 | 1222 | |
paul@61 | 1223 | # Either output a calendar view... |
paul@61 | 1224 | |
paul@61 | 1225 | if mode == "calendar": |
paul@2 | 1226 | |
paul@61 | 1227 | # Output a month. |
paul@61 | 1228 | |
paul@61 | 1229 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"})) |
paul@5 | 1230 | |
paul@61 | 1231 | # Either write a month heading or produce links for navigable |
paul@61 | 1232 | # calendars. |
paul@5 | 1233 | |
paul@122 | 1234 | output.append(view.writeMonthTableHeading(month)) |
paul@61 | 1235 | |
paul@61 | 1236 | # Weekday headings. |
paul@0 | 1237 | |
paul@122 | 1238 | output.append(view.writeWeekdayHeadings()) |
paul@5 | 1239 | |
paul@61 | 1240 | # Process the days of the month. |
paul@61 | 1241 | |
paul@67 | 1242 | start_weekday, number_of_days = month.month_properties() |
paul@61 | 1243 | |
paul@61 | 1244 | # The start weekday is the weekday of day number 1. |
paul@61 | 1245 | # Find the first day of the week, counting from below zero, if |
paul@61 | 1246 | # necessary, in order to land on the first day of the month as |
paul@61 | 1247 | # day number 1. |
paul@61 | 1248 | |
paul@61 | 1249 | first_day = 1 - start_weekday |
paul@5 | 1250 | |
paul@61 | 1251 | while first_day <= number_of_days: |
paul@61 | 1252 | |
paul@61 | 1253 | # Find events in this week and determine how to mark them on the |
paul@61 | 1254 | # calendar. |
paul@61 | 1255 | |
paul@67 | 1256 | week_start = month.as_date(max(first_day, 1)) |
paul@67 | 1257 | week_end = month.as_date(min(first_day + 6, number_of_days)) |
paul@61 | 1258 | |
paul@118 | 1259 | full_coverage, week_slots = EventAggregatorSupport.getCoverage( |
paul@67 | 1260 | week_start, week_end, shown_events.get(month, [])) |
paul@61 | 1261 | |
paul@61 | 1262 | # Output a week, starting with the day numbers. |
paul@61 | 1263 | |
paul@120 | 1264 | output.append(view.writeDayNumbers(first_day, number_of_days, month, full_coverage)) |
paul@7 | 1265 | |
paul@61 | 1266 | # Either generate empty days... |
paul@7 | 1267 | |
paul@118 | 1268 | if not week_slots: |
paul@120 | 1269 | output.append(view.writeEmptyWeek(first_day, number_of_days)) |
paul@7 | 1270 | |
paul@120 | 1271 | # Or generate each set of scheduled events... |
paul@61 | 1272 | |
paul@61 | 1273 | else: |
paul@120 | 1274 | output.append(view.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots)) |
paul@25 | 1275 | |
paul@61 | 1276 | # Process the next week... |
paul@25 | 1277 | |
paul@61 | 1278 | first_day += 7 |
paul@25 | 1279 | |
paul@61 | 1280 | # End of month. |
paul@0 | 1281 | |
paul@61 | 1282 | output.append(fmt.table(on=0)) |
paul@0 | 1283 | |
paul@61 | 1284 | # Or output a summary view... |
paul@25 | 1285 | |
paul@61 | 1286 | elif mode == "list": |
paul@0 | 1287 | |
paul@61 | 1288 | # Output a list. |
paul@0 | 1289 | |
paul@61 | 1290 | output.append(fmt.listitem(on=1, attr={"class" : "event-listings-month"})) |
paul@61 | 1291 | output.append(fmt.div(on=1, attr={"class" : "event-listings-month-heading"})) |
paul@0 | 1292 | |
paul@61 | 1293 | # Either write a month heading or produce links for navigable |
paul@61 | 1294 | # calendars. |
paul@25 | 1295 | |
paul@67 | 1296 | output.append(view.writeMonthHeading(month)) |
paul@0 | 1297 | |
paul@61 | 1298 | output.append(fmt.div(on=0)) |
paul@25 | 1299 | |
paul@61 | 1300 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-month-listings"})) |
paul@25 | 1301 | |
paul@61 | 1302 | # Get the events in order. |
paul@0 | 1303 | |
paul@67 | 1304 | ordered_events = EventAggregatorSupport.getOrderedEvents(shown_events.get(month, [])) |
paul@51 | 1305 | |
paul@61 | 1306 | # Show the events in order. |
paul@51 | 1307 | |
paul@69 | 1308 | for event in ordered_events: |
paul@69 | 1309 | event_page = event.getPage() |
paul@69 | 1310 | event_details = event.getDetails() |
paul@69 | 1311 | event_summary = event.getSummary(parent_name) |
paul@51 | 1312 | |
paul@61 | 1313 | output.append(fmt.listitem(on=1, attr={"class" : "event-listing"})) |
paul@51 | 1314 | |
paul@61 | 1315 | # Link to the page using the summary. |
paul@51 | 1316 | |
paul@61 | 1317 | output.append(fmt.paragraph(on=1)) |
paul@67 | 1318 | output.append(event_page.linkToPage(request, event_summary)) |
paul@61 | 1319 | output.append(fmt.paragraph(on=0)) |
paul@51 | 1320 | |
paul@61 | 1321 | # Start and end dates. |
paul@51 | 1322 | |
paul@61 | 1323 | output.append(fmt.paragraph(on=1)) |
paul@61 | 1324 | output.append(fmt.span(on=1)) |
paul@67 | 1325 | output.append(fmt.text(str(event_details["start"]))) |
paul@61 | 1326 | output.append(fmt.span(on=0)) |
paul@52 | 1327 | output.append(fmt.text(" - ")) |
paul@52 | 1328 | output.append(fmt.span(on=1)) |
paul@67 | 1329 | output.append(fmt.text(str(event_details["end"]))) |
paul@52 | 1330 | output.append(fmt.span(on=0)) |
paul@61 | 1331 | output.append(fmt.paragraph(on=0)) |
paul@51 | 1332 | |
paul@61 | 1333 | # Location. |
paul@51 | 1334 | |
paul@61 | 1335 | if event_details.has_key("location"): |
paul@61 | 1336 | output.append(fmt.paragraph(on=1)) |
paul@61 | 1337 | output.append(fmt.text(event_details["location"])) |
paul@61 | 1338 | output.append(fmt.paragraph(on=1)) |
paul@51 | 1339 | |
paul@61 | 1340 | # Topics. |
paul@51 | 1341 | |
paul@61 | 1342 | if event_details.has_key("topics") or event_details.has_key("categories"): |
paul@61 | 1343 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-topics"})) |
paul@51 | 1344 | |
paul@61 | 1345 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@61 | 1346 | output.append(fmt.listitem(on=1)) |
paul@61 | 1347 | output.append(fmt.text(topic)) |
paul@61 | 1348 | output.append(fmt.listitem(on=0)) |
paul@51 | 1349 | |
paul@61 | 1350 | output.append(fmt.bullet_list(on=0)) |
paul@51 | 1351 | |
paul@61 | 1352 | output.append(fmt.listitem(on=0)) |
paul@9 | 1353 | |
paul@61 | 1354 | output.append(fmt.bullet_list(on=0)) |
paul@9 | 1355 | |
paul@61 | 1356 | # Output top-level information. |
paul@0 | 1357 | |
paul@61 | 1358 | # End of list view output. |
paul@51 | 1359 | |
paul@61 | 1360 | if mode == "list": |
paul@61 | 1361 | output.append(fmt.bullet_list(on=0)) |
paul@51 | 1362 | |
paul@122 | 1363 | # Output a day view. |
paul@122 | 1364 | |
paul@122 | 1365 | elif mode == "day": |
paul@122 | 1366 | |
paul@122 | 1367 | # Visit all days in the requested range, or across known events. |
paul@122 | 1368 | |
paul@122 | 1369 | for date in first.days_until(last): |
paul@122 | 1370 | |
paul@122 | 1371 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"})) |
paul@122 | 1372 | |
paul@122 | 1373 | full_coverage, day_slots = EventAggregatorSupport.getCoverage( |
paul@122 | 1374 | date, date, shown_events.get(date, [])) |
paul@122 | 1375 | |
paul@126 | 1376 | # Work out how many columns the day title will need. |
paul@126 | 1377 | # Includer spacers before each event column. |
paul@126 | 1378 | |
paul@126 | 1379 | colspan = sum(map(len, day_slots.values())) * 2 + 1 |
paul@126 | 1380 | |
paul@126 | 1381 | output.append(view.writeDayHeading(date, colspan)) |
paul@123 | 1382 | |
paul@123 | 1383 | # Either generate empty days... |
paul@123 | 1384 | |
paul@123 | 1385 | if not day_slots: |
paul@123 | 1386 | output.append(view.writeEmptyDay(date)) |
paul@123 | 1387 | |
paul@123 | 1388 | # Or generate each set of scheduled events... |
paul@123 | 1389 | |
paul@123 | 1390 | else: |
paul@123 | 1391 | output.append(view.writeDaySlots(date, full_coverage, day_slots)) |
paul@122 | 1392 | |
paul@122 | 1393 | # End of day. |
paul@122 | 1394 | |
paul@122 | 1395 | output.append(fmt.table(on=0)) |
paul@122 | 1396 | |
paul@57 | 1397 | # Output view controls. |
paul@57 | 1398 | |
paul@57 | 1399 | output.append(fmt.div(on=1, css_class="event-controls")) |
paul@57 | 1400 | output.append(view.writeViewControls()) |
paul@57 | 1401 | output.append(fmt.div(on=0)) |
paul@57 | 1402 | |
paul@0 | 1403 | return ''.join(output) |
paul@0 | 1404 | |
paul@0 | 1405 | # vim: tabstop=4 expandtab shiftwidth=4 |