1.1 --- a/macros/EventAggregator.py Wed Apr 13 00:32:04 2011 +0200
1.2 +++ b/macros/EventAggregator.py Fri Apr 15 00:14:04 2011 +0200
1.3 @@ -23,7 +23,8 @@
1.4
1.5 def __init__(self, page, calendar_name, raw_calendar_start, raw_calendar_end,
1.6 original_calendar_start, original_calendar_end, calendar_start, calendar_end,
1.7 - first, last, category_names, template_name, parent_name, mode, name_usage):
1.8 + first, last, category_names, template_name, parent_name, mode, resolution,
1.9 + name_usage, map_name):
1.10
1.11 """
1.12 Initialise the view with the current 'page', a 'calendar_name' (which
1.13 @@ -39,8 +40,14 @@
1.14 The additional 'category_names', 'template_name', 'parent_name' and
1.15 'mode' parameters are used to configure the links employed by the view.
1.16
1.17 + The 'resolution' affects the view for certain modes and is also used to
1.18 + parameterise links.
1.19 +
1.20 The 'name_usage' parameter controls how names are shown on calendar mode
1.21 events, such as how often labels are repeated.
1.22 +
1.23 + The 'map_name' parameter provides the name of a map to be used in the
1.24 + map mode.
1.25 """
1.26
1.27 self.page = page
1.28 @@ -54,7 +61,9 @@
1.29 self.template_name = template_name
1.30 self.parent_name = parent_name
1.31 self.mode = mode
1.32 + self.resolution = resolution
1.33 self.name_usage = name_usage
1.34 + self.map_name = map_name
1.35
1.36 self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names])
1.37
1.38 @@ -62,17 +71,17 @@
1.39
1.40 # Store the view parameters.
1.41
1.42 - self.number_of_months = (last - first).months() + 1
1.43 + self.duration = (last - first).count() + 1
1.44
1.45 - self.previous_month_start = first.previous_month()
1.46 - self.next_month_start = first.next_month()
1.47 - self.previous_month_end = last.previous_month()
1.48 - self.next_month_end = last.next_month()
1.49 + self.previous_start = first.previous()
1.50 + self.next_start = first.next()
1.51 + self.previous_end = last.previous()
1.52 + self.next_end = last.next()
1.53
1.54 - self.previous_set_start = first.month_update(-self.number_of_months)
1.55 - self.next_set_start = first.month_update(self.number_of_months)
1.56 - self.previous_set_end = last.month_update(-self.number_of_months)
1.57 - self.next_set_end = last.month_update(self.number_of_months)
1.58 + self.previous_set_start = first.update(-self.duration)
1.59 + self.next_set_start = first.update(self.duration)
1.60 + self.previous_set_end = last.update(-self.duration)
1.61 + self.next_set_end = last.update(self.duration)
1.62
1.63 def getQualifiedParameterName(self, argname):
1.64
1.65 @@ -124,18 +133,20 @@
1.66 else:
1.67 return ""
1.68
1.69 - def getNavigationLink(self, start, end, mode=None):
1.70 + def getNavigationLink(self, start, end, mode=None, resolution=None):
1.71
1.72 """
1.73 Return a query string fragment for navigation to a view showing months
1.74 from 'start' to 'end' inclusive, with the optional 'mode' indicating the
1.75 - view style.
1.76 + view style and the optional 'resolution' indicating the resolution of a
1.77 + view, if configurable.
1.78 """
1.79
1.80 - return "%s&%s&%s=%s" % (
1.81 + return "%s&%s&%s=%s&%s=%s" % (
1.82 self.getRawDateQueryString("start", start),
1.83 self.getRawDateQueryString("end", end),
1.84 - self.getQualifiedParameterName("mode"), mode or self.mode
1.85 + self.getQualifiedParameterName("mode"), mode or self.mode,
1.86 + self.getQualifiedParameterName("resolution"), resolution or self.resolution
1.87 )
1.88
1.89 def getFullDateLabel(self, date):
1.90 @@ -148,6 +159,43 @@
1.91 request = page.request
1.92 return getFullMonthLabel(request, year_month)
1.93
1.94 + def getFullLabel(self, arg):
1.95 + return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg)
1.96 +
1.97 + def _getCalendarPeriod(self, start_label, end_label, default_label):
1.98 + output = []
1.99 + if start_label:
1.100 + output.append(start_label)
1.101 + if self.calendar_end and start_label != end_label:
1.102 + if output:
1.103 + output.append(" - ")
1.104 + output.append(end_label)
1.105 + return "".join(output) or default_label
1.106 +
1.107 + def getCalendarPeriod(self):
1.108 + _ = self.page.request.getText
1.109 + return self._getCalendarPeriod(
1.110 + self.calendar_start and self.getFullLabel(self.calendar_start),
1.111 + self.calendar_end and self.getFullLabel(self.calendar_end),
1.112 + _("All events")
1.113 + )
1.114 +
1.115 + def getOriginalCalendarPeriod(self):
1.116 + _ = self.page.request.getText
1.117 + return self._getCalendarPeriod(
1.118 + self.original_calendar_start and self.getFullLabel(self.original_calendar_start),
1.119 + self.original_calendar_end and self.getFullLabel(self.original_calendar_end),
1.120 + _("All events")
1.121 + )
1.122 +
1.123 + def getRawCalendarPeriod(self):
1.124 + _ = self.page.request.getText
1.125 + return self._getCalendarPeriod(
1.126 + self.raw_calendar_start,
1.127 + self.raw_calendar_end,
1.128 + _("No period specified")
1.129 + )
1.130 +
1.131 def writeDownloadControls(self):
1.132
1.133 """
1.134 @@ -166,7 +214,7 @@
1.135
1.136 download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&%s" % (
1.137 self.parent_name or "",
1.138 - self.mode == "day" and "date" or "month",
1.139 + self.resolution,
1.140 self.category_name_parameters
1.141 )
1.142 download_all_link = download_dialogue_link + "&doit=1"
1.143 @@ -204,22 +252,9 @@
1.144
1.145 # Pop-up descriptions of the downloadable calendars.
1.146
1.147 - get_label = self.mode == "day" and self.getFullDateLabel or self.getFullMonthLabel
1.148 -
1.149 - calendar_period = (self.calendar_start or self.calendar_end) and \
1.150 - "%s - %s" % (
1.151 - get_label(self.calendar_start),
1.152 - get_label(self.calendar_end)
1.153 - ) or _("All events")
1.154 -
1.155 - original_calendar_period = (self.original_calendar_start or self.original_calendar_end) and \
1.156 - "%s - %s" % (
1.157 - get_label(self.original_calendar_start),
1.158 - get_label(self.original_calendar_end)
1.159 - ) or _("All events")
1.160 -
1.161 - raw_calendar_period = (self.raw_calendar_start or self.raw_calendar_end) and \
1.162 - "%s - %s" % (self.raw_calendar_start, self.raw_calendar_end) or _("No period specified")
1.163 + calendar_period = self.getCalendarPeriod()
1.164 + original_calendar_period = self.getOriginalCalendarPeriod()
1.165 + raw_calendar_period = self.getRawCalendarPeriod()
1.166
1.167 # Write the controls.
1.168
1.169 @@ -297,29 +332,67 @@
1.170
1.171 output = []
1.172
1.173 - start = self.calendar_start and self.calendar_start.as_month()
1.174 - end = self.calendar_end and self.calendar_end.as_month()
1.175 + start = self.calendar_start
1.176 + end = self.calendar_end
1.177
1.178 - calendar_link = self.getNavigationLink(start, end, "calendar")
1.179 + calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
1.180 list_link = self.getNavigationLink(start, end, "list")
1.181 table_link = self.getNavigationLink(start, end, "table")
1.182 + map_link = self.getNavigationLink(start, end, "map")
1.183
1.184 # Write the controls.
1.185
1.186 output.append(fmt.div(on=1, css_class="event-view-controls"))
1.187 - output.append(fmt.span(on=1, css_class="event-view"))
1.188 - output.append(linkToPage(request, page, _("View as calendar"), calendar_link))
1.189 - output.append(fmt.span(on=0))
1.190 - output.append(fmt.span(on=1, css_class="event-view"))
1.191 - output.append(linkToPage(request, page, _("View as list"), list_link))
1.192 - output.append(fmt.span(on=0))
1.193 - output.append(fmt.span(on=1, css_class="event-view"))
1.194 - output.append(linkToPage(request, page, _("View as table"), table_link))
1.195 - output.append(fmt.span(on=0))
1.196 +
1.197 + if self.mode != "calendar":
1.198 + output.append(fmt.span(on=1, css_class="event-view"))
1.199 + output.append(linkToPage(request, page, _("View as calendar"), calendar_link))
1.200 + output.append(fmt.span(on=0))
1.201 +
1.202 + if self.mode != "list":
1.203 + output.append(fmt.span(on=1, css_class="event-view"))
1.204 + output.append(linkToPage(request, page, _("View as list"), list_link))
1.205 + output.append(fmt.span(on=0))
1.206 +
1.207 + if self.mode != "table":
1.208 + output.append(fmt.span(on=1, css_class="event-view"))
1.209 + output.append(linkToPage(request, page, _("View as table"), table_link))
1.210 + output.append(fmt.span(on=0))
1.211 +
1.212 + if self.mode != "map" and self.map_name is not None:
1.213 + output.append(fmt.span(on=1, css_class="event-view"))
1.214 + output.append(linkToPage(request, page, _("View as map"), map_link))
1.215 + output.append(fmt.span(on=0))
1.216 +
1.217 output.append(fmt.div(on=0))
1.218
1.219 return "".join(output)
1.220
1.221 + def writeMapHeading(self):
1.222 +
1.223 + """
1.224 + Return the calendar heading for the current calendar, providing links
1.225 + permitting navigation to other periods.
1.226 + """
1.227 +
1.228 + label = self.getCalendarPeriod()
1.229 +
1.230 + if self.raw_calendar_start is None or self.raw_calendar_end is None:
1.231 + fmt = self.page.formatter
1.232 + output = []
1.233 + output.append(fmt.span(on=1))
1.234 + output.append(fmt.text(label))
1.235 + output.append(fmt.span(on=0))
1.236 + return "".join(output)
1.237 + else:
1.238 + return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end)
1.239 +
1.240 + def writeDateHeading(self, date):
1.241 + if isinstance(date, Date):
1.242 + return self.writeDayHeading(date)
1.243 + else:
1.244 + return self.writeMonthHeading(date)
1.245 +
1.246 def writeMonthHeading(self, year_month):
1.247
1.248 """
1.249 @@ -327,11 +400,33 @@
1.250 providing links permitting navigation to other months.
1.251 """
1.252
1.253 + full_month_label = self.getFullMonthLabel(year_month)
1.254 + end_month = year_month.update(self.duration - 1)
1.255 + return self._writeCalendarHeading(full_month_label, year_month, end_month)
1.256 +
1.257 + def writeDayHeading(self, date):
1.258 +
1.259 + """
1.260 + Return the calendar heading for the given 'date' (a Date object)
1.261 + providing links permitting navigation to other dates.
1.262 + """
1.263 +
1.264 + full_date_label = self.getFullDateLabel(date)
1.265 + end_date = date.update(self.duration - 1)
1.266 + return self._writeCalendarHeading(full_date_label, date, end_date)
1.267 +
1.268 + def _writeCalendarHeading(self, label, start, end):
1.269 +
1.270 + """
1.271 + Write a calendar heading providing links permitting navigation to other
1.272 + periods, using the given 'label' along with the 'start' and 'end' dates
1.273 + to provide a link to a particular period.
1.274 + """
1.275 +
1.276 page = self.page
1.277 request = page.request
1.278 fmt = page.formatter
1.279 _ = request.getText
1.280 - full_month_label = self.getFullMonthLabel(year_month)
1.281
1.282 output = []
1.283
1.284 @@ -346,8 +441,8 @@
1.285 previous_set_link = self.getNavigationLink(
1.286 self.previous_set_start, self.previous_set_end
1.287 )
1.288 - previous_month_link = self.getNavigationLink(
1.289 - self.previous_month_start, self.previous_month_end
1.290 + previous_link = self.getNavigationLink(
1.291 + self.previous_start, self.previous_end
1.292 )
1.293
1.294 # Links to the next set of months and to a calendar shifted
1.295 @@ -356,33 +451,31 @@
1.296 next_set_link = self.getNavigationLink(
1.297 self.next_set_start, self.next_set_end
1.298 )
1.299 - next_month_link = self.getNavigationLink(
1.300 - self.next_month_start, self.next_month_end
1.301 + next_link = self.getNavigationLink(
1.302 + self.next_start, self.next_end
1.303 )
1.304
1.305 - # A link leading to this month being at the top of the calendar.
1.306 -
1.307 - end_month = year_month.month_update(self.number_of_months - 1)
1.308 + # A link leading to this date being at the top of the calendar.
1.309
1.310 - month_link = self.getNavigationLink(year_month, end_month)
1.311 + date_link = self.getNavigationLink(start, end)
1.312
1.313 - output.append(fmt.span(on=1, css_class="previous-month"))
1.314 + output.append(fmt.span(on=1, css_class="previous"))
1.315 output.append(linkToPage(request, page, "<<", previous_set_link))
1.316 output.append(fmt.text(" "))
1.317 - output.append(linkToPage(request, page, "<", previous_month_link))
1.318 + output.append(linkToPage(request, page, "<", previous_link))
1.319 output.append(fmt.span(on=0))
1.320
1.321 - output.append(fmt.span(on=1, css_class="next-month"))
1.322 - output.append(linkToPage(request, page, ">", next_month_link))
1.323 + output.append(fmt.span(on=1, css_class="next"))
1.324 + output.append(linkToPage(request, page, ">", next_link))
1.325 output.append(fmt.text(" "))
1.326 output.append(linkToPage(request, page, ">>", next_set_link))
1.327 output.append(fmt.span(on=0))
1.328
1.329 - output.append(linkToPage(request, page, full_month_label, month_link))
1.330 + output.append(linkToPage(request, page, label, date_link))
1.331
1.332 else:
1.333 output.append(fmt.span(on=1))
1.334 - output.append(fmt.text(full_month_label))
1.335 + output.append(fmt.text(label))
1.336 output.append(fmt.span(on=0))
1.337
1.338 return "".join(output)
1.339 @@ -407,7 +500,7 @@
1.340 # form.
1.341
1.342 navigation_link = self.getNavigationLink(
1.343 - self.calendar_start, self.calendar_end, self.mode
1.344 + self.calendar_start, self.calendar_end
1.345 )
1.346
1.347 # Prepare the link to the new event form, incorporating the above
1.348 @@ -420,7 +513,7 @@
1.349
1.350 # Prepare a link to the day view for this day.
1.351
1.352 - day_view_link = self.getNavigationLink(date, date, "day")
1.353 + day_view_link = self.getNavigationLink(date, date, "day", "date")
1.354
1.355 # Output the heading class.
1.356
1.357 @@ -821,18 +914,15 @@
1.358
1.359 # Day layout methods.
1.360
1.361 - def writeDayHeading(self, date, colspan=1):
1.362 + def writeDayTableHeading(self, date, colspan=1):
1.363 page = self.page
1.364 - request = page.request
1.365 fmt = page.formatter
1.366 - _ = request.getText
1.367 - full_date_label = self.getFullDateLabel(date)
1.368
1.369 output = []
1.370 output.append(fmt.table_row(on=1))
1.371
1.372 output.append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)}))
1.373 - output.append(fmt.text(full_date_label))
1.374 + output.append(self.writeDayHeading(date))
1.375 output.append(fmt.table_cell(on=0))
1.376
1.377 output.append(fmt.table_row(on=0))
1.378 @@ -921,7 +1011,7 @@
1.379
1.380 columns = len(day_slots[location]) * 2 - 1
1.381 output.append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)}))
1.382 - output.append(fmt.text(location))
1.383 + output.append(fmt.text(location or ""))
1.384 output.append(fmt.table_cell(on=0))
1.385
1.386 # Add a trailing spacer.
1.387 @@ -1048,6 +1138,19 @@
1.388 output.append(fmt.table_cell(on=0))
1.389 return "".join(output)
1.390
1.391 + # Map layout methods.
1.392 +
1.393 + def writeMapTableHeading(self):
1.394 + page = self.page
1.395 + fmt = page.formatter
1.396 +
1.397 + output = []
1.398 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"}))
1.399 + output.append(self.writeMapHeading())
1.400 + output.append(fmt.table_cell(on=0))
1.401 +
1.402 + return "".join(output)
1.403 +
1.404 def showDictError(self, text, pagename):
1.405 page = self.page
1.406 fmt = page.formatter
1.407 @@ -1192,9 +1295,12 @@
1.408
1.409 mode = getQualifiedParameter(request, calendar_name, "mode", mode or "calendar")
1.410
1.411 - # Different modes require different levels of precision.
1.412 + # Different modes require different levels of precision by default.
1.413
1.414 - if mode == "day":
1.415 + resolution = getQualifiedParameter(request, calendar_name, "resolution", mode == "day" and "date" or "month")
1.416 + resolution = mode == "calendar" and "month" or resolution
1.417 +
1.418 + if resolution == "date":
1.419 get_date = getParameterDate
1.420 get_form_date = getFormDate
1.421 else:
1.422 @@ -1218,13 +1324,14 @@
1.423
1.424 # Get a concrete period of time.
1.425
1.426 - first, last = getConcretePeriod(calendar_start, calendar_end, earliest, latest)
1.427 + first, last = getConcretePeriod(calendar_start, calendar_end, earliest, latest, resolution)
1.428
1.429 # Define a view of the calendar, retaining useful navigational information.
1.430
1.431 view = View(page, calendar_name, raw_calendar_start, raw_calendar_end,
1.432 original_calendar_start, original_calendar_end, calendar_start, calendar_end,
1.433 - first, last, category_names, template_name, parent_name, mode, name_usage)
1.434 + first, last, category_names, template_name, parent_name, mode, resolution,
1.435 + name_usage, map_name)
1.436
1.437 # Make a calendar.
1.438
1.439 @@ -1401,6 +1508,15 @@
1.440
1.441 output.append(fmt.div(on=1, css_class="event-map"))
1.442
1.443 + output.append(fmt.table(on=1))
1.444 +
1.445 + output.append(fmt.table_row(on=1))
1.446 + output.append(view.writeMapTableHeading())
1.447 + output.append(fmt.table_row(on=0))
1.448 +
1.449 + output.append(fmt.table_row(on=1))
1.450 + output.append(fmt.table_cell(on=1))
1.451 +
1.452 output.append(fmt.div(on=1, css_class="event-map-container",
1.453 style="width: %spx; height: %spx; background-image: url('%s')" % (
1.454 escattr(map_width), escattr(map_height), map_image_url)
1.455 @@ -1472,158 +1588,153 @@
1.456 # End of map view output.
1.457
1.458 output.append(fmt.div(on=0))
1.459 + output.append(fmt.table_cell(on=0))
1.460 + output.append(fmt.table_row(on=0))
1.461 + output.append(fmt.table(on=0))
1.462 output.append(fmt.div(on=0))
1.463
1.464 - # Output a list or month calendar. These views show month-by-month data.
1.465 + # Output a list.
1.466
1.467 - elif mode in ("list", "calendar"):
1.468 -
1.469 - # Output top-level information.
1.470 + elif mode == "list":
1.471
1.472 # Start of list view output.
1.473
1.474 - if mode == "list":
1.475 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"}))
1.476 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"}))
1.477 +
1.478 + # Output a list.
1.479 +
1.480 + for period in first.until(last):
1.481 +
1.482 + output.append(fmt.listitem(on=1, attr={"class" : "event-listings-period"}))
1.483 + output.append(fmt.div(on=1, attr={"class" : "event-listings-heading"}))
1.484 +
1.485 + # Either write a date heading or produce links for navigable
1.486 + # calendars.
1.487 +
1.488 + output.append(view.writeDateHeading(period))
1.489 +
1.490 + output.append(fmt.div(on=0))
1.491 +
1.492 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"}))
1.493 +
1.494 + # Show the events in order.
1.495 +
1.496 + for event in getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period)):
1.497 + event_page = event.getPage()
1.498 + event_details = event.getDetails()
1.499 + event_summary = event.getSummary(parent_name)
1.500 +
1.501 + output.append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
1.502 +
1.503 + # Link to the page using the summary.
1.504 +
1.505 + output.append(fmt.paragraph(on=1))
1.506 + output.append(event_page.linkToPage(request, event_summary))
1.507 + output.append(fmt.paragraph(on=0))
1.508 +
1.509 + # Start and end dates.
1.510 +
1.511 + output.append(fmt.paragraph(on=1))
1.512 + output.append(fmt.span(on=1))
1.513 + output.append(fmt.text(str(event_details["start"])))
1.514 + output.append(fmt.span(on=0))
1.515 + output.append(fmt.text(" - "))
1.516 + output.append(fmt.span(on=1))
1.517 + output.append(fmt.text(str(event_details["end"])))
1.518 + output.append(fmt.span(on=0))
1.519 + output.append(fmt.paragraph(on=0))
1.520 +
1.521 + # Location.
1.522 +
1.523 + if event_details.has_key("location"):
1.524 + output.append(fmt.paragraph(on=1))
1.525 + output.append(formatText(event_details["location"], request, fmt, parser_cls))
1.526 + output.append(fmt.paragraph(on=1))
1.527 +
1.528 + # Topics.
1.529 +
1.530 + if event_details.has_key("topics") or event_details.has_key("categories"):
1.531 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-topics"}))
1.532 +
1.533 + for topic in event_details.get("topics") or event_details.get("categories") or []:
1.534 + output.append(fmt.listitem(on=1))
1.535 + output.append(formatText(topic, request, fmt, parser_cls))
1.536 + output.append(fmt.listitem(on=0))
1.537 +
1.538 + output.append(fmt.bullet_list(on=0))
1.539 +
1.540 + output.append(fmt.listitem(on=0))
1.541 +
1.542 + output.append(fmt.bullet_list(on=0))
1.543 +
1.544 + # End of list view output.
1.545 +
1.546 + output.append(fmt.bullet_list(on=0))
1.547 +
1.548 + # Output a month calendar. This shows month-by-month data.
1.549 +
1.550 + elif mode == "calendar":
1.551
1.552 # Visit all months in the requested range, or across known events.
1.553
1.554 for month in first.months_until(last):
1.555
1.556 - # Either output a calendar view...
1.557 -
1.558 - if mode == "calendar":
1.559 -
1.560 - # Output a month.
1.561 + # Output a month.
1.562
1.563 - output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
1.564 -
1.565 - # Either write a month heading or produce links for navigable
1.566 - # calendars.
1.567 -
1.568 - output.append(view.writeMonthTableHeading(month))
1.569 -
1.570 - # Weekday headings.
1.571 + output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
1.572
1.573 - output.append(view.writeWeekdayHeadings())
1.574 -
1.575 - # Process the days of the month.
1.576 -
1.577 - start_weekday, number_of_days = month.month_properties()
1.578 + # Either write a month heading or produce links for navigable
1.579 + # calendars.
1.580
1.581 - # The start weekday is the weekday of day number 1.
1.582 - # Find the first day of the week, counting from below zero, if
1.583 - # necessary, in order to land on the first day of the month as
1.584 - # day number 1.
1.585 + output.append(view.writeMonthTableHeading(month))
1.586
1.587 - first_day = 1 - start_weekday
1.588 + # Weekday headings.
1.589
1.590 - while first_day <= number_of_days:
1.591 -
1.592 - # Find events in this week and determine how to mark them on the
1.593 - # calendar.
1.594 + output.append(view.writeWeekdayHeadings())
1.595
1.596 - week_start = month.as_date(max(first_day, 1))
1.597 - week_end = month.as_date(min(first_day + 6, number_of_days))
1.598 -
1.599 - full_coverage, week_slots = getCoverage(
1.600 - getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end)))
1.601 -
1.602 - # Output a week, starting with the day numbers.
1.603 + # Process the days of the month.
1.604
1.605 - output.append(view.writeDayNumbers(first_day, number_of_days, month, full_coverage))
1.606 -
1.607 - # Either generate empty days...
1.608 -
1.609 - if not week_slots:
1.610 - output.append(view.writeEmptyWeek(first_day, number_of_days))
1.611 -
1.612 - # Or generate each set of scheduled events...
1.613 + start_weekday, number_of_days = month.month_properties()
1.614
1.615 - else:
1.616 - output.append(view.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots))
1.617 -
1.618 - # Process the next week...
1.619 -
1.620 - first_day += 7
1.621 + # The start weekday is the weekday of day number 1.
1.622 + # Find the first day of the week, counting from below zero, if
1.623 + # necessary, in order to land on the first day of the month as
1.624 + # day number 1.
1.625
1.626 - # End of month.
1.627 -
1.628 - output.append(fmt.table(on=0))
1.629 + first_day = 1 - start_weekday
1.630
1.631 - # Or output a summary view...
1.632 -
1.633 - elif mode == "list":
1.634 -
1.635 - # Output a list.
1.636 + while first_day <= number_of_days:
1.637
1.638 - output.append(fmt.listitem(on=1, attr={"class" : "event-listings-month"}))
1.639 - output.append(fmt.div(on=1, attr={"class" : "event-listings-month-heading"}))
1.640 -
1.641 - # Either write a month heading or produce links for navigable
1.642 - # calendars.
1.643 + # Find events in this week and determine how to mark them on the
1.644 + # calendar.
1.645
1.646 - output.append(view.writeMonthHeading(month))
1.647 -
1.648 - output.append(fmt.div(on=0))
1.649 -
1.650 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-month-listings"}))
1.651 -
1.652 - # Show the events in order.
1.653 + week_start = month.as_date(max(first_day, 1))
1.654 + week_end = month.as_date(min(first_day + 6, number_of_days))
1.655
1.656 - for event in getEventsInPeriod(all_shown_events, getCalendarPeriod(month, month)):
1.657 - event_page = event.getPage()
1.658 - event_details = event.getDetails()
1.659 - event_summary = event.getSummary(parent_name)
1.660 -
1.661 - output.append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
1.662 + full_coverage, week_slots = getCoverage(
1.663 + getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end)))
1.664
1.665 - # Link to the page using the summary.
1.666 + # Output a week, starting with the day numbers.
1.667
1.668 - output.append(fmt.paragraph(on=1))
1.669 - output.append(event_page.linkToPage(request, event_summary))
1.670 - output.append(fmt.paragraph(on=0))
1.671 + output.append(view.writeDayNumbers(first_day, number_of_days, month, full_coverage))
1.672
1.673 - # Start and end dates.
1.674 + # Either generate empty days...
1.675
1.676 - output.append(fmt.paragraph(on=1))
1.677 - output.append(fmt.span(on=1))
1.678 - output.append(fmt.text(str(event_details["start"])))
1.679 - output.append(fmt.span(on=0))
1.680 - output.append(fmt.text(" - "))
1.681 - output.append(fmt.span(on=1))
1.682 - output.append(fmt.text(str(event_details["end"])))
1.683 - output.append(fmt.span(on=0))
1.684 - output.append(fmt.paragraph(on=0))
1.685 + if not week_slots:
1.686 + output.append(view.writeEmptyWeek(first_day, number_of_days))
1.687
1.688 - # Location.
1.689 + # Or generate each set of scheduled events...
1.690
1.691 - if event_details.has_key("location"):
1.692 - output.append(fmt.paragraph(on=1))
1.693 - output.append(formatText(event_details["location"], request, fmt, parser_cls))
1.694 - output.append(fmt.paragraph(on=1))
1.695 -
1.696 - # Topics.
1.697 + else:
1.698 + output.append(view.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots))
1.699
1.700 - if event_details.has_key("topics") or event_details.has_key("categories"):
1.701 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-topics"}))
1.702 + # Process the next week...
1.703
1.704 - for topic in event_details.get("topics") or event_details.get("categories") or []:
1.705 - output.append(fmt.listitem(on=1))
1.706 - output.append(formatText(topic, request, fmt, parser_cls))
1.707 - output.append(fmt.listitem(on=0))
1.708 -
1.709 - output.append(fmt.bullet_list(on=0))
1.710 + first_day += 7
1.711
1.712 - output.append(fmt.listitem(on=0))
1.713 -
1.714 - output.append(fmt.bullet_list(on=0))
1.715 + # End of month.
1.716
1.717 - # Output top-level information.
1.718 -
1.719 - # End of list view output.
1.720 -
1.721 - if mode == "list":
1.722 - output.append(fmt.bullet_list(on=0))
1.723 + output.append(fmt.table(on=0))
1.724
1.725 # Output a day view.
1.726
1.727 @@ -1643,7 +1754,7 @@
1.728
1.729 colspan = sum(map(len, day_slots.values())) * 2 + 2
1.730
1.731 - output.append(view.writeDayHeading(date, colspan))
1.732 + output.append(view.writeDayTableHeading(date, colspan))
1.733
1.734 # Either generate empty days...
1.735