1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/EventAggregatorSupport/View.py Tue Apr 30 23:49:32 2013 +0200
1.3 @@ -0,0 +1,2128 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - EventAggregator user interface library
1.7 +
1.8 + @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 +"""
1.11 +
1.12 +from EventAggregatorSupport.Filter import getCalendarPeriod, getEventsInPeriod, \
1.13 + getCoverage, getCoverageScale
1.14 +from EventAggregatorSupport.Locations import getMapsPage, getLocationsPage, Location
1.15 +
1.16 +from GeneralSupport import sort_none_first
1.17 +from LocationSupport import getMapReference, getNormalisedLocation, \
1.18 + getPositionForCentrePoint, getPositionForReference
1.19 +from MoinDateSupport import getFullDateLabel, getFullMonthLabel
1.20 +from MoinSupport import *
1.21 +from ViewSupport import getColour, getBlackOrWhite
1.22 +
1.23 +from MoinMoin.Page import Page
1.24 +from MoinMoin.action import AttachFile
1.25 +from MoinMoin import wikiutil
1.26 +
1.27 +try:
1.28 + set
1.29 +except NameError:
1.30 + from sets import Set as set
1.31 +
1.32 +# Utility functions.
1.33 +
1.34 +def to_plain_text(s, request):
1.35 +
1.36 + "Convert 's' to plain text."
1.37 +
1.38 + fmt = getFormatterClass(request, "plain")(request)
1.39 + fmt.setPage(request.page)
1.40 + return formatText(s, request, fmt)
1.41 +
1.42 +def getLocationPosition(location, locations):
1.43 +
1.44 + """
1.45 + Attempt to return the position of the given 'location' using the 'locations'
1.46 + dictionary provided. If no position can be found, return a latitude of None
1.47 + and a longitude of None.
1.48 + """
1.49 +
1.50 + latitude, longitude = None, None
1.51 +
1.52 + if location is not None:
1.53 + try:
1.54 + latitude, longitude = map(getMapReference, locations[location].split())
1.55 + except (KeyError, ValueError):
1.56 + pass
1.57 +
1.58 + return latitude, longitude
1.59 +
1.60 +# Event sorting.
1.61 +
1.62 +def sort_start_first(x, y):
1.63 + x_ts = x.as_limits()
1.64 + if x_ts is not None:
1.65 + x_start, x_end = x_ts
1.66 + y_ts = y.as_limits()
1.67 + if y_ts is not None:
1.68 + y_start, y_end = y_ts
1.69 + start_order = cmp(x_start, y_start)
1.70 + if start_order == 0:
1.71 + return cmp(x_end, y_end)
1.72 + else:
1.73 + return start_order
1.74 + return 0
1.75 +
1.76 +# User interface abstractions.
1.77 +
1.78 +class View:
1.79 +
1.80 + "A view of the event calendar."
1.81 +
1.82 + def __init__(self, page, calendar_name,
1.83 + raw_calendar_start, raw_calendar_end,
1.84 + original_calendar_start, original_calendar_end,
1.85 + calendar_start, calendar_end,
1.86 + wider_calendar_start, wider_calendar_end,
1.87 + first, last, category_names, remote_sources, search_pattern, template_name,
1.88 + parent_name, mode, resolution, name_usage, map_name):
1.89 +
1.90 + """
1.91 + Initialise the view with the current 'page', a 'calendar_name' (which
1.92 + may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which
1.93 + are the actual start and end values provided by the request), the
1.94 + calculated 'original_calendar_start' and 'original_calendar_end' (which
1.95 + are the result of calculating the calendar's limits from the raw start
1.96 + and end values), the requested, calculated 'calendar_start' and
1.97 + 'calendar_end' (which may involve different start and end values due to
1.98 + navigation in the user interface), and the requested
1.99 + 'wider_calendar_start' and 'wider_calendar_end' (which indicate a wider
1.100 + view used when navigating out of the day view), along with the 'first'
1.101 + and 'last' months of event coverage.
1.102 +
1.103 + The additional 'category_names', 'remote_sources', 'search_pattern',
1.104 + 'template_name', 'parent_name' and 'mode' parameters are used to
1.105 + configure the links employed by the view.
1.106 +
1.107 + The 'resolution' affects the view for certain modes and is also used to
1.108 + parameterise links.
1.109 +
1.110 + The 'name_usage' parameter controls how names are shown on calendar mode
1.111 + events, such as how often labels are repeated.
1.112 +
1.113 + The 'map_name' parameter provides the name of a map to be used in the
1.114 + map mode.
1.115 + """
1.116 +
1.117 + self.page = page
1.118 + self.calendar_name = calendar_name
1.119 + self.raw_calendar_start = raw_calendar_start
1.120 + self.raw_calendar_end = raw_calendar_end
1.121 + self.original_calendar_start = original_calendar_start
1.122 + self.original_calendar_end = original_calendar_end
1.123 + self.calendar_start = calendar_start
1.124 + self.calendar_end = calendar_end
1.125 + self.wider_calendar_start = wider_calendar_start
1.126 + self.wider_calendar_end = wider_calendar_end
1.127 + self.template_name = template_name
1.128 + self.parent_name = parent_name
1.129 + self.mode = mode
1.130 + self.resolution = resolution
1.131 + self.name_usage = name_usage
1.132 + self.map_name = map_name
1.133 +
1.134 + # Search-related parameters for links.
1.135 +
1.136 + self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names])
1.137 + self.remote_source_parameters = "&".join([("source=%s" % source) for source in remote_sources])
1.138 + self.search_pattern = search_pattern
1.139 +
1.140 + # Calculate the duration in terms of the highest common unit of time.
1.141 +
1.142 + self.first = first
1.143 + self.last = last
1.144 + self.duration = abs(last - first) + 1
1.145 +
1.146 + if self.calendar_name:
1.147 +
1.148 + # Store the view parameters.
1.149 +
1.150 + self.previous_start = first.previous()
1.151 + self.next_start = first.next()
1.152 + self.previous_end = last.previous()
1.153 + self.next_end = last.next()
1.154 +
1.155 + self.previous_set_start = first.update(-self.duration)
1.156 + self.next_set_start = first.update(self.duration)
1.157 + self.previous_set_end = last.update(-self.duration)
1.158 + self.next_set_end = last.update(self.duration)
1.159 +
1.160 + def getIdentifier(self):
1.161 +
1.162 + "Return a unique identifier to be used to refer to this view."
1.163 +
1.164 + # NOTE: Nasty hack to get a unique identifier if no name is given.
1.165 +
1.166 + return self.calendar_name or str(id(self))
1.167 +
1.168 + def getQualifiedParameterName(self, argname):
1.169 +
1.170 + "Return the 'argname' qualified using the calendar name."
1.171 +
1.172 + return getQualifiedParameterName(self.calendar_name, argname)
1.173 +
1.174 + def getDateQueryString(self, argname, date, prefix=1):
1.175 +
1.176 + """
1.177 + Return a query string fragment for the given 'argname', referring to the
1.178 + month given by the specified 'year_month' object, appropriate for this
1.179 + calendar.
1.180 +
1.181 + If 'prefix' is specified and set to a false value, the parameters in the
1.182 + query string will not be calendar-specific, but could be used with the
1.183 + summary action.
1.184 + """
1.185 +
1.186 + suffixes = ["year", "month", "day"]
1.187 +
1.188 + if date is not None:
1.189 + args = []
1.190 + for suffix, value in zip(suffixes, date.as_tuple()):
1.191 + suffixed_argname = "%s-%s" % (argname, suffix)
1.192 + if prefix:
1.193 + suffixed_argname = self.getQualifiedParameterName(suffixed_argname)
1.194 + args.append("%s=%s" % (suffixed_argname, value))
1.195 + return "&".join(args)
1.196 + else:
1.197 + return ""
1.198 +
1.199 + def getRawDateQueryString(self, argname, date, prefix=1):
1.200 +
1.201 + """
1.202 + Return a query string fragment for the given 'argname', referring to the
1.203 + date given by the specified 'date' value, appropriate for this
1.204 + calendar.
1.205 +
1.206 + If 'prefix' is specified and set to a false value, the parameters in the
1.207 + query string will not be calendar-specific, but could be used with the
1.208 + summary action.
1.209 + """
1.210 +
1.211 + if date is not None:
1.212 + if prefix:
1.213 + argname = self.getQualifiedParameterName(argname)
1.214 + return "%s=%s" % (argname, wikiutil.url_quote_plus(date))
1.215 + else:
1.216 + return ""
1.217 +
1.218 + def getNavigationLink(self, start, end, mode=None, resolution=None, wider_start=None, wider_end=None):
1.219 +
1.220 + """
1.221 + Return a query string fragment for navigation to a view showing months
1.222 + from 'start' to 'end' inclusive, with the optional 'mode' indicating the
1.223 + view style and the optional 'resolution' indicating the resolution of a
1.224 + view, if configurable.
1.225 +
1.226 + If the 'wider_start' and 'wider_end' arguments are given, parameters
1.227 + indicating a wider calendar view (when returning from a day view, for
1.228 + example) will be included in the link.
1.229 + """
1.230 +
1.231 + return "%s&%s&%s=%s&%s=%s&%s&%s" % (
1.232 + self.getRawDateQueryString("start", start),
1.233 + self.getRawDateQueryString("end", end),
1.234 + self.getQualifiedParameterName("mode"), mode or self.mode,
1.235 + self.getQualifiedParameterName("resolution"), resolution or self.resolution,
1.236 + self.getRawDateQueryString("wider-start", wider_start),
1.237 + self.getRawDateQueryString("wider-end", wider_end),
1.238 + )
1.239 +
1.240 + def getUpdateLink(self, start, end, mode=None, resolution=None, wider_start=None, wider_end=None):
1.241 +
1.242 + """
1.243 + Return a query string fragment for navigation to a view showing months
1.244 + from 'start' to 'end' inclusive, with the optional 'mode' indicating the
1.245 + view style and the optional 'resolution' indicating the resolution of a
1.246 + view, if configurable. This link differs from the conventional
1.247 + navigation link in that it is sufficient to activate the update action
1.248 + and produce an updated region of the page without needing to locate and
1.249 + process the page or any macro invocation.
1.250 +
1.251 + If the 'wider_start' and 'wider_end' arguments are given, parameters
1.252 + indicating a wider calendar view (when returning from a day view, for
1.253 + example) will be included in the link.
1.254 + """
1.255 +
1.256 + parameters = [
1.257 + self.getRawDateQueryString("start", start, 0),
1.258 + self.getRawDateQueryString("end", end, 0),
1.259 + self.category_name_parameters,
1.260 + self.remote_source_parameters,
1.261 + self.getRawDateQueryString("wider-start", wider_start, 0),
1.262 + self.getRawDateQueryString("wider-end", wider_end, 0),
1.263 + ]
1.264 +
1.265 + pairs = [
1.266 + ("calendar", self.calendar_name or ""),
1.267 + ("calendarstart", self.raw_calendar_start or ""),
1.268 + ("calendarend", self.raw_calendar_end or ""),
1.269 + ("mode", mode or self.mode),
1.270 + ("resolution", resolution or self.resolution),
1.271 + ("parent", self.parent_name or ""),
1.272 + ("template", self.template_name or ""),
1.273 + ("names", self.name_usage),
1.274 + ("map", self.map_name or ""),
1.275 + ("search", self.search_pattern or ""),
1.276 + ]
1.277 +
1.278 + url = self.page.url(self.page.request,
1.279 + "action=EventAggregatorUpdate&%s" % (
1.280 + "&".join([("%s=%s" % pair) for pair in pairs] + parameters)
1.281 + ), relative=True)
1.282 +
1.283 + return "return replaceCalendar('EventAggregator-%s', '%s')" % (self.getIdentifier(), url)
1.284 +
1.285 + def getNewEventLink(self, start):
1.286 +
1.287 + """
1.288 + Return a query string activating the new event form, incorporating the
1.289 + calendar parameters, specialising the form for the given 'start' date or
1.290 + month.
1.291 + """
1.292 +
1.293 + if start is not None:
1.294 + details = start.as_tuple()
1.295 + pairs = zip(["start-year=%d", "start-month=%d", "start-day=%d"], details)
1.296 + args = [(param % value) for (param, value) in pairs]
1.297 + args = "&".join(args)
1.298 + else:
1.299 + args = ""
1.300 +
1.301 + # Prepare navigation details for the calendar shown with the new event
1.302 + # form.
1.303 +
1.304 + navigation_link = self.getNavigationLink(
1.305 + self.calendar_start, self.calendar_end
1.306 + )
1.307 +
1.308 + return "action=EventAggregatorNewEvent%s%s&template=%s&parent=%s&%s" % (
1.309 + args and "&%s" % args,
1.310 + self.category_name_parameters and "&%s" % self.category_name_parameters,
1.311 + self.template_name, self.parent_name or "",
1.312 + navigation_link)
1.313 +
1.314 + def getFullDateLabel(self, date):
1.315 + return getFullDateLabel(self.page.request, date)
1.316 +
1.317 + def getFullMonthLabel(self, year_month):
1.318 + return getFullMonthLabel(self.page.request, year_month)
1.319 +
1.320 + def getFullLabel(self, arg):
1.321 + return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg)
1.322 +
1.323 + def _getCalendarPeriod(self, start_label, end_label, default_label):
1.324 +
1.325 + """
1.326 + Return a label describing a calendar period in terms of the given
1.327 + 'start_label' and 'end_label', with the 'default_label' being used where
1.328 + the supplied start and end labels fail to produce a meaningful label.
1.329 + """
1.330 +
1.331 + output = []
1.332 + append = output.append
1.333 +
1.334 + if start_label:
1.335 + append(start_label)
1.336 + if end_label and start_label != end_label:
1.337 + if output:
1.338 + append(" - ")
1.339 + append(end_label)
1.340 + return "".join(output) or default_label
1.341 +
1.342 + def getCalendarPeriod(self):
1.343 + _ = self.page.request.getText
1.344 + return self._getCalendarPeriod(
1.345 + self.calendar_start and self.getFullLabel(self.calendar_start),
1.346 + self.calendar_end and self.getFullLabel(self.calendar_end),
1.347 + _("All events")
1.348 + )
1.349 +
1.350 + def getOriginalCalendarPeriod(self):
1.351 + _ = self.page.request.getText
1.352 + return self._getCalendarPeriod(
1.353 + self.original_calendar_start and self.getFullLabel(self.original_calendar_start),
1.354 + self.original_calendar_end and self.getFullLabel(self.original_calendar_end),
1.355 + _("All events")
1.356 + )
1.357 +
1.358 + def getRawCalendarPeriod(self):
1.359 + _ = self.page.request.getText
1.360 + return self._getCalendarPeriod(
1.361 + self.raw_calendar_start,
1.362 + self.raw_calendar_end,
1.363 + _("No period specified")
1.364 + )
1.365 +
1.366 + def writeDownloadControls(self):
1.367 +
1.368 + """
1.369 + Return a representation of the download controls, featuring links for
1.370 + view, calendar and customised downloads and subscriptions.
1.371 + """
1.372 +
1.373 + page = self.page
1.374 + request = page.request
1.375 + fmt = request.formatter
1.376 + _ = request.getText
1.377 +
1.378 + output = []
1.379 + append = output.append
1.380 +
1.381 + # The full URL is needed for webcal links.
1.382 +
1.383 + full_url = "%s%s" % (request.getBaseURL(), getPathInfo(request))
1.384 +
1.385 + # Generate the links.
1.386 +
1.387 + download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&search=%s%s%s" % (
1.388 + self.parent_name or "",
1.389 + self.resolution,
1.390 + self.search_pattern or "",
1.391 + self.category_name_parameters and "&%s" % self.category_name_parameters,
1.392 + self.remote_source_parameters and "&%s" % self.remote_source_parameters
1.393 + )
1.394 + download_all_link = download_dialogue_link + "&doit=1"
1.395 + download_link = download_all_link + ("&%s&%s" % (
1.396 + self.getDateQueryString("start", self.calendar_start, prefix=0),
1.397 + self.getDateQueryString("end", self.calendar_end, prefix=0)
1.398 + ))
1.399 +
1.400 + # Subscription links just explicitly select the RSS format.
1.401 +
1.402 + subscribe_dialogue_link = download_dialogue_link + "&format=RSS"
1.403 + subscribe_all_link = download_all_link + "&format=RSS"
1.404 + subscribe_link = download_link + "&format=RSS"
1.405 +
1.406 + # Adjust the "download all" and "subscribe all" links if the calendar
1.407 + # has an inherent period associated with it.
1.408 +
1.409 + period_limits = []
1.410 +
1.411 + if self.raw_calendar_start:
1.412 + period_limits.append("&%s" %
1.413 + self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0)
1.414 + )
1.415 + if self.raw_calendar_end:
1.416 + period_limits.append("&%s" %
1.417 + self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0)
1.418 + )
1.419 +
1.420 + period_limits = "".join(period_limits)
1.421 +
1.422 + download_dialogue_link += period_limits
1.423 + download_all_link += period_limits
1.424 + subscribe_dialogue_link += period_limits
1.425 + subscribe_all_link += period_limits
1.426 +
1.427 + # Pop-up descriptions of the downloadable calendars.
1.428 +
1.429 + calendar_period = self.getCalendarPeriod()
1.430 + original_calendar_period = self.getOriginalCalendarPeriod()
1.431 + raw_calendar_period = self.getRawCalendarPeriod()
1.432 +
1.433 + # Write the controls.
1.434 +
1.435 + # Download controls.
1.436 +
1.437 + append(fmt.div(on=1, css_class="event-download-controls"))
1.438 +
1.439 + append(fmt.span(on=1, css_class="event-download"))
1.440 + append(fmt.text(_("Download...")))
1.441 + append(fmt.div(on=1, css_class="event-download-popup"))
1.442 +
1.443 + append(fmt.div(on=1, css_class="event-download-item"))
1.444 + append(fmt.span(on=1, css_class="event-download-types"))
1.445 + append(fmt.span(on=1, css_class="event-download-webcal"))
1.446 + append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_link))
1.447 + append(fmt.span(on=0))
1.448 + append(fmt.span(on=1, css_class="event-download-http"))
1.449 + append(linkToPage(request, page, _("http"), download_link))
1.450 + append(fmt.span(on=0))
1.451 + append(fmt.span(on=0)) # end types
1.452 + append(fmt.span(on=1, css_class="event-download-label"))
1.453 + append(fmt.text(_("Download this view")))
1.454 + append(fmt.span(on=0)) # end label
1.455 + append(fmt.span(on=1, css_class="event-download-period"))
1.456 + append(fmt.text(calendar_period))
1.457 + append(fmt.span(on=0))
1.458 + append(fmt.div(on=0))
1.459 +
1.460 + append(fmt.div(on=1, css_class="event-download-item"))
1.461 + append(fmt.span(on=1, css_class="event-download-types"))
1.462 + append(fmt.span(on=1, css_class="event-download-webcal"))
1.463 + append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_all_link))
1.464 + append(fmt.span(on=0))
1.465 + append(fmt.span(on=1, css_class="event-download-http"))
1.466 + append(linkToPage(request, page, _("http"), download_all_link))
1.467 + append(fmt.span(on=0))
1.468 + append(fmt.span(on=0)) # end types
1.469 + append(fmt.span(on=1, css_class="event-download-label"))
1.470 + append(fmt.text(_("Download this calendar")))
1.471 + append(fmt.span(on=0)) # end label
1.472 + append(fmt.span(on=1, css_class="event-download-period"))
1.473 + append(fmt.text(original_calendar_period))
1.474 + append(fmt.span(on=0))
1.475 + append(fmt.span(on=1, css_class="event-download-period-raw"))
1.476 + append(fmt.text(raw_calendar_period))
1.477 + append(fmt.span(on=0))
1.478 + append(fmt.div(on=0))
1.479 +
1.480 + append(fmt.div(on=1, css_class="event-download-item"))
1.481 + append(fmt.span(on=1, css_class="event-download-link"))
1.482 + append(linkToPage(request, page, _("Edit download options..."), download_dialogue_link))
1.483 + append(fmt.span(on=0)) # end label
1.484 + append(fmt.div(on=0))
1.485 +
1.486 + append(fmt.div(on=0)) # end of pop-up
1.487 + append(fmt.span(on=0)) # end of download
1.488 +
1.489 + # Subscription controls.
1.490 +
1.491 + append(fmt.span(on=1, css_class="event-download"))
1.492 + append(fmt.text(_("Subscribe...")))
1.493 + append(fmt.div(on=1, css_class="event-download-popup"))
1.494 +
1.495 + append(fmt.div(on=1, css_class="event-download-item"))
1.496 + append(fmt.span(on=1, css_class="event-download-label"))
1.497 + append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link))
1.498 + append(fmt.span(on=0)) # end label
1.499 + append(fmt.span(on=1, css_class="event-download-period"))
1.500 + append(fmt.text(calendar_period))
1.501 + append(fmt.span(on=0))
1.502 + append(fmt.div(on=0))
1.503 +
1.504 + append(fmt.div(on=1, css_class="event-download-item"))
1.505 + append(fmt.span(on=1, css_class="event-download-label"))
1.506 + append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link))
1.507 + append(fmt.span(on=0)) # end label
1.508 + append(fmt.span(on=1, css_class="event-download-period"))
1.509 + append(fmt.text(original_calendar_period))
1.510 + append(fmt.span(on=0))
1.511 + append(fmt.span(on=1, css_class="event-download-period-raw"))
1.512 + append(fmt.text(raw_calendar_period))
1.513 + append(fmt.span(on=0))
1.514 + append(fmt.div(on=0))
1.515 +
1.516 + append(fmt.div(on=1, css_class="event-download-item"))
1.517 + append(fmt.span(on=1, css_class="event-download-link"))
1.518 + append(linkToPage(request, page, _("Edit subscription options..."), subscribe_dialogue_link))
1.519 + append(fmt.span(on=0)) # end label
1.520 + append(fmt.div(on=0))
1.521 +
1.522 + append(fmt.div(on=0)) # end of pop-up
1.523 + append(fmt.span(on=0)) # end of download
1.524 +
1.525 + append(fmt.div(on=0)) # end of controls
1.526 +
1.527 + return "".join(output)
1.528 +
1.529 + def writeViewControls(self):
1.530 +
1.531 + """
1.532 + Return a representation of the view mode controls, permitting viewing of
1.533 + aggregated events in calendar, list or table form.
1.534 + """
1.535 +
1.536 + page = self.page
1.537 + request = page.request
1.538 + fmt = request.formatter
1.539 + _ = request.getText
1.540 +
1.541 + output = []
1.542 + append = output.append
1.543 +
1.544 + # For day view links to other views, the wider view parameters should
1.545 + # be used in order to be able to return to those other views.
1.546 +
1.547 + specific_start = self.calendar_start
1.548 + specific_end = self.calendar_end
1.549 +
1.550 + start = self.wider_calendar_start or self.original_calendar_start and specific_start
1.551 + end = self.wider_calendar_end or self.original_calendar_end and specific_end
1.552 +
1.553 + help_page = Page(request, "HelpOnEventAggregator")
1.554 +
1.555 + calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
1.556 + calendar_update_link = self.getUpdateLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
1.557 + list_link = self.getNavigationLink(start, end, "list", "month")
1.558 + list_update_link = self.getUpdateLink(start, end, "list", "month")
1.559 + table_link = self.getNavigationLink(start, end, "table", "month")
1.560 + table_update_link = self.getUpdateLink(start, end, "table", "month")
1.561 + map_link = self.getNavigationLink(start, end, "map", "month")
1.562 + map_update_link = self.getUpdateLink(start, end, "map", "month")
1.563 +
1.564 + # Specific links permit date-level navigation.
1.565 +
1.566 + specific_day_link = self.getNavigationLink(specific_start, specific_end, "day", wider_start=start, wider_end=end)
1.567 + specific_day_update_link = self.getUpdateLink(specific_start, specific_end, "day", wider_start=start, wider_end=end)
1.568 + specific_list_link = self.getNavigationLink(specific_start, specific_end, "list", wider_start=start, wider_end=end)
1.569 + specific_list_update_link = self.getUpdateLink(specific_start, specific_end, "list", wider_start=start, wider_end=end)
1.570 + specific_table_link = self.getNavigationLink(specific_start, specific_end, "table", wider_start=start, wider_end=end)
1.571 + specific_table_update_link = self.getUpdateLink(specific_start, specific_end, "table", wider_start=start, wider_end=end)
1.572 + specific_map_link = self.getNavigationLink(specific_start, specific_end, "map", wider_start=start, wider_end=end)
1.573 + specific_map_update_link = self.getUpdateLink(specific_start, specific_end, "map", wider_start=start, wider_end=end)
1.574 +
1.575 + new_event_link = self.getNewEventLink(start)
1.576 +
1.577 + # Write the controls.
1.578 +
1.579 + append(fmt.div(on=1, css_class="event-view-controls"))
1.580 +
1.581 + append(fmt.span(on=1, css_class="event-view"))
1.582 + append(linkToPage(request, help_page, _("Help")))
1.583 + append(fmt.span(on=0))
1.584 +
1.585 + append(fmt.span(on=1, css_class="event-view"))
1.586 + append(linkToPage(request, page, _("New event"), new_event_link))
1.587 + append(fmt.span(on=0))
1.588 +
1.589 + if self.mode != "calendar":
1.590 + view_label = self.resolution == "date" and _("View day in calendar") or _("View as calendar")
1.591 + append(fmt.span(on=1, css_class="event-view"))
1.592 + append(linkToPage(request, page, view_label, calendar_link, onclick=calendar_update_link))
1.593 + append(fmt.span(on=0))
1.594 +
1.595 + if self.resolution == "date" and self.mode != "day":
1.596 + append(fmt.span(on=1, css_class="event-view"))
1.597 + append(linkToPage(request, page, _("View day as calendar"), specific_day_link, onclick=specific_day_update_link))
1.598 + append(fmt.span(on=0))
1.599 +
1.600 + if self.resolution != "date" and self.mode != "list" or self.resolution == "date":
1.601 + view_label = self.resolution == "date" and _("View day in list") or _("View as list")
1.602 + append(fmt.span(on=1, css_class="event-view"))
1.603 + append(linkToPage(request, page, view_label, list_link, onclick=list_update_link))
1.604 + append(fmt.span(on=0))
1.605 +
1.606 + if self.resolution == "date" and self.mode != "list":
1.607 + append(fmt.span(on=1, css_class="event-view"))
1.608 + append(linkToPage(request, page, _("View day as list"),
1.609 + specific_list_link, onclick=specific_list_update_link
1.610 + ))
1.611 + append(fmt.span(on=0))
1.612 +
1.613 + if self.resolution != "date" and self.mode != "table" or self.resolution == "date":
1.614 + view_label = self.resolution == "date" and _("View day in table") or _("View as table")
1.615 + append(fmt.span(on=1, css_class="event-view"))
1.616 + append(linkToPage(request, page, view_label, table_link, onclick=table_update_link))
1.617 + append(fmt.span(on=0))
1.618 +
1.619 + if self.resolution == "date" and self.mode != "table":
1.620 + append(fmt.span(on=1, css_class="event-view"))
1.621 + append(linkToPage(request, page, _("View day as table"),
1.622 + specific_table_link, onclick=specific_table_update_link
1.623 + ))
1.624 + append(fmt.span(on=0))
1.625 +
1.626 + if self.map_name:
1.627 + if self.resolution != "date" and self.mode != "map" or self.resolution == "date":
1.628 + view_label = self.resolution == "date" and _("View day in map") or _("View as map")
1.629 + append(fmt.span(on=1, css_class="event-view"))
1.630 + append(linkToPage(request, page, view_label, map_link, onclick=map_update_link))
1.631 + append(fmt.span(on=0))
1.632 +
1.633 + if self.resolution == "date" and self.mode != "map":
1.634 + append(fmt.span(on=1, css_class="event-view"))
1.635 + append(linkToPage(request, page, _("View day as map"),
1.636 + specific_map_link, onclick=specific_map_update_link
1.637 + ))
1.638 + append(fmt.span(on=0))
1.639 +
1.640 + append(fmt.div(on=0))
1.641 +
1.642 + return "".join(output)
1.643 +
1.644 + def writeMapHeading(self):
1.645 +
1.646 + """
1.647 + Return the calendar heading for the current calendar, providing links
1.648 + permitting navigation to other periods.
1.649 + """
1.650 +
1.651 + label = self.getCalendarPeriod()
1.652 +
1.653 + if self.raw_calendar_start is None or self.raw_calendar_end is None:
1.654 + fmt = self.page.request.formatter
1.655 + output = []
1.656 + append = output.append
1.657 + append(fmt.span(on=1))
1.658 + append(fmt.text(label))
1.659 + append(fmt.span(on=0))
1.660 + return "".join(output)
1.661 + else:
1.662 + return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end)
1.663 +
1.664 + def writeDateHeading(self, date):
1.665 + if isinstance(date, Date):
1.666 + return self.writeDayHeading(date)
1.667 + else:
1.668 + return self.writeMonthHeading(date)
1.669 +
1.670 + def writeMonthHeading(self, year_month):
1.671 +
1.672 + """
1.673 + Return the calendar heading for the given 'year_month' (a Month object)
1.674 + providing links permitting navigation to other months.
1.675 + """
1.676 +
1.677 + full_month_label = self.getFullMonthLabel(year_month)
1.678 + end_month = year_month.update(self.duration - 1)
1.679 + return self._writeCalendarHeading(full_month_label, year_month, end_month)
1.680 +
1.681 + def writeDayHeading(self, date):
1.682 +
1.683 + """
1.684 + Return the calendar heading for the given 'date' (a Date object)
1.685 + providing links permitting navigation to other dates.
1.686 + """
1.687 +
1.688 + full_date_label = self.getFullDateLabel(date)
1.689 + end_date = date.update(self.duration - 1)
1.690 + return self._writeCalendarHeading(full_date_label, date, end_date)
1.691 +
1.692 + def _writeCalendarHeading(self, label, start, end):
1.693 +
1.694 + """
1.695 + Write a calendar heading providing links permitting navigation to other
1.696 + periods, using the given 'label' along with the 'start' and 'end' dates
1.697 + to provide a link to a particular period.
1.698 + """
1.699 +
1.700 + page = self.page
1.701 + request = page.request
1.702 + fmt = request.formatter
1.703 + _ = request.getText
1.704 +
1.705 + output = []
1.706 + append = output.append
1.707 +
1.708 + # Prepare navigation links.
1.709 +
1.710 + if self.calendar_name:
1.711 + calendar_name = self.calendar_name
1.712 +
1.713 + # Links to the previous set of months and to a calendar shifted
1.714 + # back one month.
1.715 +
1.716 + previous_set_link = self.getNavigationLink(
1.717 + self.previous_set_start, self.previous_set_end
1.718 + )
1.719 + previous_link = self.getNavigationLink(
1.720 + self.previous_start, self.previous_end
1.721 + )
1.722 + previous_set_update_link = self.getUpdateLink(
1.723 + self.previous_set_start, self.previous_set_end
1.724 + )
1.725 + previous_update_link = self.getUpdateLink(
1.726 + self.previous_start, self.previous_end
1.727 + )
1.728 +
1.729 + # Links to the next set of months and to a calendar shifted
1.730 + # forward one month.
1.731 +
1.732 + next_set_link = self.getNavigationLink(
1.733 + self.next_set_start, self.next_set_end
1.734 + )
1.735 + next_link = self.getNavigationLink(
1.736 + self.next_start, self.next_end
1.737 + )
1.738 + next_set_update_link = self.getUpdateLink(
1.739 + self.next_set_start, self.next_set_end
1.740 + )
1.741 + next_update_link = self.getUpdateLink(
1.742 + self.next_start, self.next_end
1.743 + )
1.744 +
1.745 + # A link leading to this date being at the top of the calendar.
1.746 +
1.747 + date_link = self.getNavigationLink(start, end)
1.748 + date_update_link = self.getUpdateLink(start, end)
1.749 +
1.750 + append(fmt.span(on=1, css_class="previous"))
1.751 + append(linkToPage(request, page, "<<", previous_set_link, onclick=previous_set_update_link))
1.752 + append(fmt.text(" "))
1.753 + append(linkToPage(request, page, "<", previous_link, onclick=previous_update_link))
1.754 + append(fmt.span(on=0))
1.755 +
1.756 + append(fmt.span(on=1, css_class="next"))
1.757 + append(linkToPage(request, page, ">", next_link, onclick=next_update_link))
1.758 + append(fmt.text(" "))
1.759 + append(linkToPage(request, page, ">>", next_set_link, onclick=next_set_update_link))
1.760 + append(fmt.span(on=0))
1.761 +
1.762 + append(linkToPage(request, page, label, date_link, onclick=date_update_link))
1.763 +
1.764 + else:
1.765 + append(fmt.span(on=1))
1.766 + append(fmt.text(label))
1.767 + append(fmt.span(on=0))
1.768 +
1.769 + return "".join(output)
1.770 +
1.771 + def writeDayNumberHeading(self, date, busy):
1.772 +
1.773 + """
1.774 + Return a link for the given 'date' which will activate the new event
1.775 + action for the given day. If 'busy' is given as a true value, the
1.776 + heading will be marked as busy.
1.777 + """
1.778 +
1.779 + page = self.page
1.780 + request = page.request
1.781 + fmt = request.formatter
1.782 + _ = request.getText
1.783 +
1.784 + output = []
1.785 + append = output.append
1.786 +
1.787 + year, month, day = date.as_tuple()
1.788 + new_event_link = self.getNewEventLink(date)
1.789 +
1.790 + # Prepare a link to the day view for this day.
1.791 +
1.792 + day_view_link = self.getNavigationLink(date, date, "day", "date", self.calendar_start, self.calendar_end)
1.793 + day_view_update_link = self.getUpdateLink(date, date, "day", "date", self.calendar_start, self.calendar_end)
1.794 +
1.795 + # Output the heading class.
1.796 +
1.797 + today_attr = date == getCurrentDate() and "event-day-current" or ""
1.798 +
1.799 + append(
1.800 + fmt.table_cell(on=1, attrs={
1.801 + "class" : "event-day-heading event-day-%s %s" % (busy and "busy" or "empty", today_attr),
1.802 + "colspan" : "3"
1.803 + }))
1.804 +
1.805 + # Output the number and pop-up menu.
1.806 +
1.807 + append(fmt.div(on=1, css_class="event-day-box"))
1.808 +
1.809 + append(fmt.span(on=1, css_class="event-day-number-popup"))
1.810 + append(fmt.span(on=1, css_class="event-day-number-link"))
1.811 + append(linkToPage(request, page, _("View day"), day_view_link, onclick=day_view_update_link))
1.812 + append(fmt.span(on=0))
1.813 + append(fmt.span(on=1, css_class="event-day-number-link"))
1.814 + append(linkToPage(request, page, _("New event"), new_event_link))
1.815 + append(fmt.span(on=0))
1.816 + append(fmt.span(on=0))
1.817 +
1.818 + append(fmt.span(on=1, css_class="event-day-number"))
1.819 + append(fmt.text(unicode(day)))
1.820 + append(fmt.span(on=0))
1.821 +
1.822 + append(fmt.div(on=0))
1.823 +
1.824 + # End of heading.
1.825 +
1.826 + append(fmt.table_cell(on=0))
1.827 +
1.828 + return "".join(output)
1.829 +
1.830 + # Common layout methods.
1.831 +
1.832 + def getEventStyle(self, colour_seed):
1.833 +
1.834 + "Generate colour style information using the given 'colour_seed'."
1.835 +
1.836 + bg = getColour(colour_seed)
1.837 + fg = getBlackOrWhite(bg)
1.838 + return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg)
1.839 +
1.840 + def writeEventSummaryBox(self, event):
1.841 +
1.842 + "Return an event summary box linking to the given 'event'."
1.843 +
1.844 + page = self.page
1.845 + request = page.request
1.846 + fmt = request.formatter
1.847 +
1.848 + output = []
1.849 + append = output.append
1.850 +
1.851 + event_details = event.getDetails()
1.852 + event_summary = event.getSummary(self.parent_name)
1.853 +
1.854 + is_ambiguous = event.as_timespan().ambiguous()
1.855 + style = self.getEventStyle(event_summary)
1.856 +
1.857 + # The event box contains the summary, alongside
1.858 + # other elements.
1.859 +
1.860 + append(fmt.div(on=1, css_class="event-summary-box"))
1.861 + append(fmt.div(on=1, css_class="event-summary", style=style))
1.862 +
1.863 + if is_ambiguous:
1.864 + append(fmt.icon("/!\\"))
1.865 +
1.866 + append(event.linkToEvent(request, event_summary))
1.867 + append(fmt.div(on=0))
1.868 +
1.869 + # Add a pop-up element for long summaries.
1.870 +
1.871 + append(fmt.div(on=1, css_class="event-summary-popup", style=style))
1.872 +
1.873 + if is_ambiguous:
1.874 + append(fmt.icon("/!\\"))
1.875 +
1.876 + append(event.linkToEvent(request, event_summary))
1.877 + append(fmt.div(on=0))
1.878 +
1.879 + append(fmt.div(on=0))
1.880 +
1.881 + return "".join(output)
1.882 +
1.883 + # Calendar layout methods.
1.884 +
1.885 + def writeMonthTableHeading(self, year_month):
1.886 + page = self.page
1.887 + fmt = page.request.formatter
1.888 +
1.889 + output = []
1.890 + append = output.append
1.891 +
1.892 + append(fmt.table_row(on=1))
1.893 + append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"}))
1.894 +
1.895 + append(self.writeMonthHeading(year_month))
1.896 +
1.897 + append(fmt.table_cell(on=0))
1.898 + append(fmt.table_row(on=0))
1.899 +
1.900 + return "".join(output)
1.901 +
1.902 + def writeWeekdayHeadings(self):
1.903 + page = self.page
1.904 + request = page.request
1.905 + fmt = request.formatter
1.906 + _ = request.getText
1.907 +
1.908 + output = []
1.909 + append = output.append
1.910 +
1.911 + append(fmt.table_row(on=1))
1.912 +
1.913 + for weekday in range(0, 7):
1.914 + append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"}))
1.915 + append(fmt.text(_(getDayLabel(weekday))))
1.916 + append(fmt.table_cell(on=0))
1.917 +
1.918 + append(fmt.table_row(on=0))
1.919 + return "".join(output)
1.920 +
1.921 + def writeDayNumbers(self, first_day, number_of_days, month, coverage):
1.922 + page = self.page
1.923 + fmt = page.request.formatter
1.924 +
1.925 + output = []
1.926 + append = output.append
1.927 +
1.928 + append(fmt.table_row(on=1))
1.929 +
1.930 + for weekday in range(0, 7):
1.931 + day = first_day + weekday
1.932 + date = month.as_date(day)
1.933 +
1.934 + # Output out-of-month days.
1.935 +
1.936 + if day < 1 or day > number_of_days:
1.937 + append(fmt.table_cell(on=1,
1.938 + attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"}))
1.939 + append(fmt.table_cell(on=0))
1.940 +
1.941 + # Output normal days.
1.942 +
1.943 + else:
1.944 + # Output the day heading, making a link to a new event
1.945 + # action.
1.946 +
1.947 + append(self.writeDayNumberHeading(date, date in coverage))
1.948 +
1.949 + # End of day numbers.
1.950 +
1.951 + append(fmt.table_row(on=0))
1.952 + return "".join(output)
1.953 +
1.954 + def writeEmptyWeek(self, first_day, number_of_days, month):
1.955 + page = self.page
1.956 + fmt = page.request.formatter
1.957 +
1.958 + output = []
1.959 + append = output.append
1.960 +
1.961 + append(fmt.table_row(on=1))
1.962 +
1.963 + for weekday in range(0, 7):
1.964 + day = first_day + weekday
1.965 + date = month.as_date(day)
1.966 +
1.967 + today_attr = date == getCurrentDate() and "event-day-current" or ""
1.968 +
1.969 + # Output out-of-month days.
1.970 +
1.971 + if day < 1 or day > number_of_days:
1.972 + append(fmt.table_cell(on=1,
1.973 + attrs={"class" : "event-day-content event-day-excluded %s" % today_attr, "colspan" : "3"}))
1.974 + append(fmt.table_cell(on=0))
1.975 +
1.976 + # Output empty days.
1.977 +
1.978 + else:
1.979 + append(fmt.table_cell(on=1,
1.980 + attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"}))
1.981 +
1.982 + append(fmt.table_row(on=0))
1.983 + return "".join(output)
1.984 +
1.985 + def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots):
1.986 + output = []
1.987 + append = output.append
1.988 +
1.989 + locations = week_slots.keys()
1.990 + locations.sort(sort_none_first)
1.991 +
1.992 + # Visit each slot corresponding to a location (or no location).
1.993 +
1.994 + for location in locations:
1.995 +
1.996 + # Visit each coverage span, presenting the events in the span.
1.997 +
1.998 + for events in week_slots[location]:
1.999 +
1.1000 + # Output each set.
1.1001 +
1.1002 + append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events))
1.1003 +
1.1004 + # Add a spacer.
1.1005 +
1.1006 + append(self.writeWeekSpacer(first_day, number_of_days, month))
1.1007 +
1.1008 + return "".join(output)
1.1009 +
1.1010 + def writeWeekSlot(self, first_day, number_of_days, month, week_end, events):
1.1011 + page = self.page
1.1012 + request = page.request
1.1013 + fmt = request.formatter
1.1014 +
1.1015 + output = []
1.1016 + append = output.append
1.1017 +
1.1018 + append(fmt.table_row(on=1))
1.1019 +
1.1020 + # Then, output day details.
1.1021 +
1.1022 + for weekday in range(0, 7):
1.1023 + day = first_day + weekday
1.1024 + date = month.as_date(day)
1.1025 +
1.1026 + # Skip out-of-month days.
1.1027 +
1.1028 + if day < 1 or day > number_of_days:
1.1029 + append(fmt.table_cell(on=1,
1.1030 + attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"}))
1.1031 + append(fmt.table_cell(on=0))
1.1032 + continue
1.1033 +
1.1034 + # Output the day.
1.1035 + # Where a day does not contain an event, a single cell is used.
1.1036 + # Otherwise, multiple cells are used to provide space before, during
1.1037 + # and after events.
1.1038 +
1.1039 + today_attr = date == getCurrentDate() and "event-day-current" or ""
1.1040 +
1.1041 + if date not in events:
1.1042 + append(fmt.table_cell(on=1,
1.1043 + attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"}))
1.1044 +
1.1045 + # Get event details for the current day.
1.1046 +
1.1047 + for event in events:
1.1048 + event_details = event.getDetails()
1.1049 +
1.1050 + if date not in event:
1.1051 + continue
1.1052 +
1.1053 + # Get basic properties of the event.
1.1054 +
1.1055 + starts_today = event_details["start"] == date
1.1056 + ends_today = event_details["end"] == date
1.1057 + event_summary = event.getSummary(self.parent_name)
1.1058 +
1.1059 + style = self.getEventStyle(event_summary)
1.1060 +
1.1061 + # Determine if the event name should be shown.
1.1062 +
1.1063 + start_of_period = starts_today or weekday == 0 or day == 1
1.1064 +
1.1065 + if self.name_usage == "daily" or start_of_period:
1.1066 + hide_text = 0
1.1067 + else:
1.1068 + hide_text = 1
1.1069 +
1.1070 + # Output start of day gap and determine whether
1.1071 + # any event content should be explicitly output
1.1072 + # for this day.
1.1073 +
1.1074 + if starts_today:
1.1075 +
1.1076 + # Single day events...
1.1077 +
1.1078 + if ends_today:
1.1079 + colspan = 3
1.1080 + event_day_type = "event-day-single"
1.1081 +
1.1082 + # Events starting today...
1.1083 +
1.1084 + else:
1.1085 + append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap %s" % today_attr}))
1.1086 + append(fmt.table_cell(on=0))
1.1087 +
1.1088 + # Calculate the span of this cell.
1.1089 + # Events whose names appear on every day...
1.1090 +
1.1091 + if self.name_usage == "daily":
1.1092 + colspan = 2
1.1093 + event_day_type = "event-day-starting"
1.1094 +
1.1095 + # Events whose names appear once per week...
1.1096 +
1.1097 + else:
1.1098 + if event_details["end"] <= week_end:
1.1099 + event_length = event_details["end"].day() - day + 1
1.1100 + colspan = (event_length - 2) * 3 + 4
1.1101 + else:
1.1102 + event_length = week_end.day() - day + 1
1.1103 + colspan = (event_length - 1) * 3 + 2
1.1104 +
1.1105 + event_day_type = "event-day-multiple"
1.1106 +
1.1107 + # Events continuing from a previous week...
1.1108 +
1.1109 + elif start_of_period:
1.1110 +
1.1111 + # End of continuing event...
1.1112 +
1.1113 + if ends_today:
1.1114 + colspan = 2
1.1115 + event_day_type = "event-day-ending"
1.1116 +
1.1117 + # Events continuing for at least one more day...
1.1118 +
1.1119 + else:
1.1120 +
1.1121 + # Calculate the span of this cell.
1.1122 + # Events whose names appear on every day...
1.1123 +
1.1124 + if self.name_usage == "daily":
1.1125 + colspan = 3
1.1126 + event_day_type = "event-day-full"
1.1127 +
1.1128 + # Events whose names appear once per week...
1.1129 +
1.1130 + else:
1.1131 + if event_details["end"] <= week_end:
1.1132 + event_length = event_details["end"].day() - day + 1
1.1133 + colspan = (event_length - 1) * 3 + 2
1.1134 + else:
1.1135 + event_length = week_end.day() - day + 1
1.1136 + colspan = event_length * 3
1.1137 +
1.1138 + event_day_type = "event-day-multiple"
1.1139 +
1.1140 + # Continuing events whose names appear on every day...
1.1141 +
1.1142 + elif self.name_usage == "daily":
1.1143 + if ends_today:
1.1144 + colspan = 2
1.1145 + event_day_type = "event-day-ending"
1.1146 + else:
1.1147 + colspan = 3
1.1148 + event_day_type = "event-day-full"
1.1149 +
1.1150 + # Continuing events whose names appear once per week...
1.1151 +
1.1152 + else:
1.1153 + colspan = None
1.1154 +
1.1155 + # Output the main content only if it is not
1.1156 + # continuing from a previous day.
1.1157 +
1.1158 + if colspan is not None:
1.1159 +
1.1160 + # Colour the cell for continuing events.
1.1161 +
1.1162 + attrs={
1.1163 + "class" : "event-day-content event-day-busy %s %s" % (event_day_type, today_attr),
1.1164 + "colspan" : str(colspan)
1.1165 + }
1.1166 +
1.1167 + if not (starts_today and ends_today):
1.1168 + attrs["style"] = style
1.1169 +
1.1170 + append(fmt.table_cell(on=1, attrs=attrs))
1.1171 +
1.1172 + # Output the event.
1.1173 +
1.1174 + if starts_today and ends_today or not hide_text:
1.1175 + append(self.writeEventSummaryBox(event))
1.1176 +
1.1177 + append(fmt.table_cell(on=0))
1.1178 +
1.1179 + # Output end of day gap.
1.1180 +
1.1181 + if ends_today and not starts_today:
1.1182 + append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap %s" % today_attr}))
1.1183 + append(fmt.table_cell(on=0))
1.1184 +
1.1185 + # End of set.
1.1186 +
1.1187 + append(fmt.table_row(on=0))
1.1188 + return "".join(output)
1.1189 +
1.1190 + def writeWeekSpacer(self, first_day, number_of_days, month):
1.1191 + page = self.page
1.1192 + fmt = page.request.formatter
1.1193 +
1.1194 + output = []
1.1195 + append = output.append
1.1196 +
1.1197 + append(fmt.table_row(on=1))
1.1198 +
1.1199 + for weekday in range(0, 7):
1.1200 + day = first_day + weekday
1.1201 + date = month.as_date(day)
1.1202 + today_attr = date == getCurrentDate() and "event-day-current" or ""
1.1203 +
1.1204 + css_classes = "event-day-spacer %s" % today_attr
1.1205 +
1.1206 + # Skip out-of-month days.
1.1207 +
1.1208 + if day < 1 or day > number_of_days:
1.1209 + css_classes += " event-day-excluded"
1.1210 +
1.1211 + append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"}))
1.1212 + append(fmt.table_cell(on=0))
1.1213 +
1.1214 + append(fmt.table_row(on=0))
1.1215 + return "".join(output)
1.1216 +
1.1217 + # Day layout methods.
1.1218 +
1.1219 + def writeDayTableHeading(self, date, colspan=1):
1.1220 + page = self.page
1.1221 + fmt = page.request.formatter
1.1222 +
1.1223 + output = []
1.1224 + append = output.append
1.1225 +
1.1226 + append(fmt.table_row(on=1))
1.1227 +
1.1228 + append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)}))
1.1229 + append(self.writeDayHeading(date))
1.1230 + append(fmt.table_cell(on=0))
1.1231 +
1.1232 + append(fmt.table_row(on=0))
1.1233 + return "".join(output)
1.1234 +
1.1235 + def writeEmptyDay(self, date):
1.1236 + page = self.page
1.1237 + fmt = page.request.formatter
1.1238 +
1.1239 + output = []
1.1240 + append = output.append
1.1241 +
1.1242 + append(fmt.table_row(on=1))
1.1243 +
1.1244 + append(fmt.table_cell(on=1,
1.1245 + attrs={"class" : "event-day-content event-day-empty"}))
1.1246 +
1.1247 + append(fmt.table_row(on=0))
1.1248 + return "".join(output)
1.1249 +
1.1250 + def writeDaySlots(self, date, full_coverage, day_slots):
1.1251 +
1.1252 + """
1.1253 + Given a 'date', non-empty 'full_coverage' for the day concerned, and a
1.1254 + non-empty mapping of 'day_slots' (from locations to event collections),
1.1255 + output the day slots for the day.
1.1256 + """
1.1257 +
1.1258 + page = self.page
1.1259 + fmt = page.request.formatter
1.1260 +
1.1261 + output = []
1.1262 + append = output.append
1.1263 +
1.1264 + locations = day_slots.keys()
1.1265 + locations.sort(sort_none_first)
1.1266 +
1.1267 + # Traverse the time scale of the full coverage, visiting each slot to
1.1268 + # determine whether it provides content for each period.
1.1269 +
1.1270 + scale = getCoverageScale(full_coverage)
1.1271 +
1.1272 + # Define a mapping of events to rowspans.
1.1273 +
1.1274 + rowspans = {}
1.1275 +
1.1276 + # Populate each period with event details, recording how many periods
1.1277 + # each event populates.
1.1278 +
1.1279 + day_rows = []
1.1280 +
1.1281 + for period in scale:
1.1282 +
1.1283 + # Ignore timespans before this day.
1.1284 +
1.1285 + if period != date:
1.1286 + continue
1.1287 +
1.1288 + # Visit each slot corresponding to a location (or no location).
1.1289 +
1.1290 + day_row = []
1.1291 +
1.1292 + for location in locations:
1.1293 +
1.1294 + # Visit each coverage span, presenting the events in the span.
1.1295 +
1.1296 + for events in day_slots[location]:
1.1297 + event = self.getActiveEvent(period, events)
1.1298 + if event is not None:
1.1299 + if not rowspans.has_key(event):
1.1300 + rowspans[event] = 1
1.1301 + else:
1.1302 + rowspans[event] += 1
1.1303 + day_row.append((location, event))
1.1304 +
1.1305 + day_rows.append((period, day_row))
1.1306 +
1.1307 + # Output the locations.
1.1308 +
1.1309 + append(fmt.table_row(on=1))
1.1310 +
1.1311 + # Add a spacer.
1.1312 +
1.1313 + append(self.writeDaySpacer(colspan=2, cls="location"))
1.1314 +
1.1315 + for location in locations:
1.1316 +
1.1317 + # Add spacers to the column spans.
1.1318 +
1.1319 + columns = len(day_slots[location]) * 2 - 1
1.1320 + append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)}))
1.1321 + append(fmt.text(location or ""))
1.1322 + append(fmt.table_cell(on=0))
1.1323 +
1.1324 + # Add a trailing spacer.
1.1325 +
1.1326 + append(self.writeDaySpacer(cls="location"))
1.1327 +
1.1328 + append(fmt.table_row(on=0))
1.1329 +
1.1330 + # Output the periods with event details.
1.1331 +
1.1332 + period = None
1.1333 + events_written = set()
1.1334 +
1.1335 + for period, day_row in day_rows:
1.1336 +
1.1337 + # Write an empty heading for the start of the day where the first
1.1338 + # applicable timespan starts before this day.
1.1339 +
1.1340 + if period.start < date:
1.1341 + append(fmt.table_row(on=1))
1.1342 + append(self.writeDayScaleHeading(""))
1.1343 +
1.1344 + # Otherwise, write a heading describing the time.
1.1345 +
1.1346 + else:
1.1347 + append(fmt.table_row(on=1))
1.1348 + append(self.writeDayScaleHeading(period.start.time_string()))
1.1349 +
1.1350 + append(self.writeDaySpacer())
1.1351 +
1.1352 + # Visit each slot corresponding to a location (or no location).
1.1353 +
1.1354 + for location, event in day_row:
1.1355 +
1.1356 + # Output each location slot's contribution.
1.1357 +
1.1358 + if event is None or event not in events_written:
1.1359 + append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event]))
1.1360 + if event is not None:
1.1361 + events_written.add(event)
1.1362 +
1.1363 + # Add a trailing spacer.
1.1364 +
1.1365 + append(self.writeDaySpacer())
1.1366 +
1.1367 + append(fmt.table_row(on=0))
1.1368 +
1.1369 + # Write a final time heading if the last period ends in the current day.
1.1370 +
1.1371 + if period is not None:
1.1372 + if period.end == date:
1.1373 + append(fmt.table_row(on=1))
1.1374 + append(self.writeDayScaleHeading(period.end.time_string()))
1.1375 +
1.1376 + for slot in day_row:
1.1377 + append(self.writeDaySpacer())
1.1378 + append(self.writeEmptyDaySlot())
1.1379 +
1.1380 + append(fmt.table_row(on=0))
1.1381 +
1.1382 + return "".join(output)
1.1383 +
1.1384 + def writeDayScaleHeading(self, heading):
1.1385 + page = self.page
1.1386 + fmt = page.request.formatter
1.1387 +
1.1388 + output = []
1.1389 + append = output.append
1.1390 +
1.1391 + append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"}))
1.1392 + append(fmt.text(heading))
1.1393 + append(fmt.table_cell(on=0))
1.1394 +
1.1395 + return "".join(output)
1.1396 +
1.1397 + def getActiveEvent(self, period, events):
1.1398 + for event in events:
1.1399 + if period not in event:
1.1400 + continue
1.1401 + return event
1.1402 + else:
1.1403 + return None
1.1404 +
1.1405 + def writeDaySlot(self, period, event, rowspan):
1.1406 + page = self.page
1.1407 + fmt = page.request.formatter
1.1408 +
1.1409 + output = []
1.1410 + append = output.append
1.1411 +
1.1412 + if event is not None:
1.1413 + event_summary = event.getSummary(self.parent_name)
1.1414 + style = self.getEventStyle(event_summary)
1.1415 +
1.1416 + append(fmt.table_cell(on=1, attrs={
1.1417 + "class" : "event-timespan-content event-timespan-busy",
1.1418 + "style" : style,
1.1419 + "rowspan" : str(rowspan)
1.1420 + }))
1.1421 + append(self.writeEventSummaryBox(event))
1.1422 + append(fmt.table_cell(on=0))
1.1423 + else:
1.1424 + append(self.writeEmptyDaySlot())
1.1425 +
1.1426 + return "".join(output)
1.1427 +
1.1428 + def writeEmptyDaySlot(self):
1.1429 + page = self.page
1.1430 + fmt = page.request.formatter
1.1431 +
1.1432 + output = []
1.1433 + append = output.append
1.1434 +
1.1435 + append(fmt.table_cell(on=1,
1.1436 + attrs={"class" : "event-timespan-content event-timespan-empty"}))
1.1437 + append(fmt.table_cell(on=0))
1.1438 +
1.1439 + return "".join(output)
1.1440 +
1.1441 + def writeDaySpacer(self, colspan=1, cls="timespan"):
1.1442 + page = self.page
1.1443 + fmt = page.request.formatter
1.1444 +
1.1445 + output = []
1.1446 + append = output.append
1.1447 +
1.1448 + append(fmt.table_cell(on=1, attrs={
1.1449 + "class" : "event-%s-spacer" % cls,
1.1450 + "colspan" : str(colspan)}))
1.1451 + append(fmt.table_cell(on=0))
1.1452 + return "".join(output)
1.1453 +
1.1454 + # Map layout methods.
1.1455 +
1.1456 + def writeMapTableHeading(self):
1.1457 + page = self.page
1.1458 + fmt = page.request.formatter
1.1459 +
1.1460 + output = []
1.1461 + append = output.append
1.1462 +
1.1463 + append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"}))
1.1464 + append(self.writeMapHeading())
1.1465 + append(fmt.table_cell(on=0))
1.1466 +
1.1467 + return "".join(output)
1.1468 +
1.1469 + def showDictError(self, text, pagename):
1.1470 + page = self.page
1.1471 + request = page.request
1.1472 + fmt = request.formatter
1.1473 +
1.1474 + output = []
1.1475 + append = output.append
1.1476 +
1.1477 + append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"}))
1.1478 + append(fmt.paragraph(on=1))
1.1479 + append(fmt.text(text))
1.1480 + append(fmt.paragraph(on=0))
1.1481 + append(fmt.paragraph(on=1))
1.1482 + append(linkToPage(request, Page(request, pagename), pagename))
1.1483 + append(fmt.paragraph(on=0))
1.1484 +
1.1485 + return "".join(output)
1.1486 +
1.1487 + def writeMapMarker(self, marker_x, marker_y, map_x_scale, map_y_scale, location, events):
1.1488 +
1.1489 + "Put a marker on the map."
1.1490 +
1.1491 + page = self.page
1.1492 + request = page.request
1.1493 + fmt = request.formatter
1.1494 +
1.1495 + output = []
1.1496 + append = output.append
1.1497 +
1.1498 + append(fmt.listitem(on=1, css_class="event-map-label"))
1.1499 +
1.1500 + # Have a positioned marker for the print mode.
1.1501 +
1.1502 + append(fmt.div(on=1, css_class="event-map-label-only",
1.1503 + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
1.1504 + marker_x, marker_y, map_x_scale, map_y_scale))
1.1505 + append(fmt.div(on=0))
1.1506 +
1.1507 + # Have a marker containing a pop-up when using the screen mode,
1.1508 + # providing a normal block when using the print mode.
1.1509 +
1.1510 + append(fmt.div(on=1, css_class="event-map-label",
1.1511 + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
1.1512 + marker_x, marker_y, map_x_scale, map_y_scale))
1.1513 + append(fmt.div(on=1, css_class="event-map-details"))
1.1514 + append(fmt.div(on=1, css_class="event-map-shadow"))
1.1515 + append(fmt.div(on=1, css_class="event-map-location"))
1.1516 +
1.1517 + # The location may have been given as formatted text, but this will not
1.1518 + # be usable in a heading, so it must be first converted to plain text.
1.1519 +
1.1520 + append(fmt.heading(on=1, depth=2))
1.1521 + append(fmt.text(to_plain_text(location, request)))
1.1522 + append(fmt.heading(on=0, depth=2))
1.1523 +
1.1524 + append(self.writeMapEventSummaries(events))
1.1525 +
1.1526 + append(fmt.div(on=0))
1.1527 + append(fmt.div(on=0))
1.1528 + append(fmt.div(on=0))
1.1529 + append(fmt.div(on=0))
1.1530 + append(fmt.listitem(on=0))
1.1531 +
1.1532 + return "".join(output)
1.1533 +
1.1534 + def writeMapEventSummaries(self, events):
1.1535 +
1.1536 + "Write summaries of the given 'events' for the map."
1.1537 +
1.1538 + page = self.page
1.1539 + request = page.request
1.1540 + fmt = request.formatter
1.1541 +
1.1542 + # Sort the events by date.
1.1543 +
1.1544 + events.sort(sort_start_first)
1.1545 +
1.1546 + # Write out a self-contained list of events.
1.1547 +
1.1548 + output = []
1.1549 + append = output.append
1.1550 +
1.1551 + append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"}))
1.1552 +
1.1553 + for event in events:
1.1554 +
1.1555 + # Get the event details.
1.1556 +
1.1557 + event_summary = event.getSummary(self.parent_name)
1.1558 + start, end = event.as_limits()
1.1559 + event_period = self._getCalendarPeriod(
1.1560 + start and self.getFullDateLabel(start),
1.1561 + end and self.getFullDateLabel(end),
1.1562 + "")
1.1563 +
1.1564 + append(fmt.listitem(on=1))
1.1565 +
1.1566 + # Link to the page using the summary.
1.1567 +
1.1568 + append(event.linkToEvent(request, event_summary))
1.1569 +
1.1570 + # Add the event period.
1.1571 +
1.1572 + append(fmt.text(" "))
1.1573 + append(fmt.span(on=1, css_class="event-map-period"))
1.1574 + append(fmt.text(event_period))
1.1575 + append(fmt.span(on=0))
1.1576 +
1.1577 + append(fmt.listitem(on=0))
1.1578 +
1.1579 + append(fmt.bullet_list(on=0))
1.1580 +
1.1581 + return "".join(output)
1.1582 +
1.1583 + def render(self, all_shown_events):
1.1584 +
1.1585 + """
1.1586 + Render the view, returning the rendered representation as a string.
1.1587 + The view will show a list of 'all_shown_events'.
1.1588 + """
1.1589 +
1.1590 + page = self.page
1.1591 + request = page.request
1.1592 + fmt = request.formatter
1.1593 + _ = request.getText
1.1594 +
1.1595 + # Make a calendar.
1.1596 +
1.1597 + output = []
1.1598 + append = output.append
1.1599 +
1.1600 + append(fmt.div(on=1, css_class="event-calendar", id=("EventAggregator-%s" % self.getIdentifier())))
1.1601 +
1.1602 + # Output download controls.
1.1603 +
1.1604 + append(fmt.div(on=1, css_class="event-controls"))
1.1605 + append(self.writeDownloadControls())
1.1606 + append(fmt.div(on=0))
1.1607 +
1.1608 + # Output a table.
1.1609 +
1.1610 + if self.mode == "table":
1.1611 +
1.1612 + # Start of table view output.
1.1613 +
1.1614 + append(fmt.table(on=1, attrs={"tableclass" : "event-table"}))
1.1615 +
1.1616 + append(fmt.table_row(on=1))
1.1617 + append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
1.1618 + append(fmt.text(_("Event dates")))
1.1619 + append(fmt.table_cell(on=0))
1.1620 + append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
1.1621 + append(fmt.text(_("Event location")))
1.1622 + append(fmt.table_cell(on=0))
1.1623 + append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
1.1624 + append(fmt.text(_("Event details")))
1.1625 + append(fmt.table_cell(on=0))
1.1626 + append(fmt.table_row(on=0))
1.1627 +
1.1628 + # Show the events in order.
1.1629 +
1.1630 + all_shown_events.sort(sort_start_first)
1.1631 +
1.1632 + for event in all_shown_events:
1.1633 + event_page = event.getPage()
1.1634 + event_summary = event.getSummary(self.parent_name)
1.1635 + event_details = event.getDetails()
1.1636 +
1.1637 + # Prepare CSS classes with category-related styling.
1.1638 +
1.1639 + css_classes = ["event-table-details"]
1.1640 +
1.1641 + for topic in event_details.get("topics") or event_details.get("categories") or []:
1.1642 +
1.1643 + # Filter the category text to avoid illegal characters.
1.1644 +
1.1645 + css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic)))
1.1646 +
1.1647 + attrs = {"class" : " ".join(css_classes)}
1.1648 +
1.1649 + append(fmt.table_row(on=1))
1.1650 +
1.1651 + # Start and end dates.
1.1652 +
1.1653 + append(fmt.table_cell(on=1, attrs=attrs))
1.1654 + append(fmt.span(on=1))
1.1655 + append(fmt.text(str(event_details["start"])))
1.1656 + append(fmt.span(on=0))
1.1657 +
1.1658 + if event_details["start"] != event_details["end"]:
1.1659 + append(fmt.text(" - "))
1.1660 + append(fmt.span(on=1))
1.1661 + append(fmt.text(str(event_details["end"])))
1.1662 + append(fmt.span(on=0))
1.1663 +
1.1664 + append(fmt.table_cell(on=0))
1.1665 +
1.1666 + # Location.
1.1667 +
1.1668 + append(fmt.table_cell(on=1, attrs=attrs))
1.1669 +
1.1670 + if event_details.has_key("location"):
1.1671 + append(event_page.formatText(event_details["location"], fmt))
1.1672 +
1.1673 + append(fmt.table_cell(on=0))
1.1674 +
1.1675 + # Link to the page using the summary.
1.1676 +
1.1677 + append(fmt.table_cell(on=1, attrs=attrs))
1.1678 + append(event.linkToEvent(request, event_summary))
1.1679 + append(fmt.table_cell(on=0))
1.1680 +
1.1681 + append(fmt.table_row(on=0))
1.1682 +
1.1683 + # End of table view output.
1.1684 +
1.1685 + append(fmt.table(on=0))
1.1686 +
1.1687 + # Output a map view.
1.1688 +
1.1689 + elif self.mode == "map":
1.1690 +
1.1691 + # Special dictionary pages.
1.1692 +
1.1693 + maps_page = getMapsPage(request)
1.1694 + locations_page = getLocationsPage(request)
1.1695 +
1.1696 + map_image = None
1.1697 +
1.1698 + # Get the maps and locations.
1.1699 +
1.1700 + maps = getWikiDict(maps_page, request)
1.1701 + locations = getWikiDict(locations_page, request)
1.1702 +
1.1703 + # Get the map image definition.
1.1704 +
1.1705 + if maps is not None and self.map_name:
1.1706 + try:
1.1707 + map_details = maps[self.map_name].split()
1.1708 +
1.1709 + map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \
1.1710 + map(getMapReference, map_details[:4])
1.1711 + map_width, map_height = map(int, map_details[4:6])
1.1712 + map_image = map_details[6]
1.1713 +
1.1714 + map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees()
1.1715 + map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees()
1.1716 +
1.1717 + except (KeyError, ValueError):
1.1718 + pass
1.1719 +
1.1720 + # Report errors.
1.1721 +
1.1722 + if maps is None:
1.1723 + append(self.showDictError(
1.1724 + _("You do not have read access to the maps page:"),
1.1725 + maps_page))
1.1726 +
1.1727 + elif not self.map_name:
1.1728 + append(self.showDictError(
1.1729 + _("Please specify a valid map name corresponding to an entry on the following page:"),
1.1730 + maps_page))
1.1731 +
1.1732 + elif map_image is None:
1.1733 + append(self.showDictError(
1.1734 + _("Please specify a valid entry for %s on the following page:") % self.map_name,
1.1735 + maps_page))
1.1736 +
1.1737 + elif locations is None:
1.1738 + append(self.showDictError(
1.1739 + _("You do not have read access to the locations page:"),
1.1740 + locations_page))
1.1741 +
1.1742 + # Attempt to show the map.
1.1743 +
1.1744 + else:
1.1745 +
1.1746 + # Get events by position.
1.1747 +
1.1748 + events_by_location = {}
1.1749 + event_locations = {}
1.1750 +
1.1751 + for event in all_shown_events:
1.1752 + event_details = event.getDetails()
1.1753 +
1.1754 + location = event_details.get("location")
1.1755 + geo = event_details.get("geo")
1.1756 +
1.1757 + # Make a temporary location if an explicit position is given
1.1758 + # but not a location name.
1.1759 +
1.1760 + if not location and geo:
1.1761 + location = "%s %s" % tuple(geo)
1.1762 +
1.1763 + # Map the location to a position.
1.1764 +
1.1765 + if location is not None and not event_locations.has_key(location):
1.1766 +
1.1767 + # Get any explicit position of an event.
1.1768 +
1.1769 + if geo:
1.1770 + latitude, longitude = geo
1.1771 +
1.1772 + # Or look up the position of a location using the locations
1.1773 + # page.
1.1774 +
1.1775 + else:
1.1776 + latitude, longitude = Location(location, locations).getPosition()
1.1777 +
1.1778 + # Use a normalised location if necessary.
1.1779 +
1.1780 + if latitude is None and longitude is None:
1.1781 + normalised_location = getNormalisedLocation(location)
1.1782 + if normalised_location is not None:
1.1783 + latitude, longitude = getLocationPosition(normalised_location, locations)
1.1784 + if latitude is not None and longitude is not None:
1.1785 + location = normalised_location
1.1786 +
1.1787 + # Only remember positioned locations.
1.1788 +
1.1789 + if latitude is not None and longitude is not None:
1.1790 + event_locations[location] = latitude, longitude
1.1791 +
1.1792 + # Record events according to location.
1.1793 +
1.1794 + if not events_by_location.has_key(location):
1.1795 + events_by_location[location] = []
1.1796 +
1.1797 + events_by_location[location].append(event)
1.1798 +
1.1799 + # Get the map image URL.
1.1800 +
1.1801 + map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
1.1802 +
1.1803 + # Start of map view output.
1.1804 +
1.1805 + map_identifier = "map-%s" % self.getIdentifier()
1.1806 + append(fmt.div(on=1, css_class="event-map", id=map_identifier))
1.1807 +
1.1808 + append(fmt.table(on=1))
1.1809 +
1.1810 + append(fmt.table_row(on=1))
1.1811 + append(self.writeMapTableHeading())
1.1812 + append(fmt.table_row(on=0))
1.1813 +
1.1814 + append(fmt.table_row(on=1))
1.1815 + append(fmt.table_cell(on=1))
1.1816 +
1.1817 + append(fmt.div(on=1, css_class="event-map-container"))
1.1818 + append(fmt.image(map_image_url))
1.1819 + append(fmt.number_list(on=1))
1.1820 +
1.1821 + # Events with no location are unpositioned.
1.1822 +
1.1823 + if events_by_location.has_key(None):
1.1824 + unpositioned_events = events_by_location[None]
1.1825 + del events_by_location[None]
1.1826 + else:
1.1827 + unpositioned_events = []
1.1828 +
1.1829 + # Events whose location is unpositioned are themselves considered
1.1830 + # unpositioned.
1.1831 +
1.1832 + for location in set(events_by_location.keys()).difference(event_locations.keys()):
1.1833 + unpositioned_events += events_by_location[location]
1.1834 +
1.1835 + # Sort the locations before traversing them.
1.1836 +
1.1837 + event_locations = event_locations.items()
1.1838 + event_locations.sort()
1.1839 +
1.1840 + # Show the events in the map.
1.1841 +
1.1842 + for location, (latitude, longitude) in event_locations:
1.1843 + events = events_by_location[location]
1.1844 +
1.1845 + # Skip unpositioned locations and locations outside the map.
1.1846 +
1.1847 + if latitude is None or longitude is None or \
1.1848 + latitude < map_bottom_left_latitude or \
1.1849 + longitude < map_bottom_left_longitude or \
1.1850 + latitude > map_top_right_latitude or \
1.1851 + longitude > map_top_right_longitude:
1.1852 +
1.1853 + unpositioned_events += events
1.1854 + continue
1.1855 +
1.1856 + # Get the position and dimensions of the map marker.
1.1857 + # NOTE: Use one degree as the marker size.
1.1858 +
1.1859 + marker_x, marker_y = getPositionForCentrePoint(
1.1860 + getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude,
1.1861 + map_x_scale, map_y_scale),
1.1862 + map_x_scale, map_y_scale)
1.1863 +
1.1864 + # Add the map marker.
1.1865 +
1.1866 + append(self.writeMapMarker(marker_x, marker_y, map_x_scale, map_y_scale, location, events))
1.1867 +
1.1868 + append(fmt.number_list(on=0))
1.1869 + append(fmt.div(on=0))
1.1870 + append(fmt.table_cell(on=0))
1.1871 + append(fmt.table_row(on=0))
1.1872 +
1.1873 + # Write unpositioned events.
1.1874 +
1.1875 + if unpositioned_events:
1.1876 + unpositioned_identifier = "unpositioned-%s" % self.getIdentifier()
1.1877 +
1.1878 + append(fmt.table_row(on=1, css_class="event-map-unpositioned",
1.1879 + id=unpositioned_identifier))
1.1880 + append(fmt.table_cell(on=1))
1.1881 +
1.1882 + append(fmt.heading(on=1, depth=2))
1.1883 + append(fmt.text(_("Events not shown on the map")))
1.1884 + append(fmt.heading(on=0, depth=2))
1.1885 +
1.1886 + # Show and hide controls.
1.1887 +
1.1888 + append(fmt.div(on=1, css_class="event-map-show-control"))
1.1889 + append(fmt.anchorlink(on=1, name=unpositioned_identifier))
1.1890 + append(fmt.text(_("Show unpositioned events")))
1.1891 + append(fmt.anchorlink(on=0))
1.1892 + append(fmt.div(on=0))
1.1893 +
1.1894 + append(fmt.div(on=1, css_class="event-map-hide-control"))
1.1895 + append(fmt.anchorlink(on=1, name=map_identifier))
1.1896 + append(fmt.text(_("Hide unpositioned events")))
1.1897 + append(fmt.anchorlink(on=0))
1.1898 + append(fmt.div(on=0))
1.1899 +
1.1900 + append(self.writeMapEventSummaries(unpositioned_events))
1.1901 +
1.1902 + # End of map view output.
1.1903 +
1.1904 + append(fmt.table_cell(on=0))
1.1905 + append(fmt.table_row(on=0))
1.1906 + append(fmt.table(on=0))
1.1907 + append(fmt.div(on=0))
1.1908 +
1.1909 + # Output a list.
1.1910 +
1.1911 + elif self.mode == "list":
1.1912 +
1.1913 + # Start of list view output.
1.1914 +
1.1915 + append(fmt.bullet_list(on=1, attr={"class" : "event-listings"}))
1.1916 +
1.1917 + # Output a list.
1.1918 +
1.1919 + for period in self.first.until(self.last):
1.1920 +
1.1921 + append(fmt.listitem(on=1, attr={"class" : "event-listings-period"}))
1.1922 + append(fmt.div(on=1, attr={"class" : "event-listings-heading"}))
1.1923 +
1.1924 + # Either write a date heading or produce links for navigable
1.1925 + # calendars.
1.1926 +
1.1927 + append(self.writeDateHeading(period))
1.1928 +
1.1929 + append(fmt.div(on=0))
1.1930 +
1.1931 + append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"}))
1.1932 +
1.1933 + # Show the events in order.
1.1934 +
1.1935 + events_in_period = getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period))
1.1936 + events_in_period.sort(sort_start_first)
1.1937 +
1.1938 + for event in events_in_period:
1.1939 + event_page = event.getPage()
1.1940 + event_details = event.getDetails()
1.1941 + event_summary = event.getSummary(self.parent_name)
1.1942 +
1.1943 + append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
1.1944 +
1.1945 + # Link to the page using the summary.
1.1946 +
1.1947 + append(fmt.paragraph(on=1))
1.1948 + append(event.linkToEvent(request, event_summary))
1.1949 + append(fmt.paragraph(on=0))
1.1950 +
1.1951 + # Start and end dates.
1.1952 +
1.1953 + append(fmt.paragraph(on=1))
1.1954 + append(fmt.span(on=1))
1.1955 + append(fmt.text(str(event_details["start"])))
1.1956 + append(fmt.span(on=0))
1.1957 + append(fmt.text(" - "))
1.1958 + append(fmt.span(on=1))
1.1959 + append(fmt.text(str(event_details["end"])))
1.1960 + append(fmt.span(on=0))
1.1961 + append(fmt.paragraph(on=0))
1.1962 +
1.1963 + # Location.
1.1964 +
1.1965 + if event_details.has_key("location"):
1.1966 + append(fmt.paragraph(on=1))
1.1967 + append(event_page.formatText(event_details["location"], fmt))
1.1968 + append(fmt.paragraph(on=1))
1.1969 +
1.1970 + # Topics.
1.1971 +
1.1972 + if event_details.has_key("topics") or event_details.has_key("categories"):
1.1973 + append(fmt.bullet_list(on=1, attr={"class" : "event-topics"}))
1.1974 +
1.1975 + for topic in event_details.get("topics") or event_details.get("categories") or []:
1.1976 + append(fmt.listitem(on=1))
1.1977 + append(event_page.formatText(topic, fmt))
1.1978 + append(fmt.listitem(on=0))
1.1979 +
1.1980 + append(fmt.bullet_list(on=0))
1.1981 +
1.1982 + append(fmt.listitem(on=0))
1.1983 +
1.1984 + append(fmt.bullet_list(on=0))
1.1985 +
1.1986 + # End of list view output.
1.1987 +
1.1988 + append(fmt.bullet_list(on=0))
1.1989 +
1.1990 + # Output a month calendar. This shows month-by-month data.
1.1991 +
1.1992 + elif self.mode == "calendar":
1.1993 +
1.1994 + # Visit all months in the requested range, or across known events.
1.1995 +
1.1996 + for month in self.first.months_until(self.last):
1.1997 +
1.1998 + # Output a month.
1.1999 +
1.2000 + append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
1.2001 +
1.2002 + # Either write a month heading or produce links for navigable
1.2003 + # calendars.
1.2004 +
1.2005 + append(self.writeMonthTableHeading(month))
1.2006 +
1.2007 + # Weekday headings.
1.2008 +
1.2009 + append(self.writeWeekdayHeadings())
1.2010 +
1.2011 + # Process the days of the month.
1.2012 +
1.2013 + start_weekday, number_of_days = month.month_properties()
1.2014 +
1.2015 + # The start weekday is the weekday of day number 1.
1.2016 + # Find the first day of the week, counting from below zero, if
1.2017 + # necessary, in order to land on the first day of the month as
1.2018 + # day number 1.
1.2019 +
1.2020 + first_day = 1 - start_weekday
1.2021 +
1.2022 + while first_day <= number_of_days:
1.2023 +
1.2024 + # Find events in this week and determine how to mark them on the
1.2025 + # calendar.
1.2026 +
1.2027 + week_start = month.as_date(max(first_day, 1))
1.2028 + week_end = month.as_date(min(first_day + 6, number_of_days))
1.2029 +
1.2030 + full_coverage, week_slots = getCoverage(
1.2031 + getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end)))
1.2032 +
1.2033 + # Output a week, starting with the day numbers.
1.2034 +
1.2035 + append(self.writeDayNumbers(first_day, number_of_days, month, full_coverage))
1.2036 +
1.2037 + # Either generate empty days...
1.2038 +
1.2039 + if not week_slots:
1.2040 + append(self.writeEmptyWeek(first_day, number_of_days, month))
1.2041 +
1.2042 + # Or generate each set of scheduled events...
1.2043 +
1.2044 + else:
1.2045 + append(self.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots))
1.2046 +
1.2047 + # Process the next week...
1.2048 +
1.2049 + first_day += 7
1.2050 +
1.2051 + # End of month.
1.2052 +
1.2053 + append(fmt.table(on=0))
1.2054 +
1.2055 + # Output a day view.
1.2056 +
1.2057 + elif self.mode == "day":
1.2058 +
1.2059 + # Visit all days in the requested range, or across known events.
1.2060 +
1.2061 + for date in self.first.days_until(self.last):
1.2062 +
1.2063 + append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"}))
1.2064 +
1.2065 + full_coverage, day_slots = getCoverage(
1.2066 + getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime")
1.2067 +
1.2068 + # Work out how many columns the day title will need.
1.2069 + # Include spacers after the scale and each event column.
1.2070 +
1.2071 + colspan = sum(map(len, day_slots.values())) * 2 + 2
1.2072 +
1.2073 + append(self.writeDayTableHeading(date, colspan))
1.2074 +
1.2075 + # Either generate empty days...
1.2076 +
1.2077 + if not day_slots:
1.2078 + append(self.writeEmptyDay(date))
1.2079 +
1.2080 + # Or generate each set of scheduled events...
1.2081 +
1.2082 + else:
1.2083 + append(self.writeDaySlots(date, full_coverage, day_slots))
1.2084 +
1.2085 + # End of day.
1.2086 +
1.2087 + append(fmt.table(on=0))
1.2088 +
1.2089 + # Output view controls.
1.2090 +
1.2091 + append(fmt.div(on=1, css_class="event-controls"))
1.2092 + append(self.writeViewControls())
1.2093 + append(fmt.div(on=0))
1.2094 +
1.2095 + # Close the calendar region.
1.2096 +
1.2097 + append(fmt.div(on=0))
1.2098 +
1.2099 + # Add any scripts.
1.2100 +
1.2101 + if isinstance(fmt, request.html_formatter.__class__):
1.2102 + append(self.update_script)
1.2103 +
1.2104 + return ''.join(output)
1.2105 +
1.2106 + update_script = """\
1.2107 +<script type="text/javascript">
1.2108 +function replaceCalendar(name, url) {
1.2109 + var calendar = document.getElementById(name);
1.2110 +
1.2111 + if (calendar == null) {
1.2112 + return true;
1.2113 + }
1.2114 +
1.2115 + var xmlhttp = new XMLHttpRequest();
1.2116 + xmlhttp.open("GET", url, false);
1.2117 + xmlhttp.send(null);
1.2118 +
1.2119 + var newCalendar = xmlhttp.responseText;
1.2120 +
1.2121 + if (newCalendar != null) {
1.2122 + calendar.innerHTML = newCalendar;
1.2123 + return false;
1.2124 + }
1.2125 +
1.2126 + return true;
1.2127 +}
1.2128 +</script>
1.2129 +"""
1.2130 +
1.2131 +# vim: tabstop=4 expandtab shiftwidth=4