6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/EventAggregatorSupport/Types.py Tue Apr 30 23:49:32 2013 +0200
6.3 @@ -0,0 +1,720 @@
6.4 +# -*- coding: iso-8859-1 -*-
6.5 +"""
6.6 + MoinMoin - EventAggregator object types
6.7 +
6.8 + @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
6.9 + @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
6.10 + 2005-2008 MoinMoin:ThomasWaldmann.
6.11 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
6.12 +"""
6.13 +
6.14 +from GeneralSupport import to_list
6.15 +from LocationSupport import getMapReference
6.16 +from MoinSupport import *
6.17 +
6.18 +import re
6.19 +
6.20 +try:
6.21 + set
6.22 +except NameError:
6.23 + from sets import Set as set
6.24 +
6.25 +# Page parsing.
6.26 +
6.27 +definition_list_regexp = re.compile(ur'(?P<wholeterm>^(?P<optcomment>#*)\s+(?P<term>.*?):: )(?P<desc>.*?)$', re.UNICODE | re.MULTILINE)
6.28 +category_membership_regexp = re.compile(ur"^\s*(?:(Category\S+)(?:\s+(Category\S+))*)\s*$", re.MULTILINE | re.UNICODE)
6.29 +
6.30 +# Event parsing from page texts.
6.31 +
6.32 +def parseEvents(text, event_page, fragment=None):
6.33 +
6.34 + """
6.35 + Parse events in the given 'text', returning a list of event objects for the
6.36 + given 'event_page'. An optional 'fragment' can be specified to indicate a
6.37 + specific region of the event page.
6.38 +
6.39 + If the optional 'fragment' identifier is provided, the first heading may
6.40 + also be used to provide an event summary/title.
6.41 + """
6.42 +
6.43 + template_details = {}
6.44 + if fragment:
6.45 + template_details["fragment"] = fragment
6.46 +
6.47 + details = {}
6.48 + details.update(template_details)
6.49 + raw_details = {}
6.50 +
6.51 + # Obtain a heading, if requested.
6.52 +
6.53 + if fragment:
6.54 + for level, title, (start, end) in getHeadings(text):
6.55 + raw_details["title"] = text[start:end]
6.56 + details["title"] = getSimpleWikiText(title.strip())
6.57 + break
6.58 +
6.59 + # Start populating events.
6.60 +
6.61 + events = [Event(event_page, details, raw_details)]
6.62 +
6.63 + for match in definition_list_regexp.finditer(text):
6.64 +
6.65 + # Skip commented-out items.
6.66 +
6.67 + if match.group("optcomment"):
6.68 + continue
6.69 +
6.70 + # Permit case-insensitive list terms.
6.71 +
6.72 + term = match.group("term").lower()
6.73 + raw_desc = match.group("desc")
6.74 +
6.75 + # Special value type handling.
6.76 +
6.77 + # Dates.
6.78 +
6.79 + if term in Event.date_terms:
6.80 + desc = getDateTime(raw_desc)
6.81 +
6.82 + # Lists (whose elements may be quoted).
6.83 +
6.84 + elif term in Event.list_terms:
6.85 + desc = map(getSimpleWikiText, to_list(raw_desc, ","))
6.86 +
6.87 + # Position details.
6.88 +
6.89 + elif term == "geo":
6.90 + try:
6.91 + desc = map(getMapReference, to_list(raw_desc, None))
6.92 + if len(desc) != 2:
6.93 + continue
6.94 + except (KeyError, ValueError):
6.95 + continue
6.96 +
6.97 + # Labels which may well be quoted.
6.98 +
6.99 + elif term in Event.title_terms:
6.100 + desc = getSimpleWikiText(raw_desc.strip())
6.101 +
6.102 + # Plain Wiki text terms.
6.103 +
6.104 + elif term in Event.other_terms:
6.105 + desc = raw_desc.strip()
6.106 +
6.107 + else:
6.108 + desc = raw_desc
6.109 +
6.110 + if desc is not None:
6.111 +
6.112 + # Handle apparent duplicates by creating a new set of
6.113 + # details.
6.114 +
6.115 + if details.has_key(term):
6.116 +
6.117 + # Make a new event.
6.118 +
6.119 + details = {}
6.120 + details.update(template_details)
6.121 + raw_details = {}
6.122 + events.append(Event(event_page, details, raw_details))
6.123 +
6.124 + details[term] = desc
6.125 + raw_details[term] = raw_desc
6.126 +
6.127 + return events
6.128 +
6.129 +# Event resources providing collections of events.
6.130 +
6.131 +class EventResource:
6.132 +
6.133 + "A resource providing event information."
6.134 +
6.135 + def __init__(self, url):
6.136 + self.url = url
6.137 +
6.138 + def getPageURL(self):
6.139 +
6.140 + "Return the URL of this page."
6.141 +
6.142 + return self.url
6.143 +
6.144 + def getFormat(self):
6.145 +
6.146 + "Get the format used by this resource."
6.147 +
6.148 + return "plain"
6.149 +
6.150 + def getMetadata(self):
6.151 +
6.152 + """
6.153 + Return a dictionary containing items describing the page's "created"
6.154 + time, "last-modified" time, "sequence" (or revision number) and the
6.155 + "last-comment" made about the last edit.
6.156 + """
6.157 +
6.158 + return {}
6.159 +
6.160 + def getEvents(self):
6.161 +
6.162 + "Return a list of events from this resource."
6.163 +
6.164 + return []
6.165 +
6.166 + def linkToPage(self, request, text, query_string=None, anchor=None):
6.167 +
6.168 + """
6.169 + Using 'request', return a link to this page with the given link 'text'
6.170 + and optional 'query_string' and 'anchor'.
6.171 + """
6.172 +
6.173 + return linkToResource(self.url, request, text, query_string, anchor)
6.174 +
6.175 + # Formatting-related functions.
6.176 +
6.177 + def formatText(self, text, fmt):
6.178 +
6.179 + """
6.180 + Format the given 'text' using the specified formatter 'fmt'.
6.181 + """
6.182 +
6.183 + # Assume plain text which is then formatted appropriately.
6.184 +
6.185 + return fmt.text(text)
6.186 +
6.187 +class EventCalendar(EventResource):
6.188 +
6.189 + "An iCalendar resource."
6.190 +
6.191 + def __init__(self, url, calendar):
6.192 + EventResource.__init__(self, url)
6.193 + self.calendar = calendar
6.194 + self.events = None
6.195 +
6.196 + def getEvents(self):
6.197 +
6.198 + "Return a list of events from this resource."
6.199 +
6.200 + if self.events is None:
6.201 + self.events = []
6.202 +
6.203 + _calendar, _empty, calendar = self.calendar
6.204 +
6.205 + for objtype, attrs, obj in calendar:
6.206 +
6.207 + # Read events.
6.208 +
6.209 + if objtype == "VEVENT":
6.210 + details = {}
6.211 +
6.212 + for property, attrs, value in obj:
6.213 +
6.214 + # Convert dates.
6.215 +
6.216 + if property in ("DTSTART", "DTEND", "CREATED", "DTSTAMP", "LAST-MODIFIED"):
6.217 + if property in ("DTSTART", "DTEND"):
6.218 + property = property[2:]
6.219 + if attrs.get("VALUE") == "DATE":
6.220 + value = getDateFromCalendar(value)
6.221 + if value and property == "END":
6.222 + value = value.previous_day()
6.223 + else:
6.224 + value = getDateTimeFromCalendar(value)
6.225 +
6.226 + # Convert numeric data.
6.227 +
6.228 + elif property == "SEQUENCE":
6.229 + value = int(value)
6.230 +
6.231 + # Convert lists.
6.232 +
6.233 + elif property == "CATEGORIES":
6.234 + value = to_list(value, ",")
6.235 +
6.236 + # Convert positions (using decimal values).
6.237 +
6.238 + elif property == "GEO":
6.239 + try:
6.240 + value = map(getMapReferenceFromDecimal, to_list(value, ";"))
6.241 + if len(value) != 2:
6.242 + continue
6.243 + except (KeyError, ValueError):
6.244 + continue
6.245 +
6.246 + # Accept other textual data as it is.
6.247 +
6.248 + elif property in ("LOCATION", "SUMMARY", "URL"):
6.249 + value = value or None
6.250 +
6.251 + # Ignore other properties.
6.252 +
6.253 + else:
6.254 + continue
6.255 +
6.256 + property = property.lower()
6.257 + details[property] = value
6.258 +
6.259 + self.events.append(CalendarEvent(self, details))
6.260 +
6.261 + return self.events
6.262 +
6.263 +class EventPage:
6.264 +
6.265 + "An event page acting as an event resource."
6.266 +
6.267 + def __init__(self, page):
6.268 + self.page = page
6.269 + self.events = None
6.270 + self.body = None
6.271 + self.categories = None
6.272 + self.metadata = None
6.273 +
6.274 + def copyPage(self, page):
6.275 +
6.276 + "Copy the body of the given 'page'."
6.277 +
6.278 + self.body = page.getBody()
6.279 +
6.280 + def getPageURL(self):
6.281 +
6.282 + "Return the URL of this page."
6.283 +
6.284 + return getPageURL(self.page)
6.285 +
6.286 + def getFormat(self):
6.287 +
6.288 + "Get the format used on this page."
6.289 +
6.290 + return getFormat(self.page)
6.291 +
6.292 + def getMetadata(self):
6.293 +
6.294 + """
6.295 + Return a dictionary containing items describing the page's "created"
6.296 + time, "last-modified" time, "sequence" (or revision number) and the
6.297 + "last-comment" made about the last edit.
6.298 + """
6.299 +
6.300 + if self.metadata is None:
6.301 + self.metadata = getMetadata(self.page)
6.302 + return self.metadata
6.303 +
6.304 + def getRevisions(self):
6.305 +
6.306 + "Return a list of page revisions."
6.307 +
6.308 + return self.page.getRevList()
6.309 +
6.310 + def getPageRevision(self):
6.311 +
6.312 + "Return the revision details dictionary for this page."
6.313 +
6.314 + return getPageRevision(self.page)
6.315 +
6.316 + def getPageName(self):
6.317 +
6.318 + "Return the page name."
6.319 +
6.320 + return self.page.page_name
6.321 +
6.322 + def getPrettyPageName(self):
6.323 +
6.324 + "Return a nicely formatted title/name for this page."
6.325 +
6.326 + return getPrettyPageName(self.page)
6.327 +
6.328 + def getBody(self):
6.329 +
6.330 + "Get the current page body."
6.331 +
6.332 + if self.body is None:
6.333 + self.body = self.page.get_raw_body()
6.334 + return self.body
6.335 +
6.336 + def getEvents(self):
6.337 +
6.338 + "Return a list of events from this page."
6.339 +
6.340 + if self.events is None:
6.341 + self.events = []
6.342 + if self.getFormat() == "wiki":
6.343 + for format, attributes, region in getFragments(self.getBody(), True):
6.344 + self.events += parseEvents(region, self, attributes.get("fragment"))
6.345 +
6.346 + return self.events
6.347 +
6.348 + def setEvents(self, events):
6.349 +
6.350 + "Set the given 'events' on this page."
6.351 +
6.352 + self.events = events
6.353 +
6.354 + def getCategoryMembership(self):
6.355 +
6.356 + "Get the category names from this page."
6.357 +
6.358 + if self.categories is None:
6.359 + body = self.getBody()
6.360 + match = category_membership_regexp.search(body)
6.361 + self.categories = match and [x for x in match.groups() if x] or []
6.362 +
6.363 + return self.categories
6.364 +
6.365 + def setCategoryMembership(self, category_names):
6.366 +
6.367 + """
6.368 + Set the category membership for the page using the specified
6.369 + 'category_names'.
6.370 + """
6.371 +
6.372 + self.categories = category_names
6.373 +
6.374 + def flushEventDetails(self):
6.375 +
6.376 + "Flush the current event details to this page's body text."
6.377 +
6.378 + new_body_parts = []
6.379 + end_of_last_match = 0
6.380 + body = self.getBody()
6.381 +
6.382 + events = iter(self.getEvents())
6.383 +
6.384 + event = events.next()
6.385 + event_details = event.getDetails()
6.386 + replaced_terms = set()
6.387 +
6.388 + for match in definition_list_regexp.finditer(body):
6.389 +
6.390 + # Permit case-insensitive list terms.
6.391 +
6.392 + term = match.group("term").lower()
6.393 + desc = match.group("desc")
6.394 +
6.395 + # Check that the term has not already been substituted. If so,
6.396 + # get the next event.
6.397 +
6.398 + if term in replaced_terms:
6.399 + try:
6.400 + event = events.next()
6.401 +
6.402 + # No more events.
6.403 +
6.404 + except StopIteration:
6.405 + break
6.406 +
6.407 + event_details = event.getDetails()
6.408 + replaced_terms = set()
6.409 +
6.410 + # Add preceding text to the new body.
6.411 +
6.412 + new_body_parts.append(body[end_of_last_match:match.start()])
6.413 +
6.414 + # Get the matching regions, adding the term to the new body.
6.415 +
6.416 + new_body_parts.append(match.group("wholeterm"))
6.417 +
6.418 + # Special value type handling.
6.419 +
6.420 + if event_details.has_key(term):
6.421 +
6.422 + # Dates.
6.423 +
6.424 + if term in event.date_terms:
6.425 + desc = desc.replace("YYYY-MM-DD", str(event_details[term]))
6.426 +
6.427 + # Lists (whose elements may be quoted).
6.428 +
6.429 + elif term in event.list_terms:
6.430 + desc = ", ".join([getEncodedWikiText(item) for item in event_details[term]])
6.431 +
6.432 + # Labels which must be quoted.
6.433 +
6.434 + elif term in event.title_terms:
6.435 + desc = getEncodedWikiText(event_details[term])
6.436 +
6.437 + # Position details.
6.438 +
6.439 + elif term == "geo":
6.440 + desc = " ".join(map(str, event_details[term]))
6.441 +
6.442 + # Text which need not be quoted, but it will be Wiki text.
6.443 +
6.444 + elif term in event.other_terms:
6.445 + desc = event_details[term]
6.446 +
6.447 + replaced_terms.add(term)
6.448 +
6.449 + # Add the replaced value.
6.450 +
6.451 + new_body_parts.append(desc)
6.452 +
6.453 + # Remember where in the page has been processed.
6.454 +
6.455 + end_of_last_match = match.end()
6.456 +
6.457 + # Write the rest of the page.
6.458 +
6.459 + new_body_parts.append(body[end_of_last_match:])
6.460 +
6.461 + self.body = "".join(new_body_parts)
6.462 +
6.463 + def flushCategoryMembership(self):
6.464 +
6.465 + "Flush the category membership to the page body."
6.466 +
6.467 + body = self.getBody()
6.468 + category_names = self.getCategoryMembership()
6.469 + match = category_membership_regexp.search(body)
6.470 +
6.471 + if match:
6.472 + self.body = "".join([body[:match.start()], " ".join(category_names), body[match.end():]])
6.473 +
6.474 + def saveChanges(self):
6.475 +
6.476 + "Save changes to the event."
6.477 +
6.478 + self.flushEventDetails()
6.479 + self.flushCategoryMembership()
6.480 + self.page.saveText(self.getBody(), 0)
6.481 +
6.482 + def linkToPage(self, request, text, query_string=None, anchor=None):
6.483 +
6.484 + """
6.485 + Using 'request', return a link to this page with the given link 'text'
6.486 + and optional 'query_string' and 'anchor'.
6.487 + """
6.488 +
6.489 + return linkToPage(request, self.page, text, query_string, anchor)
6.490 +
6.491 + # Formatting-related functions.
6.492 +
6.493 + def getParserClass(self, format):
6.494 +
6.495 + """
6.496 + Return a parser class for the given 'format', returning a plain text
6.497 + parser if no parser can be found for the specified 'format'.
6.498 + """
6.499 +
6.500 + return getParserClass(self.page.request, format)
6.501 +
6.502 + def formatText(self, text, fmt):
6.503 +
6.504 + """
6.505 + Format the given 'text' using the specified formatter 'fmt'.
6.506 + """
6.507 +
6.508 + fmt.page = page = self.page
6.509 + request = page.request
6.510 +
6.511 + parser_cls = self.getParserClass(self.getFormat())
6.512 + return formatText(text, request, fmt, parser_cls)
6.513 +
6.514 +# Event details.
6.515 +
6.516 +class Event(ActsAsTimespan):
6.517 +
6.518 + "A description of an event."
6.519 +
6.520 + title_terms = "title", "summary"
6.521 + date_terms = "start", "end"
6.522 + list_terms = "topics", "categories"
6.523 + other_terms = "description", "location", "link"
6.524 + geo_terms = "geo",
6.525 + all_terms = title_terms + date_terms + list_terms + other_terms + geo_terms
6.526 +
6.527 + def __init__(self, page, details, raw_details=None):
6.528 + self.page = page
6.529 + self.details = details
6.530 + self.raw_details = raw_details
6.531 +
6.532 + # Permit omission of the end of the event by duplicating the start.
6.533 +
6.534 + if self.details.has_key("start") and not self.details.get("end"):
6.535 + end = self.details["start"]
6.536 +
6.537 + # Make any end time refer to the day instead.
6.538 +
6.539 + if isinstance(end, DateTime):
6.540 + end = end.as_date()
6.541 +
6.542 + self.details["end"] = end
6.543 +
6.544 + def __repr__(self):
6.545 + return "<Event %r %r>" % (self.getSummary(), self.as_limits())
6.546 +
6.547 + def __hash__(self):
6.548 +
6.549 + """
6.550 + Return a dictionary hash, avoiding mistaken equality of events in some
6.551 + situations (notably membership tests) by including the URL as well as
6.552 + the summary.
6.553 + """
6.554 +
6.555 + return hash(self.getSummary() + self.getEventURL())
6.556 +
6.557 + def getPage(self):
6.558 +
6.559 + "Return the page describing this event."
6.560 +
6.561 + return self.page
6.562 +
6.563 + def setPage(self, page):
6.564 +
6.565 + "Set the 'page' describing this event."
6.566 +
6.567 + self.page = page
6.568 +
6.569 + def getEventURL(self):
6.570 +
6.571 + "Return the URL of this event."
6.572 +
6.573 + fragment = self.details.get("fragment")
6.574 + return self.page.getPageURL() + (fragment and "#" + fragment or "")
6.575 +
6.576 + def linkToEvent(self, request, text, query_string=None):
6.577 +
6.578 + """
6.579 + Using 'request', return a link to this event with the given link 'text'
6.580 + and optional 'query_string'.
6.581 + """
6.582 +
6.583 + return self.page.linkToPage(request, text, query_string, self.details.get("fragment"))
6.584 +
6.585 + def getMetadata(self):
6.586 +
6.587 + """
6.588 + Return a dictionary containing items describing the event's "created"
6.589 + time, "last-modified" time, "sequence" (or revision number) and the
6.590 + "last-comment" made about the last edit.
6.591 + """
6.592 +
6.593 + # Delegate this to the page.
6.594 +
6.595 + return self.page.getMetadata()
6.596 +
6.597 + def getSummary(self, event_parent=None):
6.598 +
6.599 + """
6.600 + Return either the given title or summary of the event according to the
6.601 + event details, or a summary made from using the pretty version of the
6.602 + page name.
6.603 +
6.604 + If the optional 'event_parent' is specified, any page beneath the given
6.605 + 'event_parent' page in the page hierarchy will omit this parent information
6.606 + if its name is used as the summary.
6.607 + """
6.608 +
6.609 + event_details = self.details
6.610 +
6.611 + if event_details.has_key("title"):
6.612 + return event_details["title"]
6.613 + elif event_details.has_key("summary"):
6.614 + return event_details["summary"]
6.615 + else:
6.616 + # If appropriate, remove the parent details and "/" character.
6.617 +
6.618 + title = self.page.getPageName()
6.619 +
6.620 + if event_parent and title.startswith(event_parent):
6.621 + title = title[len(event_parent.rstrip("/")) + 1:]
6.622 +
6.623 + return getPrettyTitle(title)
6.624 +
6.625 + def getDetails(self):
6.626 +
6.627 + "Return the details for this event."
6.628 +
6.629 + return self.details
6.630 +
6.631 + def setDetails(self, event_details):
6.632 +
6.633 + "Set the 'event_details' for this event."
6.634 +
6.635 + self.details = event_details
6.636 +
6.637 + def getRawDetails(self):
6.638 +
6.639 + "Return the details for this event as they were written in a page."
6.640 +
6.641 + return self.raw_details
6.642 +
6.643 + # Timespan-related methods.
6.644 +
6.645 + def __contains__(self, other):
6.646 + return self == other
6.647 +
6.648 + def __eq__(self, other):
6.649 + if isinstance(other, Event):
6.650 + return self.getSummary() == other.getSummary() and self.getEventURL() == other.getEventURL() and self._cmp(other)
6.651 + else:
6.652 + return self._cmp(other) == 0
6.653 +
6.654 + def __ne__(self, other):
6.655 + return not self.__eq__(other)
6.656 +
6.657 + def __lt__(self, other):
6.658 + return self._cmp(other) == -1
6.659 +
6.660 + def __le__(self, other):
6.661 + return self._cmp(other) in (-1, 0)
6.662 +
6.663 + def __gt__(self, other):
6.664 + return self._cmp(other) == 1
6.665 +
6.666 + def __ge__(self, other):
6.667 + return self._cmp(other) in (0, 1)
6.668 +
6.669 + def _cmp(self, other):
6.670 +
6.671 + "Compare this event to an 'other' event purely by their timespans."
6.672 +
6.673 + if isinstance(other, Event):
6.674 + return cmp(self.as_timespan(), other.as_timespan())
6.675 + else:
6.676 + return cmp(self.as_timespan(), other)
6.677 +
6.678 + def as_timespan(self):
6.679 + details = self.details
6.680 + if details.has_key("start") and details.has_key("end"):
6.681 + return Timespan(details["start"], details["end"])
6.682 + else:
6.683 + return None
6.684 +
6.685 + def as_limits(self):
6.686 + ts = self.as_timespan()
6.687 + return ts and ts.as_limits()
6.688 +
6.689 +class CalendarEvent(Event):
6.690 +
6.691 + "An event from a remote calendar."
6.692 +
6.693 + def getEventURL(self):
6.694 +
6.695 + "Return the URL of this event."
6.696 +
6.697 + return self.details.get("url") or self.page.getPageURL()
6.698 +
6.699 + def linkToEvent(self, request, text, query_string=None, anchor=None):
6.700 +
6.701 + """
6.702 + Using 'request', return a link to this event with the given link 'text'
6.703 + and optional 'query_string' and 'anchor'.
6.704 + """
6.705 +
6.706 + return linkToResource(self.getEventURL(), request, text, query_string, anchor)
6.707 +
6.708 + def getMetadata(self):
6.709 +
6.710 + """
6.711 + Return a dictionary containing items describing the event's "created"
6.712 + time, "last-modified" time, "sequence" (or revision number) and the
6.713 + "last-comment" made about the last edit.
6.714 + """
6.715 +
6.716 + return {
6.717 + "created" : self.details.get("created") or self.details["dtstamp"],
6.718 + "last-modified" : self.details.get("last-modified") or self.details["dtstamp"],
6.719 + "sequence" : self.details.get("sequence") or 0,
6.720 + "last-comment" : ""
6.721 + }
6.722 +
6.723 +# vim: tabstop=4 expandtab shiftwidth=4
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/EventAggregatorSupport/View.py Tue Apr 30 23:49:32 2013 +0200
7.3 @@ -0,0 +1,2128 @@
7.4 +# -*- coding: iso-8859-1 -*-
7.5 +"""
7.6 + MoinMoin - EventAggregator user interface library
7.7 +
7.8 + @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
7.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
7.10 +"""
7.11 +
7.12 +from EventAggregatorSupport.Filter import getCalendarPeriod, getEventsInPeriod, \
7.13 + getCoverage, getCoverageScale
7.14 +from EventAggregatorSupport.Locations import getMapsPage, getLocationsPage, Location
7.15 +
7.16 +from GeneralSupport import sort_none_first
7.17 +from LocationSupport import getMapReference, getNormalisedLocation, \
7.18 + getPositionForCentrePoint, getPositionForReference
7.19 +from MoinDateSupport import getFullDateLabel, getFullMonthLabel
7.20 +from MoinSupport import *
7.21 +from ViewSupport import getColour, getBlackOrWhite
7.22 +
7.23 +from MoinMoin.Page import Page
7.24 +from MoinMoin.action import AttachFile
7.25 +from MoinMoin import wikiutil
7.26 +
7.27 +try:
7.28 + set
7.29 +except NameError:
7.30 + from sets import Set as set
7.31 +
7.32 +# Utility functions.
7.33 +
7.34 +def to_plain_text(s, request):
7.35 +
7.36 + "Convert 's' to plain text."
7.37 +
7.38 + fmt = getFormatterClass(request, "plain")(request)
7.39 + fmt.setPage(request.page)
7.40 + return formatText(s, request, fmt)
7.41 +
7.42 +def getLocationPosition(location, locations):
7.43 +
7.44 + """
7.45 + Attempt to return the position of the given 'location' using the 'locations'
7.46 + dictionary provided. If no position can be found, return a latitude of None
7.47 + and a longitude of None.
7.48 + """
7.49 +
7.50 + latitude, longitude = None, None
7.51 +
7.52 + if location is not None:
7.53 + try:
7.54 + latitude, longitude = map(getMapReference, locations[location].split())
7.55 + except (KeyError, ValueError):
7.56 + pass
7.57 +
7.58 + return latitude, longitude
7.59 +
7.60 +# Event sorting.
7.61 +
7.62 +def sort_start_first(x, y):
7.63 + x_ts = x.as_limits()
7.64 + if x_ts is not None:
7.65 + x_start, x_end = x_ts
7.66 + y_ts = y.as_limits()
7.67 + if y_ts is not None:
7.68 + y_start, y_end = y_ts
7.69 + start_order = cmp(x_start, y_start)
7.70 + if start_order == 0:
7.71 + return cmp(x_end, y_end)
7.72 + else:
7.73 + return start_order
7.74 + return 0
7.75 +
7.76 +# User interface abstractions.
7.77 +
7.78 +class View:
7.79 +
7.80 + "A view of the event calendar."
7.81 +
7.82 + def __init__(self, page, calendar_name,
7.83 + raw_calendar_start, raw_calendar_end,
7.84 + original_calendar_start, original_calendar_end,
7.85 + calendar_start, calendar_end,
7.86 + wider_calendar_start, wider_calendar_end,
7.87 + first, last, category_names, remote_sources, search_pattern, template_name,
7.88 + parent_name, mode, resolution, name_usage, map_name):
7.89 +
7.90 + """
7.91 + Initialise the view with the current 'page', a 'calendar_name' (which
7.92 + may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which
7.93 + are the actual start and end values provided by the request), the
7.94 + calculated 'original_calendar_start' and 'original_calendar_end' (which
7.95 + are the result of calculating the calendar's limits from the raw start
7.96 + and end values), the requested, calculated 'calendar_start' and
7.97 + 'calendar_end' (which may involve different start and end values due to
7.98 + navigation in the user interface), and the requested
7.99 + 'wider_calendar_start' and 'wider_calendar_end' (which indicate a wider
7.100 + view used when navigating out of the day view), along with the 'first'
7.101 + and 'last' months of event coverage.
7.102 +
7.103 + The additional 'category_names', 'remote_sources', 'search_pattern',
7.104 + 'template_name', 'parent_name' and 'mode' parameters are used to
7.105 + configure the links employed by the view.
7.106 +
7.107 + The 'resolution' affects the view for certain modes and is also used to
7.108 + parameterise links.
7.109 +
7.110 + The 'name_usage' parameter controls how names are shown on calendar mode
7.111 + events, such as how often labels are repeated.
7.112 +
7.113 + The 'map_name' parameter provides the name of a map to be used in the
7.114 + map mode.
7.115 + """
7.116 +
7.117 + self.page = page
7.118 + self.calendar_name = calendar_name
7.119 + self.raw_calendar_start = raw_calendar_start
7.120 + self.raw_calendar_end = raw_calendar_end
7.121 + self.original_calendar_start = original_calendar_start
7.122 + self.original_calendar_end = original_calendar_end
7.123 + self.calendar_start = calendar_start
7.124 + self.calendar_end = calendar_end
7.125 + self.wider_calendar_start = wider_calendar_start
7.126 + self.wider_calendar_end = wider_calendar_end
7.127 + self.template_name = template_name
7.128 + self.parent_name = parent_name
7.129 + self.mode = mode
7.130 + self.resolution = resolution
7.131 + self.name_usage = name_usage
7.132 + self.map_name = map_name
7.133 +
7.134 + # Search-related parameters for links.
7.135 +
7.136 + self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names])
7.137 + self.remote_source_parameters = "&".join([("source=%s" % source) for source in remote_sources])
7.138 + self.search_pattern = search_pattern
7.139 +
7.140 + # Calculate the duration in terms of the highest common unit of time.
7.141 +
7.142 + self.first = first
7.143 + self.last = last
7.144 + self.duration = abs(last - first) + 1
7.145 +
7.146 + if self.calendar_name:
7.147 +
7.148 + # Store the view parameters.
7.149 +
7.150 + self.previous_start = first.previous()
7.151 + self.next_start = first.next()
7.152 + self.previous_end = last.previous()
7.153 + self.next_end = last.next()
7.154 +
7.155 + self.previous_set_start = first.update(-self.duration)
7.156 + self.next_set_start = first.update(self.duration)
7.157 + self.previous_set_end = last.update(-self.duration)
7.158 + self.next_set_end = last.update(self.duration)
7.159 +
7.160 + def getIdentifier(self):
7.161 +
7.162 + "Return a unique identifier to be used to refer to this view."
7.163 +
7.164 + # NOTE: Nasty hack to get a unique identifier if no name is given.
7.165 +
7.166 + return self.calendar_name or str(id(self))
7.167 +
7.168 + def getQualifiedParameterName(self, argname):
7.169 +
7.170 + "Return the 'argname' qualified using the calendar name."
7.171 +
7.172 + return getQualifiedParameterName(self.calendar_name, argname)
7.173 +
7.174 + def getDateQueryString(self, argname, date, prefix=1):
7.175 +
7.176 + """
7.177 + Return a query string fragment for the given 'argname', referring to the
7.178 + month given by the specified 'year_month' object, appropriate for this
7.179 + calendar.
7.180 +
7.181 + If 'prefix' is specified and set to a false value, the parameters in the
7.182 + query string will not be calendar-specific, but could be used with the
7.183 + summary action.
7.184 + """
7.185 +
7.186 + suffixes = ["year", "month", "day"]
7.187 +
7.188 + if date is not None:
7.189 + args = []
7.190 + for suffix, value in zip(suffixes, date.as_tuple()):
7.191 + suffixed_argname = "%s-%s" % (argname, suffix)
7.192 + if prefix:
7.193 + suffixed_argname = self.getQualifiedParameterName(suffixed_argname)
7.194 + args.append("%s=%s" % (suffixed_argname, value))
7.195 + return "&".join(args)
7.196 + else:
7.197 + return ""
7.198 +
7.199 + def getRawDateQueryString(self, argname, date, prefix=1):
7.200 +
7.201 + """
7.202 + Return a query string fragment for the given 'argname', referring to the
7.203 + date given by the specified 'date' value, appropriate for this
7.204 + calendar.
7.205 +
7.206 + If 'prefix' is specified and set to a false value, the parameters in the
7.207 + query string will not be calendar-specific, but could be used with the
7.208 + summary action.
7.209 + """
7.210 +
7.211 + if date is not None:
7.212 + if prefix:
7.213 + argname = self.getQualifiedParameterName(argname)
7.214 + return "%s=%s" % (argname, wikiutil.url_quote_plus(date))
7.215 + else:
7.216 + return ""
7.217 +
7.218 + def getNavigationLink(self, start, end, mode=None, resolution=None, wider_start=None, wider_end=None):
7.219 +
7.220 + """
7.221 + Return a query string fragment for navigation to a view showing months
7.222 + from 'start' to 'end' inclusive, with the optional 'mode' indicating the
7.223 + view style and the optional 'resolution' indicating the resolution of a
7.224 + view, if configurable.
7.225 +
7.226 + If the 'wider_start' and 'wider_end' arguments are given, parameters
7.227 + indicating a wider calendar view (when returning from a day view, for
7.228 + example) will be included in the link.
7.229 + """
7.230 +
7.231 + return "%s&%s&%s=%s&%s=%s&%s&%s" % (
7.232 + self.getRawDateQueryString("start", start),
7.233 + self.getRawDateQueryString("end", end),
7.234 + self.getQualifiedParameterName("mode"), mode or self.mode,
7.235 + self.getQualifiedParameterName("resolution"), resolution or self.resolution,
7.236 + self.getRawDateQueryString("wider-start", wider_start),
7.237 + self.getRawDateQueryString("wider-end", wider_end),
7.238 + )
7.239 +
7.240 + def getUpdateLink(self, start, end, mode=None, resolution=None, wider_start=None, wider_end=None):
7.241 +
7.242 + """
7.243 + Return a query string fragment for navigation to a view showing months
7.244 + from 'start' to 'end' inclusive, with the optional 'mode' indicating the
7.245 + view style and the optional 'resolution' indicating the resolution of a
7.246 + view, if configurable. This link differs from the conventional
7.247 + navigation link in that it is sufficient to activate the update action
7.248 + and produce an updated region of the page without needing to locate and
7.249 + process the page or any macro invocation.
7.250 +
7.251 + If the 'wider_start' and 'wider_end' arguments are given, parameters
7.252 + indicating a wider calendar view (when returning from a day view, for
7.253 + example) will be included in the link.
7.254 + """
7.255 +
7.256 + parameters = [
7.257 + self.getRawDateQueryString("start", start, 0),
7.258 + self.getRawDateQueryString("end", end, 0),
7.259 + self.category_name_parameters,
7.260 + self.remote_source_parameters,
7.261 + self.getRawDateQueryString("wider-start", wider_start, 0),
7.262 + self.getRawDateQueryString("wider-end", wider_end, 0),
7.263 + ]
7.264 +
7.265 + pairs = [
7.266 + ("calendar", self.calendar_name or ""),
7.267 + ("calendarstart", self.raw_calendar_start or ""),
7.268 + ("calendarend", self.raw_calendar_end or ""),
7.269 + ("mode", mode or self.mode),
7.270 + ("resolution", resolution or self.resolution),
7.271 + ("parent", self.parent_name or ""),
7.272 + ("template", self.template_name or ""),
7.273 + ("names", self.name_usage),
7.274 + ("map", self.map_name or ""),
7.275 + ("search", self.search_pattern or ""),
7.276 + ]
7.277 +
7.278 + url = self.page.url(self.page.request,
7.279 + "action=EventAggregatorUpdate&%s" % (
7.280 + "&".join([("%s=%s" % pair) for pair in pairs] + parameters)
7.281 + ), relative=True)
7.282 +
7.283 + return "return replaceCalendar('EventAggregator-%s', '%s')" % (self.getIdentifier(), url)
7.284 +
7.285 + def getNewEventLink(self, start):
7.286 +
7.287 + """
7.288 + Return a query string activating the new event form, incorporating the
7.289 + calendar parameters, specialising the form for the given 'start' date or
7.290 + month.
7.291 + """
7.292 +
7.293 + if start is not None:
7.294 + details = start.as_tuple()
7.295 + pairs = zip(["start-year=%d", "start-month=%d", "start-day=%d"], details)
7.296 + args = [(param % value) for (param, value) in pairs]
7.297 + args = "&".join(args)
7.298 + else:
7.299 + args = ""
7.300 +
7.301 + # Prepare navigation details for the calendar shown with the new event
7.302 + # form.
7.303 +
7.304 + navigation_link = self.getNavigationLink(
7.305 + self.calendar_start, self.calendar_end
7.306 + )
7.307 +
7.308 + return "action=EventAggregatorNewEvent%s%s&template=%s&parent=%s&%s" % (
7.309 + args and "&%s" % args,
7.310 + self.category_name_parameters and "&%s" % self.category_name_parameters,
7.311 + self.template_name, self.parent_name or "",
7.312 + navigation_link)
7.313 +
7.314 + def getFullDateLabel(self, date):
7.315 + return getFullDateLabel(self.page.request, date)
7.316 +
7.317 + def getFullMonthLabel(self, year_month):
7.318 + return getFullMonthLabel(self.page.request, year_month)
7.319 +
7.320 + def getFullLabel(self, arg):
7.321 + return self.resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg)
7.322 +
7.323 + def _getCalendarPeriod(self, start_label, end_label, default_label):
7.324 +
7.325 + """
7.326 + Return a label describing a calendar period in terms of the given
7.327 + 'start_label' and 'end_label', with the 'default_label' being used where
7.328 + the supplied start and end labels fail to produce a meaningful label.
7.329 + """
7.330 +
7.331 + output = []
7.332 + append = output.append
7.333 +
7.334 + if start_label:
7.335 + append(start_label)
7.336 + if end_label and start_label != end_label:
7.337 + if output:
7.338 + append(" - ")
7.339 + append(end_label)
7.340 + return "".join(output) or default_label
7.341 +
7.342 + def getCalendarPeriod(self):
7.343 + _ = self.page.request.getText
7.344 + return self._getCalendarPeriod(
7.345 + self.calendar_start and self.getFullLabel(self.calendar_start),
7.346 + self.calendar_end and self.getFullLabel(self.calendar_end),
7.347 + _("All events")
7.348 + )
7.349 +
7.350 + def getOriginalCalendarPeriod(self):
7.351 + _ = self.page.request.getText
7.352 + return self._getCalendarPeriod(
7.353 + self.original_calendar_start and self.getFullLabel(self.original_calendar_start),
7.354 + self.original_calendar_end and self.getFullLabel(self.original_calendar_end),
7.355 + _("All events")
7.356 + )
7.357 +
7.358 + def getRawCalendarPeriod(self):
7.359 + _ = self.page.request.getText
7.360 + return self._getCalendarPeriod(
7.361 + self.raw_calendar_start,
7.362 + self.raw_calendar_end,
7.363 + _("No period specified")
7.364 + )
7.365 +
7.366 + def writeDownloadControls(self):
7.367 +
7.368 + """
7.369 + Return a representation of the download controls, featuring links for
7.370 + view, calendar and customised downloads and subscriptions.
7.371 + """
7.372 +
7.373 + page = self.page
7.374 + request = page.request
7.375 + fmt = request.formatter
7.376 + _ = request.getText
7.377 +
7.378 + output = []
7.379 + append = output.append
7.380 +
7.381 + # The full URL is needed for webcal links.
7.382 +
7.383 + full_url = "%s%s" % (request.getBaseURL(), getPathInfo(request))
7.384 +
7.385 + # Generate the links.
7.386 +
7.387 + download_dialogue_link = "action=EventAggregatorSummary&parent=%s&resolution=%s&search=%s%s%s" % (
7.388 + self.parent_name or "",
7.389 + self.resolution,
7.390 + self.search_pattern or "",
7.391 + self.category_name_parameters and "&%s" % self.category_name_parameters,
7.392 + self.remote_source_parameters and "&%s" % self.remote_source_parameters
7.393 + )
7.394 + download_all_link = download_dialogue_link + "&doit=1"
7.395 + download_link = download_all_link + ("&%s&%s" % (
7.396 + self.getDateQueryString("start", self.calendar_start, prefix=0),
7.397 + self.getDateQueryString("end", self.calendar_end, prefix=0)
7.398 + ))
7.399 +
7.400 + # Subscription links just explicitly select the RSS format.
7.401 +
7.402 + subscribe_dialogue_link = download_dialogue_link + "&format=RSS"
7.403 + subscribe_all_link = download_all_link + "&format=RSS"
7.404 + subscribe_link = download_link + "&format=RSS"
7.405 +
7.406 + # Adjust the "download all" and "subscribe all" links if the calendar
7.407 + # has an inherent period associated with it.
7.408 +
7.409 + period_limits = []
7.410 +
7.411 + if self.raw_calendar_start:
7.412 + period_limits.append("&%s" %
7.413 + self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0)
7.414 + )
7.415 + if self.raw_calendar_end:
7.416 + period_limits.append("&%s" %
7.417 + self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0)
7.418 + )
7.419 +
7.420 + period_limits = "".join(period_limits)
7.421 +
7.422 + download_dialogue_link += period_limits
7.423 + download_all_link += period_limits
7.424 + subscribe_dialogue_link += period_limits
7.425 + subscribe_all_link += period_limits
7.426 +
7.427 + # Pop-up descriptions of the downloadable calendars.
7.428 +
7.429 + calendar_period = self.getCalendarPeriod()
7.430 + original_calendar_period = self.getOriginalCalendarPeriod()
7.431 + raw_calendar_period = self.getRawCalendarPeriod()
7.432 +
7.433 + # Write the controls.
7.434 +
7.435 + # Download controls.
7.436 +
7.437 + append(fmt.div(on=1, css_class="event-download-controls"))
7.438 +
7.439 + append(fmt.span(on=1, css_class="event-download"))
7.440 + append(fmt.text(_("Download...")))
7.441 + append(fmt.div(on=1, css_class="event-download-popup"))
7.442 +
7.443 + append(fmt.div(on=1, css_class="event-download-item"))
7.444 + append(fmt.span(on=1, css_class="event-download-types"))
7.445 + append(fmt.span(on=1, css_class="event-download-webcal"))
7.446 + append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_link))
7.447 + append(fmt.span(on=0))
7.448 + append(fmt.span(on=1, css_class="event-download-http"))
7.449 + append(linkToPage(request, page, _("http"), download_link))
7.450 + append(fmt.span(on=0))
7.451 + append(fmt.span(on=0)) # end types
7.452 + append(fmt.span(on=1, css_class="event-download-label"))
7.453 + append(fmt.text(_("Download this view")))
7.454 + append(fmt.span(on=0)) # end label
7.455 + append(fmt.span(on=1, css_class="event-download-period"))
7.456 + append(fmt.text(calendar_period))
7.457 + append(fmt.span(on=0))
7.458 + append(fmt.div(on=0))
7.459 +
7.460 + append(fmt.div(on=1, css_class="event-download-item"))
7.461 + append(fmt.span(on=1, css_class="event-download-types"))
7.462 + append(fmt.span(on=1, css_class="event-download-webcal"))
7.463 + append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_all_link))
7.464 + append(fmt.span(on=0))
7.465 + append(fmt.span(on=1, css_class="event-download-http"))
7.466 + append(linkToPage(request, page, _("http"), download_all_link))
7.467 + append(fmt.span(on=0))
7.468 + append(fmt.span(on=0)) # end types
7.469 + append(fmt.span(on=1, css_class="event-download-label"))
7.470 + append(fmt.text(_("Download this calendar")))
7.471 + append(fmt.span(on=0)) # end label
7.472 + append(fmt.span(on=1, css_class="event-download-period"))
7.473 + append(fmt.text(original_calendar_period))
7.474 + append(fmt.span(on=0))
7.475 + append(fmt.span(on=1, css_class="event-download-period-raw"))
7.476 + append(fmt.text(raw_calendar_period))
7.477 + append(fmt.span(on=0))
7.478 + append(fmt.div(on=0))
7.479 +
7.480 + append(fmt.div(on=1, css_class="event-download-item"))
7.481 + append(fmt.span(on=1, css_class="event-download-link"))
7.482 + append(linkToPage(request, page, _("Edit download options..."), download_dialogue_link))
7.483 + append(fmt.span(on=0)) # end label
7.484 + append(fmt.div(on=0))
7.485 +
7.486 + append(fmt.div(on=0)) # end of pop-up
7.487 + append(fmt.span(on=0)) # end of download
7.488 +
7.489 + # Subscription controls.
7.490 +
7.491 + append(fmt.span(on=1, css_class="event-download"))
7.492 + append(fmt.text(_("Subscribe...")))
7.493 + append(fmt.div(on=1, css_class="event-download-popup"))
7.494 +
7.495 + append(fmt.div(on=1, css_class="event-download-item"))
7.496 + append(fmt.span(on=1, css_class="event-download-label"))
7.497 + append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link))
7.498 + append(fmt.span(on=0)) # end label
7.499 + append(fmt.span(on=1, css_class="event-download-period"))
7.500 + append(fmt.text(calendar_period))
7.501 + append(fmt.span(on=0))
7.502 + append(fmt.div(on=0))
7.503 +
7.504 + append(fmt.div(on=1, css_class="event-download-item"))
7.505 + append(fmt.span(on=1, css_class="event-download-label"))
7.506 + append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link))
7.507 + append(fmt.span(on=0)) # end label
7.508 + append(fmt.span(on=1, css_class="event-download-period"))
7.509 + append(fmt.text(original_calendar_period))
7.510 + append(fmt.span(on=0))
7.511 + append(fmt.span(on=1, css_class="event-download-period-raw"))
7.512 + append(fmt.text(raw_calendar_period))
7.513 + append(fmt.span(on=0))
7.514 + append(fmt.div(on=0))
7.515 +
7.516 + append(fmt.div(on=1, css_class="event-download-item"))
7.517 + append(fmt.span(on=1, css_class="event-download-link"))
7.518 + append(linkToPage(request, page, _("Edit subscription options..."), subscribe_dialogue_link))
7.519 + append(fmt.span(on=0)) # end label
7.520 + append(fmt.div(on=0))
7.521 +
7.522 + append(fmt.div(on=0)) # end of pop-up
7.523 + append(fmt.span(on=0)) # end of download
7.524 +
7.525 + append(fmt.div(on=0)) # end of controls
7.526 +
7.527 + return "".join(output)
7.528 +
7.529 + def writeViewControls(self):
7.530 +
7.531 + """
7.532 + Return a representation of the view mode controls, permitting viewing of
7.533 + aggregated events in calendar, list or table form.
7.534 + """
7.535 +
7.536 + page = self.page
7.537 + request = page.request
7.538 + fmt = request.formatter
7.539 + _ = request.getText
7.540 +
7.541 + output = []
7.542 + append = output.append
7.543 +
7.544 + # For day view links to other views, the wider view parameters should
7.545 + # be used in order to be able to return to those other views.
7.546 +
7.547 + specific_start = self.calendar_start
7.548 + specific_end = self.calendar_end
7.549 +
7.550 + start = self.wider_calendar_start or self.original_calendar_start and specific_start
7.551 + end = self.wider_calendar_end or self.original_calendar_end and specific_end
7.552 +
7.553 + help_page = Page(request, "HelpOnEventAggregator")
7.554 +
7.555 + calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
7.556 + calendar_update_link = self.getUpdateLink(start and start.as_month(), end and end.as_month(), "calendar", "month")
7.557 + list_link = self.getNavigationLink(start, end, "list", "month")
7.558 + list_update_link = self.getUpdateLink(start, end, "list", "month")
7.559 + table_link = self.getNavigationLink(start, end, "table", "month")
7.560 + table_update_link = self.getUpdateLink(start, end, "table", "month")
7.561 + map_link = self.getNavigationLink(start, end, "map", "month")
7.562 + map_update_link = self.getUpdateLink(start, end, "map", "month")
7.563 +
7.564 + # Specific links permit date-level navigation.
7.565 +
7.566 + specific_day_link = self.getNavigationLink(specific_start, specific_end, "day", wider_start=start, wider_end=end)
7.567 + specific_day_update_link = self.getUpdateLink(specific_start, specific_end, "day", wider_start=start, wider_end=end)
7.568 + specific_list_link = self.getNavigationLink(specific_start, specific_end, "list", wider_start=start, wider_end=end)
7.569 + specific_list_update_link = self.getUpdateLink(specific_start, specific_end, "list", wider_start=start, wider_end=end)
7.570 + specific_table_link = self.getNavigationLink(specific_start, specific_end, "table", wider_start=start, wider_end=end)
7.571 + specific_table_update_link = self.getUpdateLink(specific_start, specific_end, "table", wider_start=start, wider_end=end)
7.572 + specific_map_link = self.getNavigationLink(specific_start, specific_end, "map", wider_start=start, wider_end=end)
7.573 + specific_map_update_link = self.getUpdateLink(specific_start, specific_end, "map", wider_start=start, wider_end=end)
7.574 +
7.575 + new_event_link = self.getNewEventLink(start)
7.576 +
7.577 + # Write the controls.
7.578 +
7.579 + append(fmt.div(on=1, css_class="event-view-controls"))
7.580 +
7.581 + append(fmt.span(on=1, css_class="event-view"))
7.582 + append(linkToPage(request, help_page, _("Help")))
7.583 + append(fmt.span(on=0))
7.584 +
7.585 + append(fmt.span(on=1, css_class="event-view"))
7.586 + append(linkToPage(request, page, _("New event"), new_event_link))
7.587 + append(fmt.span(on=0))
7.588 +
7.589 + if self.mode != "calendar":
7.590 + view_label = self.resolution == "date" and _("View day in calendar") or _("View as calendar")
7.591 + append(fmt.span(on=1, css_class="event-view"))
7.592 + append(linkToPage(request, page, view_label, calendar_link, onclick=calendar_update_link))
7.593 + append(fmt.span(on=0))
7.594 +
7.595 + if self.resolution == "date" and self.mode != "day":
7.596 + append(fmt.span(on=1, css_class="event-view"))
7.597 + append(linkToPage(request, page, _("View day as calendar"), specific_day_link, onclick=specific_day_update_link))
7.598 + append(fmt.span(on=0))
7.599 +
7.600 + if self.resolution != "date" and self.mode != "list" or self.resolution == "date":
7.601 + view_label = self.resolution == "date" and _("View day in list") or _("View as list")
7.602 + append(fmt.span(on=1, css_class="event-view"))
7.603 + append(linkToPage(request, page, view_label, list_link, onclick=list_update_link))
7.604 + append(fmt.span(on=0))
7.605 +
7.606 + if self.resolution == "date" and self.mode != "list":
7.607 + append(fmt.span(on=1, css_class="event-view"))
7.608 + append(linkToPage(request, page, _("View day as list"),
7.609 + specific_list_link, onclick=specific_list_update_link
7.610 + ))
7.611 + append(fmt.span(on=0))
7.612 +
7.613 + if self.resolution != "date" and self.mode != "table" or self.resolution == "date":
7.614 + view_label = self.resolution == "date" and _("View day in table") or _("View as table")
7.615 + append(fmt.span(on=1, css_class="event-view"))
7.616 + append(linkToPage(request, page, view_label, table_link, onclick=table_update_link))
7.617 + append(fmt.span(on=0))
7.618 +
7.619 + if self.resolution == "date" and self.mode != "table":
7.620 + append(fmt.span(on=1, css_class="event-view"))
7.621 + append(linkToPage(request, page, _("View day as table"),
7.622 + specific_table_link, onclick=specific_table_update_link
7.623 + ))
7.624 + append(fmt.span(on=0))
7.625 +
7.626 + if self.map_name:
7.627 + if self.resolution != "date" and self.mode != "map" or self.resolution == "date":
7.628 + view_label = self.resolution == "date" and _("View day in map") or _("View as map")
7.629 + append(fmt.span(on=1, css_class="event-view"))
7.630 + append(linkToPage(request, page, view_label, map_link, onclick=map_update_link))
7.631 + append(fmt.span(on=0))
7.632 +
7.633 + if self.resolution == "date" and self.mode != "map":
7.634 + append(fmt.span(on=1, css_class="event-view"))
7.635 + append(linkToPage(request, page, _("View day as map"),
7.636 + specific_map_link, onclick=specific_map_update_link
7.637 + ))
7.638 + append(fmt.span(on=0))
7.639 +
7.640 + append(fmt.div(on=0))
7.641 +
7.642 + return "".join(output)
7.643 +
7.644 + def writeMapHeading(self):
7.645 +
7.646 + """
7.647 + Return the calendar heading for the current calendar, providing links
7.648 + permitting navigation to other periods.
7.649 + """
7.650 +
7.651 + label = self.getCalendarPeriod()
7.652 +
7.653 + if self.raw_calendar_start is None or self.raw_calendar_end is None:
7.654 + fmt = self.page.request.formatter
7.655 + output = []
7.656 + append = output.append
7.657 + append(fmt.span(on=1))
7.658 + append(fmt.text(label))
7.659 + append(fmt.span(on=0))
7.660 + return "".join(output)
7.661 + else:
7.662 + return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end)
7.663 +
7.664 + def writeDateHeading(self, date):
7.665 + if isinstance(date, Date):
7.666 + return self.writeDayHeading(date)
7.667 + else:
7.668 + return self.writeMonthHeading(date)
7.669 +
7.670 + def writeMonthHeading(self, year_month):
7.671 +
7.672 + """
7.673 + Return the calendar heading for the given 'year_month' (a Month object)
7.674 + providing links permitting navigation to other months.
7.675 + """
7.676 +
7.677 + full_month_label = self.getFullMonthLabel(year_month)
7.678 + end_month = year_month.update(self.duration - 1)
7.679 + return self._writeCalendarHeading(full_month_label, year_month, end_month)
7.680 +
7.681 + def writeDayHeading(self, date):
7.682 +
7.683 + """
7.684 + Return the calendar heading for the given 'date' (a Date object)
7.685 + providing links permitting navigation to other dates.
7.686 + """
7.687 +
7.688 + full_date_label = self.getFullDateLabel(date)
7.689 + end_date = date.update(self.duration - 1)
7.690 + return self._writeCalendarHeading(full_date_label, date, end_date)
7.691 +
7.692 + def _writeCalendarHeading(self, label, start, end):
7.693 +
7.694 + """
7.695 + Write a calendar heading providing links permitting navigation to other
7.696 + periods, using the given 'label' along with the 'start' and 'end' dates
7.697 + to provide a link to a particular period.
7.698 + """
7.699 +
7.700 + page = self.page
7.701 + request = page.request
7.702 + fmt = request.formatter
7.703 + _ = request.getText
7.704 +
7.705 + output = []
7.706 + append = output.append
7.707 +
7.708 + # Prepare navigation links.
7.709 +
7.710 + if self.calendar_name:
7.711 + calendar_name = self.calendar_name
7.712 +
7.713 + # Links to the previous set of months and to a calendar shifted
7.714 + # back one month.
7.715 +
7.716 + previous_set_link = self.getNavigationLink(
7.717 + self.previous_set_start, self.previous_set_end
7.718 + )
7.719 + previous_link = self.getNavigationLink(
7.720 + self.previous_start, self.previous_end
7.721 + )
7.722 + previous_set_update_link = self.getUpdateLink(
7.723 + self.previous_set_start, self.previous_set_end
7.724 + )
7.725 + previous_update_link = self.getUpdateLink(
7.726 + self.previous_start, self.previous_end
7.727 + )
7.728 +
7.729 + # Links to the next set of months and to a calendar shifted
7.730 + # forward one month.
7.731 +
7.732 + next_set_link = self.getNavigationLink(
7.733 + self.next_set_start, self.next_set_end
7.734 + )
7.735 + next_link = self.getNavigationLink(
7.736 + self.next_start, self.next_end
7.737 + )
7.738 + next_set_update_link = self.getUpdateLink(
7.739 + self.next_set_start, self.next_set_end
7.740 + )
7.741 + next_update_link = self.getUpdateLink(
7.742 + self.next_start, self.next_end
7.743 + )
7.744 +
7.745 + # A link leading to this date being at the top of the calendar.
7.746 +
7.747 + date_link = self.getNavigationLink(start, end)
7.748 + date_update_link = self.getUpdateLink(start, end)
7.749 +
7.750 + append(fmt.span(on=1, css_class="previous"))
7.751 + append(linkToPage(request, page, "<<", previous_set_link, onclick=previous_set_update_link))
7.752 + append(fmt.text(" "))
7.753 + append(linkToPage(request, page, "<", previous_link, onclick=previous_update_link))
7.754 + append(fmt.span(on=0))
7.755 +
7.756 + append(fmt.span(on=1, css_class="next"))
7.757 + append(linkToPage(request, page, ">", next_link, onclick=next_update_link))
7.758 + append(fmt.text(" "))
7.759 + append(linkToPage(request, page, ">>", next_set_link, onclick=next_set_update_link))
7.760 + append(fmt.span(on=0))
7.761 +
7.762 + append(linkToPage(request, page, label, date_link, onclick=date_update_link))
7.763 +
7.764 + else:
7.765 + append(fmt.span(on=1))
7.766 + append(fmt.text(label))
7.767 + append(fmt.span(on=0))
7.768 +
7.769 + return "".join(output)
7.770 +
7.771 + def writeDayNumberHeading(self, date, busy):
7.772 +
7.773 + """
7.774 + Return a link for the given 'date' which will activate the new event
7.775 + action for the given day. If 'busy' is given as a true value, the
7.776 + heading will be marked as busy.
7.777 + """
7.778 +
7.779 + page = self.page
7.780 + request = page.request
7.781 + fmt = request.formatter
7.782 + _ = request.getText
7.783 +
7.784 + output = []
7.785 + append = output.append
7.786 +
7.787 + year, month, day = date.as_tuple()
7.788 + new_event_link = self.getNewEventLink(date)
7.789 +
7.790 + # Prepare a link to the day view for this day.
7.791 +
7.792 + day_view_link = self.getNavigationLink(date, date, "day", "date", self.calendar_start, self.calendar_end)
7.793 + day_view_update_link = self.getUpdateLink(date, date, "day", "date", self.calendar_start, self.calendar_end)
7.794 +
7.795 + # Output the heading class.
7.796 +
7.797 + today_attr = date == getCurrentDate() and "event-day-current" or ""
7.798 +
7.799 + append(
7.800 + fmt.table_cell(on=1, attrs={
7.801 + "class" : "event-day-heading event-day-%s %s" % (busy and "busy" or "empty", today_attr),
7.802 + "colspan" : "3"
7.803 + }))
7.804 +
7.805 + # Output the number and pop-up menu.
7.806 +
7.807 + append(fmt.div(on=1, css_class="event-day-box"))
7.808 +
7.809 + append(fmt.span(on=1, css_class="event-day-number-popup"))
7.810 + append(fmt.span(on=1, css_class="event-day-number-link"))
7.811 + append(linkToPage(request, page, _("View day"), day_view_link, onclick=day_view_update_link))
7.812 + append(fmt.span(on=0))
7.813 + append(fmt.span(on=1, css_class="event-day-number-link"))
7.814 + append(linkToPage(request, page, _("New event"), new_event_link))
7.815 + append(fmt.span(on=0))
7.816 + append(fmt.span(on=0))
7.817 +
7.818 + append(fmt.span(on=1, css_class="event-day-number"))
7.819 + append(fmt.text(unicode(day)))
7.820 + append(fmt.span(on=0))
7.821 +
7.822 + append(fmt.div(on=0))
7.823 +
7.824 + # End of heading.
7.825 +
7.826 + append(fmt.table_cell(on=0))
7.827 +
7.828 + return "".join(output)
7.829 +
7.830 + # Common layout methods.
7.831 +
7.832 + def getEventStyle(self, colour_seed):
7.833 +
7.834 + "Generate colour style information using the given 'colour_seed'."
7.835 +
7.836 + bg = getColour(colour_seed)
7.837 + fg = getBlackOrWhite(bg)
7.838 + return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg)
7.839 +
7.840 + def writeEventSummaryBox(self, event):
7.841 +
7.842 + "Return an event summary box linking to the given 'event'."
7.843 +
7.844 + page = self.page
7.845 + request = page.request
7.846 + fmt = request.formatter
7.847 +
7.848 + output = []
7.849 + append = output.append
7.850 +
7.851 + event_details = event.getDetails()
7.852 + event_summary = event.getSummary(self.parent_name)
7.853 +
7.854 + is_ambiguous = event.as_timespan().ambiguous()
7.855 + style = self.getEventStyle(event_summary)
7.856 +
7.857 + # The event box contains the summary, alongside
7.858 + # other elements.
7.859 +
7.860 + append(fmt.div(on=1, css_class="event-summary-box"))
7.861 + append(fmt.div(on=1, css_class="event-summary", style=style))
7.862 +
7.863 + if is_ambiguous:
7.864 + append(fmt.icon("/!\\"))
7.865 +
7.866 + append(event.linkToEvent(request, event_summary))
7.867 + append(fmt.div(on=0))
7.868 +
7.869 + # Add a pop-up element for long summaries.
7.870 +
7.871 + append(fmt.div(on=1, css_class="event-summary-popup", style=style))
7.872 +
7.873 + if is_ambiguous:
7.874 + append(fmt.icon("/!\\"))
7.875 +
7.876 + append(event.linkToEvent(request, event_summary))
7.877 + append(fmt.div(on=0))
7.878 +
7.879 + append(fmt.div(on=0))
7.880 +
7.881 + return "".join(output)
7.882 +
7.883 + # Calendar layout methods.
7.884 +
7.885 + def writeMonthTableHeading(self, year_month):
7.886 + page = self.page
7.887 + fmt = page.request.formatter
7.888 +
7.889 + output = []
7.890 + append = output.append
7.891 +
7.892 + append(fmt.table_row(on=1))
7.893 + append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"}))
7.894 +
7.895 + append(self.writeMonthHeading(year_month))
7.896 +
7.897 + append(fmt.table_cell(on=0))
7.898 + append(fmt.table_row(on=0))
7.899 +
7.900 + return "".join(output)
7.901 +
7.902 + def writeWeekdayHeadings(self):
7.903 + page = self.page
7.904 + request = page.request
7.905 + fmt = request.formatter
7.906 + _ = request.getText
7.907 +
7.908 + output = []
7.909 + append = output.append
7.910 +
7.911 + append(fmt.table_row(on=1))
7.912 +
7.913 + for weekday in range(0, 7):
7.914 + append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"}))
7.915 + append(fmt.text(_(getDayLabel(weekday))))
7.916 + append(fmt.table_cell(on=0))
7.917 +
7.918 + append(fmt.table_row(on=0))
7.919 + return "".join(output)
7.920 +
7.921 + def writeDayNumbers(self, first_day, number_of_days, month, coverage):
7.922 + page = self.page
7.923 + fmt = page.request.formatter
7.924 +
7.925 + output = []
7.926 + append = output.append
7.927 +
7.928 + append(fmt.table_row(on=1))
7.929 +
7.930 + for weekday in range(0, 7):
7.931 + day = first_day + weekday
7.932 + date = month.as_date(day)
7.933 +
7.934 + # Output out-of-month days.
7.935 +
7.936 + if day < 1 or day > number_of_days:
7.937 + append(fmt.table_cell(on=1,
7.938 + attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"}))
7.939 + append(fmt.table_cell(on=0))
7.940 +
7.941 + # Output normal days.
7.942 +
7.943 + else:
7.944 + # Output the day heading, making a link to a new event
7.945 + # action.
7.946 +
7.947 + append(self.writeDayNumberHeading(date, date in coverage))
7.948 +
7.949 + # End of day numbers.
7.950 +
7.951 + append(fmt.table_row(on=0))
7.952 + return "".join(output)
7.953 +
7.954 + def writeEmptyWeek(self, first_day, number_of_days, month):
7.955 + page = self.page
7.956 + fmt = page.request.formatter
7.957 +
7.958 + output = []
7.959 + append = output.append
7.960 +
7.961 + append(fmt.table_row(on=1))
7.962 +
7.963 + for weekday in range(0, 7):
7.964 + day = first_day + weekday
7.965 + date = month.as_date(day)
7.966 +
7.967 + today_attr = date == getCurrentDate() and "event-day-current" or ""
7.968 +
7.969 + # Output out-of-month days.
7.970 +
7.971 + if day < 1 or day > number_of_days:
7.972 + append(fmt.table_cell(on=1,
7.973 + attrs={"class" : "event-day-content event-day-excluded %s" % today_attr, "colspan" : "3"}))
7.974 + append(fmt.table_cell(on=0))
7.975 +
7.976 + # Output empty days.
7.977 +
7.978 + else:
7.979 + append(fmt.table_cell(on=1,
7.980 + attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"}))
7.981 +
7.982 + append(fmt.table_row(on=0))
7.983 + return "".join(output)
7.984 +
7.985 + def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots):
7.986 + output = []
7.987 + append = output.append
7.988 +
7.989 + locations = week_slots.keys()
7.990 + locations.sort(sort_none_first)
7.991 +
7.992 + # Visit each slot corresponding to a location (or no location).
7.993 +
7.994 + for location in locations:
7.995 +
7.996 + # Visit each coverage span, presenting the events in the span.
7.997 +
7.998 + for events in week_slots[location]:
7.999 +
7.1000 + # Output each set.
7.1001 +
7.1002 + append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events))
7.1003 +
7.1004 + # Add a spacer.
7.1005 +
7.1006 + append(self.writeWeekSpacer(first_day, number_of_days, month))
7.1007 +
7.1008 + return "".join(output)
7.1009 +
7.1010 + def writeWeekSlot(self, first_day, number_of_days, month, week_end, events):
7.1011 + page = self.page
7.1012 + request = page.request
7.1013 + fmt = request.formatter
7.1014 +
7.1015 + output = []
7.1016 + append = output.append
7.1017 +
7.1018 + append(fmt.table_row(on=1))
7.1019 +
7.1020 + # Then, output day details.
7.1021 +
7.1022 + for weekday in range(0, 7):
7.1023 + day = first_day + weekday
7.1024 + date = month.as_date(day)
7.1025 +
7.1026 + # Skip out-of-month days.
7.1027 +
7.1028 + if day < 1 or day > number_of_days:
7.1029 + append(fmt.table_cell(on=1,
7.1030 + attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"}))
7.1031 + append(fmt.table_cell(on=0))
7.1032 + continue
7.1033 +
7.1034 + # Output the day.
7.1035 + # Where a day does not contain an event, a single cell is used.
7.1036 + # Otherwise, multiple cells are used to provide space before, during
7.1037 + # and after events.
7.1038 +
7.1039 + today_attr = date == getCurrentDate() and "event-day-current" or ""
7.1040 +
7.1041 + if date not in events:
7.1042 + append(fmt.table_cell(on=1,
7.1043 + attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"}))
7.1044 +
7.1045 + # Get event details for the current day.
7.1046 +
7.1047 + for event in events:
7.1048 + event_details = event.getDetails()
7.1049 +
7.1050 + if date not in event:
7.1051 + continue
7.1052 +
7.1053 + # Get basic properties of the event.
7.1054 +
7.1055 + starts_today = event_details["start"] == date
7.1056 + ends_today = event_details["end"] == date
7.1057 + event_summary = event.getSummary(self.parent_name)
7.1058 +
7.1059 + style = self.getEventStyle(event_summary)
7.1060 +
7.1061 + # Determine if the event name should be shown.
7.1062 +
7.1063 + start_of_period = starts_today or weekday == 0 or day == 1
7.1064 +
7.1065 + if self.name_usage == "daily" or start_of_period:
7.1066 + hide_text = 0
7.1067 + else:
7.1068 + hide_text = 1
7.1069 +
7.1070 + # Output start of day gap and determine whether
7.1071 + # any event content should be explicitly output
7.1072 + # for this day.
7.1073 +
7.1074 + if starts_today:
7.1075 +
7.1076 + # Single day events...
7.1077 +
7.1078 + if ends_today:
7.1079 + colspan = 3
7.1080 + event_day_type = "event-day-single"
7.1081 +
7.1082 + # Events starting today...
7.1083 +
7.1084 + else:
7.1085 + append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap %s" % today_attr}))
7.1086 + append(fmt.table_cell(on=0))
7.1087 +
7.1088 + # Calculate the span of this cell.
7.1089 + # Events whose names appear on every day...
7.1090 +
7.1091 + if self.name_usage == "daily":
7.1092 + colspan = 2
7.1093 + event_day_type = "event-day-starting"
7.1094 +
7.1095 + # Events whose names appear once per week...
7.1096 +
7.1097 + else:
7.1098 + if event_details["end"] <= week_end:
7.1099 + event_length = event_details["end"].day() - day + 1
7.1100 + colspan = (event_length - 2) * 3 + 4
7.1101 + else:
7.1102 + event_length = week_end.day() - day + 1
7.1103 + colspan = (event_length - 1) * 3 + 2
7.1104 +
7.1105 + event_day_type = "event-day-multiple"
7.1106 +
7.1107 + # Events continuing from a previous week...
7.1108 +
7.1109 + elif start_of_period:
7.1110 +
7.1111 + # End of continuing event...
7.1112 +
7.1113 + if ends_today:
7.1114 + colspan = 2
7.1115 + event_day_type = "event-day-ending"
7.1116 +
7.1117 + # Events continuing for at least one more day...
7.1118 +
7.1119 + else:
7.1120 +
7.1121 + # Calculate the span of this cell.
7.1122 + # Events whose names appear on every day...
7.1123 +
7.1124 + if self.name_usage == "daily":
7.1125 + colspan = 3
7.1126 + event_day_type = "event-day-full"
7.1127 +
7.1128 + # Events whose names appear once per week...
7.1129 +
7.1130 + else:
7.1131 + if event_details["end"] <= week_end:
7.1132 + event_length = event_details["end"].day() - day + 1
7.1133 + colspan = (event_length - 1) * 3 + 2
7.1134 + else:
7.1135 + event_length = week_end.day() - day + 1
7.1136 + colspan = event_length * 3
7.1137 +
7.1138 + event_day_type = "event-day-multiple"
7.1139 +
7.1140 + # Continuing events whose names appear on every day...
7.1141 +
7.1142 + elif self.name_usage == "daily":
7.1143 + if ends_today:
7.1144 + colspan = 2
7.1145 + event_day_type = "event-day-ending"
7.1146 + else:
7.1147 + colspan = 3
7.1148 + event_day_type = "event-day-full"
7.1149 +
7.1150 + # Continuing events whose names appear once per week...
7.1151 +
7.1152 + else:
7.1153 + colspan = None
7.1154 +
7.1155 + # Output the main content only if it is not
7.1156 + # continuing from a previous day.
7.1157 +
7.1158 + if colspan is not None:
7.1159 +
7.1160 + # Colour the cell for continuing events.
7.1161 +
7.1162 + attrs={
7.1163 + "class" : "event-day-content event-day-busy %s %s" % (event_day_type, today_attr),
7.1164 + "colspan" : str(colspan)
7.1165 + }
7.1166 +
7.1167 + if not (starts_today and ends_today):
7.1168 + attrs["style"] = style
7.1169 +
7.1170 + append(fmt.table_cell(on=1, attrs=attrs))
7.1171 +
7.1172 + # Output the event.
7.1173 +
7.1174 + if starts_today and ends_today or not hide_text:
7.1175 + append(self.writeEventSummaryBox(event))
7.1176 +
7.1177 + append(fmt.table_cell(on=0))
7.1178 +
7.1179 + # Output end of day gap.
7.1180 +
7.1181 + if ends_today and not starts_today:
7.1182 + append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap %s" % today_attr}))
7.1183 + append(fmt.table_cell(on=0))
7.1184 +
7.1185 + # End of set.
7.1186 +
7.1187 + append(fmt.table_row(on=0))
7.1188 + return "".join(output)
7.1189 +
7.1190 + def writeWeekSpacer(self, first_day, number_of_days, month):
7.1191 + page = self.page
7.1192 + fmt = page.request.formatter
7.1193 +
7.1194 + output = []
7.1195 + append = output.append
7.1196 +
7.1197 + append(fmt.table_row(on=1))
7.1198 +
7.1199 + for weekday in range(0, 7):
7.1200 + day = first_day + weekday
7.1201 + date = month.as_date(day)
7.1202 + today_attr = date == getCurrentDate() and "event-day-current" or ""
7.1203 +
7.1204 + css_classes = "event-day-spacer %s" % today_attr
7.1205 +
7.1206 + # Skip out-of-month days.
7.1207 +
7.1208 + if day < 1 or day > number_of_days:
7.1209 + css_classes += " event-day-excluded"
7.1210 +
7.1211 + append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"}))
7.1212 + append(fmt.table_cell(on=0))
7.1213 +
7.1214 + append(fmt.table_row(on=0))
7.1215 + return "".join(output)
7.1216 +
7.1217 + # Day layout methods.
7.1218 +
7.1219 + def writeDayTableHeading(self, date, colspan=1):
7.1220 + page = self.page
7.1221 + fmt = page.request.formatter
7.1222 +
7.1223 + output = []
7.1224 + append = output.append
7.1225 +
7.1226 + append(fmt.table_row(on=1))
7.1227 +
7.1228 + append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)}))
7.1229 + append(self.writeDayHeading(date))
7.1230 + append(fmt.table_cell(on=0))
7.1231 +
7.1232 + append(fmt.table_row(on=0))
7.1233 + return "".join(output)
7.1234 +
7.1235 + def writeEmptyDay(self, date):
7.1236 + page = self.page
7.1237 + fmt = page.request.formatter
7.1238 +
7.1239 + output = []
7.1240 + append = output.append
7.1241 +
7.1242 + append(fmt.table_row(on=1))
7.1243 +
7.1244 + append(fmt.table_cell(on=1,
7.1245 + attrs={"class" : "event-day-content event-day-empty"}))
7.1246 +
7.1247 + append(fmt.table_row(on=0))
7.1248 + return "".join(output)
7.1249 +
7.1250 + def writeDaySlots(self, date, full_coverage, day_slots):
7.1251 +
7.1252 + """
7.1253 + Given a 'date', non-empty 'full_coverage' for the day concerned, and a
7.1254 + non-empty mapping of 'day_slots' (from locations to event collections),
7.1255 + output the day slots for the day.
7.1256 + """
7.1257 +
7.1258 + page = self.page
7.1259 + fmt = page.request.formatter
7.1260 +
7.1261 + output = []
7.1262 + append = output.append
7.1263 +
7.1264 + locations = day_slots.keys()
7.1265 + locations.sort(sort_none_first)
7.1266 +
7.1267 + # Traverse the time scale of the full coverage, visiting each slot to
7.1268 + # determine whether it provides content for each period.
7.1269 +
7.1270 + scale = getCoverageScale(full_coverage)
7.1271 +
7.1272 + # Define a mapping of events to rowspans.
7.1273 +
7.1274 + rowspans = {}
7.1275 +
7.1276 + # Populate each period with event details, recording how many periods
7.1277 + # each event populates.
7.1278 +
7.1279 + day_rows = []
7.1280 +
7.1281 + for period in scale:
7.1282 +
7.1283 + # Ignore timespans before this day.
7.1284 +
7.1285 + if period != date:
7.1286 + continue
7.1287 +
7.1288 + # Visit each slot corresponding to a location (or no location).
7.1289 +
7.1290 + day_row = []
7.1291 +
7.1292 + for location in locations:
7.1293 +
7.1294 + # Visit each coverage span, presenting the events in the span.
7.1295 +
7.1296 + for events in day_slots[location]:
7.1297 + event = self.getActiveEvent(period, events)
7.1298 + if event is not None:
7.1299 + if not rowspans.has_key(event):
7.1300 + rowspans[event] = 1
7.1301 + else:
7.1302 + rowspans[event] += 1
7.1303 + day_row.append((location, event))
7.1304 +
7.1305 + day_rows.append((period, day_row))
7.1306 +
7.1307 + # Output the locations.
7.1308 +
7.1309 + append(fmt.table_row(on=1))
7.1310 +
7.1311 + # Add a spacer.
7.1312 +
7.1313 + append(self.writeDaySpacer(colspan=2, cls="location"))
7.1314 +
7.1315 + for location in locations:
7.1316 +
7.1317 + # Add spacers to the column spans.
7.1318 +
7.1319 + columns = len(day_slots[location]) * 2 - 1
7.1320 + append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)}))
7.1321 + append(fmt.text(location or ""))
7.1322 + append(fmt.table_cell(on=0))
7.1323 +
7.1324 + # Add a trailing spacer.
7.1325 +
7.1326 + append(self.writeDaySpacer(cls="location"))
7.1327 +
7.1328 + append(fmt.table_row(on=0))
7.1329 +
7.1330 + # Output the periods with event details.
7.1331 +
7.1332 + period = None
7.1333 + events_written = set()
7.1334 +
7.1335 + for period, day_row in day_rows:
7.1336 +
7.1337 + # Write an empty heading for the start of the day where the first
7.1338 + # applicable timespan starts before this day.
7.1339 +
7.1340 + if period.start < date:
7.1341 + append(fmt.table_row(on=1))
7.1342 + append(self.writeDayScaleHeading(""))
7.1343 +
7.1344 + # Otherwise, write a heading describing the time.
7.1345 +
7.1346 + else:
7.1347 + append(fmt.table_row(on=1))
7.1348 + append(self.writeDayScaleHeading(period.start.time_string()))
7.1349 +
7.1350 + append(self.writeDaySpacer())
7.1351 +
7.1352 + # Visit each slot corresponding to a location (or no location).
7.1353 +
7.1354 + for location, event in day_row:
7.1355 +
7.1356 + # Output each location slot's contribution.
7.1357 +
7.1358 + if event is None or event not in events_written:
7.1359 + append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event]))
7.1360 + if event is not None:
7.1361 + events_written.add(event)
7.1362 +
7.1363 + # Add a trailing spacer.
7.1364 +
7.1365 + append(self.writeDaySpacer())
7.1366 +
7.1367 + append(fmt.table_row(on=0))
7.1368 +
7.1369 + # Write a final time heading if the last period ends in the current day.
7.1370 +
7.1371 + if period is not None:
7.1372 + if period.end == date:
7.1373 + append(fmt.table_row(on=1))
7.1374 + append(self.writeDayScaleHeading(period.end.time_string()))
7.1375 +
7.1376 + for slot in day_row:
7.1377 + append(self.writeDaySpacer())
7.1378 + append(self.writeEmptyDaySlot())
7.1379 +
7.1380 + append(fmt.table_row(on=0))
7.1381 +
7.1382 + return "".join(output)
7.1383 +
7.1384 + def writeDayScaleHeading(self, heading):
7.1385 + page = self.page
7.1386 + fmt = page.request.formatter
7.1387 +
7.1388 + output = []
7.1389 + append = output.append
7.1390 +
7.1391 + append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"}))
7.1392 + append(fmt.text(heading))
7.1393 + append(fmt.table_cell(on=0))
7.1394 +
7.1395 + return "".join(output)
7.1396 +
7.1397 + def getActiveEvent(self, period, events):
7.1398 + for event in events:
7.1399 + if period not in event:
7.1400 + continue
7.1401 + return event
7.1402 + else:
7.1403 + return None
7.1404 +
7.1405 + def writeDaySlot(self, period, event, rowspan):
7.1406 + page = self.page
7.1407 + fmt = page.request.formatter
7.1408 +
7.1409 + output = []
7.1410 + append = output.append
7.1411 +
7.1412 + if event is not None:
7.1413 + event_summary = event.getSummary(self.parent_name)
7.1414 + style = self.getEventStyle(event_summary)
7.1415 +
7.1416 + append(fmt.table_cell(on=1, attrs={
7.1417 + "class" : "event-timespan-content event-timespan-busy",
7.1418 + "style" : style,
7.1419 + "rowspan" : str(rowspan)
7.1420 + }))
7.1421 + append(self.writeEventSummaryBox(event))
7.1422 + append(fmt.table_cell(on=0))
7.1423 + else:
7.1424 + append(self.writeEmptyDaySlot())
7.1425 +
7.1426 + return "".join(output)
7.1427 +
7.1428 + def writeEmptyDaySlot(self):
7.1429 + page = self.page
7.1430 + fmt = page.request.formatter
7.1431 +
7.1432 + output = []
7.1433 + append = output.append
7.1434 +
7.1435 + append(fmt.table_cell(on=1,
7.1436 + attrs={"class" : "event-timespan-content event-timespan-empty"}))
7.1437 + append(fmt.table_cell(on=0))
7.1438 +
7.1439 + return "".join(output)
7.1440 +
7.1441 + def writeDaySpacer(self, colspan=1, cls="timespan"):
7.1442 + page = self.page
7.1443 + fmt = page.request.formatter
7.1444 +
7.1445 + output = []
7.1446 + append = output.append
7.1447 +
7.1448 + append(fmt.table_cell(on=1, attrs={
7.1449 + "class" : "event-%s-spacer" % cls,
7.1450 + "colspan" : str(colspan)}))
7.1451 + append(fmt.table_cell(on=0))
7.1452 + return "".join(output)
7.1453 +
7.1454 + # Map layout methods.
7.1455 +
7.1456 + def writeMapTableHeading(self):
7.1457 + page = self.page
7.1458 + fmt = page.request.formatter
7.1459 +
7.1460 + output = []
7.1461 + append = output.append
7.1462 +
7.1463 + append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"}))
7.1464 + append(self.writeMapHeading())
7.1465 + append(fmt.table_cell(on=0))
7.1466 +
7.1467 + return "".join(output)
7.1468 +
7.1469 + def showDictError(self, text, pagename):
7.1470 + page = self.page
7.1471 + request = page.request
7.1472 + fmt = request.formatter
7.1473 +
7.1474 + output = []
7.1475 + append = output.append
7.1476 +
7.1477 + append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"}))
7.1478 + append(fmt.paragraph(on=1))
7.1479 + append(fmt.text(text))
7.1480 + append(fmt.paragraph(on=0))
7.1481 + append(fmt.paragraph(on=1))
7.1482 + append(linkToPage(request, Page(request, pagename), pagename))
7.1483 + append(fmt.paragraph(on=0))
7.1484 +
7.1485 + return "".join(output)
7.1486 +
7.1487 + def writeMapMarker(self, marker_x, marker_y, map_x_scale, map_y_scale, location, events):
7.1488 +
7.1489 + "Put a marker on the map."
7.1490 +
7.1491 + page = self.page
7.1492 + request = page.request
7.1493 + fmt = request.formatter
7.1494 +
7.1495 + output = []
7.1496 + append = output.append
7.1497 +
7.1498 + append(fmt.listitem(on=1, css_class="event-map-label"))
7.1499 +
7.1500 + # Have a positioned marker for the print mode.
7.1501 +
7.1502 + append(fmt.div(on=1, css_class="event-map-label-only",
7.1503 + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
7.1504 + marker_x, marker_y, map_x_scale, map_y_scale))
7.1505 + append(fmt.div(on=0))
7.1506 +
7.1507 + # Have a marker containing a pop-up when using the screen mode,
7.1508 + # providing a normal block when using the print mode.
7.1509 +
7.1510 + append(fmt.div(on=1, css_class="event-map-label",
7.1511 + style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % (
7.1512 + marker_x, marker_y, map_x_scale, map_y_scale))
7.1513 + append(fmt.div(on=1, css_class="event-map-details"))
7.1514 + append(fmt.div(on=1, css_class="event-map-shadow"))
7.1515 + append(fmt.div(on=1, css_class="event-map-location"))
7.1516 +
7.1517 + # The location may have been given as formatted text, but this will not
7.1518 + # be usable in a heading, so it must be first converted to plain text.
7.1519 +
7.1520 + append(fmt.heading(on=1, depth=2))
7.1521 + append(fmt.text(to_plain_text(location, request)))
7.1522 + append(fmt.heading(on=0, depth=2))
7.1523 +
7.1524 + append(self.writeMapEventSummaries(events))
7.1525 +
7.1526 + append(fmt.div(on=0))
7.1527 + append(fmt.div(on=0))
7.1528 + append(fmt.div(on=0))
7.1529 + append(fmt.div(on=0))
7.1530 + append(fmt.listitem(on=0))
7.1531 +
7.1532 + return "".join(output)
7.1533 +
7.1534 + def writeMapEventSummaries(self, events):
7.1535 +
7.1536 + "Write summaries of the given 'events' for the map."
7.1537 +
7.1538 + page = self.page
7.1539 + request = page.request
7.1540 + fmt = request.formatter
7.1541 +
7.1542 + # Sort the events by date.
7.1543 +
7.1544 + events.sort(sort_start_first)
7.1545 +
7.1546 + # Write out a self-contained list of events.
7.1547 +
7.1548 + output = []
7.1549 + append = output.append
7.1550 +
7.1551 + append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"}))
7.1552 +
7.1553 + for event in events:
7.1554 +
7.1555 + # Get the event details.
7.1556 +
7.1557 + event_summary = event.getSummary(self.parent_name)
7.1558 + start, end = event.as_limits()
7.1559 + event_period = self._getCalendarPeriod(
7.1560 + start and self.getFullDateLabel(start),
7.1561 + end and self.getFullDateLabel(end),
7.1562 + "")
7.1563 +
7.1564 + append(fmt.listitem(on=1))
7.1565 +
7.1566 + # Link to the page using the summary.
7.1567 +
7.1568 + append(event.linkToEvent(request, event_summary))
7.1569 +
7.1570 + # Add the event period.
7.1571 +
7.1572 + append(fmt.text(" "))
7.1573 + append(fmt.span(on=1, css_class="event-map-period"))
7.1574 + append(fmt.text(event_period))
7.1575 + append(fmt.span(on=0))
7.1576 +
7.1577 + append(fmt.listitem(on=0))
7.1578 +
7.1579 + append(fmt.bullet_list(on=0))
7.1580 +
7.1581 + return "".join(output)
7.1582 +
7.1583 + def render(self, all_shown_events):
7.1584 +
7.1585 + """
7.1586 + Render the view, returning the rendered representation as a string.
7.1587 + The view will show a list of 'all_shown_events'.
7.1588 + """
7.1589 +
7.1590 + page = self.page
7.1591 + request = page.request
7.1592 + fmt = request.formatter
7.1593 + _ = request.getText
7.1594 +
7.1595 + # Make a calendar.
7.1596 +
7.1597 + output = []
7.1598 + append = output.append
7.1599 +
7.1600 + append(fmt.div(on=1, css_class="event-calendar", id=("EventAggregator-%s" % self.getIdentifier())))
7.1601 +
7.1602 + # Output download controls.
7.1603 +
7.1604 + append(fmt.div(on=1, css_class="event-controls"))
7.1605 + append(self.writeDownloadControls())
7.1606 + append(fmt.div(on=0))
7.1607 +
7.1608 + # Output a table.
7.1609 +
7.1610 + if self.mode == "table":
7.1611 +
7.1612 + # Start of table view output.
7.1613 +
7.1614 + append(fmt.table(on=1, attrs={"tableclass" : "event-table"}))
7.1615 +
7.1616 + append(fmt.table_row(on=1))
7.1617 + append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
7.1618 + append(fmt.text(_("Event dates")))
7.1619 + append(fmt.table_cell(on=0))
7.1620 + append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
7.1621 + append(fmt.text(_("Event location")))
7.1622 + append(fmt.table_cell(on=0))
7.1623 + append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"}))
7.1624 + append(fmt.text(_("Event details")))
7.1625 + append(fmt.table_cell(on=0))
7.1626 + append(fmt.table_row(on=0))
7.1627 +
7.1628 + # Show the events in order.
7.1629 +
7.1630 + all_shown_events.sort(sort_start_first)
7.1631 +
7.1632 + for event in all_shown_events:
7.1633 + event_page = event.getPage()
7.1634 + event_summary = event.getSummary(self.parent_name)
7.1635 + event_details = event.getDetails()
7.1636 +
7.1637 + # Prepare CSS classes with category-related styling.
7.1638 +
7.1639 + css_classes = ["event-table-details"]
7.1640 +
7.1641 + for topic in event_details.get("topics") or event_details.get("categories") or []:
7.1642 +
7.1643 + # Filter the category text to avoid illegal characters.
7.1644 +
7.1645 + css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic)))
7.1646 +
7.1647 + attrs = {"class" : " ".join(css_classes)}
7.1648 +
7.1649 + append(fmt.table_row(on=1))
7.1650 +
7.1651 + # Start and end dates.
7.1652 +
7.1653 + append(fmt.table_cell(on=1, attrs=attrs))
7.1654 + append(fmt.span(on=1))
7.1655 + append(fmt.text(str(event_details["start"])))
7.1656 + append(fmt.span(on=0))
7.1657 +
7.1658 + if event_details["start"] != event_details["end"]:
7.1659 + append(fmt.text(" - "))
7.1660 + append(fmt.span(on=1))
7.1661 + append(fmt.text(str(event_details["end"])))
7.1662 + append(fmt.span(on=0))
7.1663 +
7.1664 + append(fmt.table_cell(on=0))
7.1665 +
7.1666 + # Location.
7.1667 +
7.1668 + append(fmt.table_cell(on=1, attrs=attrs))
7.1669 +
7.1670 + if event_details.has_key("location"):
7.1671 + append(event_page.formatText(event_details["location"], fmt))
7.1672 +
7.1673 + append(fmt.table_cell(on=0))
7.1674 +
7.1675 + # Link to the page using the summary.
7.1676 +
7.1677 + append(fmt.table_cell(on=1, attrs=attrs))
7.1678 + append(event.linkToEvent(request, event_summary))
7.1679 + append(fmt.table_cell(on=0))
7.1680 +
7.1681 + append(fmt.table_row(on=0))
7.1682 +
7.1683 + # End of table view output.
7.1684 +
7.1685 + append(fmt.table(on=0))
7.1686 +
7.1687 + # Output a map view.
7.1688 +
7.1689 + elif self.mode == "map":
7.1690 +
7.1691 + # Special dictionary pages.
7.1692 +
7.1693 + maps_page = getMapsPage(request)
7.1694 + locations_page = getLocationsPage(request)
7.1695 +
7.1696 + map_image = None
7.1697 +
7.1698 + # Get the maps and locations.
7.1699 +
7.1700 + maps = getWikiDict(maps_page, request)
7.1701 + locations = getWikiDict(locations_page, request)
7.1702 +
7.1703 + # Get the map image definition.
7.1704 +
7.1705 + if maps is not None and self.map_name:
7.1706 + try:
7.1707 + map_details = maps[self.map_name].split()
7.1708 +
7.1709 + map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \
7.1710 + map(getMapReference, map_details[:4])
7.1711 + map_width, map_height = map(int, map_details[4:6])
7.1712 + map_image = map_details[6]
7.1713 +
7.1714 + map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees()
7.1715 + map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees()
7.1716 +
7.1717 + except (KeyError, ValueError):
7.1718 + pass
7.1719 +
7.1720 + # Report errors.
7.1721 +
7.1722 + if maps is None:
7.1723 + append(self.showDictError(
7.1724 + _("You do not have read access to the maps page:"),
7.1725 + maps_page))
7.1726 +
7.1727 + elif not self.map_name:
7.1728 + append(self.showDictError(
7.1729 + _("Please specify a valid map name corresponding to an entry on the following page:"),
7.1730 + maps_page))
7.1731 +
7.1732 + elif map_image is None:
7.1733 + append(self.showDictError(
7.1734 + _("Please specify a valid entry for %s on the following page:") % self.map_name,
7.1735 + maps_page))
7.1736 +
7.1737 + elif locations is None:
7.1738 + append(self.showDictError(
7.1739 + _("You do not have read access to the locations page:"),
7.1740 + locations_page))
7.1741 +
7.1742 + # Attempt to show the map.
7.1743 +
7.1744 + else:
7.1745 +
7.1746 + # Get events by position.
7.1747 +
7.1748 + events_by_location = {}
7.1749 + event_locations = {}
7.1750 +
7.1751 + for event in all_shown_events:
7.1752 + event_details = event.getDetails()
7.1753 +
7.1754 + location = event_details.get("location")
7.1755 + geo = event_details.get("geo")
7.1756 +
7.1757 + # Make a temporary location if an explicit position is given
7.1758 + # but not a location name.
7.1759 +
7.1760 + if not location and geo:
7.1761 + location = "%s %s" % tuple(geo)
7.1762 +
7.1763 + # Map the location to a position.
7.1764 +
7.1765 + if location is not None and not event_locations.has_key(location):
7.1766 +
7.1767 + # Get any explicit position of an event.
7.1768 +
7.1769 + if geo:
7.1770 + latitude, longitude = geo
7.1771 +
7.1772 + # Or look up the position of a location using the locations
7.1773 + # page.
7.1774 +
7.1775 + else:
7.1776 + latitude, longitude = Location(location, locations).getPosition()
7.1777 +
7.1778 + # Use a normalised location if necessary.
7.1779 +
7.1780 + if latitude is None and longitude is None:
7.1781 + normalised_location = getNormalisedLocation(location)
7.1782 + if normalised_location is not None:
7.1783 + latitude, longitude = getLocationPosition(normalised_location, locations)
7.1784 + if latitude is not None and longitude is not None:
7.1785 + location = normalised_location
7.1786 +
7.1787 + # Only remember positioned locations.
7.1788 +
7.1789 + if latitude is not None and longitude is not None:
7.1790 + event_locations[location] = latitude, longitude
7.1791 +
7.1792 + # Record events according to location.
7.1793 +
7.1794 + if not events_by_location.has_key(location):
7.1795 + events_by_location[location] = []
7.1796 +
7.1797 + events_by_location[location].append(event)
7.1798 +
7.1799 + # Get the map image URL.
7.1800 +
7.1801 + map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request)
7.1802 +
7.1803 + # Start of map view output.
7.1804 +
7.1805 + map_identifier = "map-%s" % self.getIdentifier()
7.1806 + append(fmt.div(on=1, css_class="event-map", id=map_identifier))
7.1807 +
7.1808 + append(fmt.table(on=1))
7.1809 +
7.1810 + append(fmt.table_row(on=1))
7.1811 + append(self.writeMapTableHeading())
7.1812 + append(fmt.table_row(on=0))
7.1813 +
7.1814 + append(fmt.table_row(on=1))
7.1815 + append(fmt.table_cell(on=1))
7.1816 +
7.1817 + append(fmt.div(on=1, css_class="event-map-container"))
7.1818 + append(fmt.image(map_image_url))
7.1819 + append(fmt.number_list(on=1))
7.1820 +
7.1821 + # Events with no location are unpositioned.
7.1822 +
7.1823 + if events_by_location.has_key(None):
7.1824 + unpositioned_events = events_by_location[None]
7.1825 + del events_by_location[None]
7.1826 + else:
7.1827 + unpositioned_events = []
7.1828 +
7.1829 + # Events whose location is unpositioned are themselves considered
7.1830 + # unpositioned.
7.1831 +
7.1832 + for location in set(events_by_location.keys()).difference(event_locations.keys()):
7.1833 + unpositioned_events += events_by_location[location]
7.1834 +
7.1835 + # Sort the locations before traversing them.
7.1836 +
7.1837 + event_locations = event_locations.items()
7.1838 + event_locations.sort()
7.1839 +
7.1840 + # Show the events in the map.
7.1841 +
7.1842 + for location, (latitude, longitude) in event_locations:
7.1843 + events = events_by_location[location]
7.1844 +
7.1845 + # Skip unpositioned locations and locations outside the map.
7.1846 +
7.1847 + if latitude is None or longitude is None or \
7.1848 + latitude < map_bottom_left_latitude or \
7.1849 + longitude < map_bottom_left_longitude or \
7.1850 + latitude > map_top_right_latitude or \
7.1851 + longitude > map_top_right_longitude:
7.1852 +
7.1853 + unpositioned_events += events
7.1854 + continue
7.1855 +
7.1856 + # Get the position and dimensions of the map marker.
7.1857 + # NOTE: Use one degree as the marker size.
7.1858 +
7.1859 + marker_x, marker_y = getPositionForCentrePoint(
7.1860 + getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude,
7.1861 + map_x_scale, map_y_scale),
7.1862 + map_x_scale, map_y_scale)
7.1863 +
7.1864 + # Add the map marker.
7.1865 +
7.1866 + append(self.writeMapMarker(marker_x, marker_y, map_x_scale, map_y_scale, location, events))
7.1867 +
7.1868 + append(fmt.number_list(on=0))
7.1869 + append(fmt.div(on=0))
7.1870 + append(fmt.table_cell(on=0))
7.1871 + append(fmt.table_row(on=0))
7.1872 +
7.1873 + # Write unpositioned events.
7.1874 +
7.1875 + if unpositioned_events:
7.1876 + unpositioned_identifier = "unpositioned-%s" % self.getIdentifier()
7.1877 +
7.1878 + append(fmt.table_row(on=1, css_class="event-map-unpositioned",
7.1879 + id=unpositioned_identifier))
7.1880 + append(fmt.table_cell(on=1))
7.1881 +
7.1882 + append(fmt.heading(on=1, depth=2))
7.1883 + append(fmt.text(_("Events not shown on the map")))
7.1884 + append(fmt.heading(on=0, depth=2))
7.1885 +
7.1886 + # Show and hide controls.
7.1887 +
7.1888 + append(fmt.div(on=1, css_class="event-map-show-control"))
7.1889 + append(fmt.anchorlink(on=1, name=unpositioned_identifier))
7.1890 + append(fmt.text(_("Show unpositioned events")))
7.1891 + append(fmt.anchorlink(on=0))
7.1892 + append(fmt.div(on=0))
7.1893 +
7.1894 + append(fmt.div(on=1, css_class="event-map-hide-control"))
7.1895 + append(fmt.anchorlink(on=1, name=map_identifier))
7.1896 + append(fmt.text(_("Hide unpositioned events")))
7.1897 + append(fmt.anchorlink(on=0))
7.1898 + append(fmt.div(on=0))
7.1899 +
7.1900 + append(self.writeMapEventSummaries(unpositioned_events))
7.1901 +
7.1902 + # End of map view output.
7.1903 +
7.1904 + append(fmt.table_cell(on=0))
7.1905 + append(fmt.table_row(on=0))
7.1906 + append(fmt.table(on=0))
7.1907 + append(fmt.div(on=0))
7.1908 +
7.1909 + # Output a list.
7.1910 +
7.1911 + elif self.mode == "list":
7.1912 +
7.1913 + # Start of list view output.
7.1914 +
7.1915 + append(fmt.bullet_list(on=1, attr={"class" : "event-listings"}))
7.1916 +
7.1917 + # Output a list.
7.1918 +
7.1919 + for period in self.first.until(self.last):
7.1920 +
7.1921 + append(fmt.listitem(on=1, attr={"class" : "event-listings-period"}))
7.1922 + append(fmt.div(on=1, attr={"class" : "event-listings-heading"}))
7.1923 +
7.1924 + # Either write a date heading or produce links for navigable
7.1925 + # calendars.
7.1926 +
7.1927 + append(self.writeDateHeading(period))
7.1928 +
7.1929 + append(fmt.div(on=0))
7.1930 +
7.1931 + append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"}))
7.1932 +
7.1933 + # Show the events in order.
7.1934 +
7.1935 + events_in_period = getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period))
7.1936 + events_in_period.sort(sort_start_first)
7.1937 +
7.1938 + for event in events_in_period:
7.1939 + event_page = event.getPage()
7.1940 + event_details = event.getDetails()
7.1941 + event_summary = event.getSummary(self.parent_name)
7.1942 +
7.1943 + append(fmt.listitem(on=1, attr={"class" : "event-listing"}))
7.1944 +
7.1945 + # Link to the page using the summary.
7.1946 +
7.1947 + append(fmt.paragraph(on=1))
7.1948 + append(event.linkToEvent(request, event_summary))
7.1949 + append(fmt.paragraph(on=0))
7.1950 +
7.1951 + # Start and end dates.
7.1952 +
7.1953 + append(fmt.paragraph(on=1))
7.1954 + append(fmt.span(on=1))
7.1955 + append(fmt.text(str(event_details["start"])))
7.1956 + append(fmt.span(on=0))
7.1957 + append(fmt.text(" - "))
7.1958 + append(fmt.span(on=1))
7.1959 + append(fmt.text(str(event_details["end"])))
7.1960 + append(fmt.span(on=0))
7.1961 + append(fmt.paragraph(on=0))
7.1962 +
7.1963 + # Location.
7.1964 +
7.1965 + if event_details.has_key("location"):
7.1966 + append(fmt.paragraph(on=1))
7.1967 + append(event_page.formatText(event_details["location"], fmt))
7.1968 + append(fmt.paragraph(on=1))
7.1969 +
7.1970 + # Topics.
7.1971 +
7.1972 + if event_details.has_key("topics") or event_details.has_key("categories"):
7.1973 + append(fmt.bullet_list(on=1, attr={"class" : "event-topics"}))
7.1974 +
7.1975 + for topic in event_details.get("topics") or event_details.get("categories") or []:
7.1976 + append(fmt.listitem(on=1))
7.1977 + append(event_page.formatText(topic, fmt))
7.1978 + append(fmt.listitem(on=0))
7.1979 +
7.1980 + append(fmt.bullet_list(on=0))
7.1981 +
7.1982 + append(fmt.listitem(on=0))
7.1983 +
7.1984 + append(fmt.bullet_list(on=0))
7.1985 +
7.1986 + # End of list view output.
7.1987 +
7.1988 + append(fmt.bullet_list(on=0))
7.1989 +
7.1990 + # Output a month calendar. This shows month-by-month data.
7.1991 +
7.1992 + elif self.mode == "calendar":
7.1993 +
7.1994 + # Visit all months in the requested range, or across known events.
7.1995 +
7.1996 + for month in self.first.months_until(self.last):
7.1997 +
7.1998 + # Output a month.
7.1999 +
7.2000 + append(fmt.table(on=1, attrs={"tableclass" : "event-month"}))
7.2001 +
7.2002 + # Either write a month heading or produce links for navigable
7.2003 + # calendars.
7.2004 +
7.2005 + append(self.writeMonthTableHeading(month))
7.2006 +
7.2007 + # Weekday headings.
7.2008 +
7.2009 + append(self.writeWeekdayHeadings())
7.2010 +
7.2011 + # Process the days of the month.
7.2012 +
7.2013 + start_weekday, number_of_days = month.month_properties()
7.2014 +
7.2015 + # The start weekday is the weekday of day number 1.
7.2016 + # Find the first day of the week, counting from below zero, if
7.2017 + # necessary, in order to land on the first day of the month as
7.2018 + # day number 1.
7.2019 +
7.2020 + first_day = 1 - start_weekday
7.2021 +
7.2022 + while first_day <= number_of_days:
7.2023 +
7.2024 + # Find events in this week and determine how to mark them on the
7.2025 + # calendar.
7.2026 +
7.2027 + week_start = month.as_date(max(first_day, 1))
7.2028 + week_end = month.as_date(min(first_day + 6, number_of_days))
7.2029 +
7.2030 + full_coverage, week_slots = getCoverage(
7.2031 + getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end)))
7.2032 +
7.2033 + # Output a week, starting with the day numbers.
7.2034 +
7.2035 + append(self.writeDayNumbers(first_day, number_of_days, month, full_coverage))
7.2036 +
7.2037 + # Either generate empty days...
7.2038 +
7.2039 + if not week_slots:
7.2040 + append(self.writeEmptyWeek(first_day, number_of_days, month))
7.2041 +
7.2042 + # Or generate each set of scheduled events...
7.2043 +
7.2044 + else:
7.2045 + append(self.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots))
7.2046 +
7.2047 + # Process the next week...
7.2048 +
7.2049 + first_day += 7
7.2050 +
7.2051 + # End of month.
7.2052 +
7.2053 + append(fmt.table(on=0))
7.2054 +
7.2055 + # Output a day view.
7.2056 +
7.2057 + elif self.mode == "day":
7.2058 +
7.2059 + # Visit all days in the requested range, or across known events.
7.2060 +
7.2061 + for date in self.first.days_until(self.last):
7.2062 +
7.2063 + append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"}))
7.2064 +
7.2065 + full_coverage, day_slots = getCoverage(
7.2066 + getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime")
7.2067 +
7.2068 + # Work out how many columns the day title will need.
7.2069 + # Include spacers after the scale and each event column.
7.2070 +
7.2071 + colspan = sum(map(len, day_slots.values())) * 2 + 2
7.2072 +
7.2073 + append(self.writeDayTableHeading(date, colspan))
7.2074 +
7.2075 + # Either generate empty days...
7.2076 +
7.2077 + if not day_slots:
7.2078 + append(self.writeEmptyDay(date))
7.2079 +
7.2080 + # Or generate each set of scheduled events...
7.2081 +
7.2082 + else:
7.2083 + append(self.writeDaySlots(date, full_coverage, day_slots))
7.2084 +
7.2085 + # End of day.
7.2086 +
7.2087 + append(fmt.table(on=0))
7.2088 +
7.2089 + # Output view controls.
7.2090 +
7.2091 + append(fmt.div(on=1, css_class="event-controls"))
7.2092 + append(self.writeViewControls())
7.2093 + append(fmt.div(on=0))
7.2094 +
7.2095 + # Close the calendar region.
7.2096 +
7.2097 + append(fmt.div(on=0))
7.2098 +
7.2099 + # Add any scripts.
7.2100 +
7.2101 + if isinstance(fmt, request.html_formatter.__class__):
7.2102 + append(self.update_script)
7.2103 +
7.2104 + return ''.join(output)
7.2105 +
7.2106 + update_script = """\
7.2107 +<script type="text/javascript">
7.2108 +function replaceCalendar(name, url) {
7.2109 + var calendar = document.getElementById(name);
7.2110 +
7.2111 + if (calendar == null) {
7.2112 + return true;
7.2113 + }
7.2114 +
7.2115 + var xmlhttp = new XMLHttpRequest();
7.2116 + xmlhttp.open("GET", url, false);
7.2117 + xmlhttp.send(null);
7.2118 +
7.2119 + var newCalendar = xmlhttp.responseText;
7.2120 +
7.2121 + if (newCalendar != null) {
7.2122 + calendar.innerHTML = newCalendar;
7.2123 + return false;
7.2124 + }
7.2125 +
7.2126 + return true;
7.2127 +}
7.2128 +</script>
7.2129 +"""
7.2130 +
7.2131 +# vim: tabstop=4 expandtab shiftwidth=4