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