paul@0 | 1 | # -*- coding: iso-8859-1 -*- |
paul@0 | 2 | """ |
paul@0 | 3 | MoinMoin - EventAggregator Macro |
paul@0 | 4 | |
paul@0 | 5 | @copyright: 2008, 2009 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@5 | 15 | try: |
paul@5 | 16 | set |
paul@5 | 17 | except NameError: |
paul@5 | 18 | from sets import Set as set |
paul@5 | 19 | |
paul@0 | 20 | Dependencies = ['pages'] |
paul@0 | 21 | |
paul@0 | 22 | # Date labels. |
paul@0 | 23 | |
paul@0 | 24 | month_labels = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] |
paul@0 | 25 | weekday_labels = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] |
paul@0 | 26 | |
paul@10 | 27 | # HTML-related functions. |
paul@2 | 28 | |
paul@2 | 29 | def getColour(s): |
paul@2 | 30 | colour = [0, 0, 0] |
paul@2 | 31 | digit = 0 |
paul@2 | 32 | for c in s: |
paul@2 | 33 | colour[digit] += ord(c) |
paul@2 | 34 | colour[digit] = colour[digit] % 256 |
paul@2 | 35 | digit += 1 |
paul@2 | 36 | digit = digit % 3 |
paul@2 | 37 | return tuple(colour) |
paul@2 | 38 | |
paul@2 | 39 | def getBlackOrWhite(colour): |
paul@2 | 40 | if sum(colour) / 3.0 > 127: |
paul@2 | 41 | return (0, 0, 0) |
paul@2 | 42 | else: |
paul@2 | 43 | return (255, 255, 255) |
paul@2 | 44 | |
paul@11 | 45 | # Macro functions. |
paul@11 | 46 | |
paul@11 | 47 | def getMonth(arg): |
paul@11 | 48 | if arg in ("current", "next", "last"): |
paul@11 | 49 | date = EventAggregatorSupport.getCurrentMonth() |
paul@11 | 50 | if arg == "next": |
paul@11 | 51 | date = EventAggregatorSupport.monthupdate(date, 1) |
paul@11 | 52 | elif arg == "last": |
paul@11 | 53 | date = EventAggregatorSupport.monthupdate(date, -1) |
paul@11 | 54 | else: |
paul@11 | 55 | date = EventAggregatorSupport.getMonth(arg) |
paul@11 | 56 | return date |
paul@11 | 57 | |
paul@11 | 58 | def getFormMonth(request, calendar_name, argname): |
paul@11 | 59 | arg = request.form.get("%s-%s" % (calendar_name, argname), [None])[0] |
paul@11 | 60 | if arg is not None: |
paul@11 | 61 | return getMonth(arg) |
paul@11 | 62 | else: |
paul@11 | 63 | return None |
paul@10 | 64 | |
paul@0 | 65 | def execute(macro, args): |
paul@0 | 66 | |
paul@0 | 67 | """ |
paul@0 | 68 | Execute the 'macro' with the given 'args': an optional list of selected |
paul@0 | 69 | category names (categories whose pages are to be shown), together with |
paul@5 | 70 | optional named arguments of the following forms: |
paul@5 | 71 | |
paul@5 | 72 | start=YYYY-MM shows event details starting from the specified month |
paul@11 | 73 | start=current shows event details starting with the current month |
paul@11 | 74 | start=next shows event details starting with next month |
paul@5 | 75 | end=YYYY-MM shows event details ending at the specified month |
paul@11 | 76 | end=current shows event details ending with the current month |
paul@11 | 77 | end=last shows event details ending with last month |
paul@11 | 78 | span=N shows event details for N months starting with the |
paul@11 | 79 | specified start month, or ending with the specified end |
paul@11 | 80 | month |
paul@5 | 81 | |
paul@5 | 82 | mode=calendar shows a calendar view of events |
paul@5 | 83 | mode=list shows a list of events by month |
paul@9 | 84 | mode=ics provides iCalendar data for the events |
paul@5 | 85 | |
paul@5 | 86 | names=daily shows the name of an event on every day of that event |
paul@5 | 87 | names=weekly shows the name of an event once per week |
paul@11 | 88 | |
paul@11 | 89 | calendar=NAME uses the given NAME to provide request parameters which |
paul@11 | 90 | can be used to control the calendar view |
paul@0 | 91 | """ |
paul@0 | 92 | |
paul@0 | 93 | request = macro.request |
paul@0 | 94 | fmt = macro.formatter |
paul@0 | 95 | page = fmt.page |
paul@0 | 96 | _ = request.getText |
paul@0 | 97 | |
paul@0 | 98 | # Interpret the arguments. |
paul@0 | 99 | |
paul@0 | 100 | try: |
paul@0 | 101 | parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] |
paul@0 | 102 | except AttributeError: |
paul@0 | 103 | parsed_args = args.split(",") |
paul@0 | 104 | |
paul@0 | 105 | parsed_args = [arg for arg in parsed_args if arg] |
paul@0 | 106 | |
paul@0 | 107 | # Get special arguments. |
paul@0 | 108 | |
paul@0 | 109 | category_names = [] |
paul@0 | 110 | calendar_start = None |
paul@0 | 111 | calendar_end = None |
paul@11 | 112 | span = None |
paul@0 | 113 | mode = "calendar" |
paul@5 | 114 | name_usage = "daily" |
paul@11 | 115 | calendar_name = None |
paul@0 | 116 | |
paul@0 | 117 | for arg in parsed_args: |
paul@0 | 118 | if arg.startswith("start="): |
paul@11 | 119 | calendar_start = getMonth(arg[6:]) |
paul@11 | 120 | |
paul@0 | 121 | elif arg.startswith("end="): |
paul@11 | 122 | calendar_end = getMonth(arg[4:]) |
paul@11 | 123 | |
paul@11 | 124 | elif arg.startswith("span="): |
paul@11 | 125 | span = abs(int(arg[5:])) |
paul@11 | 126 | |
paul@0 | 127 | elif arg.startswith("mode="): |
paul@0 | 128 | mode = arg[5:] |
paul@11 | 129 | |
paul@5 | 130 | elif arg.startswith("names="): |
paul@5 | 131 | name_usage = arg[6:] |
paul@11 | 132 | |
paul@11 | 133 | elif arg.startswith("calendar="): |
paul@11 | 134 | calendar_name = arg[9:] |
paul@11 | 135 | |
paul@0 | 136 | else: |
paul@0 | 137 | category_names.append(arg) |
paul@0 | 138 | |
paul@11 | 139 | # Find request parameters to override settings. |
paul@11 | 140 | |
paul@11 | 141 | if calendar_name is not None: |
paul@11 | 142 | new_calendar_start = getFormMonth(request, calendar_name, "start") |
paul@11 | 143 | new_calendar_end = getFormMonth(request, calendar_name, "end") |
paul@11 | 144 | if new_calendar_start is not None or new_calendar_end is not None: |
paul@11 | 145 | calendar_start = new_calendar_start |
paul@11 | 146 | calendar_end = new_calendar_end |
paul@11 | 147 | |
paul@12 | 148 | # Insist on a span in order to ensure start and end months. |
paul@12 | 149 | |
paul@12 | 150 | if span is None: |
paul@12 | 151 | span = 1 |
paul@12 | 152 | |
paul@11 | 153 | # Calculate the window of interest. |
paul@11 | 154 | |
paul@11 | 155 | if span is not None: |
paul@11 | 156 | if calendar_start is not None: |
paul@11 | 157 | calendar_end = EventAggregatorSupport.monthupdate(calendar_start, max(0, span - 1)) |
paul@11 | 158 | elif calendar_end is not None: |
paul@11 | 159 | calendar_start = EventAggregatorSupport.monthupdate(calendar_end, min(0, -span + 1)) |
paul@11 | 160 | else: |
paul@11 | 161 | calendar_start = EventAggregatorSupport.getCurrentMonth() |
paul@11 | 162 | calendar_end = EventAggregatorSupport.monthupdate(calendar_start, max(0, span - 1)) |
paul@11 | 163 | |
paul@11 | 164 | # Some useful navigation months. |
paul@11 | 165 | |
paul@11 | 166 | if calendar_name is not None: |
paul@11 | 167 | previous_year, previous_month = EventAggregatorSupport.prevmonth(calendar_start) |
paul@11 | 168 | next_year, next_month = EventAggregatorSupport.nextmonth(calendar_start) |
paul@11 | 169 | next_set_year, next_set_month = EventAggregatorSupport.nextmonth(calendar_end) |
paul@11 | 170 | |
paul@11 | 171 | # Get the events. |
paul@11 | 172 | |
paul@10 | 173 | events, shown_events, all_shown_events, earliest, latest = \ |
paul@10 | 174 | EventAggregatorSupport.getEvents(request, category_names, calendar_start, calendar_end) |
paul@2 | 175 | |
paul@0 | 176 | # Make a calendar. |
paul@0 | 177 | |
paul@0 | 178 | output = [] |
paul@0 | 179 | |
paul@9 | 180 | # Output top-level information. |
paul@9 | 181 | |
paul@2 | 182 | if mode == "list": |
paul@2 | 183 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"})) |
paul@0 | 184 | |
paul@2 | 185 | # Visit all months in the requested range, or across known events. |
paul@0 | 186 | |
paul@2 | 187 | first = calendar_start or earliest |
paul@2 | 188 | last = calendar_end or latest |
paul@1 | 189 | |
paul@10 | 190 | for year, month in EventAggregatorSupport.daterange(first, last): |
paul@2 | 191 | |
paul@2 | 192 | # Either output a calendar view... |
paul@0 | 193 | |
paul@2 | 194 | if mode == "calendar": |
paul@2 | 195 | |
paul@2 | 196 | # Output a month. |
paul@2 | 197 | |
paul@2 | 198 | output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"})) |
paul@0 | 199 | |
paul@2 | 200 | output.append(fmt.table_row(on=1)) |
paul@2 | 201 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "7"})) |
paul@11 | 202 | |
paul@11 | 203 | # Either write a month heading or produce a link for navigable |
paul@11 | 204 | # calendars. |
paul@11 | 205 | |
paul@11 | 206 | month_label = _(month_labels[month - 1]) # zero-based labels |
paul@11 | 207 | |
paul@11 | 208 | if calendar_name is not None: |
paul@11 | 209 | previous_months_link = "%s-end=%04d-%02d" % (calendar_name, previous_year, previous_month) |
paul@11 | 210 | previous_month_link = "%s-start=%04d-%02d" % (calendar_name, previous_year, previous_month) |
paul@11 | 211 | |
paul@11 | 212 | output.append(fmt.span(on=1, css_class="previous-month")) |
paul@11 | 213 | output.append(page.link_to_raw(request, wikiutil.escape("<<"), previous_months_link)) |
paul@11 | 214 | output.append(fmt.text(" ")) |
paul@11 | 215 | output.append(page.link_to_raw(request, wikiutil.escape("<"), previous_month_link)) |
paul@11 | 216 | output.append(fmt.span(on=0)) |
paul@11 | 217 | |
paul@11 | 218 | next_months_link = "%s-start=%04d-%02d" % (calendar_name, next_set_year, next_set_month) |
paul@11 | 219 | next_month_link = "%s-start=%04d-%02d" % (calendar_name, next_year, next_month) |
paul@11 | 220 | |
paul@11 | 221 | output.append(fmt.span(on=1, css_class="next-month")) |
paul@11 | 222 | output.append(page.link_to_raw(request, wikiutil.escape(">"), next_month_link)) |
paul@11 | 223 | output.append(fmt.text(" ")) |
paul@11 | 224 | output.append(page.link_to_raw(request, wikiutil.escape(">>"), next_months_link)) |
paul@11 | 225 | output.append(fmt.span(on=0)) |
paul@11 | 226 | |
paul@11 | 227 | full_month_label = "%s %s" % (month_label, year) |
paul@11 | 228 | month_link = "%s-start=%04d-%02d" % (calendar_name, year, month) |
paul@11 | 229 | output.append(page.link_to_raw(request, wikiutil.escape(full_month_label), month_link)) |
paul@11 | 230 | |
paul@11 | 231 | else: |
paul@11 | 232 | output.append(fmt.span(on=1)) |
paul@11 | 233 | output.append(fmt.text(month_label)) |
paul@11 | 234 | output.append(fmt.span(on=0)) |
paul@11 | 235 | output.append(fmt.text(" ")) |
paul@11 | 236 | output.append(fmt.span(on=1)) |
paul@11 | 237 | output.append(fmt.text(year)) |
paul@11 | 238 | output.append(fmt.span(on=0)) |
paul@11 | 239 | |
paul@2 | 240 | output.append(fmt.table_cell(on=0)) |
paul@2 | 241 | output.append(fmt.table_row(on=0)) |
paul@0 | 242 | |
paul@2 | 243 | # Weekday headings. |
paul@0 | 244 | |
paul@2 | 245 | output.append(fmt.table_row(on=1)) |
paul@0 | 246 | |
paul@2 | 247 | for weekday in range(0, 7): |
paul@5 | 248 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading"})) |
paul@2 | 249 | output.append(fmt.text(_(weekday_labels[weekday]))) |
paul@0 | 250 | output.append(fmt.table_cell(on=0)) |
paul@2 | 251 | |
paul@2 | 252 | output.append(fmt.table_row(on=0)) |
paul@2 | 253 | |
paul@2 | 254 | # Process the days of the month. |
paul@2 | 255 | |
paul@2 | 256 | start_weekday, number_of_days = calendar.monthrange(year, month) |
paul@0 | 257 | |
paul@2 | 258 | # The start weekday is the weekday of day number 1. |
paul@2 | 259 | # Find the first day of the week, counting from below zero, if |
paul@2 | 260 | # necessary, in order to land on the first day of the month as |
paul@2 | 261 | # day number 1. |
paul@2 | 262 | |
paul@2 | 263 | first_day = 1 - start_weekday |
paul@2 | 264 | |
paul@2 | 265 | while first_day <= number_of_days: |
paul@2 | 266 | |
paul@5 | 267 | # Find events in this week and determine how to mark them on the |
paul@5 | 268 | # calendar. |
paul@5 | 269 | |
paul@5 | 270 | week_events = [] |
paul@5 | 271 | week_coverage = set() |
paul@5 | 272 | |
paul@5 | 273 | week_start = (year, month, max(first_day, 1)) |
paul@5 | 274 | week_end = (year, month, min(first_day + 6, number_of_days)) |
paul@5 | 275 | |
paul@5 | 276 | # Get event details. |
paul@5 | 277 | |
paul@5 | 278 | for event in shown_events.get((year, month), []): |
paul@5 | 279 | event_page, event_details = event |
paul@5 | 280 | |
paul@5 | 281 | # Test for the event in the current week. |
paul@5 | 282 | |
paul@5 | 283 | if event_details["start"] <= week_end and event_details["end"] >= week_start: |
paul@5 | 284 | |
paul@5 | 285 | # Find the coverage of this week for the event. |
paul@5 | 286 | |
paul@5 | 287 | event_start = max(event_details["start"], week_start) |
paul@5 | 288 | event_end = min(event_details["end"], week_end) |
paul@10 | 289 | event_coverage = set(EventAggregatorSupport.daterange(event_start, event_end)) |
paul@5 | 290 | |
paul@5 | 291 | # Update the overall coverage. |
paul@5 | 292 | |
paul@5 | 293 | week_coverage.update(event_coverage) |
paul@5 | 294 | |
paul@5 | 295 | # Try and fit the event into the events list. |
paul@5 | 296 | |
paul@5 | 297 | for i, (coverage, events) in enumerate(week_events): |
paul@5 | 298 | |
paul@5 | 299 | # Where the event does not overlap with the current |
paul@5 | 300 | # element, add it alongside existing events. |
paul@5 | 301 | |
paul@5 | 302 | if not coverage.intersection(event_coverage): |
paul@5 | 303 | events.append(event) |
paul@5 | 304 | week_events[i] = coverage.union(event_coverage), events |
paul@5 | 305 | break |
paul@5 | 306 | |
paul@5 | 307 | # Make a new element in the list if the event cannot be |
paul@5 | 308 | # marked alongside existing events. |
paul@5 | 309 | |
paul@5 | 310 | else: |
paul@5 | 311 | week_events.append((event_coverage, [event])) |
paul@5 | 312 | |
paul@5 | 313 | # Output a week, starting with the day numbers. |
paul@0 | 314 | |
paul@0 | 315 | output.append(fmt.table_row(on=1)) |
paul@0 | 316 | |
paul@0 | 317 | for weekday in range(0, 7): |
paul@2 | 318 | day = first_day + weekday |
paul@5 | 319 | date = (year, month, day) |
paul@2 | 320 | |
paul@2 | 321 | # Output out-of-month days. |
paul@2 | 322 | |
paul@2 | 323 | if day < 1 or day > number_of_days: |
paul@5 | 324 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-heading event-day-excluded"})) |
paul@2 | 325 | output.append(fmt.table_cell(on=0)) |
paul@2 | 326 | |
paul@2 | 327 | # Output normal days. |
paul@2 | 328 | |
paul@2 | 329 | else: |
paul@5 | 330 | if date in week_coverage: |
paul@5 | 331 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-heading event-day-busy"})) |
paul@2 | 332 | else: |
paul@5 | 333 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-heading event-day-empty"})) |
paul@2 | 334 | |
paul@2 | 335 | output.append(fmt.div(on=1)) |
paul@2 | 336 | output.append(fmt.span(on=1, css_class="event-day-number")) |
paul@2 | 337 | output.append(fmt.text(day)) |
paul@2 | 338 | output.append(fmt.span(on=0)) |
paul@2 | 339 | output.append(fmt.div(on=0)) |
paul@2 | 340 | |
paul@5 | 341 | # End of day. |
paul@5 | 342 | |
paul@5 | 343 | output.append(fmt.table_cell(on=0)) |
paul@5 | 344 | |
paul@5 | 345 | # End of day numbers. |
paul@5 | 346 | |
paul@5 | 347 | output.append(fmt.table_row(on=0)) |
paul@5 | 348 | |
paul@7 | 349 | # Either generate empty days... |
paul@5 | 350 | |
paul@7 | 351 | if not week_events: |
paul@5 | 352 | output.append(fmt.table_row(on=1)) |
paul@5 | 353 | |
paul@5 | 354 | for weekday in range(0, 7): |
paul@5 | 355 | day = first_day + weekday |
paul@5 | 356 | date = (year, month, day) |
paul@5 | 357 | |
paul@7 | 358 | # Output out-of-month days. |
paul@5 | 359 | |
paul@5 | 360 | if day < 1 or day > number_of_days: |
paul@5 | 361 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day event-day-excluded"})) |
paul@5 | 362 | output.append(fmt.table_cell(on=0)) |
paul@2 | 363 | |
paul@7 | 364 | # Output empty days. |
paul@5 | 365 | |
paul@5 | 366 | else: |
paul@5 | 367 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day event-day-empty"})) |
paul@5 | 368 | |
paul@7 | 369 | output.append(fmt.table_row(on=0)) |
paul@7 | 370 | |
paul@7 | 371 | # Or visit each set of scheduled events... |
paul@7 | 372 | |
paul@7 | 373 | else: |
paul@7 | 374 | for coverage, events in week_events: |
paul@7 | 375 | |
paul@7 | 376 | # Output each set. |
paul@7 | 377 | |
paul@7 | 378 | output.append(fmt.table_row(on=1)) |
paul@5 | 379 | |
paul@7 | 380 | # Then, output day details. |
paul@7 | 381 | |
paul@7 | 382 | for weekday in range(0, 7): |
paul@7 | 383 | day = first_day + weekday |
paul@7 | 384 | date = (year, month, day) |
paul@7 | 385 | |
paul@7 | 386 | # Skip out-of-month days. |
paul@7 | 387 | |
paul@7 | 388 | if day < 1 or day > number_of_days: |
paul@7 | 389 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day event-day-excluded"})) |
paul@7 | 390 | output.append(fmt.table_cell(on=0)) |
paul@5 | 391 | continue |
paul@2 | 392 | |
paul@7 | 393 | # Output the day. |
paul@2 | 394 | |
paul@7 | 395 | if date in coverage: |
paul@7 | 396 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day event-day-busy"})) |
paul@7 | 397 | else: |
paul@7 | 398 | output.append(fmt.table_cell(on=1, attrs={"class" : "event-day event-day-empty"})) |
paul@2 | 399 | |
paul@7 | 400 | # Get event details for the current day. |
paul@2 | 401 | |
paul@7 | 402 | for event_page, event_details in events: |
paul@7 | 403 | if not (event_details["start"] <= date <= event_details["end"]): |
paul@7 | 404 | continue |
paul@7 | 405 | |
paul@7 | 406 | # Get a pretty version of the page name. |
paul@3 | 407 | |
paul@10 | 408 | pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page) |
paul@7 | 409 | |
paul@7 | 410 | # Generate a colour for the event. |
paul@3 | 411 | |
paul@7 | 412 | bg = getColour(event_page.page_name) |
paul@7 | 413 | fg = getBlackOrWhite(bg) |
paul@7 | 414 | |
paul@7 | 415 | css_classes = ["event-summary"] |
paul@3 | 416 | |
paul@7 | 417 | if event_details["start"] == date: |
paul@7 | 418 | css_classes.append("event-starts") |
paul@7 | 419 | start_of_event = 1 |
paul@7 | 420 | else: |
paul@7 | 421 | start_of_event = 0 |
paul@2 | 422 | |
paul@7 | 423 | if event_details["end"] == date: |
paul@7 | 424 | css_classes.append("event-ends") |
paul@7 | 425 | |
paul@7 | 426 | # Output the event. |
paul@5 | 427 | |
paul@7 | 428 | if name_usage == "daily" or start_of_event or weekday == 0 or day == 1: |
paul@7 | 429 | hide_text = 0 |
paul@7 | 430 | else: |
paul@7 | 431 | hide_text = 1 |
paul@5 | 432 | |
paul@7 | 433 | output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), |
paul@7 | 434 | style=("background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg)))) |
paul@5 | 435 | |
paul@7 | 436 | if not hide_text: |
paul@7 | 437 | output.append(event_page.link_to_raw(request, wikiutil.escape(pretty_pagename))) |
paul@7 | 438 | |
paul@7 | 439 | output.append(fmt.div(on=0)) |
paul@2 | 440 | |
paul@7 | 441 | # End of day. |
paul@2 | 442 | |
paul@7 | 443 | output.append(fmt.table_cell(on=0)) |
paul@0 | 444 | |
paul@7 | 445 | # End of set. |
paul@5 | 446 | |
paul@7 | 447 | output.append(fmt.table_row(on=0)) |
paul@5 | 448 | |
paul@5 | 449 | # Process the next week... |
paul@0 | 450 | |
paul@2 | 451 | first_day += 7 |
paul@0 | 452 | |
paul@2 | 453 | # End of month. |
paul@0 | 454 | |
paul@2 | 455 | output.append(fmt.table(on=0)) |
paul@0 | 456 | |
paul@2 | 457 | # Or output a summary view... |
paul@0 | 458 | |
paul@2 | 459 | elif mode == "list": |
paul@0 | 460 | |
paul@2 | 461 | output.append(fmt.listitem(on=1, attr={"class" : "event-listings-month"})) |
paul@2 | 462 | output.append(fmt.div(on=1, attr={"class" : "event-listings-month-heading"})) |
paul@2 | 463 | output.append(fmt.span(on=1)) |
paul@2 | 464 | output.append(fmt.text(_(month_labels[month - 1]))) # zero-based labels |
paul@2 | 465 | output.append(fmt.span(on=0)) |
paul@2 | 466 | output.append(fmt.text(" ")) |
paul@2 | 467 | output.append(fmt.span(on=1)) |
paul@2 | 468 | output.append(fmt.text(year)) |
paul@2 | 469 | output.append(fmt.span(on=0)) |
paul@2 | 470 | output.append(fmt.div(on=0)) |
paul@0 | 471 | |
paul@2 | 472 | output.append(fmt.bullet_list(on=1, attr={"class" : "event-month-listings"})) |
paul@0 | 473 | |
paul@2 | 474 | for event_page, event_details in shown_events.get((year, month), []): |
paul@0 | 475 | |
paul@2 | 476 | # Get a pretty version of the page name. |
paul@0 | 477 | |
paul@10 | 478 | pretty_pagename = EventAggregatorSupport.getPrettyPageName(event_page) |
paul@0 | 479 | |
paul@2 | 480 | output.append(fmt.listitem(on=1, attr={"class" : "event-listing"})) |
paul@0 | 481 | |
paul@2 | 482 | # Link to the page using the pretty name. |
paul@0 | 483 | |
paul@2 | 484 | output.append(event_page.link_to_raw(request, wikiutil.escape(pretty_pagename))) |
paul@0 | 485 | |
paul@2 | 486 | # Add the event details. |
paul@0 | 487 | |
paul@2 | 488 | output.append(fmt.definition_list(on=1, attr={"class" : "event-details"})) |
paul@0 | 489 | |
paul@2 | 490 | for key, value in event_details.items(): |
paul@2 | 491 | output.append(fmt.definition_term(on=1)) |
paul@2 | 492 | output.append(fmt.text(key)) |
paul@2 | 493 | output.append(fmt.definition_term(on=0)) |
paul@2 | 494 | output.append(fmt.definition_desc(on=1)) |
paul@2 | 495 | output.append(fmt.text(value)) |
paul@2 | 496 | output.append(fmt.definition_desc(on=0)) |
paul@0 | 497 | |
paul@2 | 498 | output.append(fmt.definition_list(on=0)) |
paul@2 | 499 | output.append(fmt.listitem(on=0)) |
paul@0 | 500 | |
paul@2 | 501 | output.append(fmt.bullet_list(on=0)) |
paul@0 | 502 | |
paul@9 | 503 | # Output top-level information. |
paul@9 | 504 | |
paul@9 | 505 | # End of list view output. |
paul@9 | 506 | |
paul@10 | 507 | if mode == "list": |
paul@0 | 508 | output.append(fmt.bullet_list(on=0)) |
paul@0 | 509 | |
paul@0 | 510 | return ''.join(output) |
paul@0 | 511 | |
paul@0 | 512 | # vim: tabstop=4 expandtab shiftwidth=4 |