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