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@183 | 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@183 | 12 | from MoinMoin.action import AttachFile |
paul@192 | 13 | from MoinMoin.Page import Page |
paul@168 | 14 | from EventAggregatorSupport import * |
paul@0 | 15 | import calendar |
paul@0 | 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@150 | 26 | original_calendar_start, original_calendar_end, calendar_start, calendar_end, |
paul@187 | 27 | first, last, category_names, template_name, parent_name, mode, resolution, |
paul@187 | 28 | name_usage, map_name): |
paul@37 | 29 | |
paul@37 | 30 | """ |
paul@37 | 31 | Initialise the view with the current 'page', a 'calendar_name' (which |
paul@76 | 32 | may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which |
paul@76 | 33 | are the actual start and end values provided by the request), the |
paul@150 | 34 | calculated 'original_calendar_start' and 'original_calendar_end' (which |
paul@150 | 35 | are the result of calculating the calendar's limits from the raw start |
paul@150 | 36 | and end values), and the requested, calculated 'calendar_start' and |
paul@150 | 37 | 'calendar_end' (which may involve different start and end values due to |
paul@150 | 38 | navigation in the user interface), along with the 'first' and 'last' |
paul@150 | 39 | months of event coverage. |
paul@57 | 40 | |
paul@57 | 41 | The additional 'category_names', 'template_name', 'parent_name' and |
paul@57 | 42 | 'mode' parameters are used to configure the links employed by the view. |
paul@120 | 43 | |
paul@187 | 44 | The 'resolution' affects the view for certain modes and is also used to |
paul@187 | 45 | parameterise links. |
paul@187 | 46 | |
paul@120 | 47 | The 'name_usage' parameter controls how names are shown on calendar mode |
paul@126 | 48 | events, such as how often labels are repeated. |
paul@187 | 49 | |
paul@187 | 50 | The 'map_name' parameter provides the name of a map to be used in the |
paul@187 | 51 | map mode. |
paul@37 | 52 | """ |
paul@37 | 53 | |
paul@37 | 54 | self.page = page |
paul@37 | 55 | self.calendar_name = calendar_name |
paul@76 | 56 | self.raw_calendar_start = raw_calendar_start |
paul@76 | 57 | self.raw_calendar_end = raw_calendar_end |
paul@150 | 58 | self.original_calendar_start = original_calendar_start |
paul@150 | 59 | self.original_calendar_end = original_calendar_end |
paul@57 | 60 | self.calendar_start = calendar_start |
paul@57 | 61 | self.calendar_end = calendar_end |
paul@57 | 62 | self.template_name = template_name |
paul@57 | 63 | self.parent_name = parent_name |
paul@57 | 64 | self.mode = mode |
paul@187 | 65 | self.resolution = resolution |
paul@120 | 66 | self.name_usage = name_usage |
paul@187 | 67 | self.map_name = map_name |
paul@57 | 68 | |
paul@57 | 69 | self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names]) |
paul@37 | 70 | |
paul@37 | 71 | if self.calendar_name is not None: |
paul@37 | 72 | |
paul@37 | 73 | # Store the view parameters. |
paul@37 | 74 | |
paul@187 | 75 | self.duration = (last - first).count() + 1 |
paul@37 | 76 | |
paul@187 | 77 | self.previous_start = first.previous() |
paul@187 | 78 | self.next_start = first.next() |
paul@187 | 79 | self.previous_end = last.previous() |
paul@187 | 80 | self.next_end = last.next() |
paul@37 | 81 | |
paul@187 | 82 | self.previous_set_start = first.update(-self.duration) |
paul@187 | 83 | self.next_set_start = first.update(self.duration) |
paul@187 | 84 | self.previous_set_end = last.update(-self.duration) |
paul@187 | 85 | self.next_set_end = last.update(self.duration) |
paul@37 | 86 | |
paul@58 | 87 | def getQualifiedParameterName(self, argname): |
paul@119 | 88 | |
paul@119 | 89 | "Return the 'argname' qualified using the calendar name." |
paul@119 | 90 | |
paul@168 | 91 | return getQualifiedParameterName(self.calendar_name, argname) |
paul@58 | 92 | |
paul@123 | 93 | def getDateQueryString(self, argname, date, prefix=1): |
paul@119 | 94 | |
paul@119 | 95 | """ |
paul@119 | 96 | Return a query string fragment for the given 'argname', referring to the |
paul@119 | 97 | month given by the specified 'year_month' object, appropriate for this |
paul@119 | 98 | calendar. |
paul@119 | 99 | |
paul@119 | 100 | If 'prefix' is specified and set to a false value, the parameters in the |
paul@119 | 101 | query string will not be calendar-specific, but could be used with the |
paul@119 | 102 | summary action. |
paul@119 | 103 | """ |
paul@119 | 104 | |
paul@123 | 105 | suffixes = ["year", "month", "day"] |
paul@123 | 106 | |
paul@123 | 107 | if date is not None: |
paul@123 | 108 | args = [] |
paul@123 | 109 | for suffix, value in zip(suffixes, date.as_tuple()): |
paul@123 | 110 | suffixed_argname = "%s-%s" % (argname, suffix) |
paul@123 | 111 | if prefix: |
paul@123 | 112 | suffixed_argname = self.getQualifiedParameterName(suffixed_argname) |
paul@123 | 113 | args.append("%s=%s" % (suffixed_argname, value)) |
paul@123 | 114 | return "&".join(args) |
paul@114 | 115 | else: |
paul@114 | 116 | return "" |
paul@114 | 117 | |
paul@123 | 118 | def getRawDateQueryString(self, argname, date, prefix=1): |
paul@119 | 119 | |
paul@119 | 120 | """ |
paul@119 | 121 | Return a query string fragment for the given 'argname', referring to the |
paul@123 | 122 | date given by the specified 'date' value, appropriate for this |
paul@119 | 123 | calendar. |
paul@119 | 124 | |
paul@119 | 125 | If 'prefix' is specified and set to a false value, the parameters in the |
paul@119 | 126 | query string will not be calendar-specific, but could be used with the |
paul@119 | 127 | summary action. |
paul@119 | 128 | """ |
paul@119 | 129 | |
paul@123 | 130 | if date is not None: |
paul@57 | 131 | if prefix: |
paul@58 | 132 | argname = self.getQualifiedParameterName(argname) |
paul@123 | 133 | return "%s=%s" % (argname, date) |
paul@37 | 134 | else: |
paul@37 | 135 | return "" |
paul@37 | 136 | |
paul@187 | 137 | def getNavigationLink(self, start, end, mode=None, resolution=None): |
paul@119 | 138 | |
paul@119 | 139 | """ |
paul@119 | 140 | Return a query string fragment for navigation to a view showing months |
paul@119 | 141 | from 'start' to 'end' inclusive, with the optional 'mode' indicating the |
paul@187 | 142 | view style and the optional 'resolution' indicating the resolution of a |
paul@187 | 143 | view, if configurable. |
paul@119 | 144 | """ |
paul@119 | 145 | |
paul@187 | 146 | return "%s&%s&%s=%s&%s=%s" % ( |
paul@123 | 147 | self.getRawDateQueryString("start", start), |
paul@123 | 148 | self.getRawDateQueryString("end", end), |
paul@187 | 149 | self.getQualifiedParameterName("mode"), mode or self.mode, |
paul@187 | 150 | self.getQualifiedParameterName("resolution"), resolution or self.resolution |
paul@57 | 151 | ) |
paul@57 | 152 | |
paul@122 | 153 | def getFullDateLabel(self, date): |
paul@122 | 154 | page = self.page |
paul@122 | 155 | request = page.request |
paul@168 | 156 | return getFullDateLabel(request, date) |
paul@122 | 157 | |
paul@114 | 158 | def getFullMonthLabel(self, year_month): |
paul@114 | 159 | page = self.page |
paul@114 | 160 | request = page.request |
paul@168 | 161 | return getFullMonthLabel(request, year_month) |
paul@114 | 162 | |
paul@187 | 163 | def getFullLabel(self, arg): |
paul@187 | 164 | return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg) |
paul@187 | 165 | |
paul@187 | 166 | def _getCalendarPeriod(self, start_label, end_label, default_label): |
paul@187 | 167 | output = [] |
paul@187 | 168 | if start_label: |
paul@187 | 169 | output.append(start_label) |
paul@193 | 170 | if end_label and start_label != end_label: |
paul@187 | 171 | if output: |
paul@187 | 172 | output.append(" - ") |
paul@187 | 173 | output.append(end_label) |
paul@187 | 174 | return "".join(output) or default_label |
paul@187 | 175 | |
paul@187 | 176 | def getCalendarPeriod(self): |
paul@187 | 177 | _ = self.page.request.getText |
paul@187 | 178 | return self._getCalendarPeriod( |
paul@187 | 179 | self.calendar_start and self.getFullLabel(self.calendar_start), |
paul@187 | 180 | self.calendar_end and self.getFullLabel(self.calendar_end), |
paul@187 | 181 | _("All events") |
paul@187 | 182 | ) |
paul@187 | 183 | |
paul@187 | 184 | def getOriginalCalendarPeriod(self): |
paul@187 | 185 | _ = self.page.request.getText |
paul@187 | 186 | return self._getCalendarPeriod( |
paul@187 | 187 | self.original_calendar_start and self.getFullLabel(self.original_calendar_start), |
paul@187 | 188 | self.original_calendar_end and self.getFullLabel(self.original_calendar_end), |
paul@187 | 189 | _("All events") |
paul@187 | 190 | ) |
paul@187 | 191 | |
paul@187 | 192 | def getRawCalendarPeriod(self): |
paul@187 | 193 | _ = self.page.request.getText |
paul@187 | 194 | return self._getCalendarPeriod( |
paul@187 | 195 | self.raw_calendar_start, |
paul@187 | 196 | self.raw_calendar_end, |
paul@187 | 197 | _("No period specified") |
paul@187 | 198 | ) |
paul@187 | 199 | |
paul@57 | 200 | def writeDownloadControls(self): |
paul@132 | 201 | |
paul@132 | 202 | """ |
paul@132 | 203 | Return a representation of the download controls, featuring links for |
paul@132 | 204 | view, calendar and customised downloads and subscriptions. |
paul@132 | 205 | """ |
paul@132 | 206 | |
paul@57 | 207 | page = self.page |
paul@57 | 208 | request = page.request |
paul@57 | 209 | fmt = page.formatter |
paul@57 | 210 | _ = request.getText |
paul@57 | 211 | |
paul@57 | 212 | output = [] |
paul@57 | 213 | |
paul@57 | 214 | # Generate the links. |
paul@57 | 215 | |
paul@128 | 216 | download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&%s" % ( |
paul@150 | 217 | self.parent_name or "", |
paul@187 | 218 | self.resolution, |
paul@150 | 219 | self.category_name_parameters |
paul@74 | 220 | ) |
paul@112 | 221 | download_all_link = download_dialogue_link + "&doit=1" |
paul@57 | 222 | download_link = download_all_link + ("&%s&%s" % ( |
paul@123 | 223 | self.getDateQueryString("start", self.calendar_start, prefix=0), |
paul@123 | 224 | self.getDateQueryString("end", self.calendar_end, prefix=0) |
paul@57 | 225 | )) |
paul@112 | 226 | |
paul@112 | 227 | # Subscription links just explicitly select the RSS format. |
paul@112 | 228 | |
paul@112 | 229 | subscribe_dialogue_link = download_dialogue_link + "&format=RSS" |
paul@57 | 230 | subscribe_all_link = download_all_link + "&format=RSS" |
paul@57 | 231 | subscribe_link = download_link + "&format=RSS" |
paul@57 | 232 | |
paul@76 | 233 | # Adjust the "download all" and "subscribe all" links if the calendar |
paul@76 | 234 | # has an inherent period associated with it. |
paul@76 | 235 | |
paul@76 | 236 | period_limits = [] |
paul@76 | 237 | |
paul@76 | 238 | if self.raw_calendar_start: |
paul@76 | 239 | period_limits.append("&%s" % |
paul@123 | 240 | self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0) |
paul@76 | 241 | ) |
paul@76 | 242 | if self.raw_calendar_end: |
paul@76 | 243 | period_limits.append("&%s" % |
paul@123 | 244 | self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0) |
paul@76 | 245 | ) |
paul@76 | 246 | |
paul@76 | 247 | period_limits = "".join(period_limits) |
paul@76 | 248 | |
paul@112 | 249 | download_dialogue_link += period_limits |
paul@76 | 250 | download_all_link += period_limits |
paul@112 | 251 | subscribe_dialogue_link += period_limits |
paul@76 | 252 | subscribe_all_link += period_limits |
paul@76 | 253 | |
paul@112 | 254 | # Pop-up descriptions of the downloadable calendars. |
paul@112 | 255 | |
paul@187 | 256 | calendar_period = self.getCalendarPeriod() |
paul@187 | 257 | original_calendar_period = self.getOriginalCalendarPeriod() |
paul@187 | 258 | raw_calendar_period = self.getRawCalendarPeriod() |
paul@112 | 259 | |
paul@57 | 260 | # Write the controls. |
paul@57 | 261 | |
paul@114 | 262 | # Download controls. |
paul@114 | 263 | |
paul@57 | 264 | output.append(fmt.div(on=1, css_class="event-download-controls")) |
paul@57 | 265 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 266 | output.append(linkToPage(request, page, _("Download this view"), download_link)) |
paul@112 | 267 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 268 | output.append(fmt.text(calendar_period)) |
paul@112 | 269 | output.append(fmt.span(on=0)) |
paul@57 | 270 | output.append(fmt.span(on=0)) |
paul@114 | 271 | |
paul@57 | 272 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 273 | output.append(linkToPage(request, page, _("Download this calendar"), download_all_link)) |
paul@112 | 274 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@114 | 275 | output.append(fmt.span(on=1, css_class="event-download-period")) |
paul@150 | 276 | output.append(fmt.text(original_calendar_period)) |
paul@114 | 277 | output.append(fmt.span(on=0)) |
paul@114 | 278 | output.append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@112 | 279 | output.append(fmt.text(raw_calendar_period)) |
paul@112 | 280 | output.append(fmt.span(on=0)) |
paul@112 | 281 | output.append(fmt.span(on=0)) |
paul@114 | 282 | output.append(fmt.span(on=0)) |
paul@114 | 283 | |
paul@112 | 284 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@112 | 285 | output.append(linkToPage(request, page, _("Download..."), download_dialogue_link)) |
paul@112 | 286 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 287 | output.append(fmt.text(_("Edit download options"))) |
paul@112 | 288 | output.append(fmt.span(on=0)) |
paul@57 | 289 | output.append(fmt.span(on=0)) |
paul@114 | 290 | |
paul@114 | 291 | # Subscription controls. |
paul@114 | 292 | |
paul@57 | 293 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 294 | output.append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link)) |
paul@112 | 295 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 296 | output.append(fmt.text(calendar_period)) |
paul@112 | 297 | output.append(fmt.span(on=0)) |
paul@57 | 298 | output.append(fmt.span(on=0)) |
paul@114 | 299 | |
paul@57 | 300 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@57 | 301 | output.append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link)) |
paul@112 | 302 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@114 | 303 | output.append(fmt.span(on=1, css_class="event-download-period")) |
paul@150 | 304 | output.append(fmt.text(original_calendar_period)) |
paul@114 | 305 | output.append(fmt.span(on=0)) |
paul@114 | 306 | output.append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@112 | 307 | output.append(fmt.text(raw_calendar_period)) |
paul@112 | 308 | output.append(fmt.span(on=0)) |
paul@112 | 309 | output.append(fmt.span(on=0)) |
paul@114 | 310 | output.append(fmt.span(on=0)) |
paul@114 | 311 | |
paul@112 | 312 | output.append(fmt.span(on=1, css_class="event-download")) |
paul@112 | 313 | output.append(linkToPage(request, page, _("Subscribe..."), subscribe_dialogue_link)) |
paul@112 | 314 | output.append(fmt.span(on=1, css_class="event-download-popup")) |
paul@112 | 315 | output.append(fmt.text(_("Edit subscription options"))) |
paul@112 | 316 | output.append(fmt.span(on=0)) |
paul@57 | 317 | output.append(fmt.span(on=0)) |
paul@57 | 318 | output.append(fmt.div(on=0)) |
paul@57 | 319 | |
paul@57 | 320 | return "".join(output) |
paul@57 | 321 | |
paul@57 | 322 | def writeViewControls(self): |
paul@132 | 323 | |
paul@132 | 324 | """ |
paul@132 | 325 | Return a representation of the view mode controls, permitting viewing of |
paul@132 | 326 | aggregated events in calendar, list or table form. |
paul@132 | 327 | """ |
paul@132 | 328 | |
paul@57 | 329 | page = self.page |
paul@57 | 330 | request = page.request |
paul@57 | 331 | fmt = page.formatter |
paul@57 | 332 | _ = request.getText |
paul@57 | 333 | |
paul@57 | 334 | output = [] |
paul@57 | 335 | |
paul@187 | 336 | start = self.calendar_start |
paul@187 | 337 | end = self.calendar_end |
paul@134 | 338 | |
paul@192 | 339 | help_page = Page(request, "HelpOnEventAggregator") |
paul@187 | 340 | calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month") |
paul@134 | 341 | list_link = self.getNavigationLink(start, end, "list") |
paul@134 | 342 | table_link = self.getNavigationLink(start, end, "table") |
paul@187 | 343 | map_link = self.getNavigationLink(start, end, "map") |
paul@57 | 344 | |
paul@57 | 345 | # Write the controls. |
paul@57 | 346 | |
paul@57 | 347 | output.append(fmt.div(on=1, css_class="event-view-controls")) |
paul@187 | 348 | |
paul@192 | 349 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@192 | 350 | output.append(linkToPage(request, help_page, _("Help"))) |
paul@192 | 351 | output.append(fmt.span(on=0)) |
paul@192 | 352 | |
paul@187 | 353 | if self.mode != "calendar": |
paul@187 | 354 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@187 | 355 | output.append(linkToPage(request, page, _("View as calendar"), calendar_link)) |
paul@187 | 356 | output.append(fmt.span(on=0)) |
paul@187 | 357 | |
paul@187 | 358 | if self.mode != "list": |
paul@187 | 359 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@187 | 360 | output.append(linkToPage(request, page, _("View as list"), list_link)) |
paul@187 | 361 | output.append(fmt.span(on=0)) |
paul@187 | 362 | |
paul@187 | 363 | if self.mode != "table": |
paul@187 | 364 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@187 | 365 | output.append(linkToPage(request, page, _("View as table"), table_link)) |
paul@187 | 366 | output.append(fmt.span(on=0)) |
paul@187 | 367 | |
paul@187 | 368 | if self.mode != "map" and self.map_name is not None: |
paul@187 | 369 | output.append(fmt.span(on=1, css_class="event-view")) |
paul@187 | 370 | output.append(linkToPage(request, page, _("View as map"), map_link)) |
paul@187 | 371 | output.append(fmt.span(on=0)) |
paul@187 | 372 | |
paul@57 | 373 | output.append(fmt.div(on=0)) |
paul@57 | 374 | |
paul@57 | 375 | return "".join(output) |
paul@57 | 376 | |
paul@187 | 377 | def writeMapHeading(self): |
paul@187 | 378 | |
paul@187 | 379 | """ |
paul@187 | 380 | Return the calendar heading for the current calendar, providing links |
paul@187 | 381 | permitting navigation to other periods. |
paul@187 | 382 | """ |
paul@187 | 383 | |
paul@187 | 384 | label = self.getCalendarPeriod() |
paul@187 | 385 | |
paul@187 | 386 | if self.raw_calendar_start is None or self.raw_calendar_end is None: |
paul@187 | 387 | fmt = self.page.formatter |
paul@187 | 388 | output = [] |
paul@187 | 389 | output.append(fmt.span(on=1)) |
paul@187 | 390 | output.append(fmt.text(label)) |
paul@187 | 391 | output.append(fmt.span(on=0)) |
paul@187 | 392 | return "".join(output) |
paul@187 | 393 | else: |
paul@187 | 394 | return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end) |
paul@187 | 395 | |
paul@187 | 396 | def writeDateHeading(self, date): |
paul@187 | 397 | if isinstance(date, Date): |
paul@187 | 398 | return self.writeDayHeading(date) |
paul@187 | 399 | else: |
paul@187 | 400 | return self.writeMonthHeading(date) |
paul@187 | 401 | |
paul@67 | 402 | def writeMonthHeading(self, year_month): |
paul@132 | 403 | |
paul@132 | 404 | """ |
paul@132 | 405 | Return the calendar heading for the given 'year_month' (a Month object) |
paul@132 | 406 | providing links permitting navigation to other months. |
paul@132 | 407 | """ |
paul@132 | 408 | |
paul@187 | 409 | full_month_label = self.getFullMonthLabel(year_month) |
paul@187 | 410 | end_month = year_month.update(self.duration - 1) |
paul@187 | 411 | return self._writeCalendarHeading(full_month_label, year_month, end_month) |
paul@187 | 412 | |
paul@187 | 413 | def writeDayHeading(self, date): |
paul@187 | 414 | |
paul@187 | 415 | """ |
paul@187 | 416 | Return the calendar heading for the given 'date' (a Date object) |
paul@187 | 417 | providing links permitting navigation to other dates. |
paul@187 | 418 | """ |
paul@187 | 419 | |
paul@187 | 420 | full_date_label = self.getFullDateLabel(date) |
paul@187 | 421 | end_date = date.update(self.duration - 1) |
paul@187 | 422 | return self._writeCalendarHeading(full_date_label, date, end_date) |
paul@187 | 423 | |
paul@187 | 424 | def _writeCalendarHeading(self, label, start, end): |
paul@187 | 425 | |
paul@187 | 426 | """ |
paul@187 | 427 | Write a calendar heading providing links permitting navigation to other |
paul@187 | 428 | periods, using the given 'label' along with the 'start' and 'end' dates |
paul@187 | 429 | to provide a link to a particular period. |
paul@187 | 430 | """ |
paul@187 | 431 | |
paul@37 | 432 | page = self.page |
paul@37 | 433 | request = page.request |
paul@37 | 434 | fmt = page.formatter |
paul@37 | 435 | _ = request.getText |
paul@37 | 436 | |
paul@37 | 437 | output = [] |
paul@37 | 438 | |
paul@37 | 439 | # Prepare navigation links. |
paul@37 | 440 | |
paul@37 | 441 | if self.calendar_name is not None: |
paul@37 | 442 | calendar_name = self.calendar_name |
paul@37 | 443 | |
paul@37 | 444 | # Links to the previous set of months and to a calendar shifted |
paul@37 | 445 | # back one month. |
paul@37 | 446 | |
paul@57 | 447 | previous_set_link = self.getNavigationLink( |
paul@57 | 448 | self.previous_set_start, self.previous_set_end |
paul@37 | 449 | ) |
paul@187 | 450 | previous_link = self.getNavigationLink( |
paul@187 | 451 | self.previous_start, self.previous_end |
paul@37 | 452 | ) |
paul@37 | 453 | |
paul@37 | 454 | # Links to the next set of months and to a calendar shifted |
paul@37 | 455 | # forward one month. |
paul@37 | 456 | |
paul@57 | 457 | next_set_link = self.getNavigationLink( |
paul@57 | 458 | self.next_set_start, self.next_set_end |
paul@37 | 459 | ) |
paul@187 | 460 | next_link = self.getNavigationLink( |
paul@187 | 461 | self.next_start, self.next_end |
paul@37 | 462 | ) |
paul@37 | 463 | |
paul@187 | 464 | # A link leading to this date being at the top of the calendar. |
paul@37 | 465 | |
paul@187 | 466 | date_link = self.getNavigationLink(start, end) |
paul@37 | 467 | |
paul@187 | 468 | output.append(fmt.span(on=1, css_class="previous")) |
paul@37 | 469 | output.append(linkToPage(request, page, "<<", previous_set_link)) |
paul@37 | 470 | output.append(fmt.text(" ")) |
paul@187 | 471 | output.append(linkToPage(request, page, "<", previous_link)) |
paul@37 | 472 | output.append(fmt.span(on=0)) |
paul@37 | 473 | |
paul@187 | 474 | output.append(fmt.span(on=1, css_class="next")) |
paul@187 | 475 | output.append(linkToPage(request, page, ">", next_link)) |
paul@37 | 476 | output.append(fmt.text(" ")) |
paul@37 | 477 | output.append(linkToPage(request, page, ">>", next_set_link)) |
paul@37 | 478 | output.append(fmt.span(on=0)) |
paul@37 | 479 | |
paul@187 | 480 | output.append(linkToPage(request, page, label, date_link)) |
paul@37 | 481 | |
paul@37 | 482 | else: |
paul@37 | 483 | output.append(fmt.span(on=1)) |
paul@187 | 484 | output.append(fmt.text(label)) |
paul@37 | 485 | output.append(fmt.span(on=0)) |
paul@37 | 486 | |
paul@37 | 487 | return "".join(output) |
paul@37 | 488 | |
paul@133 | 489 | def writeDayNumberHeading(self, date, busy): |
paul@132 | 490 | |
paul@132 | 491 | """ |
paul@132 | 492 | Return a link for the given 'date' which will activate the new event |
paul@133 | 493 | action for the given day. If 'busy' is given as a true value, the |
paul@133 | 494 | heading will be marked as busy. |
paul@132 | 495 | """ |
paul@132 | 496 | |
paul@57 | 497 | page = self.page |
paul@57 | 498 | request = page.request |
paul@57 | 499 | fmt = page.formatter |
paul@57 | 500 | _ = request.getText |
paul@57 | 501 | |
paul@67 | 502 | year, month, day = date.as_tuple() |
paul@57 | 503 | output = [] |
paul@57 | 504 | |
paul@58 | 505 | # Prepare navigation details for the calendar shown with the new event |
paul@58 | 506 | # form. |
paul@58 | 507 | |
paul@58 | 508 | navigation_link = self.getNavigationLink( |
paul@187 | 509 | self.calendar_start, self.calendar_end |
paul@58 | 510 | ) |
paul@58 | 511 | |
paul@58 | 512 | # Prepare the link to the new event form, incorporating the above |
paul@58 | 513 | # calendar parameters. |
paul@58 | 514 | |
paul@57 | 515 | new_event_link = "action=EventAggregatorNewEvent&start-day=%d&start-month=%d&start-year=%d" \ |
paul@58 | 516 | "&%s&template=%s&parent=%s&%s" % ( |
paul@58 | 517 | day, month, year, self.category_name_parameters, self.template_name, self.parent_name or "", |
paul@58 | 518 | navigation_link) |
paul@57 | 519 | |
paul@133 | 520 | # Prepare a link to the day view for this day. |
paul@133 | 521 | |
paul@187 | 522 | day_view_link = self.getNavigationLink(date, date, "day", "date") |
paul@133 | 523 | |
paul@133 | 524 | # Output the heading class. |
paul@133 | 525 | |
paul@133 | 526 | output.append( |
paul@133 | 527 | fmt.table_cell(on=1, attrs={ |
paul@133 | 528 | "class" : "event-day-heading event-day-%s" % (busy and "busy" or "empty"), |
paul@133 | 529 | "colspan" : "3" |
paul@133 | 530 | })) |
paul@133 | 531 | |
paul@133 | 532 | # Output the number and pop-up menu. |
paul@133 | 533 | |
paul@133 | 534 | output.append(fmt.div(on=1, css_class="event-day-box")) |
paul@133 | 535 | |
paul@133 | 536 | output.append(fmt.span(on=1, css_class="event-day-number-popup")) |
paul@133 | 537 | output.append(fmt.span(on=1, css_class="event-day-number-link")) |
paul@133 | 538 | output.append(linkToPage(request, page, _("View day"), day_view_link)) |
paul@133 | 539 | output.append(fmt.span(on=0)) |
paul@133 | 540 | output.append(fmt.span(on=1, css_class="event-day-number-link")) |
paul@133 | 541 | output.append(linkToPage(request, page, _("New event"), new_event_link)) |
paul@133 | 542 | output.append(fmt.span(on=0)) |
paul@133 | 543 | output.append(fmt.span(on=0)) |
paul@133 | 544 | |
paul@57 | 545 | output.append(fmt.span(on=1, css_class="event-day-number")) |
paul@133 | 546 | output.append(fmt.text(unicode(day))) |
paul@57 | 547 | output.append(fmt.span(on=0)) |
paul@133 | 548 | |
paul@57 | 549 | output.append(fmt.div(on=0)) |
paul@57 | 550 | |
paul@133 | 551 | # End of heading. |
paul@133 | 552 | |
paul@133 | 553 | output.append(fmt.table_cell(on=0)) |
paul@133 | 554 | |
paul@57 | 555 | return "".join(output) |
paul@57 | 556 | |
paul@126 | 557 | # Common layout methods. |
paul@126 | 558 | |
paul@126 | 559 | def getEventStyle(self, colour_seed): |
paul@126 | 560 | |
paul@126 | 561 | "Generate colour style information using the given 'colour_seed'." |
paul@126 | 562 | |
paul@126 | 563 | bg = getColour(colour_seed) |
paul@126 | 564 | fg = getBlackOrWhite(bg) |
paul@126 | 565 | return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg) |
paul@126 | 566 | |
paul@126 | 567 | def writeEventSummaryBox(self, event): |
paul@126 | 568 | |
paul@126 | 569 | "Return an event summary box linking to the given 'event'." |
paul@126 | 570 | |
paul@126 | 571 | page = self.page |
paul@126 | 572 | request = page.request |
paul@126 | 573 | fmt = page.formatter |
paul@126 | 574 | |
paul@126 | 575 | output = [] |
paul@126 | 576 | |
paul@126 | 577 | event_page = event.getPage() |
paul@126 | 578 | event_details = event.getDetails() |
paul@126 | 579 | event_summary = event.getSummary(self.parent_name) |
paul@126 | 580 | |
paul@179 | 581 | is_ambiguous = event.as_timespan().ambiguous() |
paul@126 | 582 | style = self.getEventStyle(event_summary) |
paul@126 | 583 | |
paul@126 | 584 | # The event box contains the summary, alongside |
paul@126 | 585 | # other elements. |
paul@126 | 586 | |
paul@126 | 587 | output.append(fmt.div(on=1, css_class="event-summary-box")) |
paul@126 | 588 | output.append(fmt.div(on=1, css_class="event-summary", style=style)) |
paul@126 | 589 | |
paul@126 | 590 | if is_ambiguous: |
paul@126 | 591 | output.append(fmt.icon("/!\\")) |
paul@126 | 592 | |
paul@126 | 593 | output.append(event_page.linkToPage(request, event_summary)) |
paul@126 | 594 | output.append(fmt.div(on=0)) |
paul@126 | 595 | |
paul@126 | 596 | # Add a pop-up element for long summaries. |
paul@126 | 597 | |
paul@126 | 598 | output.append(fmt.div(on=1, css_class="event-summary-popup", style=style)) |
paul@126 | 599 | |
paul@126 | 600 | if is_ambiguous: |
paul@126 | 601 | output.append(fmt.icon("/!\\")) |
paul@126 | 602 | |
paul@126 | 603 | output.append(event_page.linkToPage(request, event_summary)) |
paul@126 | 604 | output.append(fmt.div(on=0)) |
paul@126 | 605 | |
paul@57 | 606 | output.append(fmt.div(on=0)) |
paul@57 | 607 | |
paul@57 | 608 | return "".join(output) |
paul@57 | 609 | |
paul@120 | 610 | # Calendar layout methods. |
paul@120 | 611 | |
paul@122 | 612 | def writeMonthTableHeading(self, year_month): |
paul@122 | 613 | page = self.page |
paul@122 | 614 | fmt = page.formatter |
paul@122 | 615 | |
paul@122 | 616 | output = [] |
paul@122 | 617 | output.append(fmt.table_row(on=1)) |
paul@122 | 618 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"})) |
paul@122 | 619 | |
paul@122 | 620 | output.append(self.writeMonthHeading(year_month)) |
paul@122 | 621 | |
paul@122 | 622 | output.append(fmt.table_cell(on=0)) |
paul@122 | 623 | output.append(fmt.table_row(on=0)) |
paul@122 | 624 | |
paul@122 | 625 | return "".join(output) |
paul@122 | 626 | |
paul@122 | 627 | def writeWeekdayHeadings(self): |
paul@122 | 628 | page = self.page |
paul@122 | 629 | request = page.request |
paul@122 | 630 | fmt = page.formatter |
paul@122 | 631 | _ = request.getText |
paul@122 | 632 | |
paul@122 | 633 | output = [] |
paul@122 | 634 | output.append(fmt.table_row(on=1)) |
paul@122 | 635 | |
paul@122 | 636 | for weekday in range(0, 7): |
paul@122 | 637 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"})) |
paul@168 | 638 | output.append(fmt.text(_(getDayLabel(weekday)))) |
paul@122 | 639 | output.append(fmt.table_cell(on=0)) |
paul@122 | 640 | |
paul@122 | 641 | output.append(fmt.table_row(on=0)) |
paul@122 | 642 | return "".join(output) |
paul@122 | 643 | |
paul@122 | 644 | def writeDayNumbers(self, first_day, number_of_days, month, coverage): |
paul@120 | 645 | page = self.page |
paul@120 | 646 | fmt = page.formatter |
paul@120 | 647 | |
paul@120 | 648 | output = [] |
paul@120 | 649 | output.append(fmt.table_row(on=1)) |
paul@120 | 650 | |
paul@120 | 651 | for weekday in range(0, 7): |
paul@120 | 652 | day = first_day + weekday |
paul@120 | 653 | date = month.as_date(day) |
paul@120 | 654 | |
paul@120 | 655 | # Output out-of-month days. |
paul@120 | 656 | |
paul@120 | 657 | if day < 1 or day > number_of_days: |
paul@120 | 658 | output.append(fmt.table_cell(on=1, |
paul@120 | 659 | attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"})) |
paul@120 | 660 | output.append(fmt.table_cell(on=0)) |
paul@120 | 661 | |
paul@120 | 662 | # Output normal days. |
paul@120 | 663 | |
paul@120 | 664 | else: |
paul@133 | 665 | # Output the day heading, making a link to a new event |
paul@120 | 666 | # action. |
paul@120 | 667 | |
paul@133 | 668 | output.append(self.writeDayNumberHeading(date, date in coverage)) |
paul@120 | 669 | |
paul@120 | 670 | # End of day numbers. |
paul@120 | 671 | |
paul@120 | 672 | output.append(fmt.table_row(on=0)) |
paul@120 | 673 | return "".join(output) |
paul@120 | 674 | |
paul@120 | 675 | def writeEmptyWeek(self, first_day, number_of_days): |
paul@120 | 676 | page = self.page |
paul@120 | 677 | fmt = page.formatter |
paul@120 | 678 | |
paul@120 | 679 | output = [] |
paul@120 | 680 | output.append(fmt.table_row(on=1)) |
paul@120 | 681 | |
paul@120 | 682 | for weekday in range(0, 7): |
paul@120 | 683 | day = first_day + weekday |
paul@120 | 684 | |
paul@120 | 685 | # Output out-of-month days. |
paul@120 | 686 | |
paul@120 | 687 | if day < 1 or day > number_of_days: |
paul@120 | 688 | output.append(fmt.table_cell(on=1, |
paul@120 | 689 | attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"})) |
paul@120 | 690 | output.append(fmt.table_cell(on=0)) |
paul@120 | 691 | |
paul@120 | 692 | # Output empty days. |
paul@120 | 693 | |
paul@120 | 694 | else: |
paul@120 | 695 | output.append(fmt.table_cell(on=1, |
paul@120 | 696 | attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"})) |
paul@120 | 697 | |
paul@120 | 698 | output.append(fmt.table_row(on=0)) |
paul@120 | 699 | return "".join(output) |
paul@120 | 700 | |
paul@120 | 701 | def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots): |
paul@120 | 702 | output = [] |
paul@120 | 703 | |
paul@120 | 704 | locations = week_slots.keys() |
paul@168 | 705 | locations.sort(sort_none_first) |
paul@120 | 706 | |
paul@120 | 707 | # Visit each slot corresponding to a location (or no location). |
paul@120 | 708 | |
paul@120 | 709 | for location in locations: |
paul@120 | 710 | |
paul@120 | 711 | # Visit each coverage span, presenting the events in the span. |
paul@120 | 712 | |
paul@123 | 713 | for events in week_slots[location]: |
paul@120 | 714 | |
paul@120 | 715 | # Output each set. |
paul@120 | 716 | |
paul@123 | 717 | output.append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events)) |
paul@120 | 718 | |
paul@120 | 719 | # Add a spacer. |
paul@120 | 720 | |
paul@123 | 721 | output.append(self.writeWeekSpacer(first_day, number_of_days)) |
paul@120 | 722 | |
paul@120 | 723 | return "".join(output) |
paul@120 | 724 | |
paul@123 | 725 | def writeWeekSlot(self, first_day, number_of_days, month, week_end, events): |
paul@120 | 726 | page = self.page |
paul@120 | 727 | request = page.request |
paul@120 | 728 | fmt = page.formatter |
paul@120 | 729 | |
paul@120 | 730 | output = [] |
paul@120 | 731 | output.append(fmt.table_row(on=1)) |
paul@120 | 732 | |
paul@120 | 733 | # Then, output day details. |
paul@120 | 734 | |
paul@120 | 735 | for weekday in range(0, 7): |
paul@120 | 736 | day = first_day + weekday |
paul@120 | 737 | date = month.as_date(day) |
paul@120 | 738 | |
paul@120 | 739 | # Skip out-of-month days. |
paul@120 | 740 | |
paul@120 | 741 | if day < 1 or day > number_of_days: |
paul@120 | 742 | output.append(fmt.table_cell(on=1, |
paul@120 | 743 | attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"})) |
paul@120 | 744 | output.append(fmt.table_cell(on=0)) |
paul@120 | 745 | continue |
paul@120 | 746 | |
paul@120 | 747 | # Output the day. |
paul@120 | 748 | |
paul@123 | 749 | if date not in events: |
paul@120 | 750 | output.append(fmt.table_cell(on=1, |
paul@120 | 751 | attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"})) |
paul@120 | 752 | |
paul@120 | 753 | # Get event details for the current day. |
paul@120 | 754 | |
paul@120 | 755 | for event in events: |
paul@120 | 756 | event_page = event.getPage() |
paul@120 | 757 | event_details = event.getDetails() |
paul@120 | 758 | |
paul@123 | 759 | if date not in event: |
paul@120 | 760 | continue |
paul@120 | 761 | |
paul@120 | 762 | # Get basic properties of the event. |
paul@120 | 763 | |
paul@120 | 764 | starts_today = event_details["start"] == date |
paul@120 | 765 | ends_today = event_details["end"] == date |
paul@120 | 766 | event_summary = event.getSummary(self.parent_name) |
paul@120 | 767 | |
paul@126 | 768 | style = self.getEventStyle(event_summary) |
paul@120 | 769 | |
paul@120 | 770 | # Determine if the event name should be shown. |
paul@120 | 771 | |
paul@120 | 772 | start_of_period = starts_today or weekday == 0 or day == 1 |
paul@120 | 773 | |
paul@120 | 774 | if self.name_usage == "daily" or start_of_period: |
paul@120 | 775 | hide_text = 0 |
paul@120 | 776 | else: |
paul@120 | 777 | hide_text = 1 |
paul@120 | 778 | |
paul@120 | 779 | # Output start of day gap and determine whether |
paul@120 | 780 | # any event content should be explicitly output |
paul@120 | 781 | # for this day. |
paul@120 | 782 | |
paul@120 | 783 | if starts_today: |
paul@120 | 784 | |
paul@120 | 785 | # Single day events... |
paul@120 | 786 | |
paul@120 | 787 | if ends_today: |
paul@120 | 788 | colspan = 3 |
paul@120 | 789 | event_day_type = "event-day-single" |
paul@120 | 790 | |
paul@120 | 791 | # Events starting today... |
paul@120 | 792 | |
paul@120 | 793 | else: |
paul@120 | 794 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap"})) |
paul@120 | 795 | output.append(fmt.table_cell(on=0)) |
paul@120 | 796 | |
paul@120 | 797 | # Calculate the span of this cell. |
paul@120 | 798 | # Events whose names appear on every day... |
paul@120 | 799 | |
paul@120 | 800 | if self.name_usage == "daily": |
paul@120 | 801 | colspan = 2 |
paul@120 | 802 | event_day_type = "event-day-starting" |
paul@120 | 803 | |
paul@120 | 804 | # Events whose names appear once per week... |
paul@120 | 805 | |
paul@120 | 806 | else: |
paul@120 | 807 | if event_details["end"] <= week_end: |
paul@120 | 808 | event_length = event_details["end"].day() - day + 1 |
paul@120 | 809 | colspan = (event_length - 2) * 3 + 4 |
paul@120 | 810 | else: |
paul@120 | 811 | event_length = week_end.day() - day + 1 |
paul@120 | 812 | colspan = (event_length - 1) * 3 + 2 |
paul@120 | 813 | |
paul@120 | 814 | event_day_type = "event-day-multiple" |
paul@120 | 815 | |
paul@120 | 816 | # Events continuing from a previous week... |
paul@120 | 817 | |
paul@120 | 818 | elif start_of_period: |
paul@120 | 819 | |
paul@120 | 820 | # End of continuing event... |
paul@120 | 821 | |
paul@120 | 822 | if ends_today: |
paul@120 | 823 | colspan = 2 |
paul@120 | 824 | event_day_type = "event-day-ending" |
paul@120 | 825 | |
paul@120 | 826 | # Events continuing for at least one more day... |
paul@120 | 827 | |
paul@120 | 828 | else: |
paul@120 | 829 | |
paul@120 | 830 | # Calculate the span of this cell. |
paul@120 | 831 | # Events whose names appear on every day... |
paul@120 | 832 | |
paul@120 | 833 | if self.name_usage == "daily": |
paul@120 | 834 | colspan = 3 |
paul@120 | 835 | event_day_type = "event-day-full" |
paul@120 | 836 | |
paul@120 | 837 | # Events whose names appear once per week... |
paul@120 | 838 | |
paul@120 | 839 | else: |
paul@120 | 840 | if event_details["end"] <= week_end: |
paul@120 | 841 | event_length = event_details["end"].day() - day + 1 |
paul@120 | 842 | colspan = (event_length - 1) * 3 + 2 |
paul@120 | 843 | else: |
paul@120 | 844 | event_length = week_end.day() - day + 1 |
paul@120 | 845 | colspan = event_length * 3 |
paul@120 | 846 | |
paul@120 | 847 | event_day_type = "event-day-multiple" |
paul@120 | 848 | |
paul@120 | 849 | # Continuing events whose names appear on every day... |
paul@120 | 850 | |
paul@120 | 851 | elif self.name_usage == "daily": |
paul@120 | 852 | if ends_today: |
paul@120 | 853 | colspan = 2 |
paul@120 | 854 | event_day_type = "event-day-ending" |
paul@120 | 855 | else: |
paul@120 | 856 | colspan = 3 |
paul@120 | 857 | event_day_type = "event-day-full" |
paul@120 | 858 | |
paul@120 | 859 | # Continuing events whose names appear once per week... |
paul@120 | 860 | |
paul@120 | 861 | else: |
paul@120 | 862 | colspan = None |
paul@120 | 863 | |
paul@120 | 864 | # Output the main content only if it is not |
paul@120 | 865 | # continuing from a previous day. |
paul@120 | 866 | |
paul@120 | 867 | if colspan is not None: |
paul@120 | 868 | |
paul@120 | 869 | # Colour the cell for continuing events. |
paul@120 | 870 | |
paul@120 | 871 | attrs={ |
paul@120 | 872 | "class" : "event-day-content event-day-busy %s" % event_day_type, |
paul@120 | 873 | "colspan" : str(colspan) |
paul@120 | 874 | } |
paul@120 | 875 | |
paul@120 | 876 | if not (starts_today and ends_today): |
paul@120 | 877 | attrs["style"] = style |
paul@120 | 878 | |
paul@120 | 879 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@120 | 880 | |
paul@120 | 881 | # Output the event. |
paul@120 | 882 | |
paul@120 | 883 | if starts_today and ends_today or not hide_text: |
paul@126 | 884 | output.append(self.writeEventSummaryBox(event)) |
paul@120 | 885 | |
paul@126 | 886 | output.append(fmt.table_cell(on=0)) |
paul@120 | 887 | |
paul@120 | 888 | # Output end of day gap. |
paul@120 | 889 | |
paul@120 | 890 | if ends_today and not starts_today: |
paul@120 | 891 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap"})) |
paul@120 | 892 | output.append(fmt.table_cell(on=0)) |
paul@120 | 893 | |
paul@120 | 894 | # End of set. |
paul@120 | 895 | |
paul@120 | 896 | output.append(fmt.table_row(on=0)) |
paul@120 | 897 | return "".join(output) |
paul@120 | 898 | |
paul@123 | 899 | def writeWeekSpacer(self, first_day, number_of_days): |
paul@120 | 900 | page = self.page |
paul@120 | 901 | fmt = page.formatter |
paul@120 | 902 | |
paul@120 | 903 | output = [] |
paul@120 | 904 | output.append(fmt.table_row(on=1)) |
paul@120 | 905 | |
paul@120 | 906 | for weekday in range(0, 7): |
paul@120 | 907 | day = first_day + weekday |
paul@120 | 908 | css_classes = "event-day-spacer" |
paul@120 | 909 | |
paul@120 | 910 | # Skip out-of-month days. |
paul@120 | 911 | |
paul@120 | 912 | if day < 1 or day > number_of_days: |
paul@120 | 913 | css_classes += " event-day-excluded" |
paul@120 | 914 | |
paul@120 | 915 | output.append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"})) |
paul@120 | 916 | output.append(fmt.table_cell(on=0)) |
paul@120 | 917 | |
paul@120 | 918 | output.append(fmt.table_row(on=0)) |
paul@120 | 919 | return "".join(output) |
paul@120 | 920 | |
paul@122 | 921 | # Day layout methods. |
paul@122 | 922 | |
paul@187 | 923 | def writeDayTableHeading(self, date, colspan=1): |
paul@122 | 924 | page = self.page |
paul@122 | 925 | fmt = page.formatter |
paul@122 | 926 | |
paul@122 | 927 | output = [] |
paul@122 | 928 | output.append(fmt.table_row(on=1)) |
paul@122 | 929 | |
paul@146 | 930 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)})) |
paul@187 | 931 | output.append(self.writeDayHeading(date)) |
paul@122 | 932 | output.append(fmt.table_cell(on=0)) |
paul@122 | 933 | |
paul@122 | 934 | output.append(fmt.table_row(on=0)) |
paul@122 | 935 | return "".join(output) |
paul@122 | 936 | |
paul@123 | 937 | def writeEmptyDay(self, date): |
paul@123 | 938 | page = self.page |
paul@123 | 939 | fmt = page.formatter |
paul@123 | 940 | |
paul@123 | 941 | output = [] |
paul@123 | 942 | output.append(fmt.table_row(on=1)) |
paul@123 | 943 | |
paul@123 | 944 | output.append(fmt.table_cell(on=1, |
paul@123 | 945 | attrs={"class" : "event-day-content event-day-empty"})) |
paul@123 | 946 | |
paul@123 | 947 | output.append(fmt.table_row(on=0)) |
paul@123 | 948 | return "".join(output) |
paul@123 | 949 | |
paul@123 | 950 | def writeDaySlots(self, date, full_coverage, day_slots): |
paul@179 | 951 | |
paul@179 | 952 | """ |
paul@179 | 953 | Given a 'date', non-empty 'full_coverage' for the day concerned, and a |
paul@179 | 954 | non-empty mapping of 'day_slots' (from locations to event collections), |
paul@179 | 955 | output the day slots for the day. |
paul@179 | 956 | """ |
paul@179 | 957 | |
paul@123 | 958 | page = self.page |
paul@123 | 959 | fmt = page.formatter |
paul@123 | 960 | |
paul@123 | 961 | output = [] |
paul@123 | 962 | |
paul@123 | 963 | locations = day_slots.keys() |
paul@168 | 964 | locations.sort(sort_none_first) |
paul@123 | 965 | |
paul@123 | 966 | # Traverse the time scale of the full coverage, visiting each slot to |
paul@123 | 967 | # determine whether it provides content for each period. |
paul@123 | 968 | |
paul@168 | 969 | scale = getCoverageScale(full_coverage) |
paul@128 | 970 | |
paul@128 | 971 | # Define a mapping of events to rowspans. |
paul@128 | 972 | |
paul@128 | 973 | rowspans = {} |
paul@128 | 974 | |
paul@128 | 975 | # Populate each period with event details, recording how many periods |
paul@128 | 976 | # each event populates. |
paul@128 | 977 | |
paul@128 | 978 | day_rows = [] |
paul@123 | 979 | |
paul@123 | 980 | for period in scale: |
paul@126 | 981 | |
paul@126 | 982 | # Ignore timespans before this day. |
paul@126 | 983 | |
paul@128 | 984 | if period != date: |
paul@126 | 985 | continue |
paul@126 | 986 | |
paul@128 | 987 | # Visit each slot corresponding to a location (or no location). |
paul@128 | 988 | |
paul@128 | 989 | day_row = [] |
paul@128 | 990 | |
paul@128 | 991 | for location in locations: |
paul@128 | 992 | |
paul@128 | 993 | # Visit each coverage span, presenting the events in the span. |
paul@128 | 994 | |
paul@128 | 995 | for events in day_slots[location]: |
paul@128 | 996 | event = self.getActiveEvent(period, events) |
paul@128 | 997 | if event is not None: |
paul@128 | 998 | if not rowspans.has_key(event): |
paul@128 | 999 | rowspans[event] = 1 |
paul@128 | 1000 | else: |
paul@128 | 1001 | rowspans[event] += 1 |
paul@128 | 1002 | day_row.append((location, event)) |
paul@128 | 1003 | |
paul@128 | 1004 | day_rows.append((period, day_row)) |
paul@128 | 1005 | |
paul@179 | 1006 | # Output the locations. |
paul@179 | 1007 | |
paul@179 | 1008 | output.append(fmt.table_row(on=1)) |
paul@179 | 1009 | |
paul@179 | 1010 | # Add a spacer. |
paul@179 | 1011 | |
paul@179 | 1012 | output.append(self.writeDaySpacer(colspan=2, cls="location")) |
paul@179 | 1013 | |
paul@179 | 1014 | for location in locations: |
paul@179 | 1015 | |
paul@179 | 1016 | # Add spacers to the column spans. |
paul@179 | 1017 | |
paul@179 | 1018 | columns = len(day_slots[location]) * 2 - 1 |
paul@179 | 1019 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)})) |
paul@187 | 1020 | output.append(fmt.text(location or "")) |
paul@179 | 1021 | output.append(fmt.table_cell(on=0)) |
paul@179 | 1022 | |
paul@179 | 1023 | # Add a trailing spacer. |
paul@179 | 1024 | |
paul@179 | 1025 | output.append(self.writeDaySpacer(cls="location")) |
paul@179 | 1026 | |
paul@179 | 1027 | output.append(fmt.table_row(on=0)) |
paul@179 | 1028 | |
paul@128 | 1029 | # Output the periods with event details. |
paul@128 | 1030 | |
paul@128 | 1031 | period = None |
paul@128 | 1032 | events_written = set() |
paul@128 | 1033 | |
paul@128 | 1034 | for period, day_row in day_rows: |
paul@128 | 1035 | |
paul@126 | 1036 | # Write an empty heading for the start of the day where the first |
paul@126 | 1037 | # applicable timespan starts before this day. |
paul@123 | 1038 | |
paul@126 | 1039 | if period.start < date: |
paul@126 | 1040 | output.append(fmt.table_row(on=1)) |
paul@126 | 1041 | output.append(self.writeDayScaleHeading("")) |
paul@126 | 1042 | |
paul@126 | 1043 | # Otherwise, write a heading describing the time. |
paul@126 | 1044 | |
paul@126 | 1045 | else: |
paul@126 | 1046 | output.append(fmt.table_row(on=1)) |
paul@128 | 1047 | output.append(self.writeDayScaleHeading(period.start.time_string())) |
paul@123 | 1048 | |
paul@179 | 1049 | output.append(self.writeDaySpacer()) |
paul@179 | 1050 | |
paul@123 | 1051 | # Visit each slot corresponding to a location (or no location). |
paul@123 | 1052 | |
paul@128 | 1053 | for location, event in day_row: |
paul@123 | 1054 | |
paul@128 | 1055 | # Output each location slot's contribution. |
paul@123 | 1056 | |
paul@128 | 1057 | if event is None or event not in events_written: |
paul@128 | 1058 | output.append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event])) |
paul@128 | 1059 | if event is not None: |
paul@128 | 1060 | events_written.add(event) |
paul@123 | 1061 | |
paul@179 | 1062 | # Add a trailing spacer. |
paul@179 | 1063 | |
paul@179 | 1064 | output.append(self.writeDaySpacer()) |
paul@179 | 1065 | |
paul@123 | 1066 | output.append(fmt.table_row(on=0)) |
paul@123 | 1067 | |
paul@126 | 1068 | # Write a final time heading if the last period ends in the current day. |
paul@126 | 1069 | |
paul@126 | 1070 | if period is not None: |
paul@126 | 1071 | if period.end == date: |
paul@126 | 1072 | output.append(fmt.table_row(on=1)) |
paul@128 | 1073 | output.append(self.writeDayScaleHeading(period.end.time_string())) |
paul@126 | 1074 | |
paul@128 | 1075 | for slot in day_row: |
paul@128 | 1076 | output.append(self.writeDaySpacer()) |
paul@128 | 1077 | output.append(self.writeEmptyDaySlot()) |
paul@126 | 1078 | |
paul@126 | 1079 | output.append(fmt.table_row(on=0)) |
paul@126 | 1080 | |
paul@126 | 1081 | return "".join(output) |
paul@126 | 1082 | |
paul@126 | 1083 | def writeDayScaleHeading(self, heading): |
paul@126 | 1084 | page = self.page |
paul@126 | 1085 | fmt = page.formatter |
paul@126 | 1086 | |
paul@126 | 1087 | output = [] |
paul@126 | 1088 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"})) |
paul@126 | 1089 | output.append(fmt.text(heading)) |
paul@126 | 1090 | output.append(fmt.table_cell(on=0)) |
paul@126 | 1091 | |
paul@123 | 1092 | return "".join(output) |
paul@123 | 1093 | |
paul@128 | 1094 | def getActiveEvent(self, period, events): |
paul@128 | 1095 | for event in events: |
paul@128 | 1096 | if period not in event: |
paul@128 | 1097 | continue |
paul@128 | 1098 | return event |
paul@128 | 1099 | else: |
paul@128 | 1100 | return None |
paul@128 | 1101 | |
paul@128 | 1102 | def writeDaySlot(self, period, event, rowspan): |
paul@126 | 1103 | page = self.page |
paul@126 | 1104 | fmt = page.formatter |
paul@126 | 1105 | |
paul@126 | 1106 | output = [] |
paul@126 | 1107 | |
paul@128 | 1108 | if event is not None: |
paul@126 | 1109 | event_summary = event.getSummary(self.parent_name) |
paul@126 | 1110 | style = self.getEventStyle(event_summary) |
paul@126 | 1111 | |
paul@126 | 1112 | output.append(fmt.table_cell(on=1, attrs={ |
paul@126 | 1113 | "class" : "event-timespan-content event-timespan-busy", |
paul@128 | 1114 | "style" : style, |
paul@128 | 1115 | "rowspan" : str(rowspan) |
paul@128 | 1116 | })) |
paul@126 | 1117 | output.append(self.writeEventSummaryBox(event)) |
paul@126 | 1118 | output.append(fmt.table_cell(on=0)) |
paul@126 | 1119 | else: |
paul@126 | 1120 | output.append(self.writeEmptyDaySlot()) |
paul@126 | 1121 | |
paul@126 | 1122 | return "".join(output) |
paul@126 | 1123 | |
paul@126 | 1124 | def writeEmptyDaySlot(self): |
paul@126 | 1125 | page = self.page |
paul@126 | 1126 | fmt = page.formatter |
paul@126 | 1127 | |
paul@126 | 1128 | output = [] |
paul@126 | 1129 | |
paul@126 | 1130 | output.append(fmt.table_cell(on=1, |
paul@126 | 1131 | attrs={"class" : "event-timespan-content event-timespan-empty"})) |
paul@126 | 1132 | output.append(fmt.table_cell(on=0)) |
paul@126 | 1133 | |
paul@126 | 1134 | return "".join(output) |
paul@126 | 1135 | |
paul@179 | 1136 | def writeDaySpacer(self, colspan=1, cls="timespan"): |
paul@126 | 1137 | page = self.page |
paul@126 | 1138 | fmt = page.formatter |
paul@126 | 1139 | |
paul@126 | 1140 | output = [] |
paul@147 | 1141 | output.append(fmt.table_cell(on=1, attrs={ |
paul@179 | 1142 | "class" : "event-%s-spacer" % cls, |
paul@147 | 1143 | "colspan" : str(colspan)})) |
paul@126 | 1144 | output.append(fmt.table_cell(on=0)) |
paul@126 | 1145 | return "".join(output) |
paul@123 | 1146 | |
paul@187 | 1147 | # Map layout methods. |
paul@187 | 1148 | |
paul@187 | 1149 | def writeMapTableHeading(self): |
paul@187 | 1150 | page = self.page |
paul@187 | 1151 | fmt = page.formatter |
paul@187 | 1152 | |
paul@187 | 1153 | output = [] |
paul@187 | 1154 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"})) |
paul@187 | 1155 | output.append(self.writeMapHeading()) |
paul@187 | 1156 | output.append(fmt.table_cell(on=0)) |
paul@187 | 1157 | |
paul@187 | 1158 | return "".join(output) |
paul@187 | 1159 | |
paul@183 | 1160 | def showDictError(self, text, pagename): |
paul@183 | 1161 | page = self.page |
paul@183 | 1162 | fmt = page.formatter |
paul@183 | 1163 | request = page.request |
paul@183 | 1164 | |
paul@183 | 1165 | output = [] |
paul@183 | 1166 | |
paul@183 | 1167 | output.append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"})) |
paul@183 | 1168 | output.append(fmt.paragraph(on=1)) |
paul@183 | 1169 | output.append(fmt.text(text)) |
paul@183 | 1170 | output.append(fmt.paragraph(on=0)) |
paul@183 | 1171 | output.append(fmt.paragraph(on=1)) |
paul@183 | 1172 | output.append(linkToPage(request, Page(request, pagename), pagename)) |
paul@183 | 1173 | output.append(fmt.paragraph(on=0)) |
paul@183 | 1174 | |
paul@183 | 1175 | return "".join(output) |
paul@183 | 1176 | |
paul@193 | 1177 | def writeMapEventSummaries(self, events): |
paul@193 | 1178 | page = self.page |
paul@193 | 1179 | fmt = page.formatter |
paul@193 | 1180 | request = page.request |
paul@193 | 1181 | |
paul@194 | 1182 | # Sort the events by date. |
paul@194 | 1183 | |
paul@195 | 1184 | events.sort(sort_start_first) |
paul@194 | 1185 | |
paul@194 | 1186 | # Write out a self-contained list of events. |
paul@194 | 1187 | |
paul@193 | 1188 | output = [] |
paul@194 | 1189 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"})) |
paul@193 | 1190 | |
paul@193 | 1191 | for event in events: |
paul@193 | 1192 | |
paul@193 | 1193 | # Get the event details. |
paul@193 | 1194 | |
paul@193 | 1195 | event_page = event.getPage() |
paul@193 | 1196 | event_summary = event.getSummary(self.parent_name) |
paul@193 | 1197 | start, end = event.as_limits() |
paul@193 | 1198 | event_period = self._getCalendarPeriod( |
paul@193 | 1199 | start and self.getFullDateLabel(start), |
paul@193 | 1200 | end and self.getFullDateLabel(end), |
paul@193 | 1201 | "") |
paul@193 | 1202 | |
paul@193 | 1203 | output.append(fmt.listitem(on=1)) |
paul@193 | 1204 | |
paul@193 | 1205 | # Link to the page using the summary. |
paul@193 | 1206 | |
paul@193 | 1207 | output.append(event_page.linkToPage(request, event_summary)) |
paul@193 | 1208 | |
paul@193 | 1209 | # Add the event period. |
paul@193 | 1210 | |
paul@193 | 1211 | output.append(fmt.text(" ")) |
paul@193 | 1212 | output.append(fmt.span(on=1, css_class="event-map-period")) |
paul@193 | 1213 | output.append(fmt.text(event_period)) |
paul@193 | 1214 | output.append(fmt.span(on=0)) |
paul@193 | 1215 | |
paul@193 | 1216 | output.append(fmt.listitem(on=0)) |
paul@193 | 1217 | |
paul@193 | 1218 | output.append(fmt.bullet_list(on=0)) |
paul@193 | 1219 | |
paul@193 | 1220 | return "".join(output) |
paul@193 | 1221 | |
paul@10 | 1222 | # HTML-related functions. |
paul@2 | 1223 | |
paul@2 | 1224 | def getColour(s): |
paul@2 | 1225 | colour = [0, 0, 0] |
paul@2 | 1226 | digit = 0 |
paul@2 | 1227 | for c in s: |
paul@2 | 1228 | colour[digit] += ord(c) |
paul@2 | 1229 | colour[digit] = colour[digit] % 256 |
paul@2 | 1230 | digit += 1 |
paul@2 | 1231 | digit = digit % 3 |
paul@2 | 1232 | return tuple(colour) |
paul@2 | 1233 | |
paul@2 | 1234 | def getBlackOrWhite(colour): |
paul@2 | 1235 | if sum(colour) / 3.0 > 127: |
paul@2 | 1236 | return (0, 0, 0) |
paul@2 | 1237 | else: |
paul@2 | 1238 | return (255, 255, 255) |
paul@2 | 1239 | |
paul@11 | 1240 | # Macro functions. |
paul@11 | 1241 | |
paul@0 | 1242 | def execute(macro, args): |
paul@0 | 1243 | |
paul@0 | 1244 | """ |
paul@0 | 1245 | Execute the 'macro' with the given 'args': an optional list of selected |
paul@0 | 1246 | category names (categories whose pages are to be shown), together with |
paul@5 | 1247 | optional named arguments of the following forms: |
paul@5 | 1248 | |
paul@5 | 1249 | start=YYYY-MM shows event details starting from the specified month |
paul@122 | 1250 | start=YYYY-MM-DD shows event details starting from the specified day |
paul@13 | 1251 | start=current-N shows event details relative to the current month |
paul@122 | 1252 | (or relative to the current day in "day" mode) |
paul@5 | 1253 | end=YYYY-MM shows event details ending at the specified month |
paul@122 | 1254 | end=YYYY-MM-DD shows event details ending on the specified day |
paul@13 | 1255 | end=current+N shows event details relative to the current month |
paul@122 | 1256 | (or relative to the current day in "day" mode) |
paul@5 | 1257 | |
paul@5 | 1258 | mode=calendar shows a calendar view of events |
paul@122 | 1259 | mode=day shows a calendar day view of events |
paul@5 | 1260 | mode=list shows a list of events by month |
paul@121 | 1261 | mode=table shows a table of events |
paul@183 | 1262 | mode=map shows a map of events |
paul@11 | 1263 | |
paul@11 | 1264 | calendar=NAME uses the given NAME to provide request parameters which |
paul@11 | 1265 | can be used to control the calendar view |
paul@55 | 1266 | |
paul@55 | 1267 | template=PAGE uses the given PAGE as the default template for new |
paul@55 | 1268 | events (or the default template from the configuration |
paul@55 | 1269 | if not specified) |
paul@55 | 1270 | |
paul@55 | 1271 | parent=PAGE uses the given PAGE as the parent of any new event page |
paul@183 | 1272 | |
paul@183 | 1273 | Calendar view options: |
paul@183 | 1274 | |
paul@183 | 1275 | names=daily shows the name of an event on every day of that event |
paul@183 | 1276 | names=weekly shows the name of an event once per week |
paul@183 | 1277 | |
paul@183 | 1278 | Map view options: |
paul@183 | 1279 | |
paul@183 | 1280 | map=NAME uses the given NAME as the map image, where an entry for |
paul@183 | 1281 | the map must be found in the EventMaps page (or another |
paul@183 | 1282 | page specified in the configuration by the |
paul@183 | 1283 | 'event_aggregator_maps_page' setting) along with an |
paul@183 | 1284 | attached map image |
paul@0 | 1285 | """ |
paul@0 | 1286 | |
paul@0 | 1287 | request = macro.request |
paul@0 | 1288 | fmt = macro.formatter |
paul@0 | 1289 | page = fmt.page |
paul@0 | 1290 | _ = request.getText |
paul@0 | 1291 | |
paul@180 | 1292 | parser_cls = getParserClass(request, page.pi["format"]) |
paul@180 | 1293 | |
paul@0 | 1294 | # Interpret the arguments. |
paul@0 | 1295 | |
paul@0 | 1296 | try: |
paul@0 | 1297 | parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] |
paul@0 | 1298 | except AttributeError: |
paul@0 | 1299 | parsed_args = args.split(",") |
paul@0 | 1300 | |
paul@0 | 1301 | parsed_args = [arg for arg in parsed_args if arg] |
paul@0 | 1302 | |
paul@0 | 1303 | # Get special arguments. |
paul@0 | 1304 | |
paul@0 | 1305 | category_names = [] |
paul@76 | 1306 | raw_calendar_start = None |
paul@76 | 1307 | raw_calendar_end = None |
paul@0 | 1308 | calendar_start = None |
paul@0 | 1309 | calendar_end = None |
paul@57 | 1310 | mode = None |
paul@35 | 1311 | name_usage = "weekly" |
paul@11 | 1312 | calendar_name = None |
paul@55 | 1313 | template_name = getattr(request.cfg, "event_aggregator_new_event_template", "EventTemplate") |
paul@55 | 1314 | parent_name = None |
paul@183 | 1315 | map_name = None |
paul@0 | 1316 | |
paul@0 | 1317 | for arg in parsed_args: |
paul@0 | 1318 | if arg.startswith("start="): |
paul@76 | 1319 | raw_calendar_start = arg[6:] |
paul@11 | 1320 | |
paul@0 | 1321 | elif arg.startswith("end="): |
paul@76 | 1322 | raw_calendar_end = arg[4:] |
paul@11 | 1323 | |
paul@0 | 1324 | elif arg.startswith("mode="): |
paul@0 | 1325 | mode = arg[5:] |
paul@11 | 1326 | |
paul@5 | 1327 | elif arg.startswith("names="): |
paul@5 | 1328 | name_usage = arg[6:] |
paul@11 | 1329 | |
paul@11 | 1330 | elif arg.startswith("calendar="): |
paul@11 | 1331 | calendar_name = arg[9:] |
paul@11 | 1332 | |
paul@55 | 1333 | elif arg.startswith("template="): |
paul@55 | 1334 | template_name = arg[9:] |
paul@55 | 1335 | |
paul@55 | 1336 | elif arg.startswith("parent="): |
paul@55 | 1337 | parent_name = arg[7:] |
paul@55 | 1338 | |
paul@183 | 1339 | elif arg.startswith("map="): |
paul@183 | 1340 | map_name = arg[4:] |
paul@183 | 1341 | |
paul@0 | 1342 | else: |
paul@0 | 1343 | category_names.append(arg) |
paul@0 | 1344 | |
paul@11 | 1345 | # Find request parameters to override settings. |
paul@11 | 1346 | |
paul@168 | 1347 | mode = getQualifiedParameter(request, calendar_name, "mode", mode or "calendar") |
paul@55 | 1348 | |
paul@187 | 1349 | # Different modes require different levels of precision by default. |
paul@126 | 1350 | |
paul@187 | 1351 | resolution = getQualifiedParameter(request, calendar_name, "resolution", mode == "day" and "date" or "month") |
paul@187 | 1352 | resolution = mode == "calendar" and "month" or resolution |
paul@187 | 1353 | |
paul@187 | 1354 | if resolution == "date": |
paul@168 | 1355 | get_date = getParameterDate |
paul@168 | 1356 | get_form_date = getFormDate |
paul@122 | 1357 | else: |
paul@168 | 1358 | get_date = getParameterMonth |
paul@168 | 1359 | get_form_date = getFormMonth |
paul@122 | 1360 | |
paul@122 | 1361 | # Determine the limits of the calendar. |
paul@122 | 1362 | |
paul@128 | 1363 | original_calendar_start = calendar_start = get_date(raw_calendar_start) |
paul@128 | 1364 | original_calendar_end = calendar_end = get_date(raw_calendar_end) |
paul@122 | 1365 | |
paul@134 | 1366 | calendar_start = get_form_date(request, calendar_name, "start") or calendar_start |
paul@134 | 1367 | calendar_end = get_form_date(request, calendar_name, "end") or calendar_end |
paul@122 | 1368 | |
paul@122 | 1369 | # Get the events according to the resolution of the calendar. |
paul@11 | 1370 | |
paul@168 | 1371 | event_pages = getPagesFromResults(getAllCategoryPages(category_names, request), request) |
paul@168 | 1372 | events = getEventsFromPages(event_pages) |
paul@171 | 1373 | all_shown_events = getEventsInPeriod(events, getCalendarPeriod(calendar_start, calendar_end)) |
paul@171 | 1374 | earliest, latest = getEventLimits(all_shown_events) |
paul@2 | 1375 | |
paul@13 | 1376 | # Get a concrete period of time. |
paul@13 | 1377 | |
paul@187 | 1378 | first, last = getConcretePeriod(calendar_start, calendar_end, earliest, latest, resolution) |
paul@13 | 1379 | |
paul@37 | 1380 | # Define a view of the calendar, retaining useful navigational information. |
paul@13 | 1381 | |
paul@150 | 1382 | view = View(page, calendar_name, raw_calendar_start, raw_calendar_end, |
paul@150 | 1383 | original_calendar_start, original_calendar_end, calendar_start, calendar_end, |
paul@187 | 1384 | first, last, category_names, template_name, parent_name, mode, resolution, |
paul@187 | 1385 | name_usage, map_name) |
paul@13 | 1386 | |
paul@0 | 1387 | # Make a calendar. |
paul@0 | 1388 | |
paul@0 | 1389 | output = [] |
paul@0 | 1390 | |
paul@167 | 1391 | output.append(fmt.div(on=1, css_class="event-calendar")) |
paul@167 | 1392 | |
paul@26 | 1393 | # Output download controls. |
paul@26 | 1394 | |
paul@26 | 1395 | output.append(fmt.div(on=1, css_class="event-controls")) |
paul@57 | 1396 | output.append(view.writeDownloadControls()) |
paul@26 | 1397 | output.append(fmt.div(on=0)) |
paul@26 | 1398 | |
paul@61 | 1399 | # Output a table. |
paul@51 | 1400 | |
paul@61 | 1401 | if mode == "table": |
paul@0 | 1402 | |
paul@61 | 1403 | # Start of table view output. |
paul@51 | 1404 | |
paul@51 | 1405 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-table"})) |
paul@51 | 1406 | |
paul@51 | 1407 | output.append(fmt.table_row(on=1)) |
paul@51 | 1408 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@51 | 1409 | output.append(fmt.text(_("Event dates"))) |
paul@51 | 1410 | output.append(fmt.table_cell(on=0)) |
paul@51 | 1411 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@51 | 1412 | output.append(fmt.text(_("Event location"))) |
paul@51 | 1413 | output.append(fmt.table_cell(on=0)) |
paul@51 | 1414 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@51 | 1415 | output.append(fmt.text(_("Event details"))) |
paul@51 | 1416 | output.append(fmt.table_cell(on=0)) |
paul@51 | 1417 | output.append(fmt.table_row(on=0)) |
paul@51 | 1418 | |
paul@61 | 1419 | # Show the events in order. |
paul@2 | 1420 | |
paul@171 | 1421 | for event in all_shown_events: |
paul@69 | 1422 | event_page = event.getPage() |
paul@69 | 1423 | event_summary = event.getSummary(parent_name) |
paul@69 | 1424 | event_details = event.getDetails() |
paul@0 | 1425 | |
paul@61 | 1426 | # Prepare CSS classes with category-related styling. |
paul@11 | 1427 | |
paul@61 | 1428 | css_classes = ["event-table-details"] |
paul@61 | 1429 | |
paul@61 | 1430 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@11 | 1431 | |
paul@61 | 1432 | # Filter the category text to avoid illegal characters. |
paul@11 | 1433 | |
paul@61 | 1434 | css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic))) |
paul@0 | 1435 | |
paul@61 | 1436 | attrs = {"class" : " ".join(css_classes)} |
paul@0 | 1437 | |
paul@2 | 1438 | output.append(fmt.table_row(on=1)) |
paul@0 | 1439 | |
paul@61 | 1440 | # Start and end dates. |
paul@61 | 1441 | |
paul@61 | 1442 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@61 | 1443 | output.append(fmt.span(on=1)) |
paul@67 | 1444 | output.append(fmt.text(str(event_details["start"]))) |
paul@61 | 1445 | output.append(fmt.span(on=0)) |
paul@61 | 1446 | |
paul@61 | 1447 | if event_details["start"] != event_details["end"]: |
paul@61 | 1448 | output.append(fmt.text(" - ")) |
paul@61 | 1449 | output.append(fmt.span(on=1)) |
paul@67 | 1450 | output.append(fmt.text(str(event_details["end"]))) |
paul@61 | 1451 | output.append(fmt.span(on=0)) |
paul@61 | 1452 | |
paul@61 | 1453 | output.append(fmt.table_cell(on=0)) |
paul@61 | 1454 | |
paul@61 | 1455 | # Location. |
paul@61 | 1456 | |
paul@61 | 1457 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@61 | 1458 | |
paul@61 | 1459 | if event_details.has_key("location"): |
paul@180 | 1460 | output.append(formatText(event_details["location"], request, fmt, parser_cls)) |
paul@61 | 1461 | |
paul@61 | 1462 | output.append(fmt.table_cell(on=0)) |
paul@61 | 1463 | |
paul@61 | 1464 | # Link to the page using the summary. |
paul@61 | 1465 | |
paul@61 | 1466 | output.append(fmt.table_cell(on=1, attrs=attrs)) |
paul@67 | 1467 | output.append(event_page.linkToPage(request, event_summary)) |
paul@61 | 1468 | output.append(fmt.table_cell(on=0)) |
paul@2 | 1469 | |
paul@2 | 1470 | output.append(fmt.table_row(on=0)) |
paul@2 | 1471 | |
paul@61 | 1472 | # End of table view output. |
paul@61 | 1473 | |
paul@61 | 1474 | output.append(fmt.table(on=0)) |
paul@2 | 1475 | |
paul@183 | 1476 | # Output a map view. |
paul@183 | 1477 | |
paul@183 | 1478 | elif mode == "map": |
paul@183 | 1479 | |
paul@183 | 1480 | # Special dictionary pages. |
paul@183 | 1481 | |
paul@183 | 1482 | maps_page = getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict") |
paul@183 | 1483 | locations_page = getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict") |
paul@183 | 1484 | |
paul@183 | 1485 | map_image = None |
paul@183 | 1486 | |
paul@183 | 1487 | # Get the maps and locations. |
paul@183 | 1488 | |
paul@183 | 1489 | if request.user.may.read(maps_page): |
paul@183 | 1490 | maps = request.dicts.dict(maps_page) |
paul@183 | 1491 | else: |
paul@183 | 1492 | maps = None |
paul@183 | 1493 | |
paul@183 | 1494 | if request.user.may.read(locations_page): |
paul@183 | 1495 | locations = request.dicts.dict(locations_page) |
paul@183 | 1496 | else: |
paul@183 | 1497 | locations = None |
paul@183 | 1498 | |
paul@183 | 1499 | # Get the map image definition. |
paul@183 | 1500 | |
paul@183 | 1501 | if maps is not None and map_name is not None: |
paul@183 | 1502 | try: |
paul@184 | 1503 | map_details = maps[map_name].split() |
paul@184 | 1504 | |
paul@184 | 1505 | map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \ |
paul@184 | 1506 | map(getMapReference, map_details[:4]) |
paul@184 | 1507 | map_width, map_height = map(int, map_details[4:6]) |
paul@184 | 1508 | map_image = map_details[6] |
paul@184 | 1509 | |
paul@184 | 1510 | map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees() |
paul@184 | 1511 | map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees() |
paul@184 | 1512 | |
paul@183 | 1513 | except (KeyError, ValueError): |
paul@183 | 1514 | pass |
paul@183 | 1515 | |
paul@183 | 1516 | # Report errors. |
paul@183 | 1517 | |
paul@183 | 1518 | if maps is None: |
paul@183 | 1519 | output.append(view.showDictError( |
paul@183 | 1520 | _("You do not have read access to the maps page:"), |
paul@183 | 1521 | maps_page)) |
paul@183 | 1522 | |
paul@183 | 1523 | elif map_name is None: |
paul@183 | 1524 | output.append(view.showDictError( |
paul@183 | 1525 | _("Please specify a valid map name corresponding to an entry on the following page:"), |
paul@183 | 1526 | maps_page)) |
paul@183 | 1527 | |
paul@183 | 1528 | elif map_image is None: |
paul@183 | 1529 | output.append(view.showDictError( |
paul@183 | 1530 | _("Please specify a valid entry for %s on the following page:") % map_name, |
paul@183 | 1531 | maps_page)) |
paul@183 | 1532 | |
paul@183 | 1533 | elif locations is None: |
paul@183 | 1534 | output.append(view.showDictError( |
paul@183 | 1535 | _("You do not have read access to the locations page:"), |
paul@183 | 1536 | locations_page)) |
paul@183 | 1537 | |
paul@184 | 1538 | # Attempt to show the map. |
paul@183 | 1539 | |
paul@183 | 1540 | else: |
paul@183 | 1541 | |
paul@184 | 1542 | # Get events by position. |
paul@184 | 1543 | |
paul@184 | 1544 | events_by_location = {} |
paul@184 | 1545 | |
paul@184 | 1546 | for event in all_shown_events: |
paul@184 | 1547 | event_details = event.getDetails() |
paul@184 | 1548 | |
paul@184 | 1549 | location = event_details.get("location") |
paul@189 | 1550 | |
paul@189 | 1551 | # Use a normalised location if possible. |
paul@189 | 1552 | |
paul@189 | 1553 | location = location and getNormalisedLocation(location) or location |
paul@189 | 1554 | |
paul@184 | 1555 | if not events_by_location.has_key(location): |
paul@184 | 1556 | events_by_location[location] = [] |
paul@184 | 1557 | events_by_location[location].append(event) |
paul@184 | 1558 | |
paul@183 | 1559 | # Get the map image URL. |
paul@183 | 1560 | |
paul@183 | 1561 | map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request) |
paul@183 | 1562 | |
paul@183 | 1563 | # Start of map view output. |
paul@183 | 1564 | |
paul@183 | 1565 | output.append(fmt.div(on=1, css_class="event-map")) |
paul@183 | 1566 | |
paul@187 | 1567 | output.append(fmt.table(on=1)) |
paul@187 | 1568 | |
paul@187 | 1569 | output.append(fmt.table_row(on=1)) |
paul@187 | 1570 | output.append(view.writeMapTableHeading()) |
paul@187 | 1571 | output.append(fmt.table_row(on=0)) |
paul@187 | 1572 | |
paul@187 | 1573 | output.append(fmt.table_row(on=1)) |
paul@187 | 1574 | output.append(fmt.table_cell(on=1)) |
paul@187 | 1575 | |
paul@188 | 1576 | output.append(fmt.div(on=1, css_class="event-map-container")) |
paul@188 | 1577 | output.append(fmt.image(map_image_url)) |
paul@188 | 1578 | output.append(fmt.number_list(on=1)) |
paul@183 | 1579 | |
paul@194 | 1580 | unpositioned_events = [] |
paul@194 | 1581 | event_locations = events_by_location.keys() |
paul@194 | 1582 | event_locations.sort() |
paul@194 | 1583 | |
paul@184 | 1584 | # Show the events in the map. |
paul@184 | 1585 | |
paul@194 | 1586 | for location in event_locations: |
paul@194 | 1587 | events = events_by_location[location] |
paul@184 | 1588 | |
paul@184 | 1589 | # Look up the position of a location using the locations page. |
paul@184 | 1590 | |
paul@184 | 1591 | latitude, longitude = None, None |
paul@184 | 1592 | |
paul@184 | 1593 | if location is not None: |
paul@184 | 1594 | try: |
paul@184 | 1595 | latitude, longitude = map(getMapReference, locations[location].split()) |
paul@184 | 1596 | except (KeyError, ValueError): |
paul@184 | 1597 | pass |
paul@184 | 1598 | |
paul@185 | 1599 | # Skip unpositioned locations and locations outside the map. |
paul@184 | 1600 | |
paul@185 | 1601 | if latitude is None or longitude is None or \ |
paul@185 | 1602 | latitude < map_bottom_left_latitude or \ |
paul@185 | 1603 | longitude < map_bottom_left_longitude or \ |
paul@185 | 1604 | latitude > map_top_right_latitude or \ |
paul@185 | 1605 | longitude > map_top_right_longitude: |
paul@194 | 1606 | |
paul@194 | 1607 | unpositioned_events += events |
paul@184 | 1608 | continue |
paul@184 | 1609 | |
paul@184 | 1610 | # Get the position and dimensions of the map marker. |
paul@184 | 1611 | # NOTE: Use one degree as the marker size. |
paul@184 | 1612 | |
paul@184 | 1613 | marker_x, marker_y = getPositionForCentrePoint( |
paul@188 | 1614 | getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude, |
paul@184 | 1615 | map_x_scale, map_y_scale), |
paul@184 | 1616 | map_x_scale, map_y_scale) |
paul@184 | 1617 | |
paul@184 | 1618 | # Put a marker on the map. |
paul@184 | 1619 | |
paul@188 | 1620 | output.append(fmt.listitem(on=1, css_class="event-map-label")) |
paul@188 | 1621 | |
paul@188 | 1622 | # Have a positioned marker for the print mode. |
paul@188 | 1623 | |
paul@188 | 1624 | output.append(fmt.div(on=1, css_class="event-map-label-only", |
paul@188 | 1625 | style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( |
paul@188 | 1626 | marker_x, marker_y, map_x_scale, map_y_scale)) |
paul@188 | 1627 | output.append(fmt.div(on=0)) |
paul@188 | 1628 | |
paul@188 | 1629 | # Have a marker containing a pop-up when using the screen mode, |
paul@188 | 1630 | # providing a normal block when using the print mode. |
paul@188 | 1631 | |
paul@184 | 1632 | output.append(fmt.div(on=1, css_class="event-map-label", |
paul@188 | 1633 | style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( |
paul@184 | 1634 | marker_x, marker_y, map_x_scale, map_y_scale)) |
paul@184 | 1635 | output.append(fmt.div(on=1, css_class="event-map-details")) |
paul@184 | 1636 | output.append(fmt.div(on=1, css_class="event-map-shadow")) |
paul@194 | 1637 | output.append(fmt.div(on=1, css_class="event-map-location")) |
paul@184 | 1638 | |
paul@200 | 1639 | output.append(fmt.heading(on=1, depth=2)) |
paul@184 | 1640 | output.append(fmt.text(location)) |
paul@200 | 1641 | output.append(fmt.heading(on=0, depth=2)) |
paul@184 | 1642 | |
paul@193 | 1643 | output.append(view.writeMapEventSummaries(events)) |
paul@184 | 1644 | |
paul@184 | 1645 | output.append(fmt.div(on=0)) |
paul@184 | 1646 | output.append(fmt.div(on=0)) |
paul@184 | 1647 | output.append(fmt.div(on=0)) |
paul@184 | 1648 | output.append(fmt.div(on=0)) |
paul@188 | 1649 | output.append(fmt.listitem(on=0)) |
paul@184 | 1650 | |
paul@200 | 1651 | output.append(fmt.number_list(on=0)) |
paul@200 | 1652 | output.append(fmt.div(on=0)) |
paul@200 | 1653 | output.append(fmt.table_cell(on=0)) |
paul@200 | 1654 | output.append(fmt.table_row(on=0)) |
paul@200 | 1655 | |
paul@194 | 1656 | # Write unpositioned events. |
paul@194 | 1657 | |
paul@200 | 1658 | output.append(fmt.table_row(on=1, css_class="event-map-unpositioned")) |
paul@200 | 1659 | output.append(fmt.table_cell(on=1)) |
paul@200 | 1660 | |
paul@200 | 1661 | output.append(fmt.heading(on=1, depth=2)) |
paul@194 | 1662 | output.append(fmt.text(_("Events not shown on the map"))) |
paul@200 | 1663 | output.append(fmt.heading(on=0, depth=2)) |
paul@194 | 1664 | |
paul@194 | 1665 | output.append(view.writeMapEventSummaries(unpositioned_events)) |
paul@194 | 1666 | |
paul@183 | 1667 | # End of map view output. |
paul@183 | 1668 | |
paul@187 | 1669 | output.append(fmt.table_cell(on=0)) |
paul@187 | 1670 | output.append(fmt.table_row(on=0)) |
paul@187 | 1671 | output.append(fmt.table(on=0)) |
paul@183 | 1672 | output.append(fmt.div(on=0)) |
paul@183 | 1673 | |
paul@187 | 1674 | # Output a list. |
paul@61 | 1675 | |
paul@187 | 1676 | elif mode == "list": |
paul@61 | 1677 | |
paul@61 | 1678 | # Start of list view output. |
paul@2 | 1679 | |
paul@187 | 1680 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"})) |
paul@187 | 1681 | |
paul@187 | 1682 | # Output a list. |
paul@187 | 1683 | |
paul@187 | 1684 | for period in first.until(last): |
paul@187 | 1685 | |
paul@187 | 1686 | output.append(fmt.listitem(on=1, attr={"class" : "event-listings-period"})) |
paul@187 | 1687 | output.append(fmt.div(on=1, attr={"class" : "event-listings-heading"})) |
paul@187 | 1688 | |
paul@187 | 1689 | # Either write a date heading or produce links for navigable |
paul@187 | 1690 | # calendars. |
paul@187 | 1691 | |
paul@187 | 1692 | output.append(view.writeDateHeading(period)) |
paul@187 | 1693 | |
paul@187 | 1694 | output.append(fmt.div(on=0)) |
paul@187 | 1695 | |
paul@187 | 1696 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"})) |
paul@187 | 1697 | |
paul@187 | 1698 | # Show the events in order. |
paul@187 | 1699 | |
paul@187 | 1700 | for event in getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period)): |
paul@187 | 1701 | event_page = event.getPage() |
paul@187 | 1702 | event_details = event.getDetails() |
paul@187 | 1703 | event_summary = event.getSummary(parent_name) |
paul@187 | 1704 | |
paul@187 | 1705 | output.append(fmt.listitem(on=1, attr={"class" : "event-listing"})) |
paul@187 | 1706 | |
paul@187 | 1707 | # Link to the page using the summary. |
paul@187 | 1708 | |
paul@187 | 1709 | output.append(fmt.paragraph(on=1)) |
paul@187 | 1710 | output.append(event_page.linkToPage(request, event_summary)) |
paul@187 | 1711 | output.append(fmt.paragraph(on=0)) |
paul@187 | 1712 | |
paul@187 | 1713 | # Start and end dates. |
paul@187 | 1714 | |
paul@187 | 1715 | output.append(fmt.paragraph(on=1)) |
paul@187 | 1716 | output.append(fmt.span(on=1)) |
paul@187 | 1717 | output.append(fmt.text(str(event_details["start"]))) |
paul@187 | 1718 | output.append(fmt.span(on=0)) |
paul@187 | 1719 | output.append(fmt.text(" - ")) |
paul@187 | 1720 | output.append(fmt.span(on=1)) |
paul@187 | 1721 | output.append(fmt.text(str(event_details["end"]))) |
paul@187 | 1722 | output.append(fmt.span(on=0)) |
paul@187 | 1723 | output.append(fmt.paragraph(on=0)) |
paul@187 | 1724 | |
paul@187 | 1725 | # Location. |
paul@187 | 1726 | |
paul@187 | 1727 | if event_details.has_key("location"): |
paul@187 | 1728 | output.append(fmt.paragraph(on=1)) |
paul@187 | 1729 | output.append(formatText(event_details["location"], request, fmt, parser_cls)) |
paul@187 | 1730 | output.append(fmt.paragraph(on=1)) |
paul@187 | 1731 | |
paul@187 | 1732 | # Topics. |
paul@187 | 1733 | |
paul@187 | 1734 | if event_details.has_key("topics") or event_details.has_key("categories"): |
paul@187 | 1735 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-topics"})) |
paul@187 | 1736 | |
paul@187 | 1737 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@187 | 1738 | output.append(fmt.listitem(on=1)) |
paul@187 | 1739 | output.append(formatText(topic, request, fmt, parser_cls)) |
paul@187 | 1740 | output.append(fmt.listitem(on=0)) |
paul@187 | 1741 | |
paul@187 | 1742 | output.append(fmt.bullet_list(on=0)) |
paul@187 | 1743 | |
paul@187 | 1744 | output.append(fmt.listitem(on=0)) |
paul@187 | 1745 | |
paul@187 | 1746 | output.append(fmt.bullet_list(on=0)) |
paul@187 | 1747 | |
paul@187 | 1748 | # End of list view output. |
paul@187 | 1749 | |
paul@187 | 1750 | output.append(fmt.bullet_list(on=0)) |
paul@187 | 1751 | |
paul@187 | 1752 | # Output a month calendar. This shows month-by-month data. |
paul@187 | 1753 | |
paul@187 | 1754 | elif mode == "calendar": |
paul@61 | 1755 | |
paul@61 | 1756 | # Visit all months in the requested range, or across known events. |
paul@61 | 1757 | |
paul@67 | 1758 | for month in first.months_until(last): |
paul@2 | 1759 | |
paul@187 | 1760 | # Output a month. |
paul@61 | 1761 | |
paul@187 | 1762 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"})) |
paul@0 | 1763 | |
paul@187 | 1764 | # Either write a month heading or produce links for navigable |
paul@187 | 1765 | # calendars. |
paul@61 | 1766 | |
paul@187 | 1767 | output.append(view.writeMonthTableHeading(month)) |
paul@61 | 1768 | |
paul@187 | 1769 | # Weekday headings. |
paul@5 | 1770 | |
paul@187 | 1771 | output.append(view.writeWeekdayHeadings()) |
paul@61 | 1772 | |
paul@187 | 1773 | # Process the days of the month. |
paul@61 | 1774 | |
paul@187 | 1775 | start_weekday, number_of_days = month.month_properties() |
paul@61 | 1776 | |
paul@187 | 1777 | # The start weekday is the weekday of day number 1. |
paul@187 | 1778 | # Find the first day of the week, counting from below zero, if |
paul@187 | 1779 | # necessary, in order to land on the first day of the month as |
paul@187 | 1780 | # day number 1. |
paul@25 | 1781 | |
paul@187 | 1782 | first_day = 1 - start_weekday |
paul@0 | 1783 | |
paul@187 | 1784 | while first_day <= number_of_days: |
paul@0 | 1785 | |
paul@187 | 1786 | # Find events in this week and determine how to mark them on the |
paul@187 | 1787 | # calendar. |
paul@25 | 1788 | |
paul@187 | 1789 | week_start = month.as_date(max(first_day, 1)) |
paul@187 | 1790 | week_end = month.as_date(min(first_day + 6, number_of_days)) |
paul@51 | 1791 | |
paul@187 | 1792 | full_coverage, week_slots = getCoverage( |
paul@187 | 1793 | getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end))) |
paul@51 | 1794 | |
paul@187 | 1795 | # Output a week, starting with the day numbers. |
paul@51 | 1796 | |
paul@187 | 1797 | output.append(view.writeDayNumbers(first_day, number_of_days, month, full_coverage)) |
paul@51 | 1798 | |
paul@187 | 1799 | # Either generate empty days... |
paul@51 | 1800 | |
paul@187 | 1801 | if not week_slots: |
paul@187 | 1802 | output.append(view.writeEmptyWeek(first_day, number_of_days)) |
paul@51 | 1803 | |
paul@187 | 1804 | # Or generate each set of scheduled events... |
paul@51 | 1805 | |
paul@187 | 1806 | else: |
paul@187 | 1807 | output.append(view.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots)) |
paul@51 | 1808 | |
paul@187 | 1809 | # Process the next week... |
paul@51 | 1810 | |
paul@187 | 1811 | first_day += 7 |
paul@51 | 1812 | |
paul@187 | 1813 | # End of month. |
paul@9 | 1814 | |
paul@187 | 1815 | output.append(fmt.table(on=0)) |
paul@51 | 1816 | |
paul@122 | 1817 | # Output a day view. |
paul@122 | 1818 | |
paul@122 | 1819 | elif mode == "day": |
paul@122 | 1820 | |
paul@122 | 1821 | # Visit all days in the requested range, or across known events. |
paul@122 | 1822 | |
paul@122 | 1823 | for date in first.days_until(last): |
paul@122 | 1824 | |
paul@122 | 1825 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"})) |
paul@122 | 1826 | |
paul@168 | 1827 | full_coverage, day_slots = getCoverage( |
paul@171 | 1828 | getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime") |
paul@122 | 1829 | |
paul@126 | 1830 | # Work out how many columns the day title will need. |
paul@179 | 1831 | # Include spacers after the scale and each event column. |
paul@126 | 1832 | |
paul@179 | 1833 | colspan = sum(map(len, day_slots.values())) * 2 + 2 |
paul@126 | 1834 | |
paul@187 | 1835 | output.append(view.writeDayTableHeading(date, colspan)) |
paul@123 | 1836 | |
paul@123 | 1837 | # Either generate empty days... |
paul@123 | 1838 | |
paul@123 | 1839 | if not day_slots: |
paul@123 | 1840 | output.append(view.writeEmptyDay(date)) |
paul@123 | 1841 | |
paul@123 | 1842 | # Or generate each set of scheduled events... |
paul@123 | 1843 | |
paul@123 | 1844 | else: |
paul@123 | 1845 | output.append(view.writeDaySlots(date, full_coverage, day_slots)) |
paul@122 | 1846 | |
paul@122 | 1847 | # End of day. |
paul@122 | 1848 | |
paul@122 | 1849 | output.append(fmt.table(on=0)) |
paul@122 | 1850 | |
paul@57 | 1851 | # Output view controls. |
paul@57 | 1852 | |
paul@57 | 1853 | output.append(fmt.div(on=1, css_class="event-controls")) |
paul@57 | 1854 | output.append(view.writeViewControls()) |
paul@57 | 1855 | output.append(fmt.div(on=0)) |
paul@57 | 1856 | |
paul@167 | 1857 | # Close the calendar region. |
paul@167 | 1858 | |
paul@167 | 1859 | output.append(fmt.div(on=0)) |
paul@167 | 1860 | |
paul@0 | 1861 | return ''.join(output) |
paul@0 | 1862 | |
paul@0 | 1863 | # vim: tabstop=4 expandtab shiftwidth=4 |