1.1 --- a/EventAggregatorSupport.py Sun Jan 22 00:45:28 2012 +0100
1.2 +++ b/EventAggregatorSupport.py Sun Feb 05 01:29:45 2012 +0100
1.3 @@ -13,7 +13,7 @@
1.4 from MoinSupport import *
1.5
1.6 from MoinMoin.Page import Page
1.7 -from MoinMoin.action import cache
1.8 +from MoinMoin.action import AttachFile, cache
1.9 from MoinMoin import caching
1.10 from MoinMoin import search
1.11 from MoinMoin import wikiutil
1.12 @@ -1362,4 +1362,1851 @@
1.13
1.14 return new_event_page.getBody()
1.15
1.16 +# Colour-related functions.
1.17 +
1.18 +def getColour(s):
1.19 + colour = [0, 0, 0]
1.20 + digit = 0
1.21 + for c in s:
1.22 + colour[digit] += ord(c)
1.23 + colour[digit] = colour[digit] % 256
1.24 + digit += 1
1.25 + digit = digit % 3
1.26 + return tuple(colour)
1.27 +
1.28 +def getBlackOrWhite(colour):
1.29 + if sum(colour) / 3.0 > 127:
1.30 + return (0, 0, 0)
1.31 + else:
1.32 + return (255, 255, 255)
1.33 +
1.34 +# User interface abstractions.
1.35 +
1.36 +class View:
1.37 +
1.38 + "A view of the event calendar."
1.39 +
1.40 + def __init__(self, page, calendar_name, raw_calendar_start, raw_calendar_end,
1.41 + original_calendar_start, original_calendar_end, calendar_start, calendar_end,
1.42 + first, last, category_names, remote_sources, template_name, parent_name, mode,
1.43 + resolution, name_usage, map_name):
1.44 +
1.45 + """
1.46 + Initialise the view with the current 'page', a 'calendar_name' (which
1.47 + may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which
1.48 + are the actual start and end values provided by the request), the
1.49 + calculated 'original_calendar_start' and 'original_calendar_end' (which
1.50 + are the result of calculating the calendar's limits from the raw start
1.51 + and end values), and the requested, calculated 'calendar_start' and
1.52 + 'calendar_end' (which may involve different start and end values due to
1.53 + navigation in the user interface), along with the 'first' and 'last'
1.54 + months of event coverage.
1.55 +
1.56 + The additional 'category_names', 'remote_sources', 'template_name',
1.57 + 'parent_name' and 'mode' parameters are used to configure the links
1.58 + employed by the view.
1.59 +
1.60 + The 'resolution' affects the view for certain modes and is also used to
1.61 + parameterise links.
1.62 +
1.63 + The 'name_usage' parameter controls how names are shown on calendar mode
1.64 + events, such as how often labels are repeated.
1.65 +
1.66 + The 'map_name' parameter provides the name of a map to be used in the
1.67 + map mode.
1.68 + """
1.69 +
1.70 + self.page = page
1.71 + self.calendar_name = calendar_name
1.72 + self.raw_calendar_start = raw_calendar_start
1.73 + self.raw_calendar_end = raw_calendar_end
1.74 + self.original_calendar_start = original_calendar_start
1.75 + self.original_calendar_end = original_calendar_end
1.76 + self.calendar_start = calendar_start
1.77 + self.calendar_end = calendar_end
1.78 + self.template_name = template_name
1.79 + self.parent_name = parent_name
1.80 + self.mode = mode
1.81 + self.resolution = resolution
1.82 + self.name_usage = name_usage
1.83 + self.map_name = map_name
1.84 +
1.85 + self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names])
1.86 + self.remote_source_parameters = "&".join([("source=%s" % source) for source in remote_sources])
1.87 +
1.88 + # Calculate the duration in terms of the highest common unit of time.
1.89 +
1.90 + self.first = first
1.91 + self.last = last
1.92 + self.duration = last - first
1.93 +
1.94 + if self.calendar_name is not None:
1.95 +
1.96 + # Store the view parameters.
1.97 +
1.98 + self.previous_start = first.previous()
1.99 + self.next_start = first.next()
1.100 + self.previous_end = last.previous()
1.101 + self.next_end = last.next()
1.102 +
1.103 + self.previous_set_start = first.update(-self.duration)
1.104 + self.next_set_start = first.update(self.duration)
1.105 + self.previous_set_end = last.update(-self.duration)
1.106 + self.next_set_end = last.update(self.duration)
1.107 +
1.108 + def getIdentifier(self):
1.109 +
1.110 + "Return a unique identifier to be used to refer to this view."
1.111 +
1.112 + # NOTE: Nasty hack to get a unique identifier if no name is given.
1.113 +
1.114 + return self.calendar_name or str(id(self))
1.115 +
1.116 + def getQualifiedParameterName(self, argname):
1.117 +
1.118 + "Return the 'argname' qualified using the calendar name."
1.119 +
1.120 + return getQualifiedParameterName(self.calendar_name, argname)
1.121 +
1.122 + def getDateQueryString(self, argname, date, prefix=1):
1.123 +
1.124 + """
1.125 + Return a query string fragment for the given 'argname', referring to the
1.126 + month given by the specified 'year_month' object, appropriate for this
1.127 + calendar.
1.128 +
1.129 + If 'prefix' is specified and set to a false value, the parameters in the
1.130 + query string will not be calendar-specific, but could be used with the
1.131 + summary action.
1.132 + """
1.133 +
1.134 + suffixes = ["year", "month", "day"]
1.135 +
1.136 + if date is not None:
1.137 + args = []
1.138 + for suffix, value in zip(suffixes, date.as_tuple()):
1.139 + suffixed_argname = "%s-%s" % (argname, suffix)
1.140 + if prefix:
1.141 + suffixed_argname = self.getQualifiedParameterName(suffixed_argname)
1.142 + args.append("%s=%s" % (suffixed_argname, value))
1.143 + return "&".join(args)
1.144 + else:
1.145 + return ""
1.146 +
1.147 + def getRawDateQueryString(self, argname, date, prefix=1):
1.148 +
1.149 + """
1.150 + Return a query string fragment for the given 'argname', referring to the
1.151 + date given by the specified 'date' value, appropriate for this
1.152 + calendar.
1.153 +
1.154 + If 'prefix' is specified and set to a false value, the parameters in the
1.155 + query string will not be calendar-specific, but could be used with the
1.156 + summary action.
1.157 + """
1.158 +
1.159 + if date is not None:
1.160 + if prefix:
1.161 + argname = self.getQualifiedParameterName(argname)
1.162 + return "%s=%s" % (argname, wikiutil.url_quote_plus(date))
1.163 + else:
1.164 + return ""
1.165 +
1.166 + def getNavigationLink(self, start, end, mode=None, resolution=None):
1.167 +
1.168 + """
1.169 + Return a query string fragment for navigation to a view showing months
1.170 + from 'start' to 'end' inclusive, with the optional 'mode' indicating the
1.171 + view style and the optional 'resolution' indicating the resolution of a
1.172 + view, if configurable.
1.173 + """
1.174 +
1.175 + return "%s&%s&%s=%s&%s=%s" % (
1.176 + self.getRawDateQueryString("start", start),
1.177 + self.getRawDateQueryString("end", end),
1.178 + self.getQualifiedParameterName("mode"), mode or self.mode,
1.179 + self.getQualifiedParameterName("resolution"), resolution or self.resolution
1.180 + )
1.181 +
1.182 + def getUpdateLink(self, start, end, mode=None, resolution=None):
1.183 +
1.184 + """
1.185 + Return a query string fragment for navigation to a view showing months
1.186 + from 'start' to 'end' inclusive, with the optional 'mode' indicating the
1.187 + view style and the optional 'resolution' indicating the resolution of a
1.188 + view, if configurable. This link differs from the conventional
1.189 + navigation link in that it is sufficient to activate the update action
1.190 + and produce an updated region of the page without needing to locate and
1.191 + process the page or any macro invocation.
1.192 + """
1.193 +
1.194 + return "calendar=%s&%s&%s&%s=%s&%s=%s" % (
1.195 + self.calendar_name,
1.196 + self.getRawDateQueryString("start", start),
1.197 + self.getRawDateQueryString("end", end),
1.198 + self.getQualifiedParameterName("mode"), mode or self.mode,
1.199 + self.getQualifiedParameterName("resolution"), resolution or self.resolution
1.200 + )
1.201 +
1.202 + def getNewEventLink(self, start):
1.203 +
1.204 + """
1.205 + Return a query string activating the new event form, incorporating the
1.206 + calendar parameters, specialising the form for the given 'start' date or
1.207 + month.
1.208 + """
1.209 +
1.210 + if start is not None:
1.211 + details = start.as_tuple()
1.212 + pairs = zip(["start-year=%d", "start-month=%d", "start-day=%d"], details)
1.213 + args = [(param % value) for (param, value) in pairs]
1.214 + args = "&".join(args)
1.215 + else:
1.216 + args = ""
1.217 +
1.218 + # Prepare navigation details for the calendar shown with the new event
1.219 + # form.
1.220 +
1.221 + navigation_link = self.getNavigationLink(
1.222 + self.calendar_start, self.calendar_end
1.223 + )
1.224 +
1.225 + return "action=EventAggregatorNewEvent&%s&%s&template=%s&parent=%s&%s" % (
1.226 + args, self.category_name_parameters, self.template_name, self.parent_name or "",
1.227 + navigation_link)
1.228 +
1.229 + def getFullDateLabel(self, date):
1.230 + page = self.page
1.231 + request = page.request
1.232 + return getFullDateLabel(request, date)
1.233 +
1.234 + def getFullMonthLabel(self, year_month):
1.235 + page = self.page
1.236 + request = page.request
1.237 + return getFullMonthLabel(request, year_month)
1.238 +
1.239 + def getFullLabel(self, arg):
1.240 + return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg)
1.241 +
1.242 + def _getCalendarPeriod(self, start_label, end_label, default_label):
1.243 + output = []
1.244 + if start_label:
1.245 + output.append(start_label)
1.246 + if end_label and start_label != end_label:
1.247 + if output:
1.248 + output.append(" - ")
1.249 + output.append(end_label)
1.250 + return "".join(output) or default_label
1.251 +
1.252 + def getCalendarPeriod(self):
1.253 + _ = self.page.request.getText
1.254 + return self._getCalendarPeriod(
1.255 + self.calendar_start and self.getFullLabel(self.calendar_start),
1.256 + self.calendar_end and self.getFullLabel(self.calendar_end),
1.257 + _("All events")
1.258 + )
1.259 +
1.260 + def getOriginalCalendarPeriod(self):
1.261 + _ = self.page.request.getText
1.262 + return self._getCalendarPeriod(
1.263 + self.original_calendar_start and self.getFullLabel(self.original_calendar_start),
1.264 + self.original_calendar_end and self.getFullLabel(self.original_calendar_end),
1.265 + _("All events")
1.266 + )
1.267 +
1.268 + def getRawCalendarPeriod(self):
1.269 + _ = self.page.request.getText
1.270 + return self._getCalendarPeriod(
1.271 + self.raw_calendar_start,
1.272 + self.raw_calendar_end,
1.273 + _("No period specified")
1.274 + )
1.275 +
1.276 + def writeDownloadControls(self):
1.277 +
1.278 + """
1.279 + Return a representation of the download controls, featuring links for
1.280 + view, calendar and customised downloads and subscriptions.
1.281 + """
1.282 +
1.283 + page = self.page
1.284 + request = page.request
1.285 + fmt = page.formatter
1.286 + _ = request.getText
1.287 +
1.288 + output = []
1.289 +
1.290 + # The full URL is needed for webcal links.
1.291 +
1.292 + full_url = "%s%s" % (request.getBaseURL(), getPathInfo(request))
1.293 +
1.294 + # Generate the links.
1.295 +
1.296 + download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&%s&%s" % (
1.297 + self.parent_name or "",
1.298 + self.resolution,
1.299 + self.category_name_parameters,
1.300 + self.remote_source_parameters
1.301 + )
1.302 + download_all_link = download_dialogue_link + "&doit=1"
1.303 + download_link = download_all_link + ("&%s&%s" % (
1.304 + self.getDateQueryString("start", self.calendar_start, prefix=0),
1.305 + self.getDateQueryString("end", self.calendar_end, prefix=0)
1.306 + ))
1.307 +
1.308 + # Subscription links just explicitly select the RSS format.
1.309 +
1.310 + subscribe_dialogue_link = download_dialogue_link + "&format=RSS"
1.311 + subscribe_all_link = download_all_link + "&format=RSS"
1.312 + subscribe_link = download_link + "&format=RSS"
1.313 +
1.314 + # Adjust the "download all" and "subscribe all" links if the calendar
1.315 + # has an inherent period associated with it.
1.316 +
1.317 + period_limits = []
1.318 +
1.319 + if self.raw_calendar_start:
1.320 + period_limits.append("&%s" %
1.321 + self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0)
1.322 + )
1.323 + if self.raw_calendar_end:
1.324 + period_limits.append("&%s" %
1.325 + self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0)
1.326 + )
1.327 +
1.328 + period_limits = "".join(period_limits)
1.329 +
1.330 + download_dialogue_link += period_limits
1.331 + download_all_link += period_limits
1.332 + subscribe_dialogue_link += period_limits
1.333 + subscribe_all_link += period_limits
1.334 +
1.335 + # Pop-up descriptions of the downloadable calendars.
1.336 +
1.337 + calendar_period = self.getCalendarPeriod()
1.338 + original_calendar_period = self.getOriginalCalendarPeriod()
1.339 + raw_calendar_period = self.getRawCalendarPeriod()
1.340 +
1.341 + # Write the controls.
1.342 +
1.343 + # Download controls.
1.344 +
1.345 + output.append(fmt.div(on=1, css_class="event-download-controls"))
1.346 +
1.347 + output.append(fmt.span(on=1, css_class="event-download"))
1.348 + output.append(fmt.text(_("Download...")))
1.349 + output.append(fmt.div(on=1, css_class="event-download-popup"))
1.350 +
1.351 + output.append(fmt.div(on=1, css_class="event-download-item"))
1.352 + output.append(fmt.span(on=1, css_class="event-download-types"))
1.353 + output.append(fmt.span(on=1, css_class="event-download-webcal"))
1.354 + output.append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_link))
1.355 + output.append(fmt.span(on=0))
1.356 + output.append(fmt.span(on=1, css_class="event-download-http"))
1.357 + output.append(linkToPage(request, page, _("http"), download_link))
1.358 + output.append(fmt.span(on=0))
1.359 + output.append(fmt.span(on=0)) # end types
1.360 + output.append(fmt.span(on=1, css_class="event-download-label"))
1.361 + output.append(fmt.text(_("Download this view")))
1.362 + output.append(fmt.span(on=0)) # end label
1.363 + output.append(fmt.span(on=1, css_class="event-download-period"))
1.364 + output.append(fmt.text(calendar_period))
1.365 + output.append(fmt.span(on=0))
1.366 + output.append(fmt.div(on=0))
1.367 +
1.368 + output.append(fmt.div(on=1, css_class="event-download-item"))
1.369 + output.append(fmt.span(on=1, css_class="event-download-types"))
1.370 + output.append(fmt.span(on=1, css_class="event-download-webcal"))
1.371 + output.append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_all_link))
1.372 + output.append(fmt.span(on=0))
1.373 + output.append(fmt.span(on=1, css_class="event-download-http"))
1.374 + output.append(linkToPage(request, page, _("http"), download_all_link))
1.375 + output.append(fmt.span(on=0))
1.376 + output.append(fmt.span(on=0)) # end types
1.377 + output.append(fmt.span(on=1, css_class="event-download-label"))
1.378 + output.append(fmt.text(_("Download this calendar")))
1.379 + output.append(fmt.span(on=0)) # end label
1.380 + output.append(fmt.span(on=1, css_class="event-download-period"))
1.381 + output.append(fmt.text(original_calendar_period))
1.382 + output.append(fmt.span(on=0))
1.383 + output.append(fmt.span(on=1, css_class="event-download-period-raw"))
1.384 + output.append(fmt.text(raw_calendar_period))
1.385 + output.append(fmt.span(on=0))
1.386 + output.append(fmt.div(on=0))
1.387 +
1.388 + output.append(fmt.div(on=1, css_class="event-download-item"))
1.389 + output.append(fmt.span(on=1, css_class="event-download-link"))
1.390 + output.append(linkToPage(request, page, _("Edit download options..."), download_dialogue_link))
1.391 + output.append(fmt.span(on=0)) # end label
1.392 + output.append(fmt.div(on=0))
1.393 +
1.394 + output.append(fmt.div(on=0)) # end of pop-up
1.395 + output.append(fmt.span(on=0)) # end of download
1.396 +
1.397 + # Subscription controls.
1.398 +
1.399 + output.append(fmt.span(on=1, css_class="event-download"))
1.400 + output.append(fmt.text(_("Subscribe...")))
1.401 + output.append(fmt.div(on=1, css_class="event-download-popup"))
1.402 +
1.403 + output.append(fmt.div(on=1, css_class="event-download-item"))
1.404 + output.append(fmt.span(on=1, css_class="event-download-label"))
1.405 + output.append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link))
1.406 + output.append(fmt.span(on=0)) # end label
1.407 + output.append(fmt.span(on=1, css_class="event-download-period"))
1.408 + output.append(fmt.text(calendar_period))
1.409 + output.append(fmt.span(on=0))
1.410 + output.append(fmt.div(on=0))
1.411 +
1.412 + output.append(fmt.div(on=1, css_class="event-download-item"))
1.413 + output.append(fmt.span(on=1, css_class="event-download-label"))
1.414 + output.append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link))
1.415 + output.append(fmt.span(on=0)) # end label
1.416 + output.append(fmt.span(on=1, css_class="event-download-period"))
1.417 + output.append(fmt.text(original_calendar_period))
1.418 + output.append(fmt.span(on=0))
1.419 + output.append(fmt.span(on=1, css_class="event-download-period-raw"))
1.420 + output.append(fmt.text(raw_calendar_period))
1.421 + output.append(fmt.span(on=0))
1.422 + output.append(fmt.div(on=0))
1.423 +
1.424 + output.append(fmt.div(on=1, css_class="event-download-item"))
1.425 + output.append(fmt.span(on=1, css_class="event-download-link"))
1.426 + output.append(linkToPage(request, page, _("Edit subscription options..."), subscribe_dialogue_link))
1.427 + output.append(fmt.span(on=0)) # end label
1.428 + output.append(fmt.div(on=0))
1.429 +
1.430 + output.append(fmt.div(on=0)) # end of pop-up
1.431 + output.append(fmt.span(on=0)) # end of download
1.432 +
1.433 + output.append(fmt.div(on=0)) # end of controls
1.434 +
1.435 + return "".join(output)
1.436 +
1.437 + def writeViewControls(self):
1.438 +
1.439 + """
1.440 + Return a representation of the view mode controls, permitting viewing of
1.441 + aggregated events in calendar, list or table form.
1.442 + """
1.443 +
1.444 + page = self.page
1.445 + request = page.request
1.446 + fmt = page.formatter
1.447 + _ = request.getText
1.448 +
1.449 + output = []
1.450 +
1.451 + start = self.calendar_start
1.452 + end = self.calendar_end
1.453 +
1.454 + help_page = Page(request, "HelpOnEventAggregator")
1.455 + calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
1.456 + list_link = self.getNavigationLink(start, end, "list")
1.457 + table_link = self.getNavigationLink(start, end, "table")
1.458 + map_link = self.getNavigationLink(start, end, "map")
1.459 + new_event_link = self.getNewEventLink(start)
1.460 +
1.461 + # Write the controls.
1.462 +
1.463 + output.append(fmt.div(on=1, css_class="event-view-controls"))
1.464 +
1.465 + output.append(fmt.span(on=1, css_class="event-view"))
1.466 + output.append(linkToPage(request, help_page, _("Help")))
1.467 + output.append(fmt.span(on=0))
1.468 +
1.469 + output.append(fmt.span(on=1, css_class="event-view"))
1.470 + output.append(linkToPage(request, page, _("New event"), new_event_link))
1.471 + output.append(fmt.span(on=0))
1.472 +
1.473 + if self.mode != "calendar":
1.474 + output.append(fmt.span(on=1, css_class="event-view"))
1.475 + output.append(linkToPage(request, page, _("View as calendar"), calendar_link))
1.476 + output.append(fmt.span(on=0))
1.477 +
1.478 + if self.mode != "list":
1.479 + output.append(fmt.span(on=1, css_class="event-view"))
1.480 + output.append(linkToPage(request, page, _("View as list"), list_link))
1.481 + output.append(fmt.span(on=0))
1.482 +
1.483 + if self.mode != "table":
1.484 + output.append(fmt.span(on=1, css_class="event-view"))
1.485 + output.append(linkToPage(request, page, _("View as table"), table_link))
1.486 + output.append(fmt.span(on=0))
1.487 +
1.488 + if self.mode != "map" and self.map_name is not None:
1.489 + output.append(fmt.span(on=1, css_class="event-view"))
1.490 + output.append(linkToPage(request, page, _("View as map"), map_link))
1.491 + output.append(fmt.span(on=0))
1.492 +
1.493 + output.append(fmt.div(on=0))
1.494 +
1.495 + return "".join(output)
1.496 +
1.497 + def writeMapHeading(self):
1.498 +
1.499 + """
1.500 + Return the calendar heading for the current calendar, providing links
1.501 + permitting navigation to other periods.
1.502 + """
1.503 +
1.504 + label = self.getCalendarPeriod()
1.505 +
1.506 + if self.raw_calendar_start is None or self.raw_calendar_end is None:
1.507 + fmt = self.page.formatter
1.508 + output = []
1.509 + output.append(fmt.span(on=1))
1.510 + output.append(fmt.text(label))
1.511 + output.append(fmt.span(on=0))
1.512 + return "".join(output)
1.513 + else:
1.514 + return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end)
1.515 +
1.516 + def writeDateHeading(self, date):
1.517 + if isinstance(date, Date):
1.518 + return self.writeDayHeading(date)
1.519 + else:
1.520 + return self.writeMonthHeading(date)
1.521 +
1.522 + def writeMonthHeading(self, year_month):
1.523 +
1.524 + """
1.525 + Return the calendar heading for the given 'year_month' (a Month object)
1.526 + providing links permitting navigation to other months.
1.527 + """
1.528 +
1.529 + full_month_label = self.getFullMonthLabel(year_month)
1.530 + end_month = year_month.update(self.duration - 1)
1.531 + return self._writeCalendarHeading(full_month_label, year_month, end_month)
1.532 +
1.533 + def writeDayHeading(self, date):
1.534 +
1.535 + """
1.536 + Return the calendar heading for the given 'date' (a Date object)
1.537 + providing links permitting navigation to other dates.
1.538 + """
1.539 +
1.540 + full_date_label = self.getFullDateLabel(date)
1.541 + end_date = date.update(self.duration - 1)
1.542 + return self._writeCalendarHeading(full_date_label, date, end_date)
1.543 +
1.544 + def _writeCalendarHeading(self, label, start, end):
1.545 +
1.546 + """
1.547 + Write a calendar heading providing links permitting navigation to other
1.548 + periods, using the given 'label' along with the 'start' and 'end' dates
1.549 + to provide a link to a particular period.
1.550 + """
1.551 +
1.552 + page = self.page
1.553 + request = page.request
1.554 + fmt = page.formatter
1.555 + _ = request.getText
1.556 +
1.557 + output = []
1.558 +
1.559 + # Prepare navigation links.
1.560 +
1.561 + if self.calendar_name is not None:
1.562 + calendar_name = self.calendar_name
1.563 +
1.564 + # Links to the previous set of months and to a calendar shifted
1.565 + # back one month.
1.566 +
1.567 + previous_set_link = self.getNavigationLink(
1.568 + self.previous_set_start, self.previous_set_end
1.569 + )
1.570 + previous_link = self.getNavigationLink(
1.571 + self.previous_start, self.previous_end
1.572 + )
1.573 +
1.574 + # Links to the next set of months and to a calendar shifted
1.575 + # forward one month.
1.576 +
1.577 + next_set_link = self.getNavigationLink(
1.578 + self.next_set_start, self.next_set_end
1.579 + )
1.580 + next_link = self.getNavigationLink(
1.581 + self.next_start, self.next_end
1.582 + )
1.583 +
1.584 + # A link leading to this date being at the top of the calendar.
1.585 +
1.586 + date_link = self.getNavigationLink(start, end)
1.587 +
1.588 + output.append(fmt.span(on=1, css_class="previous"))
1.589 + output.append(linkToPage(request, page, "<<", previous_set_link))
1.590 + output.append(fmt.text(" "))
1.591 + output.append(linkToPage(request, page, "<", previous_link))
1.592 + output.append(fmt.span(on=0))
1.593 +
1.594 + output.append(fmt.span(on=1, css_class="next"))
1.595 + output.append(linkToPage(request, page, ">", next_link))
1.596 + output.append(fmt.text(" "))
1.597 + output.append(linkToPage(request, page, ">>", next_set_link))
1.598 + output.append(fmt.span(on=0))
1.599 +
1.600 + output.append(linkToPage(request, page, label, date_link))
1.601 +
1.602 + else:
1.603 + output.append(fmt.span(on=1))
1.604 + output.append(fmt.text(label))
1.605 + output.append(fmt.span(on=0))
1.606 +
1.607 + return "".join(output)
1.608 +
1.609 + def writeDayNumberHeading(self, date, busy):
1.610 +
1.611 + """
1.612 + Return a link for the given 'date' which will activate the new event
1.613 + action for the given day. If 'busy' is given as a true value, the
1.614 + heading will be marked as busy.
1.615 + """
1.616 +
1.617 + page = self.page
1.618 + request = page.request
1.619 + fmt = page.formatter
1.620 + _ = request.getText
1.621 +
1.622 + output = []
1.623 +
1.624 + year, month, day = date.as_tuple()
1.625 + new_event_link = self.getNewEventLink(date)
1.626 +
1.627 + # Prepare a link to the day view for this day.
1.628 +
1.629 + day_view_link = self.getNavigationLink(date, date, "day", "date")
1.630 +
1.631 + # Output the heading class.
1.632 +
1.633 + output.append(
1.634 + fmt.table_cell(on=1, attrs={
1.635 + "class" : "event-day-heading event-day-%s" % (busy and "busy" or "empty"),
1.636 + "colspan" : "3"
1.637 + }))
1.638 +
1.639 + # Output the number and pop-up menu.
1.640 +
1.641 + output.append(fmt.div(on=1, css_class="event-day-box"))
1.642 +
1.643 + output.append(fmt.span(on=1, css_class="event-day-number-popup"))
1.644 + output.append(fmt.span(on=1, css_class="event-day-number-link"))
1.645 + output.append(linkToPage(request, page, _("View day"), day_view_link))
1.646 + output.append(fmt.span(on=0))
1.647 + output.append(fmt.span(on=1, css_class="event-day-number-link"))
1.648 + output.append(linkToPage(request, page, _("New event"), new_event_link))
1.649 + output.append(fmt.span(on=0))
1.650 + output.append(fmt.span(on=0))
1.651 +
1.652 + output.append(fmt.span(on=1, css_class="event-day-number"))
1.653 + output.append(fmt.text(unicode(day)))
1.654 + output.append(fmt.span(on=0))
1.655 +
1.656 + output.append(fmt.div(on=0))
1.657 +
1.658 + # End of heading.
1.659 +
1.660 + output.append(fmt.table_cell(on=0))
1.661 +
1.662 + return "".join(output)
1.663 +
1.664 + # Common layout methods.
1.665 +
1.666 + def getEventStyle(self, colour_seed):
1.667 +
1.668 + "Generate colour style information using the given 'colour_seed'."
1.669 +
1.670 + bg = getColour(colour_seed)
1.671 + fg = getBlackOrWhite(bg)
1.672 + return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg)
1.673 +
1.674 + def writeEventSummaryBox(self, event):
1.675 +
1.676 + "Return an event summary box linking to the given 'event'."
1.677 +
1.678 + page = self.page
1.679 + request = page.request
1.680 + fmt = page.formatter
1.681 +
1.682 + output = []
1.683 +
1.684 + event_details = event.getDetails()
1.685 + event_summary = event.getSummary(self.parent_name)
1.686 +
1.687 + is_ambiguous = event.as_timespan().ambiguous()
1.688 + style = self.getEventStyle(event_summary)
1.689 +
1.690 + # The event box contains the summary, alongside
1.691 + # other elements.
1.692 +
1.693 + output.append(fmt.div(on=1, css_class="event-summary-box"))
1.694 + output.append(fmt.div(on=1, css_class="event-summary", style=style))
1.695 +
1.696 + if is_ambiguous:
1.697 + output.append(fmt.icon("/!\\"))
1.698 +
1.699 + output.append(event.linkToEvent(request, event_summary))
1.700 + output.append(fmt.div(on=0))
1.701 +
1.702 + # Add a pop-up element for long summaries.
1.703 +
1.704 + output.append(fmt.div(on=1, css_class="event-summary-popup", style=style))
1.705 +
1.706 + if is_ambiguous:
1.707 + output.append(fmt.icon("/!\\"))
1.708 +
1.709 + output.append(event.linkToEvent(request, event_summary))
1.710 + output.append(fmt.div(on=0))
1.711 +
1.712 + output.append(fmt.div(on=0))
1.713 +
1.714 + return "".join(output)
1.715 +
1.716 + # Calendar layout methods.
1.717 +
1.718 + def writeMonthTableHeading(self, year_month):
1.719 + page = self.page
1.720 + fmt = page.formatter
1.721 +
1.722 + output = []
1.723 + output.append(fmt.table_row(on=1))
1.724 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"}))
1.725 +
1.726 + output.append(self.writeMonthHeading(year_month))
1.727 +
1.728 + output.append(fmt.table_cell(on=0))
1.729 + output.append(fmt.table_row(on=0))
1.730 +
1.731 + return "".join(output)
1.732 +
1.733 + def writeWeekdayHeadings(self):
1.734 + page = self.page
1.735 + request = page.request
1.736 + fmt = page.formatter
1.737 + _ = request.getText
1.738 +
1.739 + output = []
1.740 + output.append(fmt.table_row(on=1))
1.741 +
1.742 + for weekday in range(0, 7):
1.743 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"}))
1.744 + output.append(fmt.text(_(getDayLabel(weekday))))
1.745 + output.append(fmt.table_cell(on=0))
1.746 +
1.747 + output.append(fmt.table_row(on=0))
1.748 + return "".join(output)
1.749 +
1.750 + def writeDayNumbers(self, first_day, number_of_days, month, coverage):
1.751 + page = self.page
1.752 + fmt = page.formatter
1.753 +
1.754 + output = []
1.755 + output.append(fmt.table_row(on=1))
1.756 +
1.757 + for weekday in range(0, 7):
1.758 + day = first_day + weekday
1.759 + date = month.as_date(day)
1.760 +
1.761 + # Output out-of-month days.
1.762 +
1.763 + if day < 1 or day > number_of_days:
1.764 + output.append(fmt.table_cell(on=1,
1.765 + attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"}))
1.766 + output.append(fmt.table_cell(on=0))
1.767 +
1.768 + # Output normal days.
1.769 +
1.770 + else:
1.771 + # Output the day heading, making a link to a new event
1.772 + # action.
1.773 +
1.774 + output.append(self.writeDayNumberHeading(date, date in coverage))
1.775 +
1.776 + # End of day numbers.
1.777 +
1.778 + output.append(fmt.table_row(on=0))
1.779 + return "".join(output)
1.780 +
1.781 + def writeEmptyWeek(self, first_day, number_of_days):
1.782 + page = self.page
1.783 + fmt = page.formatter
1.784 +
1.785 + output = []
1.786 + output.append(fmt.table_row(on=1))
1.787 +
1.788 + for weekday in range(0, 7):
1.789 + day = first_day + weekday
1.790 +
1.791 + # Output out-of-month days.
1.792 +
1.793 + if day < 1 or day > number_of_days:
1.794 + output.append(fmt.table_cell(on=1,
1.795 + attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"}))
1.796 + output.append(fmt.table_cell(on=0))
1.797 +
1.798 + # Output empty days.
1.799 +
1.800 + else:
1.801 + output.append(fmt.table_cell(on=1,
1.802 + attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"}))
1.803 +
1.804 + output.append(fmt.table_row(on=0))
1.805 + return "".join(output)
1.806 +
1.807 + def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots):
1.808 + output = []
1.809 +
1.810 + locations = week_slots.keys()
1.811 + locations.sort(sort_none_first)
1.812 +
1.813 + # Visit each slot corresponding to a location (or no location).
1.814 +
1.815 + for location in locations:
1.816 +
1.817 + # Visit each coverage span, presenting the events in the span.
1.818 +
1.819 + for events in week_slots[location]:
1.820 +
1.821 + # Output each set.
1.822 +
1.823 + output.append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events))
1.824 +
1.825 + # Add a spacer.
1.826 +
1.827 + output.append(self.writeWeekSpacer(first_day, number_of_days))
1.828 +
1.829 + return "".join(output)
1.830 +
1.831 + def writeWeekSlot(self, first_day, number_of_days, month, week_end, events):
1.832 + page = self.page
1.833 + request = page.request
1.834 + fmt = page.formatter
1.835 +
1.836 + output = []
1.837 + output.append(fmt.table_row(on=1))
1.838 +
1.839 + # Then, output day details.
1.840 +
1.841 + for weekday in range(0, 7):
1.842 + day = first_day + weekday
1.843 + date = month.as_date(day)
1.844 +
1.845 + # Skip out-of-month days.
1.846 +
1.847 + if day < 1 or day > number_of_days:
1.848 + output.append(fmt.table_cell(on=1,
1.849 + attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"}))
1.850 + output.append(fmt.table_cell(on=0))
1.851 + continue
1.852 +
1.853 + # Output the day.
1.854 +
1.855 + if date not in events:
1.856 + output.append(fmt.table_cell(on=1,
1.857 + attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"}))
1.858 +
1.859 + # Get event details for the current day.
1.860 +
1.861 + for event in events:
1.862 + event_details = event.getDetails()
1.863 +
1.864 + if date not in event:
1.865 + continue
1.866 +
1.867 + # Get basic properties of the event.
1.868 +
1.869 + starts_today = event_details["start"] == date
1.870 + ends_today = event_details["end"] == date
1.871 + event_summary = event.getSummary(self.parent_name)
1.872 +
1.873 + style = self.getEventStyle(event_summary)
1.874 +
1.875 + # Determine if the event name should be shown.
1.876 +
1.877 + start_of_period = starts_today or weekday == 0 or day == 1
1.878 +
1.879 + if self.name_usage == "daily" or start_of_period:
1.880 + hide_text = 0
1.881 + else:
1.882 + hide_text = 1
1.883 +
1.884 + # Output start of day gap and determine whether
1.885 + # any event content should be explicitly output
1.886 + # for this day.
1.887 +
1.888 + if starts_today:
1.889 +
1.890 + # Single day events...
1.891 +
1.892 + if ends_today:
1.893 + colspan = 3
1.894 + event_day_type = "event-day-single"
1.895 +
1.896 + # Events starting today...
1.897 +
1.898 + else:
1.899 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap"}))
1.900 + output.append(fmt.table_cell(on=0))
1.901 +
1.902 + # Calculate the span of this cell.
1.903 + # Events whose names appear on every day...
1.904 +
1.905 + if self.name_usage == "daily":
1.906 + colspan = 2
1.907 + event_day_type = "event-day-starting"
1.908 +
1.909 + # Events whose names appear once per week...
1.910 +
1.911 + else:
1.912 + if event_details["end"] <= week_end:
1.913 + event_length = event_details["end"].day() - day + 1
1.914 + colspan = (event_length - 2) * 3 + 4
1.915 + else:
1.916 + event_length = week_end.day() - day + 1
1.917 + colspan = (event_length - 1) * 3 + 2
1.918 +
1.919 + event_day_type = "event-day-multiple"
1.920 +
1.921 + # Events continuing from a previous week...
1.922 +
1.923 + elif start_of_period:
1.924 +
1.925 + # End of continuing event...
1.926 +
1.927 + if ends_today:
1.928 + colspan = 2
1.929 + event_day_type = "event-day-ending"
1.930 +
1.931 + # Events continuing for at least one more day...
1.932 +
1.933 + else:
1.934 +
1.935 + # Calculate the span of this cell.
1.936 + # Events whose names appear on every day...
1.937 +
1.938 + if self.name_usage == "daily":
1.939 + colspan = 3
1.940 + event_day_type = "event-day-full"
1.941 +
1.942 + # Events whose names appear once per week...
1.943 +
1.944 + else:
1.945 + if event_details["end"] <= week_end:
1.946 + event_length = event_details["end"].day() - day + 1
1.947 + colspan = (event_length - 1) * 3 + 2
1.948 + else:
1.949 + event_length = week_end.day() - day + 1
1.950 + colspan = event_length * 3
1.951 +
1.952 + event_day_type = "event-day-multiple"
1.953 +
1.954 + # Continuing events whose names appear on every day...
1.955 +
1.956 + elif self.name_usage == "daily":
1.957 + if ends_today:
1.958 + colspan = 2
1.959 + event_day_type = "event-day-ending"
1.960 + else:
1.961 + colspan = 3
1.962 + event_day_type = "event-day-full"
1.963 +
1.964 + # Continuing events whose names appear once per week...
1.965 +
1.966 + else:
1.967 + colspan = None
1.968 +
1.969 + # Output the main content only if it is not
1.970 + # continuing from a previous day.
1.971 +
1.972 + if colspan is not None:
1.973 +
1.974 + # Colour the cell for continuing events.
1.975 +
1.976 + attrs={
1.977 + "class" : "event-day-content event-day-busy %s" % event_day_type,
1.978 + "colspan" : str(colspan)
1.979 + }
1.980 +
1.981 + if not (starts_today and ends_today):
1.982 + attrs["style"] = style
1.983 +
1.984 + output.append(fmt.table_cell(on=1, attrs=attrs))
1.985 +
1.986 + # Output the event.
1.987 +
1.988 + if starts_today and ends_today or not hide_text:
1.989 + output.append(self.writeEventSummaryBox(event))
1.990 +
1.991 + output.append(fmt.table_cell(on=0))
1.992 +
1.993 + # Output end of day gap.
1.994 +
1.995 + if ends_today and not starts_today:
1.996 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap"}))
1.997 + output.append(fmt.table_cell(on=0))
1.998 +
1.999 + # End of set.
1.1000 +
1.1001 + output.append(fmt.table_row(on=0))
1.1002 + return "".join(output)
1.1003 +
1.1004 + def writeWeekSpacer(self, first_day, number_of_days):
1.1005 + page = self.page
1.1006 + fmt = page.formatter
1.1007 +
1.1008 + output = []
1.1009 + output.append(fmt.table_row(on=1))
1.1010 +
1.1011 + for weekday in range(0, 7):
1.1012 + day = first_day + weekday
1.1013 + css_classes = "event-day-spacer"
1.1014 +
1.1015 + # Skip out-of-month days.
1.1016 +
1.1017 + if day < 1 or day > number_of_days:
1.1018 + css_classes += " event-day-excluded"
1.1019 +
1.1020 + output.append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"}))
1.1021 + output.append(fmt.table_cell(on=0))
1.1022 +
1.1023 + output.append(fmt.table_row(on=0))
1.1024 + return "".join(output)
1.1025 +
1.1026 + # Day layout methods.
1.1027 +
1.1028 + def writeDayTableHeading(self, date, colspan=1):
1.1029 + page = self.page
1.1030 + fmt = page.formatter
1.1031 +
1.1032 + output = []
1.1033 + output.append(fmt.table_row(on=1))
1.1034 +
1.1035 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)}))
1.1036 + output.append(self.writeDayHeading(date))
1.1037 + output.append(fmt.table_cell(on=0))
1.1038 +
1.1039 + output.append(fmt.table_row(on=0))
1.1040 + return "".join(output)
1.1041 +
1.1042 + def writeEmptyDay(self, date):
1.1043 + page = self.page
1.1044 + fmt = page.formatter
1.1045 +
1.1046 + output = []
1.1047 + output.append(fmt.table_row(on=1))
1.1048 +
1.1049 + output.append(fmt.table_cell(on=1,
1.1050 + attrs={"class" : "event-day-content event-day-empty"}))
1.1051 +
1.1052 + output.append(fmt.table_row(on=0))
1.1053 + return "".join(output)
1.1054 +
1.1055 + def writeDaySlots(self, date, full_coverage, day_slots):
1.1056 +
1.1057 + """
1.1058 + Given a 'date', non-empty 'full_coverage' for the day concerned, and a
1.1059 + non-empty mapping of 'day_slots' (from locations to event collections),
1.1060 + output the day slots for the day.
1.1061 + """
1.1062 +
1.1063 + page = self.page
1.1064 + fmt = page.formatter
1.1065 +
1.1066 + output = []
1.1067 +
1.1068 + locations = day_slots.keys()
1.1069 + locations.sort(sort_none_first)
1.1070 +
1.1071 + # Traverse the time scale of the full coverage, visiting each slot to
1.1072 + # determine whether it provides content for each period.
1.1073 +
1.1074 + scale = getCoverageScale(full_coverage)
1.1075 +
1.1076 + # Define a mapping of events to rowspans.
1.1077 +
1.1078 + rowspans = {}
1.1079 +
1.1080 + # Populate each period with event details, recording how many periods
1.1081 + # each event populates.
1.1082 +
1.1083 + day_rows = []
1.1084 +
1.1085 + for period in scale:
1.1086 +
1.1087 + # Ignore timespans before this day.
1.1088 +
1.1089 + if period != date:
1.1090 + continue
1.1091 +
1.1092 + # Visit each slot corresponding to a location (or no location).
1.1093 +
1.1094 + day_row = []
1.1095 +
1.1096 + for location in locations:
1.1097 +
1.1098 + # Visit each coverage span, presenting the events in the span.
1.1099 +
1.1100 + for events in day_slots[location]:
1.1101 + event = self.getActiveEvent(period, events)
1.1102 + if event is not None:
1.1103 + if not rowspans.has_key(event):
1.1104 + rowspans[event] = 1
1.1105 + else:
1.1106 + rowspans[event] += 1
1.1107 + day_row.append((location, event))
1.1108 +
1.1109 + day_rows.append((period, day_row))
1.1110 +
1.1111 + # Output the locations.
1.1112 +
1.1113 + output.append(fmt.table_row(on=1))
1.1114 +
1.1115 + # Add a spacer.
1.1116 +
1.1117 + output.append(self.writeDaySpacer(colspan=2, cls="location"))
1.1118 +
1.1119 + for location in locations:
1.1120 +
1.1121 + # Add spacers to the column spans.
1.1122 +
1.1123 + columns = len(day_slots[location]) * 2 - 1
1.1124 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)}))
1.1125 + output.append(fmt.text(location or ""))
1.1126 + output.append(fmt.table_cell(on=0))
1.1127 +
1.1128 + # Add a trailing spacer.
1.1129 +
1.1130 + output.append(self.writeDaySpacer(cls="location"))
1.1131 +
1.1132 + output.append(fmt.table_row(on=0))
1.1133 +
1.1134 + # Output the periods with event details.
1.1135 +
1.1136 + period = None
1.1137 + events_written = set()
1.1138 +
1.1139 + for period, day_row in day_rows:
1.1140 +
1.1141 + # Write an empty heading for the start of the day where the first
1.1142 + # applicable timespan starts before this day.
1.1143 +
1.1144 + if period.start < date:
1.1145 + output.append(fmt.table_row(on=1))
1.1146 + output.append(self.writeDayScaleHeading(""))
1.1147 +
1.1148 + # Otherwise, write a heading describing the time.
1.1149 +
1.1150 + else:
1.1151 + output.append(fmt.table_row(on=1))
1.1152 + output.append(self.writeDayScaleHeading(period.start.time_string()))
1.1153 +
1.1154 + output.append(self.writeDaySpacer())
1.1155 +
1.1156 + # Visit each slot corresponding to a location (or no location).
1.1157 +
1.1158 + for location, event in day_row:
1.1159 +
1.1160 + # Output each location slot's contribution.
1.1161 +
1.1162 + if event is None or event not in events_written:
1.1163 + output.append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event]))
1.1164 + if event is not None:
1.1165 + events_written.add(event)
1.1166 +
1.1167 + # Add a trailing spacer.
1.1168 +
1.1169 + output.append(self.writeDaySpacer())
1.1170 +
1.1171 + output.append(fmt.table_row(on=0))
1.1172 +
1.1173 + # Write a final time heading if the last period ends in the current day.
1.1174 +
1.1175 + if period is not None:
1.1176 + if period.end == date:
1.1177 + output.append(fmt.table_row(on=1))
1.1178 + output.append(self.writeDayScaleHeading(period.end.time_string()))
1.1179 +
1.1180 + for slot in day_row:
1.1181 + output.append(self.writeDaySpacer())
1.1182 + output.append(self.writeEmptyDaySlot())
1.1183 +
1.1184 + output.append(fmt.table_row(on=0))
1.1185 +
1.1186 + return "".join(output)
1.1187 +
1.1188 + def writeDayScaleHeading(self, heading):
1.1189 + page = self.page
1.1190 + fmt = page.formatter
1.1191 +
1.1192 + output = []
1.1193 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"}))
1.1194 + output.append(fmt.text(heading))
1.1195 + output.append(fmt.table_cell(on=0))
1.1196 +
1.1197 + return "".join(output)
1.1198 +
1.1199 + def getActiveEvent(self, period, events):
1.1200 + for event in events:
1.1201 + if period not in event:
1.1202 + continue
1.1203 + return event
1.1204 + else:
1.1205 + return None
1.1206 +
1.1207 + def writeDaySlot(self, period, event, rowspan):
1.1208 + page = self.page
1.1209 + fmt = page.formatter
1.1210 +
1.1211 + output = []
1.1212 +
1.1213 + if event is not None:
1.1214 + event_summary = event.getSummary(self.parent_name)
1.1215 + style = self.getEventStyle(event_summary)
1.1216 +
1.1217 + output.append(fmt.table_cell(on=1, attrs={
1.1218 + "class" : "event-timespan-content event-timespan-busy",
1.1219 + "style" : style,
1.1220 + "rowspan" : str(rowspan)
1.1221 + }))
1.1222 + output.append(self.writeEventSummaryBox(event))
1.1223 + output.append(fmt.table_cell(on=0))
1.1224 + else:
1.1225 + output.append(self.writeEmptyDaySlot())
1.1226 +
1.1227 + return "".join(output)
1.1228 +
1.1229 + def writeEmptyDaySlot(self):
1.1230 + page = self.page
1.1231 + fmt = page.formatter
1.1232 +
1.1233 + output = []
1.1234 +
1.1235 + output.append(fmt.table_cell(on=1,
1.1236 + attrs={"class" : "event-timespan-content event-timespan-empty"}))
1.1237 + output.append(fmt.table_cell(on=0))
1.1238 +
1.1239 + return "".join(output)
1.1240 +
1.1241 + def writeDaySpacer(self, colspan=1, cls="timespan"):
1.1242 + page = self.page
1.1243 + fmt = page.formatter
1.1244 +
1.1245 + output = []
1.1246 + output.append(fmt.table_cell(on=1, attrs={
1.1247 + "class" : "event-%s-spacer" % cls,
1.1248 + "colspan" : str(colspan)}))
1.1249 + output.append(fmt.table_cell(on=0))
1.1250 + return "".join(output)
1.1251 +
1.1252 + # Map layout methods.
1.1253 +
1.1254 + def writeMapTableHeading(self):
1.1255 + page = self.page
1.1256 + fmt = page.formatter
1.1257 +
1.1258 + output = []
1.1259 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"}))
1.1260 + output.append(self.writeMapHeading())
1.1261 + output.append(fmt.table_cell(on=0))
1.1262 +
1.1263 + return "".join(output)
1.1264 +
1.1265 + def showDictError(self, text, pagename):
1.1266 + page = self.page
1.1267 + fmt = page.formatter
1.1268 + request = page.request
1.1269 +
1.1270 + output = []
1.1271 +
1.1272 + output.append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"}))
1.1273 + output.append(fmt.paragraph(on=1))
1.1274 + output.append(fmt.text(text))
1.1275 + output.append(fmt.paragraph(on=0))
1.1276 + output.append(fmt.paragraph(on=1))
1.1277 + output.append(linkToPage(request, Page(request, pagename), pagename))
1.1278 + output.append(fmt.paragraph(on=0))
1.1279 +
1.1280 + return "".join(output)
1.1281 +
1.1282 + def writeMapEventSummaries(self, events):
1.1283 + page = self.page
1.1284 + fmt = page.formatter
1.1285 + request = page.request
1.1286 +
1.1287 + # Sort the events by date.
1.1288 +
1.1289 + events.sort(sort_start_first)
1.1290 +
1.1291 + # Write out a self-contained list of events.
1.1292 +
1.1293 + output = []
1.1294 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"}))
1.1295 +
1.1296 + for event in events:
1.1297 +
1.1298 + # Get the event details.
1.1299 +
1.1300 + event_summary = event.getSummary(self.parent_name)
1.1301 + start, end = event.as_limits()
1.1302 + event_period = self._getCalendarPeriod(
1.1303 + start and self.getFullDateLabel(start),
1.1304 + end and self.getFullDateLabel(end),
1.1305 + "")
1.1306 +
1.1307 + output.append(fmt.listitem(on=1))
1.1308 +
1.1309 + # Link to the page using the summary.
1.1310 +
1.1311 + output.append(event.linkToEvent(request, event_summary))
1.1312 +
1.1313 + # Add the event period.
1.1314 +
1.1315 + output.append(fmt.text(" "))
1.1316 + output.append(fmt.span(on=1, css_class="event-map-period"))
1.1317 + output.append(fmt.text(event_period))
1.1318 + output.append(fmt.span(on=0))
1.1319 +
1.1320 + output.append(fmt.listitem(on=0))
1.1321 +
1.1322 + output.append(fmt.bullet_list(on=0))
1.1323 +
1.1324 + return "".join(output)
1.1325 +
1.1326 + def render(self, all_shown_events):
1.1327 +
1.1328 + """
1.1329 + Render the view, returning the rendered representation as a string.
1.1330 + The view will show a list of 'all_shown_events'.
1.1331 + """
1.1332 +
1.1333 + page = self.page
1.1334 + fmt = page.formatter
1.1335 + request = page.request
1.1336 + _ = request.getText
1.1337 +
1.1338 + # Make a calendar.
1.1339 +
1.1340 + output = []
1.1341 +
1.1342 + output.append(fmt.div(on=1, css_class="event-calendar"))
1.1343 +
1.1344 + # Output download controls.
1.1345 +
1.1346 + output.append(fmt.div(on=1, css_class="event-controls"))
1.1347 + output.append(self.writeDownloadControls())
1.1348 + output.append(fmt.div(on=0))
1.1349 +
1.1350 + # Output a table.
1.1351 +
1.1352 + if self.mode == "table":
1.1353 +
1.1354 + # Start of table view output.
1.1355 +
1.1356 + output.append(fmt.table(on=1, attrs={"tableclass" : "event-table"}))
1.1357 +
1.1358 + output.append(fmt.table_row(on=1))
1.1359 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
1.1360 + output.append(fmt.text(_("Event dates")))
1.1361 + output.append(fmt.table_cell(on=0))
1.1362 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
1.1363 + output.append(fmt.text(_("Event location")))
1.1364 + output.append(fmt.table_cell(on=0))
1.1365 + output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
1.1366 + output.append(fmt.text(_("Event details")))
1.1367 + output.append(fmt.table_cell(on=0))
1.1368 + output.append(fmt.table_row(on=0))
1.1369 +
1.1370 + # Show the events in order.
1.1371 +
1.1372 + all_shown_events.sort(sort_start_first)
1.1373 +
1.1374 + for event in all_shown_events:
1.1375 + event_page = event.getPage()
1.1376 + event_summary = event.getSummary(self.parent_name)
1.1377 + event_details = event.getDetails()
1.1378 +
1.1379 + # Prepare CSS classes with category-related styling.
1.1380 +
1.1381 + css_classes = ["event-table-details"]
1.1382 +
1.1383 + for topic in event_details.get("topics") or event_details.get("categories") or []:
1.1384 +
1.1385 + # Filter the category text to avoid illegal characters.
1.1386 +
1.1387 + css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic)))
1.1388 +
1.1389 + attrs = {"class" : " ".join(css_classes)}
1.1390 +
1.1391 + output.append(fmt.table_row(on=1))
1.1392 +
1.1393 + # Start and end dates.
1.1394 +
1.1395 + output.append(fmt.table_cell(on=1, attrs=attrs))
1.1396 + output.append(fmt.span(on=1))
1.1397 + output.append(fmt.text(str(event_details["start"])))
1.1398 + output.append(fmt.span(on=0))
1.1399 +
1.1400 + if event_details["start"] != event_details["end"]:
1.1401 + output.append(fmt.text(" - "))
1.1402 + output.append(fmt.span(on=1))
1.1403 + output.append(fmt.text(str(event_details["end"])))
1.1404 + output.append(fmt.span(on=0))
1.1405 +
1.1406 + output.append(fmt.table_cell(on=0))
1.1407 +
1.1408 + # Location.
1.1409 +
1.1410 + output.append(fmt.table_cell(on=1, attrs=attrs))
1.1411 +
1.1412 + if event_details.has_key("location"):
1.1413 + output.append(event_page.formatText(event_details["location"], request, fmt))
1.1414 +
1.1415 + output.append(fmt.table_cell(on=0))
1.1416 +
1.1417 + # Link to the page using the summary.
1.1418 +
1.1419 + output.append(fmt.table_cell(on=1, attrs=attrs))
1.1420 + output.append(event.linkToEvent(request, event_summary))
1.1421 + output.append(fmt.table_cell(on=0))
1.1422 +
1.1423 + output.append(fmt.table_row(on=0))
1.1424 +
1.1425 + # End of table view output.
1.1426 +
1.1427 + output.append(fmt.table(on=0))
1.1428 +
1.1429 + # Output a map view.
1.1430 +
1.1431 + elif self.mode == "map":
1.1432 +
1.1433 + # Special dictionary pages.
1.1434 +
1.1435 + maps_page = getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict")
1.1436 + locations_page = getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict")
1.1437 +
1.1438 + map_image = None
1.1439 +
1.1440 + # Get the maps and locations.
1.1441 +
1.1442 + maps = getWikiDict(maps_page, request)
1.1443 + locations = getWikiDict(locations_page, request)
1.1444 +
1.1445 + # Get the map image definition.
1.1446 +
1.1447 + if maps is not None and self.map_name is not None:
1.1448 + try:
1.1449 + map_details = maps[self.map_name].split()
1.1450 +
1.1451 + map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \
1.1452 + map(getMapReference, map_details[:4])
1.1453 + map_width, map_height = map(int, map_details[4:6])
1.1454 + map_image = map_details[6]
1.1455 +
1.1456 + map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees()
1.1457 + map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees()
1.1458 +
1.1459 + except (KeyError, ValueError):
1.1460 + pass
1.1461 +
1.1462 + # Report errors.
1.1463 +
1.1464 + if maps is None:
1.1465 + output.append(self.showDictError(
1.1466 + _("You do not have read access to the maps page:"),
1.1467 + maps_page))
1.1468 +
1.1469 + elif self.map_name is None:
1.1470 + output.append(self.showDictError(
1.1471 + _("Please specify a valid map name corresponding to an entry on the following page:"),
1.1472 + maps_page))
1.1473 +
1.1474 + elif map_image is None:
1.1475 + output.append(self.showDictError(
1.1476 + _("Please specify a valid entry for %s on the following page:") % self.map_name,
1.1477 + maps_page))
1.1478 +
1.1479 + elif locations is None:
1.1480 + output.append(self.showDictError(
1.1481 + _("You do not have read access to the locations page:"),
1.1482 + locations_page))
1.1483 +
1.1484 + # Attempt to show the map.
1.1485 +
1.1486 + else:
1.1487 +
1.1488 + # Get events by position.
1.1489 +
1.1490 + events_by_location = {}
1.1491 + event_locations = {}
1.1492 +
1.1493 + for event in all_shown_events:
1.1494 + event_details = event.getDetails()
1.1495 +
1.1496 + location = event_details.get("location")
1.1497 +
1.1498 + if location is not None and not event_locations.has_key(location):
1.1499 +
1.1500 + # Get any explicit position of an event.
1.1501 +
1.1502 + if event_details.has_key("geo"):
1.1503 + latitude, longitude = event_details["geo"]
1.1504 +
1.1505 + # Or look up the position of a location using the locations
1.1506 + # page.
1.1507 +
1.1508 + else:
1.1509 + latitude, longitude = getLocationPosition(location, locations)
1.1510 +
1.1511 + # Use a normalised location if necessary.
1.1512 +
1.1513 + if latitude is None and longitude is None:
1.1514 + normalised_location = getNormalisedLocation(location)
1.1515 + if normalised_location is not None:
1.1516 + latitude, longitude = getLocationPosition(normalised_location, locations)
1.1517 + if latitude is not None and longitude is not None:
1.1518 + location = normalised_location
1.1519 +
1.1520 + # Only remember positioned locations.
1.1521 +
1.1522 + if latitude is not None and longitude is not None:
1.1523 + event_locations[location] = latitude, longitude
1.1524 +
1.1525 + # Record events according to location.
1.1526 +
1.1527 + if not events_by_location.has_key(location):
1.1528 + events_by_location[location] = []
1.1529 +
1.1530 + events_by_location[location].append(event)
1.1531 +
1.1532 + # Get the map image URL.
1.1533 +
1.1534 + map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
1.1535 +
1.1536 + # Start of map view output.
1.1537 +
1.1538 + map_identifier = "map-%s" % self.getIdentifier()
1.1539 + output.append(fmt.div(on=1, css_class="event-map", id=map_identifier))
1.1540 +
1.1541 + output.append(fmt.table(on=1))
1.1542 +
1.1543 + output.append(fmt.table_row(on=1))
1.1544 + output.append(self.writeMapTableHeading())
1.1545 + output.append(fmt.table_row(on=0))
1.1546 +
1.1547 + output.append(fmt.table_row(on=1))
1.1548 + output.append(fmt.table_cell(on=1))
1.1549 +
1.1550 + output.append(fmt.div(on=1, css_class="event-map-container"))
1.1551 + output.append(fmt.image(map_image_url))
1.1552 + output.append(fmt.number_list(on=1))
1.1553 +
1.1554 + # Events with no location are unpositioned.
1.1555 +
1.1556 + if events_by_location.has_key(None):
1.1557 + unpositioned_events = events_by_location[None]
1.1558 + del events_by_location[None]
1.1559 + else:
1.1560 + unpositioned_events = []
1.1561 +
1.1562 + # Events whose location is unpositioned are themselves considered
1.1563 + # unpositioned.
1.1564 +
1.1565 + for location in set(events_by_location.keys()).difference(event_locations.keys()):
1.1566 + unpositioned_events += events_by_location[location]
1.1567 +
1.1568 + # Sort the locations before traversing them.
1.1569 +
1.1570 + event_locations = event_locations.items()
1.1571 + event_locations.sort()
1.1572 +
1.1573 + # Show the events in the map.
1.1574 +
1.1575 + for location, (latitude, longitude) in event_locations:
1.1576 + events = events_by_location[location]
1.1577 +
1.1578 + # Skip unpositioned locations and locations outside the map.
1.1579 +
1.1580 + if latitude is None or longitude is None or \
1.1581 + latitude < map_bottom_left_latitude or \
1.1582 + longitude < map_bottom_left_longitude or \
1.1583 + latitude > map_top_right_latitude or \
1.1584 + longitude > map_top_right_longitude:
1.1585 +
1.1586 + unpositioned_events += events
1.1587 + continue
1.1588 +
1.1589 + # Get the position and dimensions of the map marker.
1.1590 + # NOTE: Use one degree as the marker size.
1.1591 +
1.1592 + marker_x, marker_y = getPositionForCentrePoint(
1.1593 + getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude,
1.1594 + map_x_scale, map_y_scale),
1.1595 + map_x_scale, map_y_scale)
1.1596 +
1.1597 + # Put a marker on the map.
1.1598 +
1.1599 + output.append(fmt.listitem(on=1, css_class="event-map-label"))
1.1600 +
1.1601 + # Have a positioned marker for the print mode.
1.1602 +
1.1603 + output.append(fmt.div(on=1, css_class="event-map-label-only",
1.1604 + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
1.1605 + marker_x, marker_y, map_x_scale, map_y_scale))
1.1606 + output.append(fmt.div(on=0))
1.1607 +
1.1608 + # Have a marker containing a pop-up when using the screen mode,
1.1609 + # providing a normal block when using the print mode.
1.1610 +
1.1611 + output.append(fmt.div(on=1, css_class="event-map-label",
1.1612 + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
1.1613 + marker_x, marker_y, map_x_scale, map_y_scale))
1.1614 + output.append(fmt.div(on=1, css_class="event-map-details"))
1.1615 + output.append(fmt.div(on=1, css_class="event-map-shadow"))
1.1616 + output.append(fmt.div(on=1, css_class="event-map-location"))
1.1617 +
1.1618 + output.append(fmt.heading(on=1, depth=2))
1.1619 + output.append(fmt.text(location))
1.1620 + output.append(fmt.heading(on=0, depth=2))
1.1621 +
1.1622 + output.append(self.writeMapEventSummaries(events))
1.1623 +
1.1624 + output.append(fmt.div(on=0))
1.1625 + output.append(fmt.div(on=0))
1.1626 + output.append(fmt.div(on=0))
1.1627 + output.append(fmt.div(on=0))
1.1628 + output.append(fmt.listitem(on=0))
1.1629 +
1.1630 + output.append(fmt.number_list(on=0))
1.1631 + output.append(fmt.div(on=0))
1.1632 + output.append(fmt.table_cell(on=0))
1.1633 + output.append(fmt.table_row(on=0))
1.1634 +
1.1635 + # Write unpositioned events.
1.1636 +
1.1637 + if unpositioned_events:
1.1638 + unpositioned_identifier = "unpositioned-%s" % self.getIdentifier()
1.1639 +
1.1640 + output.append(fmt.table_row(on=1, css_class="event-map-unpositioned",
1.1641 + id=unpositioned_identifier))
1.1642 + output.append(fmt.table_cell(on=1))
1.1643 +
1.1644 + output.append(fmt.heading(on=1, depth=2))
1.1645 + output.append(fmt.text(_("Events not shown on the map")))
1.1646 + output.append(fmt.heading(on=0, depth=2))
1.1647 +
1.1648 + # Show and hide controls.
1.1649 +
1.1650 + output.append(fmt.div(on=1, css_class="event-map-show-control"))
1.1651 + output.append(fmt.anchorlink(on=1, name=unpositioned_identifier))
1.1652 + output.append(fmt.text(_("Show unpositioned events")))
1.1653 + output.append(fmt.anchorlink(on=0))
1.1654 + output.append(fmt.div(on=0))
1.1655 +
1.1656 + output.append(fmt.div(on=1, css_class="event-map-hide-control"))
1.1657 + output.append(fmt.anchorlink(on=1, name=map_identifier))
1.1658 + output.append(fmt.text(_("Hide unpositioned events")))
1.1659 + output.append(fmt.anchorlink(on=0))
1.1660 + output.append(fmt.div(on=0))
1.1661 +
1.1662 + output.append(self.writeMapEventSummaries(unpositioned_events))
1.1663 +
1.1664 + # End of map view output.
1.1665 +
1.1666 + output.append(fmt.table_cell(on=0))
1.1667 + output.append(fmt.table_row(on=0))
1.1668 + output.append(fmt.table(on=0))
1.1669 + output.append(fmt.div(on=0))
1.1670 +
1.1671 + # Output a list.
1.1672 +
1.1673 + elif self.mode == "list":
1.1674 +
1.1675 + # Start of list view output.
1.1676 +
1.1677 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"}))
1.1678 +
1.1679 + # Output a list.
1.1680 +
1.1681 + for period in self.first.until(self.last):
1.1682 +
1.1683 + output.append(fmt.listitem(on=1, attr={"class" : "event-listings-period"}))
1.1684 + output.append(fmt.div(on=1, attr={"class" : "event-listings-heading"}))
1.1685 +
1.1686 + # Either write a date heading or produce links for navigable
1.1687 + # calendars.
1.1688 +
1.1689 + output.append(self.writeDateHeading(period))
1.1690 +
1.1691 + output.append(fmt.div(on=0))
1.1692 +
1.1693 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"}))
1.1694 +
1.1695 + # Show the events in order.
1.1696 +
1.1697 + events_in_period = getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period))
1.1698 + events_in_period.sort(sort_start_first)
1.1699 +
1.1700 + for event in events_in_period:
1.1701 + event_page = event.getPage()
1.1702 + event_details = event.getDetails()
1.1703 + event_summary = event.getSummary(self.parent_name)
1.1704 +
1.1705 + output.append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
1.1706 +
1.1707 + # Link to the page using the summary.
1.1708 +
1.1709 + output.append(fmt.paragraph(on=1))
1.1710 + output.append(event.linkToEvent(request, event_summary))
1.1711 + output.append(fmt.paragraph(on=0))
1.1712 +
1.1713 + # Start and end dates.
1.1714 +
1.1715 + output.append(fmt.paragraph(on=1))
1.1716 + output.append(fmt.span(on=1))
1.1717 + output.append(fmt.text(str(event_details["start"])))
1.1718 + output.append(fmt.span(on=0))
1.1719 + output.append(fmt.text(" - "))
1.1720 + output.append(fmt.span(on=1))
1.1721 + output.append(fmt.text(str(event_details["end"])))
1.1722 + output.append(fmt.span(on=0))
1.1723 + output.append(fmt.paragraph(on=0))
1.1724 +
1.1725 + # Location.
1.1726 +
1.1727 + if event_details.has_key("location"):
1.1728 + output.append(fmt.paragraph(on=1))
1.1729 + output.append(event_page.formatText(event_details["location"], request, fmt))
1.1730 + output.append(fmt.paragraph(on=1))
1.1731 +
1.1732 + # Topics.
1.1733 +
1.1734 + if event_details.has_key("topics") or event_details.has_key("categories"):
1.1735 + output.append(fmt.bullet_list(on=1, attr={"class" : "event-topics"}))
1.1736 +
1.1737 + for topic in event_details.get("topics") or event_details.get("categories") or []:
1.1738 + output.append(fmt.listitem(on=1))
1.1739 + output.append(event_page.formatText(topic, request, fmt))
1.1740 + output.append(fmt.listitem(on=0))
1.1741 +
1.1742 + output.append(fmt.bullet_list(on=0))
1.1743 +
1.1744 + output.append(fmt.listitem(on=0))
1.1745 +
1.1746 + output.append(fmt.bullet_list(on=0))
1.1747 +
1.1748 + # End of list view output.
1.1749 +
1.1750 + output.append(fmt.bullet_list(on=0))
1.1751 +
1.1752 + # Output a month calendar. This shows month-by-month data.
1.1753 +
1.1754 + elif self.mode == "calendar":
1.1755 +
1.1756 + # Visit all months in the requested range, or across known events.
1.1757 +
1.1758 + for month in self.first.months_until(self.last):
1.1759 +
1.1760 + # Output a month.
1.1761 +
1.1762 + output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
1.1763 +
1.1764 + # Either write a month heading or produce links for navigable
1.1765 + # calendars.
1.1766 +
1.1767 + output.append(self.writeMonthTableHeading(month))
1.1768 +
1.1769 + # Weekday headings.
1.1770 +
1.1771 + output.append(self.writeWeekdayHeadings())
1.1772 +
1.1773 + # Process the days of the month.
1.1774 +
1.1775 + start_weekday, number_of_days = month.month_properties()
1.1776 +
1.1777 + # The start weekday is the weekday of day number 1.
1.1778 + # Find the first day of the week, counting from below zero, if
1.1779 + # necessary, in order to land on the first day of the month as
1.1780 + # day number 1.
1.1781 +
1.1782 + first_day = 1 - start_weekday
1.1783 +
1.1784 + while first_day <= number_of_days:
1.1785 +
1.1786 + # Find events in this week and determine how to mark them on the
1.1787 + # calendar.
1.1788 +
1.1789 + week_start = month.as_date(max(first_day, 1))
1.1790 + week_end = month.as_date(min(first_day + 6, number_of_days))
1.1791 +
1.1792 + full_coverage, week_slots = getCoverage(
1.1793 + getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end)))
1.1794 +
1.1795 + # Output a week, starting with the day numbers.
1.1796 +
1.1797 + output.append(self.writeDayNumbers(first_day, number_of_days, month, full_coverage))
1.1798 +
1.1799 + # Either generate empty days...
1.1800 +
1.1801 + if not week_slots:
1.1802 + output.append(self.writeEmptyWeek(first_day, number_of_days))
1.1803 +
1.1804 + # Or generate each set of scheduled events...
1.1805 +
1.1806 + else:
1.1807 + output.append(self.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots))
1.1808 +
1.1809 + # Process the next week...
1.1810 +
1.1811 + first_day += 7
1.1812 +
1.1813 + # End of month.
1.1814 +
1.1815 + output.append(fmt.table(on=0))
1.1816 +
1.1817 + # Output a day view.
1.1818 +
1.1819 + elif self.mode == "day":
1.1820 +
1.1821 + # Visit all days in the requested range, or across known events.
1.1822 +
1.1823 + for date in self.first.days_until(self.last):
1.1824 +
1.1825 + output.append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"}))
1.1826 +
1.1827 + full_coverage, day_slots = getCoverage(
1.1828 + getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime")
1.1829 +
1.1830 + # Work out how many columns the day title will need.
1.1831 + # Include spacers after the scale and each event column.
1.1832 +
1.1833 + colspan = sum(map(len, day_slots.values())) * 2 + 2
1.1834 +
1.1835 + output.append(self.writeDayTableHeading(date, colspan))
1.1836 +
1.1837 + # Either generate empty days...
1.1838 +
1.1839 + if not day_slots:
1.1840 + output.append(self.writeEmptyDay(date))
1.1841 +
1.1842 + # Or generate each set of scheduled events...
1.1843 +
1.1844 + else:
1.1845 + output.append(self.writeDaySlots(date, full_coverage, day_slots))
1.1846 +
1.1847 + # End of day.
1.1848 +
1.1849 + output.append(fmt.table(on=0))
1.1850 +
1.1851 + # Output view controls.
1.1852 +
1.1853 + output.append(fmt.div(on=1, css_class="event-controls"))
1.1854 + output.append(self.writeViewControls())
1.1855 + output.append(fmt.div(on=0))
1.1856 +
1.1857 + # Close the calendar region.
1.1858 +
1.1859 + output.append(fmt.div(on=0))
1.1860 +
1.1861 + return ''.join(output)
1.1862 +
1.1863 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/macros/EventAggregator.py Sun Jan 22 00:45:28 2012 +0100
2.2 +++ b/macros/EventAggregator.py Sun Feb 05 01:29:45 2012 +0100
2.3 @@ -9,1301 +9,10 @@
2.4 """
2.5
2.6 from MoinMoin import wikiutil
2.7 -from MoinMoin.action import AttachFile
2.8 -from MoinMoin.Page import Page
2.9 from EventAggregatorSupport import *
2.10 -import calendar
2.11
2.12 Dependencies = ['pages']
2.13
2.14 -# Abstractions.
2.15 -
2.16 -class View:
2.17 -
2.18 - "A view of the event calendar."
2.19 -
2.20 - def __init__(self, page, calendar_name, raw_calendar_start, raw_calendar_end,
2.21 - original_calendar_start, original_calendar_end, calendar_start, calendar_end,
2.22 - first, last, category_names, remote_sources, template_name, parent_name, mode,
2.23 - resolution, name_usage, map_name):
2.24 -
2.25 - """
2.26 - Initialise the view with the current 'page', a 'calendar_name' (which
2.27 - may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which
2.28 - are the actual start and end values provided by the request), the
2.29 - calculated 'original_calendar_start' and 'original_calendar_end' (which
2.30 - are the result of calculating the calendar's limits from the raw start
2.31 - and end values), and the requested, calculated 'calendar_start' and
2.32 - 'calendar_end' (which may involve different start and end values due to
2.33 - navigation in the user interface), along with the 'first' and 'last'
2.34 - months of event coverage.
2.35 -
2.36 - The additional 'category_names', 'remote_sources', 'template_name',
2.37 - 'parent_name' and 'mode' parameters are used to configure the links
2.38 - employed by the view.
2.39 -
2.40 - The 'resolution' affects the view for certain modes and is also used to
2.41 - parameterise links.
2.42 -
2.43 - The 'name_usage' parameter controls how names are shown on calendar mode
2.44 - events, such as how often labels are repeated.
2.45 -
2.46 - The 'map_name' parameter provides the name of a map to be used in the
2.47 - map mode.
2.48 - """
2.49 -
2.50 - self.page = page
2.51 - self.calendar_name = calendar_name
2.52 - self.raw_calendar_start = raw_calendar_start
2.53 - self.raw_calendar_end = raw_calendar_end
2.54 - self.original_calendar_start = original_calendar_start
2.55 - self.original_calendar_end = original_calendar_end
2.56 - self.calendar_start = calendar_start
2.57 - self.calendar_end = calendar_end
2.58 - self.template_name = template_name
2.59 - self.parent_name = parent_name
2.60 - self.mode = mode
2.61 - self.resolution = resolution
2.62 - self.name_usage = name_usage
2.63 - self.map_name = map_name
2.64 -
2.65 - self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names])
2.66 - self.remote_source_parameters = "&".join([("source=%s" % source) for source in remote_sources])
2.67 -
2.68 - # Calculate the duration in terms of the highest common unit of time.
2.69 -
2.70 - self.duration = last - first
2.71 -
2.72 - if self.calendar_name is not None:
2.73 -
2.74 - # Store the view parameters.
2.75 -
2.76 - self.previous_start = first.previous()
2.77 - self.next_start = first.next()
2.78 - self.previous_end = last.previous()
2.79 - self.next_end = last.next()
2.80 -
2.81 - self.previous_set_start = first.update(-self.duration)
2.82 - self.next_set_start = first.update(self.duration)
2.83 - self.previous_set_end = last.update(-self.duration)
2.84 - self.next_set_end = last.update(self.duration)
2.85 -
2.86 - def getIdentifier(self):
2.87 -
2.88 - "Return a unique identifier to be used to refer to this view."
2.89 -
2.90 - # NOTE: Nasty hack to get a unique identifier if no name is given.
2.91 -
2.92 - return self.calendar_name or str(id(self))
2.93 -
2.94 - def getQualifiedParameterName(self, argname):
2.95 -
2.96 - "Return the 'argname' qualified using the calendar name."
2.97 -
2.98 - return getQualifiedParameterName(self.calendar_name, argname)
2.99 -
2.100 - def getDateQueryString(self, argname, date, prefix=1):
2.101 -
2.102 - """
2.103 - Return a query string fragment for the given 'argname', referring to the
2.104 - month given by the specified 'year_month' object, appropriate for this
2.105 - calendar.
2.106 -
2.107 - If 'prefix' is specified and set to a false value, the parameters in the
2.108 - query string will not be calendar-specific, but could be used with the
2.109 - summary action.
2.110 - """
2.111 -
2.112 - suffixes = ["year", "month", "day"]
2.113 -
2.114 - if date is not None:
2.115 - args = []
2.116 - for suffix, value in zip(suffixes, date.as_tuple()):
2.117 - suffixed_argname = "%s-%s" % (argname, suffix)
2.118 - if prefix:
2.119 - suffixed_argname = self.getQualifiedParameterName(suffixed_argname)
2.120 - args.append("%s=%s" % (suffixed_argname, value))
2.121 - return "&".join(args)
2.122 - else:
2.123 - return ""
2.124 -
2.125 - def getRawDateQueryString(self, argname, date, prefix=1):
2.126 -
2.127 - """
2.128 - Return a query string fragment for the given 'argname', referring to the
2.129 - date given by the specified 'date' value, appropriate for this
2.130 - calendar.
2.131 -
2.132 - If 'prefix' is specified and set to a false value, the parameters in the
2.133 - query string will not be calendar-specific, but could be used with the
2.134 - summary action.
2.135 - """
2.136 -
2.137 - if date is not None:
2.138 - if prefix:
2.139 - argname = self.getQualifiedParameterName(argname)
2.140 - return "%s=%s" % (argname, wikiutil.url_quote_plus(date))
2.141 - else:
2.142 - return ""
2.143 -
2.144 - def getNavigationLink(self, start, end, mode=None, resolution=None):
2.145 -
2.146 - """
2.147 - Return a query string fragment for navigation to a view showing months
2.148 - from 'start' to 'end' inclusive, with the optional 'mode' indicating the
2.149 - view style and the optional 'resolution' indicating the resolution of a
2.150 - view, if configurable.
2.151 - """
2.152 -
2.153 - return "%s&%s&%s=%s&%s=%s" % (
2.154 - self.getRawDateQueryString("start", start),
2.155 - self.getRawDateQueryString("end", end),
2.156 - self.getQualifiedParameterName("mode"), mode or self.mode,
2.157 - self.getQualifiedParameterName("resolution"), resolution or self.resolution
2.158 - )
2.159 -
2.160 - def getNewEventLink(self, start):
2.161 -
2.162 - """
2.163 - Return a query string activating the new event form, incorporating the
2.164 - calendar parameters, specialising the form for the given 'start' date or
2.165 - month.
2.166 - """
2.167 -
2.168 - if start is not None:
2.169 - details = start.as_tuple()
2.170 - pairs = zip(["start-year=%d", "start-month=%d", "start-day=%d"], details)
2.171 - args = [(param % value) for (param, value) in pairs]
2.172 - args = "&".join(args)
2.173 - else:
2.174 - args = ""
2.175 -
2.176 - # Prepare navigation details for the calendar shown with the new event
2.177 - # form.
2.178 -
2.179 - navigation_link = self.getNavigationLink(
2.180 - self.calendar_start, self.calendar_end
2.181 - )
2.182 -
2.183 - return "action=EventAggregatorNewEvent&%s&%s&template=%s&parent=%s&%s" % (
2.184 - args, self.category_name_parameters, self.template_name, self.parent_name or "",
2.185 - navigation_link)
2.186 -
2.187 - def getFullDateLabel(self, date):
2.188 - page = self.page
2.189 - request = page.request
2.190 - return getFullDateLabel(request, date)
2.191 -
2.192 - def getFullMonthLabel(self, year_month):
2.193 - page = self.page
2.194 - request = page.request
2.195 - return getFullMonthLabel(request, year_month)
2.196 -
2.197 - def getFullLabel(self, arg):
2.198 - return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg)
2.199 -
2.200 - def _getCalendarPeriod(self, start_label, end_label, default_label):
2.201 - output = []
2.202 - if start_label:
2.203 - output.append(start_label)
2.204 - if end_label and start_label != end_label:
2.205 - if output:
2.206 - output.append(" - ")
2.207 - output.append(end_label)
2.208 - return "".join(output) or default_label
2.209 -
2.210 - def getCalendarPeriod(self):
2.211 - _ = self.page.request.getText
2.212 - return self._getCalendarPeriod(
2.213 - self.calendar_start and self.getFullLabel(self.calendar_start),
2.214 - self.calendar_end and self.getFullLabel(self.calendar_end),
2.215 - _("All events")
2.216 - )
2.217 -
2.218 - def getOriginalCalendarPeriod(self):
2.219 - _ = self.page.request.getText
2.220 - return self._getCalendarPeriod(
2.221 - self.original_calendar_start and self.getFullLabel(self.original_calendar_start),
2.222 - self.original_calendar_end and self.getFullLabel(self.original_calendar_end),
2.223 - _("All events")
2.224 - )
2.225 -
2.226 - def getRawCalendarPeriod(self):
2.227 - _ = self.page.request.getText
2.228 - return self._getCalendarPeriod(
2.229 - self.raw_calendar_start,
2.230 - self.raw_calendar_end,
2.231 - _("No period specified")
2.232 - )
2.233 -
2.234 - def writeDownloadControls(self):
2.235 -
2.236 - """
2.237 - Return a representation of the download controls, featuring links for
2.238 - view, calendar and customised downloads and subscriptions.
2.239 - """
2.240 -
2.241 - page = self.page
2.242 - request = page.request
2.243 - fmt = page.formatter
2.244 - _ = request.getText
2.245 -
2.246 - output = []
2.247 -
2.248 - # The full URL is needed for webcal links.
2.249 -
2.250 - full_url = "%s%s" % (request.getBaseURL(), getPathInfo(request))
2.251 -
2.252 - # Generate the links.
2.253 -
2.254 - download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&%s&%s" % (
2.255 - self.parent_name or "",
2.256 - self.resolution,
2.257 - self.category_name_parameters,
2.258 - self.remote_source_parameters
2.259 - )
2.260 - download_all_link = download_dialogue_link + "&doit=1"
2.261 - download_link = download_all_link + ("&%s&%s" % (
2.262 - self.getDateQueryString("start", self.calendar_start, prefix=0),
2.263 - self.getDateQueryString("end", self.calendar_end, prefix=0)
2.264 - ))
2.265 -
2.266 - # Subscription links just explicitly select the RSS format.
2.267 -
2.268 - subscribe_dialogue_link = download_dialogue_link + "&format=RSS"
2.269 - subscribe_all_link = download_all_link + "&format=RSS"
2.270 - subscribe_link = download_link + "&format=RSS"
2.271 -
2.272 - # Adjust the "download all" and "subscribe all" links if the calendar
2.273 - # has an inherent period associated with it.
2.274 -
2.275 - period_limits = []
2.276 -
2.277 - if self.raw_calendar_start:
2.278 - period_limits.append("&%s" %
2.279 - self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0)
2.280 - )
2.281 - if self.raw_calendar_end:
2.282 - period_limits.append("&%s" %
2.283 - self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0)
2.284 - )
2.285 -
2.286 - period_limits = "".join(period_limits)
2.287 -
2.288 - download_dialogue_link += period_limits
2.289 - download_all_link += period_limits
2.290 - subscribe_dialogue_link += period_limits
2.291 - subscribe_all_link += period_limits
2.292 -
2.293 - # Pop-up descriptions of the downloadable calendars.
2.294 -
2.295 - calendar_period = self.getCalendarPeriod()
2.296 - original_calendar_period = self.getOriginalCalendarPeriod()
2.297 - raw_calendar_period = self.getRawCalendarPeriod()
2.298 -
2.299 - # Write the controls.
2.300 -
2.301 - # Download controls.
2.302 -
2.303 - output.append(fmt.div(on=1, css_class="event-download-controls"))
2.304 -
2.305 - output.append(fmt.span(on=1, css_class="event-download"))
2.306 - output.append(fmt.text(_("Download...")))
2.307 - output.append(fmt.div(on=1, css_class="event-download-popup"))
2.308 -
2.309 - output.append(fmt.div(on=1, css_class="event-download-item"))
2.310 - output.append(fmt.span(on=1, css_class="event-download-types"))
2.311 - output.append(fmt.span(on=1, css_class="event-download-webcal"))
2.312 - output.append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_link))
2.313 - output.append(fmt.span(on=0))
2.314 - output.append(fmt.span(on=1, css_class="event-download-http"))
2.315 - output.append(linkToPage(request, page, _("http"), download_link))
2.316 - output.append(fmt.span(on=0))
2.317 - output.append(fmt.span(on=0)) # end types
2.318 - output.append(fmt.span(on=1, css_class="event-download-label"))
2.319 - output.append(fmt.text(_("Download this view")))
2.320 - output.append(fmt.span(on=0)) # end label
2.321 - output.append(fmt.span(on=1, css_class="event-download-period"))
2.322 - output.append(fmt.text(calendar_period))
2.323 - output.append(fmt.span(on=0))
2.324 - output.append(fmt.div(on=0))
2.325 -
2.326 - output.append(fmt.div(on=1, css_class="event-download-item"))
2.327 - output.append(fmt.span(on=1, css_class="event-download-types"))
2.328 - output.append(fmt.span(on=1, css_class="event-download-webcal"))
2.329 - output.append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_all_link))
2.330 - output.append(fmt.span(on=0))
2.331 - output.append(fmt.span(on=1, css_class="event-download-http"))
2.332 - output.append(linkToPage(request, page, _("http"), download_all_link))
2.333 - output.append(fmt.span(on=0))
2.334 - output.append(fmt.span(on=0)) # end types
2.335 - output.append(fmt.span(on=1, css_class="event-download-label"))
2.336 - output.append(fmt.text(_("Download this calendar")))
2.337 - output.append(fmt.span(on=0)) # end label
2.338 - output.append(fmt.span(on=1, css_class="event-download-period"))
2.339 - output.append(fmt.text(original_calendar_period))
2.340 - output.append(fmt.span(on=0))
2.341 - output.append(fmt.span(on=1, css_class="event-download-period-raw"))
2.342 - output.append(fmt.text(raw_calendar_period))
2.343 - output.append(fmt.span(on=0))
2.344 - output.append(fmt.div(on=0))
2.345 -
2.346 - output.append(fmt.div(on=1, css_class="event-download-item"))
2.347 - output.append(fmt.span(on=1, css_class="event-download-link"))
2.348 - output.append(linkToPage(request, page, _("Edit download options..."), download_dialogue_link))
2.349 - output.append(fmt.span(on=0)) # end label
2.350 - output.append(fmt.div(on=0))
2.351 -
2.352 - output.append(fmt.div(on=0)) # end of pop-up
2.353 - output.append(fmt.span(on=0)) # end of download
2.354 -
2.355 - # Subscription controls.
2.356 -
2.357 - output.append(fmt.span(on=1, css_class="event-download"))
2.358 - output.append(fmt.text(_("Subscribe...")))
2.359 - output.append(fmt.div(on=1, css_class="event-download-popup"))
2.360 -
2.361 - output.append(fmt.div(on=1, css_class="event-download-item"))
2.362 - output.append(fmt.span(on=1, css_class="event-download-label"))
2.363 - output.append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link))
2.364 - output.append(fmt.span(on=0)) # end label
2.365 - output.append(fmt.span(on=1, css_class="event-download-period"))
2.366 - output.append(fmt.text(calendar_period))
2.367 - output.append(fmt.span(on=0))
2.368 - output.append(fmt.div(on=0))
2.369 -
2.370 - output.append(fmt.div(on=1, css_class="event-download-item"))
2.371 - output.append(fmt.span(on=1, css_class="event-download-label"))
2.372 - output.append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link))
2.373 - output.append(fmt.span(on=0)) # end label
2.374 - output.append(fmt.span(on=1, css_class="event-download-period"))
2.375 - output.append(fmt.text(original_calendar_period))
2.376 - output.append(fmt.span(on=0))
2.377 - output.append(fmt.span(on=1, css_class="event-download-period-raw"))
2.378 - output.append(fmt.text(raw_calendar_period))
2.379 - output.append(fmt.span(on=0))
2.380 - output.append(fmt.div(on=0))
2.381 -
2.382 - output.append(fmt.div(on=1, css_class="event-download-item"))
2.383 - output.append(fmt.span(on=1, css_class="event-download-link"))
2.384 - output.append(linkToPage(request, page, _("Edit subscription options..."), subscribe_dialogue_link))
2.385 - output.append(fmt.span(on=0)) # end label
2.386 - output.append(fmt.div(on=0))
2.387 -
2.388 - output.append(fmt.div(on=0)) # end of pop-up
2.389 - output.append(fmt.span(on=0)) # end of download
2.390 -
2.391 - output.append(fmt.div(on=0)) # end of controls
2.392 -
2.393 - return "".join(output)
2.394 -
2.395 - def writeViewControls(self):
2.396 -
2.397 - """
2.398 - Return a representation of the view mode controls, permitting viewing of
2.399 - aggregated events in calendar, list or table form.
2.400 - """
2.401 -
2.402 - page = self.page
2.403 - request = page.request
2.404 - fmt = page.formatter
2.405 - _ = request.getText
2.406 -
2.407 - output = []
2.408 -
2.409 - start = self.calendar_start
2.410 - end = self.calendar_end
2.411 -
2.412 - help_page = Page(request, "HelpOnEventAggregator")
2.413 - calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
2.414 - list_link = self.getNavigationLink(start, end, "list")
2.415 - table_link = self.getNavigationLink(start, end, "table")
2.416 - map_link = self.getNavigationLink(start, end, "map")
2.417 - new_event_link = self.getNewEventLink(start)
2.418 -
2.419 - # Write the controls.
2.420 -
2.421 - output.append(fmt.div(on=1, css_class="event-view-controls"))
2.422 -
2.423 - output.append(fmt.span(on=1, css_class="event-view"))
2.424 - output.append(linkToPage(request, help_page, _("Help")))
2.425 - output.append(fmt.span(on=0))
2.426 -
2.427 - output.append(fmt.span(on=1, css_class="event-view"))
2.428 - output.append(linkToPage(request, page, _("New event"), new_event_link))
2.429 - output.append(fmt.span(on=0))
2.430 -
2.431 - if self.mode != "calendar":
2.432 - output.append(fmt.span(on=1, css_class="event-view"))
2.433 - output.append(linkToPage(request, page, _("View as calendar"), calendar_link))
2.434 - output.append(fmt.span(on=0))
2.435 -
2.436 - if self.mode != "list":
2.437 - output.append(fmt.span(on=1, css_class="event-view"))
2.438 - output.append(linkToPage(request, page, _("View as list"), list_link))
2.439 - output.append(fmt.span(on=0))
2.440 -
2.441 - if self.mode != "table":
2.442 - output.append(fmt.span(on=1, css_class="event-view"))
2.443 - output.append(linkToPage(request, page, _("View as table"), table_link))
2.444 - output.append(fmt.span(on=0))
2.445 -
2.446 - if self.mode != "map" and self.map_name is not None:
2.447 - output.append(fmt.span(on=1, css_class="event-view"))
2.448 - output.append(linkToPage(request, page, _("View as map"), map_link))
2.449 - output.append(fmt.span(on=0))
2.450 -
2.451 - output.append(fmt.div(on=0))
2.452 -
2.453 - return "".join(output)
2.454 -
2.455 - def writeMapHeading(self):
2.456 -
2.457 - """
2.458 - Return the calendar heading for the current calendar, providing links
2.459 - permitting navigation to other periods.
2.460 - """
2.461 -
2.462 - label = self.getCalendarPeriod()
2.463 -
2.464 - if self.raw_calendar_start is None or self.raw_calendar_end is None:
2.465 - fmt = self.page.formatter
2.466 - output = []
2.467 - output.append(fmt.span(on=1))
2.468 - output.append(fmt.text(label))
2.469 - output.append(fmt.span(on=0))
2.470 - return "".join(output)
2.471 - else:
2.472 - return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end)
2.473 -
2.474 - def writeDateHeading(self, date):
2.475 - if isinstance(date, Date):
2.476 - return self.writeDayHeading(date)
2.477 - else:
2.478 - return self.writeMonthHeading(date)
2.479 -
2.480 - def writeMonthHeading(self, year_month):
2.481 -
2.482 - """
2.483 - Return the calendar heading for the given 'year_month' (a Month object)
2.484 - providing links permitting navigation to other months.
2.485 - """
2.486 -
2.487 - full_month_label = self.getFullMonthLabel(year_month)
2.488 - end_month = year_month.update(self.duration - 1)
2.489 - return self._writeCalendarHeading(full_month_label, year_month, end_month)
2.490 -
2.491 - def writeDayHeading(self, date):
2.492 -
2.493 - """
2.494 - Return the calendar heading for the given 'date' (a Date object)
2.495 - providing links permitting navigation to other dates.
2.496 - """
2.497 -
2.498 - full_date_label = self.getFullDateLabel(date)
2.499 - end_date = date.update(self.duration - 1)
2.500 - return self._writeCalendarHeading(full_date_label, date, end_date)
2.501 -
2.502 - def _writeCalendarHeading(self, label, start, end):
2.503 -
2.504 - """
2.505 - Write a calendar heading providing links permitting navigation to other
2.506 - periods, using the given 'label' along with the 'start' and 'end' dates
2.507 - to provide a link to a particular period.
2.508 - """
2.509 -
2.510 - page = self.page
2.511 - request = page.request
2.512 - fmt = page.formatter
2.513 - _ = request.getText
2.514 -
2.515 - output = []
2.516 -
2.517 - # Prepare navigation links.
2.518 -
2.519 - if self.calendar_name is not None:
2.520 - calendar_name = self.calendar_name
2.521 -
2.522 - # Links to the previous set of months and to a calendar shifted
2.523 - # back one month.
2.524 -
2.525 - previous_set_link = self.getNavigationLink(
2.526 - self.previous_set_start, self.previous_set_end
2.527 - )
2.528 - previous_link = self.getNavigationLink(
2.529 - self.previous_start, self.previous_end
2.530 - )
2.531 -
2.532 - # Links to the next set of months and to a calendar shifted
2.533 - # forward one month.
2.534 -
2.535 - next_set_link = self.getNavigationLink(
2.536 - self.next_set_start, self.next_set_end
2.537 - )
2.538 - next_link = self.getNavigationLink(
2.539 - self.next_start, self.next_end
2.540 - )
2.541 -
2.542 - # A link leading to this date being at the top of the calendar.
2.543 -
2.544 - date_link = self.getNavigationLink(start, end)
2.545 -
2.546 - output.append(fmt.span(on=1, css_class="previous"))
2.547 - output.append(linkToPage(request, page, "<<", previous_set_link))
2.548 - output.append(fmt.text(" "))
2.549 - output.append(linkToPage(request, page, "<", previous_link))
2.550 - output.append(fmt.span(on=0))
2.551 -
2.552 - output.append(fmt.span(on=1, css_class="next"))
2.553 - output.append(linkToPage(request, page, ">", next_link))
2.554 - output.append(fmt.text(" "))
2.555 - output.append(linkToPage(request, page, ">>", next_set_link))
2.556 - output.append(fmt.span(on=0))
2.557 -
2.558 - output.append(linkToPage(request, page, label, date_link))
2.559 -
2.560 - else:
2.561 - output.append(fmt.span(on=1))
2.562 - output.append(fmt.text(label))
2.563 - output.append(fmt.span(on=0))
2.564 -
2.565 - return "".join(output)
2.566 -
2.567 - def writeDayNumberHeading(self, date, busy):
2.568 -
2.569 - """
2.570 - Return a link for the given 'date' which will activate the new event
2.571 - action for the given day. If 'busy' is given as a true value, the
2.572 - heading will be marked as busy.
2.573 - """
2.574 -
2.575 - page = self.page
2.576 - request = page.request
2.577 - fmt = page.formatter
2.578 - _ = request.getText
2.579 -
2.580 - output = []
2.581 -
2.582 - year, month, day = date.as_tuple()
2.583 - new_event_link = self.getNewEventLink(date)
2.584 -
2.585 - # Prepare a link to the day view for this day.
2.586 -
2.587 - day_view_link = self.getNavigationLink(date, date, "day", "date")
2.588 -
2.589 - # Output the heading class.
2.590 -
2.591 - output.append(
2.592 - fmt.table_cell(on=1, attrs={
2.593 - "class" : "event-day-heading event-day-%s" % (busy and "busy" or "empty"),
2.594 - "colspan" : "3"
2.595 - }))
2.596 -
2.597 - # Output the number and pop-up menu.
2.598 -
2.599 - output.append(fmt.div(on=1, css_class="event-day-box"))
2.600 -
2.601 - output.append(fmt.span(on=1, css_class="event-day-number-popup"))
2.602 - output.append(fmt.span(on=1, css_class="event-day-number-link"))
2.603 - output.append(linkToPage(request, page, _("View day"), day_view_link))
2.604 - output.append(fmt.span(on=0))
2.605 - output.append(fmt.span(on=1, css_class="event-day-number-link"))
2.606 - output.append(linkToPage(request, page, _("New event"), new_event_link))
2.607 - output.append(fmt.span(on=0))
2.608 - output.append(fmt.span(on=0))
2.609 -
2.610 - output.append(fmt.span(on=1, css_class="event-day-number"))
2.611 - output.append(fmt.text(unicode(day)))
2.612 - output.append(fmt.span(on=0))
2.613 -
2.614 - output.append(fmt.div(on=0))
2.615 -
2.616 - # End of heading.
2.617 -
2.618 - output.append(fmt.table_cell(on=0))
2.619 -
2.620 - return "".join(output)
2.621 -
2.622 - # Common layout methods.
2.623 -
2.624 - def getEventStyle(self, colour_seed):
2.625 -
2.626 - "Generate colour style information using the given 'colour_seed'."
2.627 -
2.628 - bg = getColour(colour_seed)
2.629 - fg = getBlackOrWhite(bg)
2.630 - return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg)
2.631 -
2.632 - def writeEventSummaryBox(self, event):
2.633 -
2.634 - "Return an event summary box linking to the given 'event'."
2.635 -
2.636 - page = self.page
2.637 - request = page.request
2.638 - fmt = page.formatter
2.639 -
2.640 - output = []
2.641 -
2.642 - event_details = event.getDetails()
2.643 - event_summary = event.getSummary(self.parent_name)
2.644 -
2.645 - is_ambiguous = event.as_timespan().ambiguous()
2.646 - style = self.getEventStyle(event_summary)
2.647 -
2.648 - # The event box contains the summary, alongside
2.649 - # other elements.
2.650 -
2.651 - output.append(fmt.div(on=1, css_class="event-summary-box"))
2.652 - output.append(fmt.div(on=1, css_class="event-summary", style=style))
2.653 -
2.654 - if is_ambiguous:
2.655 - output.append(fmt.icon("/!\\"))
2.656 -
2.657 - output.append(event.linkToEvent(request, event_summary))
2.658 - output.append(fmt.div(on=0))
2.659 -
2.660 - # Add a pop-up element for long summaries.
2.661 -
2.662 - output.append(fmt.div(on=1, css_class="event-summary-popup", style=style))
2.663 -
2.664 - if is_ambiguous:
2.665 - output.append(fmt.icon("/!\\"))
2.666 -
2.667 - output.append(event.linkToEvent(request, event_summary))
2.668 - output.append(fmt.div(on=0))
2.669 -
2.670 - output.append(fmt.div(on=0))
2.671 -
2.672 - return "".join(output)
2.673 -
2.674 - # Calendar layout methods.
2.675 -
2.676 - def writeMonthTableHeading(self, year_month):
2.677 - page = self.page
2.678 - fmt = page.formatter
2.679 -
2.680 - output = []
2.681 - output.append(fmt.table_row(on=1))
2.682 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"}))
2.683 -
2.684 - output.append(self.writeMonthHeading(year_month))
2.685 -
2.686 - output.append(fmt.table_cell(on=0))
2.687 - output.append(fmt.table_row(on=0))
2.688 -
2.689 - return "".join(output)
2.690 -
2.691 - def writeWeekdayHeadings(self):
2.692 - page = self.page
2.693 - request = page.request
2.694 - fmt = page.formatter
2.695 - _ = request.getText
2.696 -
2.697 - output = []
2.698 - output.append(fmt.table_row(on=1))
2.699 -
2.700 - for weekday in range(0, 7):
2.701 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"}))
2.702 - output.append(fmt.text(_(getDayLabel(weekday))))
2.703 - output.append(fmt.table_cell(on=0))
2.704 -
2.705 - output.append(fmt.table_row(on=0))
2.706 - return "".join(output)
2.707 -
2.708 - def writeDayNumbers(self, first_day, number_of_days, month, coverage):
2.709 - page = self.page
2.710 - fmt = page.formatter
2.711 -
2.712 - output = []
2.713 - output.append(fmt.table_row(on=1))
2.714 -
2.715 - for weekday in range(0, 7):
2.716 - day = first_day + weekday
2.717 - date = month.as_date(day)
2.718 -
2.719 - # Output out-of-month days.
2.720 -
2.721 - if day < 1 or day > number_of_days:
2.722 - output.append(fmt.table_cell(on=1,
2.723 - attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"}))
2.724 - output.append(fmt.table_cell(on=0))
2.725 -
2.726 - # Output normal days.
2.727 -
2.728 - else:
2.729 - # Output the day heading, making a link to a new event
2.730 - # action.
2.731 -
2.732 - output.append(self.writeDayNumberHeading(date, date in coverage))
2.733 -
2.734 - # End of day numbers.
2.735 -
2.736 - output.append(fmt.table_row(on=0))
2.737 - return "".join(output)
2.738 -
2.739 - def writeEmptyWeek(self, first_day, number_of_days):
2.740 - page = self.page
2.741 - fmt = page.formatter
2.742 -
2.743 - output = []
2.744 - output.append(fmt.table_row(on=1))
2.745 -
2.746 - for weekday in range(0, 7):
2.747 - day = first_day + weekday
2.748 -
2.749 - # Output out-of-month days.
2.750 -
2.751 - if day < 1 or day > number_of_days:
2.752 - output.append(fmt.table_cell(on=1,
2.753 - attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"}))
2.754 - output.append(fmt.table_cell(on=0))
2.755 -
2.756 - # Output empty days.
2.757 -
2.758 - else:
2.759 - output.append(fmt.table_cell(on=1,
2.760 - attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"}))
2.761 -
2.762 - output.append(fmt.table_row(on=0))
2.763 - return "".join(output)
2.764 -
2.765 - def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots):
2.766 - output = []
2.767 -
2.768 - locations = week_slots.keys()
2.769 - locations.sort(sort_none_first)
2.770 -
2.771 - # Visit each slot corresponding to a location (or no location).
2.772 -
2.773 - for location in locations:
2.774 -
2.775 - # Visit each coverage span, presenting the events in the span.
2.776 -
2.777 - for events in week_slots[location]:
2.778 -
2.779 - # Output each set.
2.780 -
2.781 - output.append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events))
2.782 -
2.783 - # Add a spacer.
2.784 -
2.785 - output.append(self.writeWeekSpacer(first_day, number_of_days))
2.786 -
2.787 - return "".join(output)
2.788 -
2.789 - def writeWeekSlot(self, first_day, number_of_days, month, week_end, events):
2.790 - page = self.page
2.791 - request = page.request
2.792 - fmt = page.formatter
2.793 -
2.794 - output = []
2.795 - output.append(fmt.table_row(on=1))
2.796 -
2.797 - # Then, output day details.
2.798 -
2.799 - for weekday in range(0, 7):
2.800 - day = first_day + weekday
2.801 - date = month.as_date(day)
2.802 -
2.803 - # Skip out-of-month days.
2.804 -
2.805 - if day < 1 or day > number_of_days:
2.806 - output.append(fmt.table_cell(on=1,
2.807 - attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"}))
2.808 - output.append(fmt.table_cell(on=0))
2.809 - continue
2.810 -
2.811 - # Output the day.
2.812 -
2.813 - if date not in events:
2.814 - output.append(fmt.table_cell(on=1,
2.815 - attrs={"class" : "event-day-content event-day-empty", "colspan" : "3"}))
2.816 -
2.817 - # Get event details for the current day.
2.818 -
2.819 - for event in events:
2.820 - event_details = event.getDetails()
2.821 -
2.822 - if date not in event:
2.823 - continue
2.824 -
2.825 - # Get basic properties of the event.
2.826 -
2.827 - starts_today = event_details["start"] == date
2.828 - ends_today = event_details["end"] == date
2.829 - event_summary = event.getSummary(self.parent_name)
2.830 -
2.831 - style = self.getEventStyle(event_summary)
2.832 -
2.833 - # Determine if the event name should be shown.
2.834 -
2.835 - start_of_period = starts_today or weekday == 0 or day == 1
2.836 -
2.837 - if self.name_usage == "daily" or start_of_period:
2.838 - hide_text = 0
2.839 - else:
2.840 - hide_text = 1
2.841 -
2.842 - # Output start of day gap and determine whether
2.843 - # any event content should be explicitly output
2.844 - # for this day.
2.845 -
2.846 - if starts_today:
2.847 -
2.848 - # Single day events...
2.849 -
2.850 - if ends_today:
2.851 - colspan = 3
2.852 - event_day_type = "event-day-single"
2.853 -
2.854 - # Events starting today...
2.855 -
2.856 - else:
2.857 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap"}))
2.858 - output.append(fmt.table_cell(on=0))
2.859 -
2.860 - # Calculate the span of this cell.
2.861 - # Events whose names appear on every day...
2.862 -
2.863 - if self.name_usage == "daily":
2.864 - colspan = 2
2.865 - event_day_type = "event-day-starting"
2.866 -
2.867 - # Events whose names appear once per week...
2.868 -
2.869 - else:
2.870 - if event_details["end"] <= week_end:
2.871 - event_length = event_details["end"].day() - day + 1
2.872 - colspan = (event_length - 2) * 3 + 4
2.873 - else:
2.874 - event_length = week_end.day() - day + 1
2.875 - colspan = (event_length - 1) * 3 + 2
2.876 -
2.877 - event_day_type = "event-day-multiple"
2.878 -
2.879 - # Events continuing from a previous week...
2.880 -
2.881 - elif start_of_period:
2.882 -
2.883 - # End of continuing event...
2.884 -
2.885 - if ends_today:
2.886 - colspan = 2
2.887 - event_day_type = "event-day-ending"
2.888 -
2.889 - # Events continuing for at least one more day...
2.890 -
2.891 - else:
2.892 -
2.893 - # Calculate the span of this cell.
2.894 - # Events whose names appear on every day...
2.895 -
2.896 - if self.name_usage == "daily":
2.897 - colspan = 3
2.898 - event_day_type = "event-day-full"
2.899 -
2.900 - # Events whose names appear once per week...
2.901 -
2.902 - else:
2.903 - if event_details["end"] <= week_end:
2.904 - event_length = event_details["end"].day() - day + 1
2.905 - colspan = (event_length - 1) * 3 + 2
2.906 - else:
2.907 - event_length = week_end.day() - day + 1
2.908 - colspan = event_length * 3
2.909 -
2.910 - event_day_type = "event-day-multiple"
2.911 -
2.912 - # Continuing events whose names appear on every day...
2.913 -
2.914 - elif self.name_usage == "daily":
2.915 - if ends_today:
2.916 - colspan = 2
2.917 - event_day_type = "event-day-ending"
2.918 - else:
2.919 - colspan = 3
2.920 - event_day_type = "event-day-full"
2.921 -
2.922 - # Continuing events whose names appear once per week...
2.923 -
2.924 - else:
2.925 - colspan = None
2.926 -
2.927 - # Output the main content only if it is not
2.928 - # continuing from a previous day.
2.929 -
2.930 - if colspan is not None:
2.931 -
2.932 - # Colour the cell for continuing events.
2.933 -
2.934 - attrs={
2.935 - "class" : "event-day-content event-day-busy %s" % event_day_type,
2.936 - "colspan" : str(colspan)
2.937 - }
2.938 -
2.939 - if not (starts_today and ends_today):
2.940 - attrs["style"] = style
2.941 -
2.942 - output.append(fmt.table_cell(on=1, attrs=attrs))
2.943 -
2.944 - # Output the event.
2.945 -
2.946 - if starts_today and ends_today or not hide_text:
2.947 - output.append(self.writeEventSummaryBox(event))
2.948 -
2.949 - output.append(fmt.table_cell(on=0))
2.950 -
2.951 - # Output end of day gap.
2.952 -
2.953 - if ends_today and not starts_today:
2.954 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap"}))
2.955 - output.append(fmt.table_cell(on=0))
2.956 -
2.957 - # End of set.
2.958 -
2.959 - output.append(fmt.table_row(on=0))
2.960 - return "".join(output)
2.961 -
2.962 - def writeWeekSpacer(self, first_day, number_of_days):
2.963 - page = self.page
2.964 - fmt = page.formatter
2.965 -
2.966 - output = []
2.967 - output.append(fmt.table_row(on=1))
2.968 -
2.969 - for weekday in range(0, 7):
2.970 - day = first_day + weekday
2.971 - css_classes = "event-day-spacer"
2.972 -
2.973 - # Skip out-of-month days.
2.974 -
2.975 - if day < 1 or day > number_of_days:
2.976 - css_classes += " event-day-excluded"
2.977 -
2.978 - output.append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"}))
2.979 - output.append(fmt.table_cell(on=0))
2.980 -
2.981 - output.append(fmt.table_row(on=0))
2.982 - return "".join(output)
2.983 -
2.984 - # Day layout methods.
2.985 -
2.986 - def writeDayTableHeading(self, date, colspan=1):
2.987 - page = self.page
2.988 - fmt = page.formatter
2.989 -
2.990 - output = []
2.991 - output.append(fmt.table_row(on=1))
2.992 -
2.993 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)}))
2.994 - output.append(self.writeDayHeading(date))
2.995 - output.append(fmt.table_cell(on=0))
2.996 -
2.997 - output.append(fmt.table_row(on=0))
2.998 - return "".join(output)
2.999 -
2.1000 - def writeEmptyDay(self, date):
2.1001 - page = self.page
2.1002 - fmt = page.formatter
2.1003 -
2.1004 - output = []
2.1005 - output.append(fmt.table_row(on=1))
2.1006 -
2.1007 - output.append(fmt.table_cell(on=1,
2.1008 - attrs={"class" : "event-day-content event-day-empty"}))
2.1009 -
2.1010 - output.append(fmt.table_row(on=0))
2.1011 - return "".join(output)
2.1012 -
2.1013 - def writeDaySlots(self, date, full_coverage, day_slots):
2.1014 -
2.1015 - """
2.1016 - Given a 'date', non-empty 'full_coverage' for the day concerned, and a
2.1017 - non-empty mapping of 'day_slots' (from locations to event collections),
2.1018 - output the day slots for the day.
2.1019 - """
2.1020 -
2.1021 - page = self.page
2.1022 - fmt = page.formatter
2.1023 -
2.1024 - output = []
2.1025 -
2.1026 - locations = day_slots.keys()
2.1027 - locations.sort(sort_none_first)
2.1028 -
2.1029 - # Traverse the time scale of the full coverage, visiting each slot to
2.1030 - # determine whether it provides content for each period.
2.1031 -
2.1032 - scale = getCoverageScale(full_coverage)
2.1033 -
2.1034 - # Define a mapping of events to rowspans.
2.1035 -
2.1036 - rowspans = {}
2.1037 -
2.1038 - # Populate each period with event details, recording how many periods
2.1039 - # each event populates.
2.1040 -
2.1041 - day_rows = []
2.1042 -
2.1043 - for period in scale:
2.1044 -
2.1045 - # Ignore timespans before this day.
2.1046 -
2.1047 - if period != date:
2.1048 - continue
2.1049 -
2.1050 - # Visit each slot corresponding to a location (or no location).
2.1051 -
2.1052 - day_row = []
2.1053 -
2.1054 - for location in locations:
2.1055 -
2.1056 - # Visit each coverage span, presenting the events in the span.
2.1057 -
2.1058 - for events in day_slots[location]:
2.1059 - event = self.getActiveEvent(period, events)
2.1060 - if event is not None:
2.1061 - if not rowspans.has_key(event):
2.1062 - rowspans[event] = 1
2.1063 - else:
2.1064 - rowspans[event] += 1
2.1065 - day_row.append((location, event))
2.1066 -
2.1067 - day_rows.append((period, day_row))
2.1068 -
2.1069 - # Output the locations.
2.1070 -
2.1071 - output.append(fmt.table_row(on=1))
2.1072 -
2.1073 - # Add a spacer.
2.1074 -
2.1075 - output.append(self.writeDaySpacer(colspan=2, cls="location"))
2.1076 -
2.1077 - for location in locations:
2.1078 -
2.1079 - # Add spacers to the column spans.
2.1080 -
2.1081 - columns = len(day_slots[location]) * 2 - 1
2.1082 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)}))
2.1083 - output.append(fmt.text(location or ""))
2.1084 - output.append(fmt.table_cell(on=0))
2.1085 -
2.1086 - # Add a trailing spacer.
2.1087 -
2.1088 - output.append(self.writeDaySpacer(cls="location"))
2.1089 -
2.1090 - output.append(fmt.table_row(on=0))
2.1091 -
2.1092 - # Output the periods with event details.
2.1093 -
2.1094 - period = None
2.1095 - events_written = set()
2.1096 -
2.1097 - for period, day_row in day_rows:
2.1098 -
2.1099 - # Write an empty heading for the start of the day where the first
2.1100 - # applicable timespan starts before this day.
2.1101 -
2.1102 - if period.start < date:
2.1103 - output.append(fmt.table_row(on=1))
2.1104 - output.append(self.writeDayScaleHeading(""))
2.1105 -
2.1106 - # Otherwise, write a heading describing the time.
2.1107 -
2.1108 - else:
2.1109 - output.append(fmt.table_row(on=1))
2.1110 - output.append(self.writeDayScaleHeading(period.start.time_string()))
2.1111 -
2.1112 - output.append(self.writeDaySpacer())
2.1113 -
2.1114 - # Visit each slot corresponding to a location (or no location).
2.1115 -
2.1116 - for location, event in day_row:
2.1117 -
2.1118 - # Output each location slot's contribution.
2.1119 -
2.1120 - if event is None or event not in events_written:
2.1121 - output.append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event]))
2.1122 - if event is not None:
2.1123 - events_written.add(event)
2.1124 -
2.1125 - # Add a trailing spacer.
2.1126 -
2.1127 - output.append(self.writeDaySpacer())
2.1128 -
2.1129 - output.append(fmt.table_row(on=0))
2.1130 -
2.1131 - # Write a final time heading if the last period ends in the current day.
2.1132 -
2.1133 - if period is not None:
2.1134 - if period.end == date:
2.1135 - output.append(fmt.table_row(on=1))
2.1136 - output.append(self.writeDayScaleHeading(period.end.time_string()))
2.1137 -
2.1138 - for slot in day_row:
2.1139 - output.append(self.writeDaySpacer())
2.1140 - output.append(self.writeEmptyDaySlot())
2.1141 -
2.1142 - output.append(fmt.table_row(on=0))
2.1143 -
2.1144 - return "".join(output)
2.1145 -
2.1146 - def writeDayScaleHeading(self, heading):
2.1147 - page = self.page
2.1148 - fmt = page.formatter
2.1149 -
2.1150 - output = []
2.1151 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"}))
2.1152 - output.append(fmt.text(heading))
2.1153 - output.append(fmt.table_cell(on=0))
2.1154 -
2.1155 - return "".join(output)
2.1156 -
2.1157 - def getActiveEvent(self, period, events):
2.1158 - for event in events:
2.1159 - if period not in event:
2.1160 - continue
2.1161 - return event
2.1162 - else:
2.1163 - return None
2.1164 -
2.1165 - def writeDaySlot(self, period, event, rowspan):
2.1166 - page = self.page
2.1167 - fmt = page.formatter
2.1168 -
2.1169 - output = []
2.1170 -
2.1171 - if event is not None:
2.1172 - event_summary = event.getSummary(self.parent_name)
2.1173 - style = self.getEventStyle(event_summary)
2.1174 -
2.1175 - output.append(fmt.table_cell(on=1, attrs={
2.1176 - "class" : "event-timespan-content event-timespan-busy",
2.1177 - "style" : style,
2.1178 - "rowspan" : str(rowspan)
2.1179 - }))
2.1180 - output.append(self.writeEventSummaryBox(event))
2.1181 - output.append(fmt.table_cell(on=0))
2.1182 - else:
2.1183 - output.append(self.writeEmptyDaySlot())
2.1184 -
2.1185 - return "".join(output)
2.1186 -
2.1187 - def writeEmptyDaySlot(self):
2.1188 - page = self.page
2.1189 - fmt = page.formatter
2.1190 -
2.1191 - output = []
2.1192 -
2.1193 - output.append(fmt.table_cell(on=1,
2.1194 - attrs={"class" : "event-timespan-content event-timespan-empty"}))
2.1195 - output.append(fmt.table_cell(on=0))
2.1196 -
2.1197 - return "".join(output)
2.1198 -
2.1199 - def writeDaySpacer(self, colspan=1, cls="timespan"):
2.1200 - page = self.page
2.1201 - fmt = page.formatter
2.1202 -
2.1203 - output = []
2.1204 - output.append(fmt.table_cell(on=1, attrs={
2.1205 - "class" : "event-%s-spacer" % cls,
2.1206 - "colspan" : str(colspan)}))
2.1207 - output.append(fmt.table_cell(on=0))
2.1208 - return "".join(output)
2.1209 -
2.1210 - # Map layout methods.
2.1211 -
2.1212 - def writeMapTableHeading(self):
2.1213 - page = self.page
2.1214 - fmt = page.formatter
2.1215 -
2.1216 - output = []
2.1217 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"}))
2.1218 - output.append(self.writeMapHeading())
2.1219 - output.append(fmt.table_cell(on=0))
2.1220 -
2.1221 - return "".join(output)
2.1222 -
2.1223 - def showDictError(self, text, pagename):
2.1224 - page = self.page
2.1225 - fmt = page.formatter
2.1226 - request = page.request
2.1227 -
2.1228 - output = []
2.1229 -
2.1230 - output.append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"}))
2.1231 - output.append(fmt.paragraph(on=1))
2.1232 - output.append(fmt.text(text))
2.1233 - output.append(fmt.paragraph(on=0))
2.1234 - output.append(fmt.paragraph(on=1))
2.1235 - output.append(linkToPage(request, Page(request, pagename), pagename))
2.1236 - output.append(fmt.paragraph(on=0))
2.1237 -
2.1238 - return "".join(output)
2.1239 -
2.1240 - def writeMapEventSummaries(self, events):
2.1241 - page = self.page
2.1242 - fmt = page.formatter
2.1243 - request = page.request
2.1244 -
2.1245 - # Sort the events by date.
2.1246 -
2.1247 - events.sort(sort_start_first)
2.1248 -
2.1249 - # Write out a self-contained list of events.
2.1250 -
2.1251 - output = []
2.1252 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"}))
2.1253 -
2.1254 - for event in events:
2.1255 -
2.1256 - # Get the event details.
2.1257 -
2.1258 - event_summary = event.getSummary(self.parent_name)
2.1259 - start, end = event.as_limits()
2.1260 - event_period = self._getCalendarPeriod(
2.1261 - start and self.getFullDateLabel(start),
2.1262 - end and self.getFullDateLabel(end),
2.1263 - "")
2.1264 -
2.1265 - output.append(fmt.listitem(on=1))
2.1266 -
2.1267 - # Link to the page using the summary.
2.1268 -
2.1269 - output.append(event.linkToEvent(request, event_summary))
2.1270 -
2.1271 - # Add the event period.
2.1272 -
2.1273 - output.append(fmt.text(" "))
2.1274 - output.append(fmt.span(on=1, css_class="event-map-period"))
2.1275 - output.append(fmt.text(event_period))
2.1276 - output.append(fmt.span(on=0))
2.1277 -
2.1278 - output.append(fmt.listitem(on=0))
2.1279 -
2.1280 - output.append(fmt.bullet_list(on=0))
2.1281 -
2.1282 - return "".join(output)
2.1283 -
2.1284 -# HTML-related functions.
2.1285 -
2.1286 -def getColour(s):
2.1287 - colour = [0, 0, 0]
2.1288 - digit = 0
2.1289 - for c in s:
2.1290 - colour[digit] += ord(c)
2.1291 - colour[digit] = colour[digit] % 256
2.1292 - digit += 1
2.1293 - digit = digit % 3
2.1294 - return tuple(colour)
2.1295 -
2.1296 -def getBlackOrWhite(colour):
2.1297 - if sum(colour) / 3.0 > 127:
2.1298 - return (0, 0, 0)
2.1299 - else:
2.1300 - return (255, 255, 255)
2.1301 -
2.1302 # Macro functions.
2.1303
2.1304 def execute(macro, args):
2.1305 @@ -1354,7 +63,6 @@
2.1306 request = macro.request
2.1307 fmt = macro.formatter
2.1308 page = fmt.page
2.1309 - _ = request.getText
2.1310
2.1311 # Interpret the arguments.
2.1312
2.1313 @@ -1454,529 +162,6 @@
2.1314 first, last, category_names, remote_sources, template_name, parent_name,
2.1315 mode, resolution, name_usage, map_name)
2.1316
2.1317 - # Make a calendar.
2.1318 -
2.1319 - output = []
2.1320 -
2.1321 - output.append(fmt.div(on=1, css_class="event-calendar"))
2.1322 -
2.1323 - # Output download controls.
2.1324 -
2.1325 - output.append(fmt.div(on=1, css_class="event-controls"))
2.1326 - output.append(view.writeDownloadControls())
2.1327 - output.append(fmt.div(on=0))
2.1328 -
2.1329 - # Output a table.
2.1330 -
2.1331 - if mode == "table":
2.1332 -
2.1333 - # Start of table view output.
2.1334 -
2.1335 - output.append(fmt.table(on=1, attrs={"tableclass" : "event-table"}))
2.1336 -
2.1337 - output.append(fmt.table_row(on=1))
2.1338 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
2.1339 - output.append(fmt.text(_("Event dates")))
2.1340 - output.append(fmt.table_cell(on=0))
2.1341 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
2.1342 - output.append(fmt.text(_("Event location")))
2.1343 - output.append(fmt.table_cell(on=0))
2.1344 - output.append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
2.1345 - output.append(fmt.text(_("Event details")))
2.1346 - output.append(fmt.table_cell(on=0))
2.1347 - output.append(fmt.table_row(on=0))
2.1348 -
2.1349 - # Show the events in order.
2.1350 -
2.1351 - all_shown_events.sort(sort_start_first)
2.1352 -
2.1353 - for event in all_shown_events:
2.1354 - event_page = event.getPage()
2.1355 - event_summary = event.getSummary(parent_name)
2.1356 - event_details = event.getDetails()
2.1357 -
2.1358 - # Prepare CSS classes with category-related styling.
2.1359 -
2.1360 - css_classes = ["event-table-details"]
2.1361 -
2.1362 - for topic in event_details.get("topics") or event_details.get("categories") or []:
2.1363 -
2.1364 - # Filter the category text to avoid illegal characters.
2.1365 -
2.1366 - css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic)))
2.1367 -
2.1368 - attrs = {"class" : " ".join(css_classes)}
2.1369 -
2.1370 - output.append(fmt.table_row(on=1))
2.1371 -
2.1372 - # Start and end dates.
2.1373 -
2.1374 - output.append(fmt.table_cell(on=1, attrs=attrs))
2.1375 - output.append(fmt.span(on=1))
2.1376 - output.append(fmt.text(str(event_details["start"])))
2.1377 - output.append(fmt.span(on=0))
2.1378 -
2.1379 - if event_details["start"] != event_details["end"]:
2.1380 - output.append(fmt.text(" - "))
2.1381 - output.append(fmt.span(on=1))
2.1382 - output.append(fmt.text(str(event_details["end"])))
2.1383 - output.append(fmt.span(on=0))
2.1384 -
2.1385 - output.append(fmt.table_cell(on=0))
2.1386 -
2.1387 - # Location.
2.1388 -
2.1389 - output.append(fmt.table_cell(on=1, attrs=attrs))
2.1390 -
2.1391 - if event_details.has_key("location"):
2.1392 - output.append(event_page.formatText(event_details["location"], request, fmt))
2.1393 -
2.1394 - output.append(fmt.table_cell(on=0))
2.1395 -
2.1396 - # Link to the page using the summary.
2.1397 -
2.1398 - output.append(fmt.table_cell(on=1, attrs=attrs))
2.1399 - output.append(event.linkToEvent(request, event_summary))
2.1400 - output.append(fmt.table_cell(on=0))
2.1401 -
2.1402 - output.append(fmt.table_row(on=0))
2.1403 -
2.1404 - # End of table view output.
2.1405 -
2.1406 - output.append(fmt.table(on=0))
2.1407 -
2.1408 - # Output a map view.
2.1409 -
2.1410 - elif mode == "map":
2.1411 -
2.1412 - # Special dictionary pages.
2.1413 -
2.1414 - maps_page = getattr(request.cfg, "event_aggregator_maps_page", "EventMapsDict")
2.1415 - locations_page = getattr(request.cfg, "event_aggregator_locations_page", "EventLocationsDict")
2.1416 -
2.1417 - map_image = None
2.1418 -
2.1419 - # Get the maps and locations.
2.1420 -
2.1421 - maps = getWikiDict(maps_page, request)
2.1422 - locations = getWikiDict(locations_page, request)
2.1423 -
2.1424 - # Get the map image definition.
2.1425 -
2.1426 - if maps is not None and map_name is not None:
2.1427 - try:
2.1428 - map_details = maps[map_name].split()
2.1429 -
2.1430 - map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \
2.1431 - map(getMapReference, map_details[:4])
2.1432 - map_width, map_height = map(int, map_details[4:6])
2.1433 - map_image = map_details[6]
2.1434 -
2.1435 - map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees()
2.1436 - map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees()
2.1437 -
2.1438 - except (KeyError, ValueError):
2.1439 - pass
2.1440 -
2.1441 - # Report errors.
2.1442 -
2.1443 - if maps is None:
2.1444 - output.append(view.showDictError(
2.1445 - _("You do not have read access to the maps page:"),
2.1446 - maps_page))
2.1447 -
2.1448 - elif map_name is None:
2.1449 - output.append(view.showDictError(
2.1450 - _("Please specify a valid map name corresponding to an entry on the following page:"),
2.1451 - maps_page))
2.1452 -
2.1453 - elif map_image is None:
2.1454 - output.append(view.showDictError(
2.1455 - _("Please specify a valid entry for %s on the following page:") % map_name,
2.1456 - maps_page))
2.1457 -
2.1458 - elif locations is None:
2.1459 - output.append(view.showDictError(
2.1460 - _("You do not have read access to the locations page:"),
2.1461 - locations_page))
2.1462 -
2.1463 - # Attempt to show the map.
2.1464 -
2.1465 - else:
2.1466 -
2.1467 - # Get events by position.
2.1468 -
2.1469 - events_by_location = {}
2.1470 - event_locations = {}
2.1471 -
2.1472 - for event in all_shown_events:
2.1473 - event_details = event.getDetails()
2.1474 -
2.1475 - location = event_details.get("location")
2.1476 -
2.1477 - if location is not None and not event_locations.has_key(location):
2.1478 -
2.1479 - # Get any explicit position of an event.
2.1480 -
2.1481 - if event_details.has_key("geo"):
2.1482 - latitude, longitude = event_details["geo"]
2.1483 -
2.1484 - # Or look up the position of a location using the locations
2.1485 - # page.
2.1486 -
2.1487 - else:
2.1488 - latitude, longitude = getLocationPosition(location, locations)
2.1489 -
2.1490 - # Use a normalised location if necessary.
2.1491 -
2.1492 - if latitude is None and longitude is None:
2.1493 - normalised_location = getNormalisedLocation(location)
2.1494 - if normalised_location is not None:
2.1495 - latitude, longitude = getLocationPosition(normalised_location, locations)
2.1496 - if latitude is not None and longitude is not None:
2.1497 - location = normalised_location
2.1498 -
2.1499 - # Only remember positioned locations.
2.1500 -
2.1501 - if latitude is not None and longitude is not None:
2.1502 - event_locations[location] = latitude, longitude
2.1503 -
2.1504 - # Record events according to location.
2.1505 -
2.1506 - if not events_by_location.has_key(location):
2.1507 - events_by_location[location] = []
2.1508 -
2.1509 - events_by_location[location].append(event)
2.1510 -
2.1511 - # Get the map image URL.
2.1512 -
2.1513 - map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
2.1514 -
2.1515 - # Start of map view output.
2.1516 -
2.1517 - map_identifier = "map-%s" % view.getIdentifier()
2.1518 - output.append(fmt.div(on=1, css_class="event-map", id=map_identifier))
2.1519 -
2.1520 - output.append(fmt.table(on=1))
2.1521 -
2.1522 - output.append(fmt.table_row(on=1))
2.1523 - output.append(view.writeMapTableHeading())
2.1524 - output.append(fmt.table_row(on=0))
2.1525 -
2.1526 - output.append(fmt.table_row(on=1))
2.1527 - output.append(fmt.table_cell(on=1))
2.1528 -
2.1529 - output.append(fmt.div(on=1, css_class="event-map-container"))
2.1530 - output.append(fmt.image(map_image_url))
2.1531 - output.append(fmt.number_list(on=1))
2.1532 -
2.1533 - # Events with no location are unpositioned.
2.1534 -
2.1535 - if events_by_location.has_key(None):
2.1536 - unpositioned_events = events_by_location[None]
2.1537 - del events_by_location[None]
2.1538 - else:
2.1539 - unpositioned_events = []
2.1540 -
2.1541 - # Events whose location is unpositioned are themselves considered
2.1542 - # unpositioned.
2.1543 -
2.1544 - for location in set(events_by_location.keys()).difference(event_locations.keys()):
2.1545 - unpositioned_events += events_by_location[location]
2.1546 -
2.1547 - # Sort the locations before traversing them.
2.1548 -
2.1549 - event_locations = event_locations.items()
2.1550 - event_locations.sort()
2.1551 -
2.1552 - # Show the events in the map.
2.1553 -
2.1554 - for location, (latitude, longitude) in event_locations:
2.1555 - events = events_by_location[location]
2.1556 -
2.1557 - # Skip unpositioned locations and locations outside the map.
2.1558 -
2.1559 - if latitude is None or longitude is None or \
2.1560 - latitude < map_bottom_left_latitude or \
2.1561 - longitude < map_bottom_left_longitude or \
2.1562 - latitude > map_top_right_latitude or \
2.1563 - longitude > map_top_right_longitude:
2.1564 -
2.1565 - unpositioned_events += events
2.1566 - continue
2.1567 -
2.1568 - # Get the position and dimensions of the map marker.
2.1569 - # NOTE: Use one degree as the marker size.
2.1570 -
2.1571 - marker_x, marker_y = getPositionForCentrePoint(
2.1572 - getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude,
2.1573 - map_x_scale, map_y_scale),
2.1574 - map_x_scale, map_y_scale)
2.1575 -
2.1576 - # Put a marker on the map.
2.1577 -
2.1578 - output.append(fmt.listitem(on=1, css_class="event-map-label"))
2.1579 -
2.1580 - # Have a positioned marker for the print mode.
2.1581 -
2.1582 - output.append(fmt.div(on=1, css_class="event-map-label-only",
2.1583 - style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
2.1584 - marker_x, marker_y, map_x_scale, map_y_scale))
2.1585 - output.append(fmt.div(on=0))
2.1586 -
2.1587 - # Have a marker containing a pop-up when using the screen mode,
2.1588 - # providing a normal block when using the print mode.
2.1589 -
2.1590 - output.append(fmt.div(on=1, css_class="event-map-label",
2.1591 - style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
2.1592 - marker_x, marker_y, map_x_scale, map_y_scale))
2.1593 - output.append(fmt.div(on=1, css_class="event-map-details"))
2.1594 - output.append(fmt.div(on=1, css_class="event-map-shadow"))
2.1595 - output.append(fmt.div(on=1, css_class="event-map-location"))
2.1596 -
2.1597 - output.append(fmt.heading(on=1, depth=2))
2.1598 - output.append(fmt.text(location))
2.1599 - output.append(fmt.heading(on=0, depth=2))
2.1600 -
2.1601 - output.append(view.writeMapEventSummaries(events))
2.1602 -
2.1603 - output.append(fmt.div(on=0))
2.1604 - output.append(fmt.div(on=0))
2.1605 - output.append(fmt.div(on=0))
2.1606 - output.append(fmt.div(on=0))
2.1607 - output.append(fmt.listitem(on=0))
2.1608 -
2.1609 - output.append(fmt.number_list(on=0))
2.1610 - output.append(fmt.div(on=0))
2.1611 - output.append(fmt.table_cell(on=0))
2.1612 - output.append(fmt.table_row(on=0))
2.1613 -
2.1614 - # Write unpositioned events.
2.1615 -
2.1616 - if unpositioned_events:
2.1617 - unpositioned_identifier = "unpositioned-%s" % view.getIdentifier()
2.1618 -
2.1619 - output.append(fmt.table_row(on=1, css_class="event-map-unpositioned",
2.1620 - id=unpositioned_identifier))
2.1621 - output.append(fmt.table_cell(on=1))
2.1622 -
2.1623 - output.append(fmt.heading(on=1, depth=2))
2.1624 - output.append(fmt.text(_("Events not shown on the map")))
2.1625 - output.append(fmt.heading(on=0, depth=2))
2.1626 -
2.1627 - # Show and hide controls.
2.1628 -
2.1629 - output.append(fmt.div(on=1, css_class="event-map-show-control"))
2.1630 - output.append(fmt.anchorlink(on=1, name=unpositioned_identifier))
2.1631 - output.append(fmt.text(_("Show unpositioned events")))
2.1632 - output.append(fmt.anchorlink(on=0))
2.1633 - output.append(fmt.div(on=0))
2.1634 -
2.1635 - output.append(fmt.div(on=1, css_class="event-map-hide-control"))
2.1636 - output.append(fmt.anchorlink(on=1, name=map_identifier))
2.1637 - output.append(fmt.text(_("Hide unpositioned events")))
2.1638 - output.append(fmt.anchorlink(on=0))
2.1639 - output.append(fmt.div(on=0))
2.1640 -
2.1641 - output.append(view.writeMapEventSummaries(unpositioned_events))
2.1642 -
2.1643 - # End of map view output.
2.1644 -
2.1645 - output.append(fmt.table_cell(on=0))
2.1646 - output.append(fmt.table_row(on=0))
2.1647 - output.append(fmt.table(on=0))
2.1648 - output.append(fmt.div(on=0))
2.1649 -
2.1650 - # Output a list.
2.1651 -
2.1652 - elif mode == "list":
2.1653 -
2.1654 - # Start of list view output.
2.1655 -
2.1656 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-listings"}))
2.1657 -
2.1658 - # Output a list.
2.1659 -
2.1660 - for period in first.until(last):
2.1661 -
2.1662 - output.append(fmt.listitem(on=1, attr={"class" : "event-listings-period"}))
2.1663 - output.append(fmt.div(on=1, attr={"class" : "event-listings-heading"}))
2.1664 -
2.1665 - # Either write a date heading or produce links for navigable
2.1666 - # calendars.
2.1667 -
2.1668 - output.append(view.writeDateHeading(period))
2.1669 -
2.1670 - output.append(fmt.div(on=0))
2.1671 -
2.1672 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"}))
2.1673 -
2.1674 - # Show the events in order.
2.1675 -
2.1676 - events_in_period = getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period))
2.1677 - events_in_period.sort(sort_start_first)
2.1678 -
2.1679 - for event in events_in_period:
2.1680 - event_page = event.getPage()
2.1681 - event_details = event.getDetails()
2.1682 - event_summary = event.getSummary(parent_name)
2.1683 -
2.1684 - output.append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
2.1685 -
2.1686 - # Link to the page using the summary.
2.1687 -
2.1688 - output.append(fmt.paragraph(on=1))
2.1689 - output.append(event.linkToEvent(request, event_summary))
2.1690 - output.append(fmt.paragraph(on=0))
2.1691 -
2.1692 - # Start and end dates.
2.1693 -
2.1694 - output.append(fmt.paragraph(on=1))
2.1695 - output.append(fmt.span(on=1))
2.1696 - output.append(fmt.text(str(event_details["start"])))
2.1697 - output.append(fmt.span(on=0))
2.1698 - output.append(fmt.text(" - "))
2.1699 - output.append(fmt.span(on=1))
2.1700 - output.append(fmt.text(str(event_details["end"])))
2.1701 - output.append(fmt.span(on=0))
2.1702 - output.append(fmt.paragraph(on=0))
2.1703 -
2.1704 - # Location.
2.1705 -
2.1706 - if event_details.has_key("location"):
2.1707 - output.append(fmt.paragraph(on=1))
2.1708 - output.append(event_page.formatText(event_details["location"], request, fmt))
2.1709 - output.append(fmt.paragraph(on=1))
2.1710 -
2.1711 - # Topics.
2.1712 -
2.1713 - if event_details.has_key("topics") or event_details.has_key("categories"):
2.1714 - output.append(fmt.bullet_list(on=1, attr={"class" : "event-topics"}))
2.1715 -
2.1716 - for topic in event_details.get("topics") or event_details.get("categories") or []:
2.1717 - output.append(fmt.listitem(on=1))
2.1718 - output.append(event_page.formatText(topic, request, fmt))
2.1719 - output.append(fmt.listitem(on=0))
2.1720 -
2.1721 - output.append(fmt.bullet_list(on=0))
2.1722 -
2.1723 - output.append(fmt.listitem(on=0))
2.1724 -
2.1725 - output.append(fmt.bullet_list(on=0))
2.1726 -
2.1727 - # End of list view output.
2.1728 -
2.1729 - output.append(fmt.bullet_list(on=0))
2.1730 -
2.1731 - # Output a month calendar. This shows month-by-month data.
2.1732 -
2.1733 - elif mode == "calendar":
2.1734 -
2.1735 - # Visit all months in the requested range, or across known events.
2.1736 -
2.1737 - for month in first.months_until(last):
2.1738 -
2.1739 - # Output a month.
2.1740 -
2.1741 - output.append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
2.1742 -
2.1743 - # Either write a month heading or produce links for navigable
2.1744 - # calendars.
2.1745 -
2.1746 - output.append(view.writeMonthTableHeading(month))
2.1747 -
2.1748 - # Weekday headings.
2.1749 -
2.1750 - output.append(view.writeWeekdayHeadings())
2.1751 -
2.1752 - # Process the days of the month.
2.1753 -
2.1754 - start_weekday, number_of_days = month.month_properties()
2.1755 -
2.1756 - # The start weekday is the weekday of day number 1.
2.1757 - # Find the first day of the week, counting from below zero, if
2.1758 - # necessary, in order to land on the first day of the month as
2.1759 - # day number 1.
2.1760 -
2.1761 - first_day = 1 - start_weekday
2.1762 -
2.1763 - while first_day <= number_of_days:
2.1764 -
2.1765 - # Find events in this week and determine how to mark them on the
2.1766 - # calendar.
2.1767 -
2.1768 - week_start = month.as_date(max(first_day, 1))
2.1769 - week_end = month.as_date(min(first_day + 6, number_of_days))
2.1770 -
2.1771 - full_coverage, week_slots = getCoverage(
2.1772 - getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end)))
2.1773 -
2.1774 - # Output a week, starting with the day numbers.
2.1775 -
2.1776 - output.append(view.writeDayNumbers(first_day, number_of_days, month, full_coverage))
2.1777 -
2.1778 - # Either generate empty days...
2.1779 -
2.1780 - if not week_slots:
2.1781 - output.append(view.writeEmptyWeek(first_day, number_of_days))
2.1782 -
2.1783 - # Or generate each set of scheduled events...
2.1784 -
2.1785 - else:
2.1786 - output.append(view.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots))
2.1787 -
2.1788 - # Process the next week...
2.1789 -
2.1790 - first_day += 7
2.1791 -
2.1792 - # End of month.
2.1793 -
2.1794 - output.append(fmt.table(on=0))
2.1795 -
2.1796 - # Output a day view.
2.1797 -
2.1798 - elif mode == "day":
2.1799 -
2.1800 - # Visit all days in the requested range, or across known events.
2.1801 -
2.1802 - for date in first.days_until(last):
2.1803 -
2.1804 - output.append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"}))
2.1805 -
2.1806 - full_coverage, day_slots = getCoverage(
2.1807 - getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime")
2.1808 -
2.1809 - # Work out how many columns the day title will need.
2.1810 - # Include spacers after the scale and each event column.
2.1811 -
2.1812 - colspan = sum(map(len, day_slots.values())) * 2 + 2
2.1813 -
2.1814 - output.append(view.writeDayTableHeading(date, colspan))
2.1815 -
2.1816 - # Either generate empty days...
2.1817 -
2.1818 - if not day_slots:
2.1819 - output.append(view.writeEmptyDay(date))
2.1820 -
2.1821 - # Or generate each set of scheduled events...
2.1822 -
2.1823 - else:
2.1824 - output.append(view.writeDaySlots(date, full_coverage, day_slots))
2.1825 -
2.1826 - # End of day.
2.1827 -
2.1828 - output.append(fmt.table(on=0))
2.1829 -
2.1830 - # Output view controls.
2.1831 -
2.1832 - output.append(fmt.div(on=1, css_class="event-controls"))
2.1833 - output.append(view.writeViewControls())
2.1834 - output.append(fmt.div(on=0))
2.1835 -
2.1836 - # Close the calendar region.
2.1837 -
2.1838 - output.append(fmt.div(on=0))
2.1839 -
2.1840 - return ''.join(output)
2.1841 + return view.render(all_shown_events)
2.1842
2.1843 # vim: tabstop=4 expandtab shiftwidth=4