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