paul@347 | 1 | # -*- coding: iso-8859-1 -*- |
paul@347 | 2 | """ |
paul@347 | 3 | MoinMoin - EventAggregator user interface library |
paul@347 | 4 | |
paul@347 | 5 | @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk> |
paul@347 | 6 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@347 | 7 | """ |
paul@347 | 8 | |
paul@347 | 9 | from EventAggregatorSupport.Filter import getCalendarPeriod, getEventsInPeriod, \ |
paul@347 | 10 | getCoverage, getCoverageScale |
paul@347 | 11 | from EventAggregatorSupport.Locations import getMapsPage, getLocationsPage, Location |
paul@347 | 12 | |
paul@347 | 13 | from GeneralSupport import sort_none_first |
paul@347 | 14 | from LocationSupport import getMapReference, getNormalisedLocation, \ |
paul@347 | 15 | getPositionForCentrePoint, getPositionForReference |
paul@347 | 16 | from MoinDateSupport import getFullDateLabel, getFullMonthLabel |
paul@347 | 17 | from MoinSupport import * |
paul@347 | 18 | from ViewSupport import getColour, getBlackOrWhite |
paul@347 | 19 | |
paul@347 | 20 | from MoinMoin.Page import Page |
paul@347 | 21 | from MoinMoin.action import AttachFile |
paul@347 | 22 | from MoinMoin import wikiutil |
paul@347 | 23 | |
paul@347 | 24 | try: |
paul@347 | 25 | set |
paul@347 | 26 | except NameError: |
paul@347 | 27 | from sets import Set as set |
paul@347 | 28 | |
paul@347 | 29 | # Utility functions. |
paul@347 | 30 | |
paul@347 | 31 | def to_plain_text(s, request): |
paul@347 | 32 | |
paul@347 | 33 | "Convert 's' to plain text." |
paul@347 | 34 | |
paul@347 | 35 | fmt = getFormatterClass(request, "plain")(request) |
paul@347 | 36 | fmt.setPage(request.page) |
paul@347 | 37 | return formatText(s, request, fmt) |
paul@347 | 38 | |
paul@347 | 39 | def getLocationPosition(location, locations): |
paul@347 | 40 | |
paul@347 | 41 | """ |
paul@347 | 42 | Attempt to return the position of the given 'location' using the 'locations' |
paul@347 | 43 | dictionary provided. If no position can be found, return a latitude of None |
paul@347 | 44 | and a longitude of None. |
paul@347 | 45 | """ |
paul@347 | 46 | |
paul@347 | 47 | latitude, longitude = None, None |
paul@347 | 48 | |
paul@347 | 49 | if location is not None: |
paul@347 | 50 | try: |
paul@347 | 51 | latitude, longitude = map(getMapReference, locations[location].split()) |
paul@347 | 52 | except (KeyError, ValueError): |
paul@347 | 53 | pass |
paul@347 | 54 | |
paul@347 | 55 | return latitude, longitude |
paul@347 | 56 | |
paul@347 | 57 | # Event sorting. |
paul@347 | 58 | |
paul@347 | 59 | def sort_start_first(x, y): |
paul@347 | 60 | x_ts = x.as_limits() |
paul@347 | 61 | if x_ts is not None: |
paul@347 | 62 | x_start, x_end = x_ts |
paul@347 | 63 | y_ts = y.as_limits() |
paul@347 | 64 | if y_ts is not None: |
paul@347 | 65 | y_start, y_end = y_ts |
paul@347 | 66 | start_order = cmp(x_start, y_start) |
paul@347 | 67 | if start_order == 0: |
paul@347 | 68 | return cmp(x_end, y_end) |
paul@347 | 69 | else: |
paul@347 | 70 | return start_order |
paul@347 | 71 | return 0 |
paul@347 | 72 | |
paul@347 | 73 | # User interface abstractions. |
paul@347 | 74 | |
paul@347 | 75 | class View: |
paul@347 | 76 | |
paul@347 | 77 | "A view of the event calendar." |
paul@347 | 78 | |
paul@347 | 79 | def __init__(self, page, calendar_name, |
paul@347 | 80 | raw_calendar_start, raw_calendar_end, |
paul@347 | 81 | original_calendar_start, original_calendar_end, |
paul@347 | 82 | calendar_start, calendar_end, |
paul@347 | 83 | wider_calendar_start, wider_calendar_end, |
paul@347 | 84 | first, last, category_names, remote_sources, search_pattern, template_name, |
paul@352 | 85 | parent_name, mode, raw_resolution, resolution, name_usage, map_name): |
paul@347 | 86 | |
paul@347 | 87 | """ |
paul@347 | 88 | Initialise the view with the current 'page', a 'calendar_name' (which |
paul@347 | 89 | may be None), the 'raw_calendar_start' and 'raw_calendar_end' (which |
paul@347 | 90 | are the actual start and end values provided by the request), the |
paul@347 | 91 | calculated 'original_calendar_start' and 'original_calendar_end' (which |
paul@347 | 92 | are the result of calculating the calendar's limits from the raw start |
paul@347 | 93 | and end values), the requested, calculated 'calendar_start' and |
paul@347 | 94 | 'calendar_end' (which may involve different start and end values due to |
paul@347 | 95 | navigation in the user interface), and the requested |
paul@347 | 96 | 'wider_calendar_start' and 'wider_calendar_end' (which indicate a wider |
paul@347 | 97 | view used when navigating out of the day view), along with the 'first' |
paul@347 | 98 | and 'last' months of event coverage. |
paul@347 | 99 | |
paul@347 | 100 | The additional 'category_names', 'remote_sources', 'search_pattern', |
paul@347 | 101 | 'template_name', 'parent_name' and 'mode' parameters are used to |
paul@347 | 102 | configure the links employed by the view. |
paul@347 | 103 | |
paul@352 | 104 | The 'raw_resolution' is used to parameterise download links, whereas the |
paul@352 | 105 | 'resolution' affects the view for certain modes and is also used to |
paul@347 | 106 | parameterise links. |
paul@347 | 107 | |
paul@347 | 108 | The 'name_usage' parameter controls how names are shown on calendar mode |
paul@347 | 109 | events, such as how often labels are repeated. |
paul@347 | 110 | |
paul@347 | 111 | The 'map_name' parameter provides the name of a map to be used in the |
paul@347 | 112 | map mode. |
paul@347 | 113 | """ |
paul@347 | 114 | |
paul@347 | 115 | self.page = page |
paul@347 | 116 | self.calendar_name = calendar_name |
paul@347 | 117 | self.raw_calendar_start = raw_calendar_start |
paul@347 | 118 | self.raw_calendar_end = raw_calendar_end |
paul@347 | 119 | self.original_calendar_start = original_calendar_start |
paul@347 | 120 | self.original_calendar_end = original_calendar_end |
paul@347 | 121 | self.calendar_start = calendar_start |
paul@347 | 122 | self.calendar_end = calendar_end |
paul@347 | 123 | self.wider_calendar_start = wider_calendar_start |
paul@347 | 124 | self.wider_calendar_end = wider_calendar_end |
paul@347 | 125 | self.template_name = template_name |
paul@347 | 126 | self.parent_name = parent_name |
paul@347 | 127 | self.mode = mode |
paul@352 | 128 | self.raw_resolution = raw_resolution |
paul@347 | 129 | self.resolution = resolution |
paul@347 | 130 | self.name_usage = name_usage |
paul@347 | 131 | self.map_name = map_name |
paul@347 | 132 | |
paul@347 | 133 | # Search-related parameters for links. |
paul@347 | 134 | |
paul@347 | 135 | self.category_name_parameters = "&".join([("category=%s" % name) for name in category_names]) |
paul@347 | 136 | self.remote_source_parameters = "&".join([("source=%s" % source) for source in remote_sources]) |
paul@347 | 137 | self.search_pattern = search_pattern |
paul@347 | 138 | |
paul@347 | 139 | # Calculate the duration in terms of the highest common unit of time. |
paul@347 | 140 | |
paul@347 | 141 | self.first = first |
paul@347 | 142 | self.last = last |
paul@347 | 143 | self.duration = abs(last - first) + 1 |
paul@347 | 144 | |
paul@347 | 145 | if self.calendar_name: |
paul@347 | 146 | |
paul@347 | 147 | # Store the view parameters. |
paul@347 | 148 | |
paul@347 | 149 | self.previous_start = first.previous() |
paul@347 | 150 | self.next_start = first.next() |
paul@347 | 151 | self.previous_end = last.previous() |
paul@347 | 152 | self.next_end = last.next() |
paul@347 | 153 | |
paul@347 | 154 | self.previous_set_start = first.update(-self.duration) |
paul@347 | 155 | self.next_set_start = first.update(self.duration) |
paul@347 | 156 | self.previous_set_end = last.update(-self.duration) |
paul@347 | 157 | self.next_set_end = last.update(self.duration) |
paul@347 | 158 | |
paul@347 | 159 | def getIdentifier(self): |
paul@347 | 160 | |
paul@347 | 161 | "Return a unique identifier to be used to refer to this view." |
paul@347 | 162 | |
paul@347 | 163 | # NOTE: Nasty hack to get a unique identifier if no name is given. |
paul@347 | 164 | |
paul@347 | 165 | return self.calendar_name or str(id(self)) |
paul@347 | 166 | |
paul@347 | 167 | def getQualifiedParameterName(self, argname): |
paul@347 | 168 | |
paul@347 | 169 | "Return the 'argname' qualified using the calendar name." |
paul@347 | 170 | |
paul@347 | 171 | return getQualifiedParameterName(self.calendar_name, argname) |
paul@347 | 172 | |
paul@347 | 173 | def getDateQueryString(self, argname, date, prefix=1): |
paul@347 | 174 | |
paul@347 | 175 | """ |
paul@347 | 176 | Return a query string fragment for the given 'argname', referring to the |
paul@347 | 177 | month given by the specified 'year_month' object, appropriate for this |
paul@347 | 178 | calendar. |
paul@347 | 179 | |
paul@347 | 180 | If 'prefix' is specified and set to a false value, the parameters in the |
paul@347 | 181 | query string will not be calendar-specific, but could be used with the |
paul@347 | 182 | summary action. |
paul@347 | 183 | """ |
paul@347 | 184 | |
paul@347 | 185 | suffixes = ["year", "month", "day"] |
paul@347 | 186 | |
paul@347 | 187 | if date is not None: |
paul@347 | 188 | args = [] |
paul@347 | 189 | for suffix, value in zip(suffixes, date.as_tuple()): |
paul@347 | 190 | suffixed_argname = "%s-%s" % (argname, suffix) |
paul@347 | 191 | if prefix: |
paul@347 | 192 | suffixed_argname = self.getQualifiedParameterName(suffixed_argname) |
paul@347 | 193 | args.append("%s=%s" % (suffixed_argname, value)) |
paul@347 | 194 | return "&".join(args) |
paul@347 | 195 | else: |
paul@347 | 196 | return "" |
paul@347 | 197 | |
paul@347 | 198 | def getRawDateQueryString(self, argname, date, prefix=1): |
paul@347 | 199 | |
paul@347 | 200 | """ |
paul@347 | 201 | Return a query string fragment for the given 'argname', referring to the |
paul@347 | 202 | date given by the specified 'date' value, appropriate for this |
paul@347 | 203 | calendar. |
paul@347 | 204 | |
paul@347 | 205 | If 'prefix' is specified and set to a false value, the parameters in the |
paul@347 | 206 | query string will not be calendar-specific, but could be used with the |
paul@347 | 207 | summary action. |
paul@347 | 208 | """ |
paul@347 | 209 | |
paul@347 | 210 | if date is not None: |
paul@347 | 211 | if prefix: |
paul@347 | 212 | argname = self.getQualifiedParameterName(argname) |
paul@348 | 213 | return "%s=%s" % (argname, wikiutil.url_quote(date)) |
paul@347 | 214 | else: |
paul@347 | 215 | return "" |
paul@347 | 216 | |
paul@347 | 217 | def getNavigationLink(self, start, end, mode=None, resolution=None, wider_start=None, wider_end=None): |
paul@347 | 218 | |
paul@347 | 219 | """ |
paul@347 | 220 | Return a query string fragment for navigation to a view showing months |
paul@347 | 221 | from 'start' to 'end' inclusive, with the optional 'mode' indicating the |
paul@347 | 222 | view style and the optional 'resolution' indicating the resolution of a |
paul@347 | 223 | view, if configurable. |
paul@347 | 224 | |
paul@347 | 225 | If the 'wider_start' and 'wider_end' arguments are given, parameters |
paul@347 | 226 | indicating a wider calendar view (when returning from a day view, for |
paul@347 | 227 | example) will be included in the link. |
paul@347 | 228 | """ |
paul@347 | 229 | |
paul@347 | 230 | return "%s&%s&%s=%s&%s=%s&%s&%s" % ( |
paul@347 | 231 | self.getRawDateQueryString("start", start), |
paul@347 | 232 | self.getRawDateQueryString("end", end), |
paul@347 | 233 | self.getQualifiedParameterName("mode"), mode or self.mode, |
paul@347 | 234 | self.getQualifiedParameterName("resolution"), resolution or self.resolution, |
paul@347 | 235 | self.getRawDateQueryString("wider-start", wider_start), |
paul@347 | 236 | self.getRawDateQueryString("wider-end", wider_end), |
paul@347 | 237 | ) |
paul@347 | 238 | |
paul@347 | 239 | def getUpdateLink(self, start, end, mode=None, resolution=None, wider_start=None, wider_end=None): |
paul@347 | 240 | |
paul@347 | 241 | """ |
paul@347 | 242 | Return a query string fragment for navigation to a view showing months |
paul@347 | 243 | from 'start' to 'end' inclusive, with the optional 'mode' indicating the |
paul@347 | 244 | view style and the optional 'resolution' indicating the resolution of a |
paul@347 | 245 | view, if configurable. This link differs from the conventional |
paul@347 | 246 | navigation link in that it is sufficient to activate the update action |
paul@347 | 247 | and produce an updated region of the page without needing to locate and |
paul@347 | 248 | process the page or any macro invocation. |
paul@347 | 249 | |
paul@347 | 250 | If the 'wider_start' and 'wider_end' arguments are given, parameters |
paul@347 | 251 | indicating a wider calendar view (when returning from a day view, for |
paul@347 | 252 | example) will be included in the link. |
paul@347 | 253 | """ |
paul@347 | 254 | |
paul@347 | 255 | parameters = [ |
paul@347 | 256 | self.getRawDateQueryString("start", start, 0), |
paul@347 | 257 | self.getRawDateQueryString("end", end, 0), |
paul@347 | 258 | self.category_name_parameters, |
paul@347 | 259 | self.remote_source_parameters, |
paul@347 | 260 | self.getRawDateQueryString("wider-start", wider_start, 0), |
paul@347 | 261 | self.getRawDateQueryString("wider-end", wider_end, 0), |
paul@347 | 262 | ] |
paul@347 | 263 | |
paul@347 | 264 | pairs = [ |
paul@347 | 265 | ("calendar", self.calendar_name or ""), |
paul@347 | 266 | ("calendarstart", self.raw_calendar_start or ""), |
paul@347 | 267 | ("calendarend", self.raw_calendar_end or ""), |
paul@347 | 268 | ("mode", mode or self.mode), |
paul@347 | 269 | ("resolution", resolution or self.resolution), |
paul@352 | 270 | ("raw-resolution", self.raw_resolution), |
paul@347 | 271 | ("parent", self.parent_name or ""), |
paul@347 | 272 | ("template", self.template_name or ""), |
paul@347 | 273 | ("names", self.name_usage), |
paul@347 | 274 | ("map", self.map_name or ""), |
paul@347 | 275 | ("search", self.search_pattern or ""), |
paul@347 | 276 | ] |
paul@347 | 277 | |
paul@347 | 278 | url = self.page.url(self.page.request, |
paul@347 | 279 | "action=EventAggregatorUpdate&%s" % ( |
paul@348 | 280 | "&".join([("%s=%s" % (key, wikiutil.url_quote(value))) for (key, value) in pairs] + parameters) |
paul@347 | 281 | ), relative=True) |
paul@347 | 282 | |
paul@347 | 283 | return "return replaceCalendar('EventAggregator-%s', '%s')" % (self.getIdentifier(), url) |
paul@347 | 284 | |
paul@347 | 285 | def getNewEventLink(self, start): |
paul@347 | 286 | |
paul@347 | 287 | """ |
paul@347 | 288 | Return a query string activating the new event form, incorporating the |
paul@347 | 289 | calendar parameters, specialising the form for the given 'start' date or |
paul@347 | 290 | month. |
paul@347 | 291 | """ |
paul@347 | 292 | |
paul@347 | 293 | if start is not None: |
paul@347 | 294 | details = start.as_tuple() |
paul@347 | 295 | pairs = zip(["start-year=%d", "start-month=%d", "start-day=%d"], details) |
paul@347 | 296 | args = [(param % value) for (param, value) in pairs] |
paul@347 | 297 | args = "&".join(args) |
paul@347 | 298 | else: |
paul@347 | 299 | args = "" |
paul@347 | 300 | |
paul@347 | 301 | # Prepare navigation details for the calendar shown with the new event |
paul@347 | 302 | # form. |
paul@347 | 303 | |
paul@347 | 304 | navigation_link = self.getNavigationLink( |
paul@347 | 305 | self.calendar_start, self.calendar_end |
paul@347 | 306 | ) |
paul@347 | 307 | |
paul@347 | 308 | return "action=EventAggregatorNewEvent%s%s&template=%s&parent=%s&%s" % ( |
paul@347 | 309 | args and "&%s" % args, |
paul@347 | 310 | self.category_name_parameters and "&%s" % self.category_name_parameters, |
paul@347 | 311 | self.template_name, self.parent_name or "", |
paul@347 | 312 | navigation_link) |
paul@347 | 313 | |
paul@347 | 314 | def getFullDateLabel(self, date): |
paul@347 | 315 | return getFullDateLabel(self.page.request, date) |
paul@347 | 316 | |
paul@347 | 317 | def getFullMonthLabel(self, year_month): |
paul@347 | 318 | return getFullMonthLabel(self.page.request, year_month) |
paul@347 | 319 | |
paul@352 | 320 | def getFullLabel(self, arg, resolution): |
paul@352 | 321 | return resolution == "date" and self.getFullDateLabel(arg) or self.getFullMonthLabel(arg) |
paul@347 | 322 | |
paul@347 | 323 | def _getCalendarPeriod(self, start_label, end_label, default_label): |
paul@347 | 324 | |
paul@347 | 325 | """ |
paul@347 | 326 | Return a label describing a calendar period in terms of the given |
paul@347 | 327 | 'start_label' and 'end_label', with the 'default_label' being used where |
paul@347 | 328 | the supplied start and end labels fail to produce a meaningful label. |
paul@347 | 329 | """ |
paul@347 | 330 | |
paul@347 | 331 | output = [] |
paul@347 | 332 | append = output.append |
paul@347 | 333 | |
paul@347 | 334 | if start_label: |
paul@347 | 335 | append(start_label) |
paul@347 | 336 | if end_label and start_label != end_label: |
paul@347 | 337 | if output: |
paul@347 | 338 | append(" - ") |
paul@347 | 339 | append(end_label) |
paul@347 | 340 | return "".join(output) or default_label |
paul@347 | 341 | |
paul@347 | 342 | def getCalendarPeriod(self): |
paul@352 | 343 | |
paul@352 | 344 | "Return the period description for the shown calendar." |
paul@352 | 345 | |
paul@347 | 346 | _ = self.page.request.getText |
paul@347 | 347 | return self._getCalendarPeriod( |
paul@352 | 348 | self.calendar_start and self.getFullLabel(self.calendar_start, self.resolution), |
paul@352 | 349 | self.calendar_end and self.getFullLabel(self.calendar_end, self.resolution), |
paul@347 | 350 | _("All events") |
paul@347 | 351 | ) |
paul@347 | 352 | |
paul@347 | 353 | def getOriginalCalendarPeriod(self): |
paul@352 | 354 | |
paul@352 | 355 | "Return the period description for the originally specified calendar." |
paul@352 | 356 | |
paul@347 | 357 | _ = self.page.request.getText |
paul@347 | 358 | return self._getCalendarPeriod( |
paul@352 | 359 | self.original_calendar_start and self.getFullLabel(self.original_calendar_start, self.raw_resolution), |
paul@352 | 360 | self.original_calendar_end and self.getFullLabel(self.original_calendar_end, self.raw_resolution), |
paul@347 | 361 | _("All events") |
paul@347 | 362 | ) |
paul@347 | 363 | |
paul@347 | 364 | def getRawCalendarPeriod(self): |
paul@352 | 365 | |
paul@352 | 366 | "Return the raw period description for the calendar." |
paul@352 | 367 | |
paul@347 | 368 | _ = self.page.request.getText |
paul@347 | 369 | return self._getCalendarPeriod( |
paul@347 | 370 | self.raw_calendar_start, |
paul@347 | 371 | self.raw_calendar_end, |
paul@347 | 372 | _("No period specified") |
paul@347 | 373 | ) |
paul@347 | 374 | |
paul@347 | 375 | def writeDownloadControls(self): |
paul@347 | 376 | |
paul@347 | 377 | """ |
paul@347 | 378 | Return a representation of the download controls, featuring links for |
paul@347 | 379 | view, calendar and customised downloads and subscriptions. |
paul@347 | 380 | """ |
paul@347 | 381 | |
paul@347 | 382 | page = self.page |
paul@347 | 383 | request = page.request |
paul@347 | 384 | fmt = request.formatter |
paul@347 | 385 | _ = request.getText |
paul@347 | 386 | |
paul@347 | 387 | output = [] |
paul@347 | 388 | append = output.append |
paul@347 | 389 | |
paul@347 | 390 | # The full URL is needed for webcal links. |
paul@347 | 391 | |
paul@347 | 392 | full_url = "%s%s" % (request.getBaseURL(), getPathInfo(request)) |
paul@347 | 393 | |
paul@347 | 394 | # Generate the links. |
paul@347 | 395 | |
paul@352 | 396 | download_dialogue_link = "action=EventAggregatorSummary&parent=%s&search=%s%s%s" % ( |
paul@347 | 397 | self.parent_name or "", |
paul@347 | 398 | self.search_pattern or "", |
paul@347 | 399 | self.category_name_parameters and "&%s" % self.category_name_parameters, |
paul@347 | 400 | self.remote_source_parameters and "&%s" % self.remote_source_parameters |
paul@347 | 401 | ) |
paul@347 | 402 | download_all_link = download_dialogue_link + "&doit=1" |
paul@347 | 403 | download_link = download_all_link + ("&%s&%s" % ( |
paul@347 | 404 | self.getDateQueryString("start", self.calendar_start, prefix=0), |
paul@347 | 405 | self.getDateQueryString("end", self.calendar_end, prefix=0) |
paul@347 | 406 | )) |
paul@347 | 407 | |
paul@352 | 408 | # The entire calendar download uses the originally specified resolution |
paul@352 | 409 | # of the calendar as does the dialogue. The other link uses the current |
paul@352 | 410 | # resolution. |
paul@352 | 411 | |
paul@352 | 412 | download_dialogue_link += "&resolution=%s" % self.raw_resolution |
paul@352 | 413 | download_all_link += "&resolution=%s" % self.raw_resolution |
paul@352 | 414 | download_link += "&resolution=%s" % self.resolution |
paul@352 | 415 | |
paul@347 | 416 | # Subscription links just explicitly select the RSS format. |
paul@347 | 417 | |
paul@347 | 418 | subscribe_dialogue_link = download_dialogue_link + "&format=RSS" |
paul@347 | 419 | subscribe_all_link = download_all_link + "&format=RSS" |
paul@347 | 420 | subscribe_link = download_link + "&format=RSS" |
paul@347 | 421 | |
paul@347 | 422 | # Adjust the "download all" and "subscribe all" links if the calendar |
paul@347 | 423 | # has an inherent period associated with it. |
paul@347 | 424 | |
paul@347 | 425 | period_limits = [] |
paul@347 | 426 | |
paul@347 | 427 | if self.raw_calendar_start: |
paul@347 | 428 | period_limits.append("&%s" % |
paul@347 | 429 | self.getRawDateQueryString("start", self.raw_calendar_start, prefix=0) |
paul@347 | 430 | ) |
paul@347 | 431 | if self.raw_calendar_end: |
paul@347 | 432 | period_limits.append("&%s" % |
paul@347 | 433 | self.getRawDateQueryString("end", self.raw_calendar_end, prefix=0) |
paul@347 | 434 | ) |
paul@347 | 435 | |
paul@347 | 436 | period_limits = "".join(period_limits) |
paul@347 | 437 | |
paul@347 | 438 | download_dialogue_link += period_limits |
paul@347 | 439 | download_all_link += period_limits |
paul@347 | 440 | subscribe_dialogue_link += period_limits |
paul@347 | 441 | subscribe_all_link += period_limits |
paul@347 | 442 | |
paul@347 | 443 | # Pop-up descriptions of the downloadable calendars. |
paul@347 | 444 | |
paul@352 | 445 | shown_calendar_period = self.getCalendarPeriod() |
paul@347 | 446 | original_calendar_period = self.getOriginalCalendarPeriod() |
paul@347 | 447 | raw_calendar_period = self.getRawCalendarPeriod() |
paul@347 | 448 | |
paul@347 | 449 | # Write the controls. |
paul@347 | 450 | |
paul@347 | 451 | # Download controls. |
paul@347 | 452 | |
paul@371 | 453 | controls_target = "%s-controls" % self.getIdentifier() |
paul@371 | 454 | |
paul@371 | 455 | append(fmt.div(on=1, css_class="event-download-controls", id=controls_target)) |
paul@371 | 456 | |
paul@371 | 457 | download_target = "%s-download" % self.getIdentifier() |
paul@371 | 458 | |
paul@371 | 459 | append(fmt.span(on=1, css_class="event-download", id=download_target)) |
paul@373 | 460 | append(linkToPage(request, page, _("Download..."), anchor=download_target)) |
paul@347 | 461 | append(fmt.div(on=1, css_class="event-download-popup")) |
paul@347 | 462 | |
paul@347 | 463 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 464 | append(fmt.span(on=1, css_class="event-download-types")) |
paul@347 | 465 | append(fmt.span(on=1, css_class="event-download-webcal")) |
paul@347 | 466 | append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_link)) |
paul@347 | 467 | append(fmt.span(on=0)) |
paul@347 | 468 | append(fmt.span(on=1, css_class="event-download-http")) |
paul@368 | 469 | append(linkToPage(request, page, _("http"), download_link, title=_("Download this view in the browser"))) |
paul@347 | 470 | append(fmt.span(on=0)) |
paul@347 | 471 | append(fmt.span(on=0)) # end types |
paul@347 | 472 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 473 | append(fmt.text(_("Download this view"))) |
paul@347 | 474 | append(fmt.span(on=0)) # end label |
paul@347 | 475 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@352 | 476 | append(fmt.text(shown_calendar_period)) |
paul@347 | 477 | append(fmt.span(on=0)) |
paul@347 | 478 | append(fmt.div(on=0)) |
paul@347 | 479 | |
paul@347 | 480 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 481 | append(fmt.span(on=1, css_class="event-download-types")) |
paul@347 | 482 | append(fmt.span(on=1, css_class="event-download-webcal")) |
paul@347 | 483 | append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_all_link)) |
paul@347 | 484 | append(fmt.span(on=0)) |
paul@347 | 485 | append(fmt.span(on=1, css_class="event-download-http")) |
paul@368 | 486 | append(linkToPage(request, page, _("http"), download_all_link, title=_("Download this calendar in the browser"))) |
paul@347 | 487 | append(fmt.span(on=0)) |
paul@347 | 488 | append(fmt.span(on=0)) # end types |
paul@347 | 489 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 490 | append(fmt.text(_("Download this calendar"))) |
paul@347 | 491 | append(fmt.span(on=0)) # end label |
paul@347 | 492 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@347 | 493 | append(fmt.text(original_calendar_period)) |
paul@347 | 494 | append(fmt.span(on=0)) |
paul@347 | 495 | append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@347 | 496 | append(fmt.text(raw_calendar_period)) |
paul@347 | 497 | append(fmt.span(on=0)) |
paul@347 | 498 | append(fmt.div(on=0)) |
paul@347 | 499 | |
paul@347 | 500 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 501 | append(fmt.span(on=1, css_class="event-download-link")) |
paul@347 | 502 | append(linkToPage(request, page, _("Edit download options..."), download_dialogue_link)) |
paul@347 | 503 | append(fmt.span(on=0)) # end label |
paul@347 | 504 | append(fmt.div(on=0)) |
paul@347 | 505 | |
paul@374 | 506 | append(fmt.div(on=1, css_class="event-download-item focus-only")) |
paul@371 | 507 | append(fmt.span(on=1, css_class="event-download-link")) |
paul@373 | 508 | append(linkToPage(request, page, _("Cancel"), anchor=controls_target)) |
paul@371 | 509 | append(fmt.span(on=0)) # end label |
paul@371 | 510 | append(fmt.div(on=0)) |
paul@371 | 511 | |
paul@347 | 512 | append(fmt.div(on=0)) # end of pop-up |
paul@347 | 513 | append(fmt.span(on=0)) # end of download |
paul@347 | 514 | |
paul@347 | 515 | # Subscription controls. |
paul@347 | 516 | |
paul@371 | 517 | subscribe_target = "%s-subscribe" % self.getIdentifier() |
paul@371 | 518 | |
paul@371 | 519 | append(fmt.span(on=1, css_class="event-download", id=subscribe_target)) |
paul@373 | 520 | append(linkToPage(request, page, _("Subscribe..."), anchor=subscribe_target)) |
paul@347 | 521 | append(fmt.div(on=1, css_class="event-download-popup")) |
paul@347 | 522 | |
paul@347 | 523 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 524 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 525 | append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link)) |
paul@347 | 526 | append(fmt.span(on=0)) # end label |
paul@347 | 527 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@352 | 528 | append(fmt.text(shown_calendar_period)) |
paul@347 | 529 | append(fmt.span(on=0)) |
paul@347 | 530 | append(fmt.div(on=0)) |
paul@347 | 531 | |
paul@347 | 532 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 533 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 534 | append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link)) |
paul@347 | 535 | append(fmt.span(on=0)) # end label |
paul@347 | 536 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@347 | 537 | append(fmt.text(original_calendar_period)) |
paul@347 | 538 | append(fmt.span(on=0)) |
paul@347 | 539 | append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@347 | 540 | append(fmt.text(raw_calendar_period)) |
paul@347 | 541 | append(fmt.span(on=0)) |
paul@347 | 542 | append(fmt.div(on=0)) |
paul@347 | 543 | |
paul@347 | 544 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 545 | append(fmt.span(on=1, css_class="event-download-link")) |
paul@347 | 546 | append(linkToPage(request, page, _("Edit subscription options..."), subscribe_dialogue_link)) |
paul@347 | 547 | append(fmt.span(on=0)) # end label |
paul@347 | 548 | append(fmt.div(on=0)) |
paul@347 | 549 | |
paul@374 | 550 | append(fmt.div(on=1, css_class="event-download-item focus-only")) |
paul@371 | 551 | append(fmt.span(on=1, css_class="event-download-link")) |
paul@373 | 552 | append(linkToPage(request, page, _("Cancel"), anchor=controls_target)) |
paul@371 | 553 | append(fmt.span(on=0)) # end label |
paul@371 | 554 | append(fmt.div(on=0)) |
paul@371 | 555 | |
paul@347 | 556 | append(fmt.div(on=0)) # end of pop-up |
paul@347 | 557 | append(fmt.span(on=0)) # end of download |
paul@347 | 558 | |
paul@347 | 559 | append(fmt.div(on=0)) # end of controls |
paul@347 | 560 | |
paul@347 | 561 | return "".join(output) |
paul@347 | 562 | |
paul@347 | 563 | def writeViewControls(self): |
paul@347 | 564 | |
paul@347 | 565 | """ |
paul@347 | 566 | Return a representation of the view mode controls, permitting viewing of |
paul@347 | 567 | aggregated events in calendar, list or table form. |
paul@347 | 568 | """ |
paul@347 | 569 | |
paul@347 | 570 | page = self.page |
paul@347 | 571 | request = page.request |
paul@347 | 572 | fmt = request.formatter |
paul@347 | 573 | _ = request.getText |
paul@347 | 574 | |
paul@347 | 575 | output = [] |
paul@347 | 576 | append = output.append |
paul@347 | 577 | |
paul@347 | 578 | # For day view links to other views, the wider view parameters should |
paul@347 | 579 | # be used in order to be able to return to those other views. |
paul@347 | 580 | |
paul@347 | 581 | specific_start = self.calendar_start |
paul@347 | 582 | specific_end = self.calendar_end |
paul@347 | 583 | |
paul@355 | 584 | multiday = self.resolution == "date" and len(specific_start.days_until(specific_end)) > 1 |
paul@355 | 585 | |
paul@347 | 586 | start = self.wider_calendar_start or self.original_calendar_start and specific_start |
paul@347 | 587 | end = self.wider_calendar_end or self.original_calendar_end and specific_end |
paul@347 | 588 | |
paul@347 | 589 | help_page = Page(request, "HelpOnEventAggregator") |
paul@347 | 590 | |
paul@347 | 591 | calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month") |
paul@347 | 592 | calendar_update_link = self.getUpdateLink(start and start.as_month(), end and end.as_month(), "calendar", "month") |
paul@347 | 593 | list_link = self.getNavigationLink(start, end, "list", "month") |
paul@347 | 594 | list_update_link = self.getUpdateLink(start, end, "list", "month") |
paul@347 | 595 | table_link = self.getNavigationLink(start, end, "table", "month") |
paul@347 | 596 | table_update_link = self.getUpdateLink(start, end, "table", "month") |
paul@347 | 597 | map_link = self.getNavigationLink(start, end, "map", "month") |
paul@347 | 598 | map_update_link = self.getUpdateLink(start, end, "map", "month") |
paul@347 | 599 | |
paul@347 | 600 | # Specific links permit date-level navigation. |
paul@347 | 601 | |
paul@347 | 602 | specific_day_link = self.getNavigationLink(specific_start, specific_end, "day", wider_start=start, wider_end=end) |
paul@347 | 603 | specific_day_update_link = self.getUpdateLink(specific_start, specific_end, "day", wider_start=start, wider_end=end) |
paul@347 | 604 | specific_list_link = self.getNavigationLink(specific_start, specific_end, "list", wider_start=start, wider_end=end) |
paul@347 | 605 | specific_list_update_link = self.getUpdateLink(specific_start, specific_end, "list", wider_start=start, wider_end=end) |
paul@347 | 606 | specific_table_link = self.getNavigationLink(specific_start, specific_end, "table", wider_start=start, wider_end=end) |
paul@347 | 607 | specific_table_update_link = self.getUpdateLink(specific_start, specific_end, "table", wider_start=start, wider_end=end) |
paul@347 | 608 | specific_map_link = self.getNavigationLink(specific_start, specific_end, "map", wider_start=start, wider_end=end) |
paul@347 | 609 | specific_map_update_link = self.getUpdateLink(specific_start, specific_end, "map", wider_start=start, wider_end=end) |
paul@347 | 610 | |
paul@347 | 611 | new_event_link = self.getNewEventLink(start) |
paul@347 | 612 | |
paul@347 | 613 | # Write the controls. |
paul@347 | 614 | |
paul@347 | 615 | append(fmt.div(on=1, css_class="event-view-controls")) |
paul@347 | 616 | |
paul@347 | 617 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 618 | append(linkToPage(request, help_page, _("Help"))) |
paul@347 | 619 | append(fmt.span(on=0)) |
paul@347 | 620 | |
paul@347 | 621 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 622 | append(linkToPage(request, page, _("New event"), new_event_link)) |
paul@347 | 623 | append(fmt.span(on=0)) |
paul@347 | 624 | |
paul@347 | 625 | if self.mode != "calendar": |
paul@355 | 626 | view_label = self.resolution == "date" and \ |
paul@355 | 627 | (multiday and _("View days in calendar") or _("View day in calendar")) or \ |
paul@355 | 628 | _("View as calendar") |
paul@347 | 629 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 630 | append(linkToPage(request, page, view_label, calendar_link, onclick=calendar_update_link)) |
paul@347 | 631 | append(fmt.span(on=0)) |
paul@347 | 632 | |
paul@347 | 633 | if self.resolution == "date" and self.mode != "day": |
paul@355 | 634 | view_label = multiday and _("View days as calendar") or _("View day as calendar") |
paul@347 | 635 | append(fmt.span(on=1, css_class="event-view")) |
paul@355 | 636 | append(linkToPage(request, page, view_label, specific_day_link, onclick=specific_day_update_link)) |
paul@347 | 637 | append(fmt.span(on=0)) |
paul@347 | 638 | |
paul@347 | 639 | if self.resolution != "date" and self.mode != "list" or self.resolution == "date": |
paul@355 | 640 | view_label = self.resolution == "date" and \ |
paul@355 | 641 | (multiday and _("View days in list") or _("View day in list")) or \ |
paul@355 | 642 | _("View as list") |
paul@347 | 643 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 644 | append(linkToPage(request, page, view_label, list_link, onclick=list_update_link)) |
paul@347 | 645 | append(fmt.span(on=0)) |
paul@347 | 646 | |
paul@347 | 647 | if self.resolution == "date" and self.mode != "list": |
paul@355 | 648 | view_label = multiday and _("View days as list") or _("View day as list") |
paul@347 | 649 | append(fmt.span(on=1, css_class="event-view")) |
paul@355 | 650 | append(linkToPage(request, page, view_label, specific_list_link, onclick=specific_list_update_link)) |
paul@347 | 651 | append(fmt.span(on=0)) |
paul@347 | 652 | |
paul@347 | 653 | if self.resolution != "date" and self.mode != "table" or self.resolution == "date": |
paul@355 | 654 | view_label = self.resolution == "date" and \ |
paul@355 | 655 | (multiday and _("View days in table") or _("View day in table")) or \ |
paul@355 | 656 | _("View as table") |
paul@347 | 657 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 658 | append(linkToPage(request, page, view_label, table_link, onclick=table_update_link)) |
paul@347 | 659 | append(fmt.span(on=0)) |
paul@347 | 660 | |
paul@347 | 661 | if self.resolution == "date" and self.mode != "table": |
paul@355 | 662 | view_label = multiday and _("View days as table") or _("View day as table") |
paul@347 | 663 | append(fmt.span(on=1, css_class="event-view")) |
paul@355 | 664 | append(linkToPage(request, page, view_label, specific_table_link, onclick=specific_table_update_link)) |
paul@347 | 665 | append(fmt.span(on=0)) |
paul@347 | 666 | |
paul@347 | 667 | if self.map_name: |
paul@347 | 668 | if self.resolution != "date" and self.mode != "map" or self.resolution == "date": |
paul@355 | 669 | view_label = self.resolution == "date" and \ |
paul@355 | 670 | (multiday and _("View days in map") or _("View day in map")) or \ |
paul@355 | 671 | _("View as map") |
paul@347 | 672 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 673 | append(linkToPage(request, page, view_label, map_link, onclick=map_update_link)) |
paul@347 | 674 | append(fmt.span(on=0)) |
paul@347 | 675 | |
paul@347 | 676 | if self.resolution == "date" and self.mode != "map": |
paul@355 | 677 | view_label = multiday and _("View days as map") or _("View day as map") |
paul@347 | 678 | append(fmt.span(on=1, css_class="event-view")) |
paul@355 | 679 | append(linkToPage(request, page, view_label, specific_map_link, onclick=specific_map_update_link)) |
paul@347 | 680 | append(fmt.span(on=0)) |
paul@347 | 681 | |
paul@347 | 682 | append(fmt.div(on=0)) |
paul@347 | 683 | |
paul@347 | 684 | return "".join(output) |
paul@347 | 685 | |
paul@347 | 686 | def writeMapHeading(self): |
paul@347 | 687 | |
paul@347 | 688 | """ |
paul@347 | 689 | Return the calendar heading for the current calendar, providing links |
paul@347 | 690 | permitting navigation to other periods. |
paul@347 | 691 | """ |
paul@347 | 692 | |
paul@347 | 693 | label = self.getCalendarPeriod() |
paul@347 | 694 | |
paul@347 | 695 | if self.raw_calendar_start is None or self.raw_calendar_end is None: |
paul@347 | 696 | fmt = self.page.request.formatter |
paul@347 | 697 | output = [] |
paul@347 | 698 | append = output.append |
paul@347 | 699 | append(fmt.span(on=1)) |
paul@347 | 700 | append(fmt.text(label)) |
paul@347 | 701 | append(fmt.span(on=0)) |
paul@347 | 702 | return "".join(output) |
paul@347 | 703 | else: |
paul@347 | 704 | return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end) |
paul@347 | 705 | |
paul@347 | 706 | def writeDateHeading(self, date): |
paul@347 | 707 | if isinstance(date, Date): |
paul@347 | 708 | return self.writeDayHeading(date) |
paul@347 | 709 | else: |
paul@347 | 710 | return self.writeMonthHeading(date) |
paul@347 | 711 | |
paul@347 | 712 | def writeMonthHeading(self, year_month): |
paul@347 | 713 | |
paul@347 | 714 | """ |
paul@347 | 715 | Return the calendar heading for the given 'year_month' (a Month object) |
paul@347 | 716 | providing links permitting navigation to other months. |
paul@347 | 717 | """ |
paul@347 | 718 | |
paul@347 | 719 | full_month_label = self.getFullMonthLabel(year_month) |
paul@347 | 720 | end_month = year_month.update(self.duration - 1) |
paul@347 | 721 | return self._writeCalendarHeading(full_month_label, year_month, end_month) |
paul@347 | 722 | |
paul@347 | 723 | def writeDayHeading(self, date): |
paul@347 | 724 | |
paul@347 | 725 | """ |
paul@347 | 726 | Return the calendar heading for the given 'date' (a Date object) |
paul@347 | 727 | providing links permitting navigation to other dates. |
paul@347 | 728 | """ |
paul@347 | 729 | |
paul@347 | 730 | full_date_label = self.getFullDateLabel(date) |
paul@347 | 731 | end_date = date.update(self.duration - 1) |
paul@347 | 732 | return self._writeCalendarHeading(full_date_label, date, end_date) |
paul@347 | 733 | |
paul@347 | 734 | def _writeCalendarHeading(self, label, start, end): |
paul@347 | 735 | |
paul@347 | 736 | """ |
paul@347 | 737 | Write a calendar heading providing links permitting navigation to other |
paul@347 | 738 | periods, using the given 'label' along with the 'start' and 'end' dates |
paul@347 | 739 | to provide a link to a particular period. |
paul@347 | 740 | """ |
paul@347 | 741 | |
paul@347 | 742 | page = self.page |
paul@347 | 743 | request = page.request |
paul@347 | 744 | fmt = request.formatter |
paul@347 | 745 | _ = request.getText |
paul@347 | 746 | |
paul@347 | 747 | output = [] |
paul@347 | 748 | append = output.append |
paul@347 | 749 | |
paul@347 | 750 | # Prepare navigation links. |
paul@347 | 751 | |
paul@347 | 752 | if self.calendar_name: |
paul@347 | 753 | calendar_name = self.calendar_name |
paul@347 | 754 | |
paul@347 | 755 | # Links to the previous set of months and to a calendar shifted |
paul@347 | 756 | # back one month. |
paul@347 | 757 | |
paul@347 | 758 | previous_set_link = self.getNavigationLink( |
paul@347 | 759 | self.previous_set_start, self.previous_set_end |
paul@347 | 760 | ) |
paul@347 | 761 | previous_link = self.getNavigationLink( |
paul@347 | 762 | self.previous_start, self.previous_end |
paul@347 | 763 | ) |
paul@347 | 764 | previous_set_update_link = self.getUpdateLink( |
paul@347 | 765 | self.previous_set_start, self.previous_set_end |
paul@347 | 766 | ) |
paul@347 | 767 | previous_update_link = self.getUpdateLink( |
paul@347 | 768 | self.previous_start, self.previous_end |
paul@347 | 769 | ) |
paul@347 | 770 | |
paul@347 | 771 | # Links to the next set of months and to a calendar shifted |
paul@347 | 772 | # forward one month. |
paul@347 | 773 | |
paul@347 | 774 | next_set_link = self.getNavigationLink( |
paul@347 | 775 | self.next_set_start, self.next_set_end |
paul@347 | 776 | ) |
paul@347 | 777 | next_link = self.getNavigationLink( |
paul@347 | 778 | self.next_start, self.next_end |
paul@347 | 779 | ) |
paul@347 | 780 | next_set_update_link = self.getUpdateLink( |
paul@347 | 781 | self.next_set_start, self.next_set_end |
paul@347 | 782 | ) |
paul@347 | 783 | next_update_link = self.getUpdateLink( |
paul@347 | 784 | self.next_start, self.next_end |
paul@347 | 785 | ) |
paul@347 | 786 | |
paul@347 | 787 | # A link leading to this date being at the top of the calendar. |
paul@347 | 788 | |
paul@347 | 789 | date_link = self.getNavigationLink(start, end) |
paul@347 | 790 | date_update_link = self.getUpdateLink(start, end) |
paul@347 | 791 | |
paul@347 | 792 | append(fmt.span(on=1, css_class="previous")) |
paul@368 | 793 | append(linkToPage(request, page, "<<", previous_set_link, onclick=previous_set_update_link, title=_("Previous set"))) |
paul@347 | 794 | append(fmt.text(" ")) |
paul@368 | 795 | append(linkToPage(request, page, "<", previous_link, onclick=previous_update_link, title=_("Previous"))) |
paul@347 | 796 | append(fmt.span(on=0)) |
paul@347 | 797 | |
paul@347 | 798 | append(fmt.span(on=1, css_class="next")) |
paul@368 | 799 | append(linkToPage(request, page, ">", next_link, onclick=next_update_link, title=_("Next"))) |
paul@347 | 800 | append(fmt.text(" ")) |
paul@368 | 801 | append(linkToPage(request, page, ">>", next_set_link, onclick=next_set_update_link, title=_("Next set"))) |
paul@347 | 802 | append(fmt.span(on=0)) |
paul@347 | 803 | |
paul@368 | 804 | append(linkToPage(request, page, label, date_link, onclick=date_update_link, title=_("Show this period first"))) |
paul@347 | 805 | |
paul@347 | 806 | else: |
paul@347 | 807 | append(fmt.span(on=1)) |
paul@347 | 808 | append(fmt.text(label)) |
paul@347 | 809 | append(fmt.span(on=0)) |
paul@347 | 810 | |
paul@347 | 811 | return "".join(output) |
paul@347 | 812 | |
paul@347 | 813 | def writeDayNumberHeading(self, date, busy): |
paul@347 | 814 | |
paul@347 | 815 | """ |
paul@347 | 816 | Return a link for the given 'date' which will activate the new event |
paul@347 | 817 | action for the given day. If 'busy' is given as a true value, the |
paul@347 | 818 | heading will be marked as busy. |
paul@347 | 819 | """ |
paul@347 | 820 | |
paul@347 | 821 | page = self.page |
paul@347 | 822 | request = page.request |
paul@347 | 823 | fmt = request.formatter |
paul@347 | 824 | _ = request.getText |
paul@347 | 825 | |
paul@347 | 826 | output = [] |
paul@347 | 827 | append = output.append |
paul@347 | 828 | |
paul@347 | 829 | year, month, day = date.as_tuple() |
paul@347 | 830 | new_event_link = self.getNewEventLink(date) |
paul@347 | 831 | |
paul@347 | 832 | # Prepare a link to the day view for this day. |
paul@347 | 833 | |
paul@347 | 834 | day_view_link = self.getNavigationLink(date, date, "day", "date", self.calendar_start, self.calendar_end) |
paul@347 | 835 | day_view_update_link = self.getUpdateLink(date, date, "day", "date", self.calendar_start, self.calendar_end) |
paul@347 | 836 | |
paul@347 | 837 | # Output the heading class. |
paul@347 | 838 | |
paul@347 | 839 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 840 | |
paul@347 | 841 | append( |
paul@347 | 842 | fmt.table_cell(on=1, attrs={ |
paul@347 | 843 | "class" : "event-day-heading event-day-%s %s" % (busy and "busy" or "empty", today_attr), |
paul@347 | 844 | "colspan" : "3" |
paul@347 | 845 | })) |
paul@347 | 846 | |
paul@347 | 847 | # Output the number and pop-up menu. |
paul@347 | 848 | |
paul@372 | 849 | day_target = "%s-day-%d" % (self.getIdentifier(), day) |
paul@372 | 850 | |
paul@372 | 851 | append(fmt.div(on=1, css_class="event-day-box", id=day_target)) |
paul@347 | 852 | |
paul@347 | 853 | append(fmt.span(on=1, css_class="event-day-number-popup")) |
paul@347 | 854 | append(fmt.span(on=1, css_class="event-day-number-link")) |
paul@347 | 855 | append(linkToPage(request, page, _("View day"), day_view_link, onclick=day_view_update_link)) |
paul@347 | 856 | append(fmt.span(on=0)) |
paul@347 | 857 | append(fmt.span(on=1, css_class="event-day-number-link")) |
paul@372 | 858 | append(linkToPage(request, page, _("New event on this day"), new_event_link)) |
paul@347 | 859 | append(fmt.span(on=0)) |
paul@347 | 860 | append(fmt.span(on=0)) |
paul@347 | 861 | |
paul@368 | 862 | # Link the number to the day view. |
paul@368 | 863 | |
paul@347 | 864 | append(fmt.span(on=1, css_class="event-day-number")) |
paul@373 | 865 | append(linkToPage(request, page, unicode(day), anchor=day_target, title=_("View day options"))) |
paul@347 | 866 | append(fmt.span(on=0)) |
paul@347 | 867 | |
paul@347 | 868 | append(fmt.div(on=0)) |
paul@347 | 869 | |
paul@347 | 870 | # End of heading. |
paul@347 | 871 | |
paul@347 | 872 | append(fmt.table_cell(on=0)) |
paul@347 | 873 | |
paul@347 | 874 | return "".join(output) |
paul@347 | 875 | |
paul@347 | 876 | # Common layout methods. |
paul@347 | 877 | |
paul@347 | 878 | def getEventStyle(self, colour_seed): |
paul@347 | 879 | |
paul@347 | 880 | "Generate colour style information using the given 'colour_seed'." |
paul@347 | 881 | |
paul@347 | 882 | bg = getColour(colour_seed) |
paul@347 | 883 | fg = getBlackOrWhite(bg) |
paul@347 | 884 | return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg) |
paul@347 | 885 | |
paul@347 | 886 | def writeEventSummaryBox(self, event): |
paul@347 | 887 | |
paul@347 | 888 | "Return an event summary box linking to the given 'event'." |
paul@347 | 889 | |
paul@347 | 890 | page = self.page |
paul@347 | 891 | request = page.request |
paul@347 | 892 | fmt = request.formatter |
paul@347 | 893 | |
paul@347 | 894 | output = [] |
paul@347 | 895 | append = output.append |
paul@347 | 896 | |
paul@347 | 897 | event_details = event.getDetails() |
paul@347 | 898 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 899 | |
paul@347 | 900 | is_ambiguous = event.as_timespan().ambiguous() |
paul@347 | 901 | style = self.getEventStyle(event_summary) |
paul@347 | 902 | |
paul@347 | 903 | # The event box contains the summary, alongside |
paul@347 | 904 | # other elements. |
paul@347 | 905 | |
paul@347 | 906 | append(fmt.div(on=1, css_class="event-summary-box")) |
paul@347 | 907 | append(fmt.div(on=1, css_class="event-summary", style=style)) |
paul@347 | 908 | |
paul@347 | 909 | if is_ambiguous: |
paul@347 | 910 | append(fmt.icon("/!\\")) |
paul@347 | 911 | |
paul@347 | 912 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 913 | append(fmt.div(on=0)) |
paul@347 | 914 | |
paul@347 | 915 | # Add a pop-up element for long summaries. |
paul@347 | 916 | |
paul@347 | 917 | append(fmt.div(on=1, css_class="event-summary-popup", style=style)) |
paul@347 | 918 | |
paul@347 | 919 | if is_ambiguous: |
paul@347 | 920 | append(fmt.icon("/!\\")) |
paul@347 | 921 | |
paul@347 | 922 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 923 | append(fmt.div(on=0)) |
paul@347 | 924 | |
paul@347 | 925 | append(fmt.div(on=0)) |
paul@347 | 926 | |
paul@347 | 927 | return "".join(output) |
paul@347 | 928 | |
paul@347 | 929 | # Calendar layout methods. |
paul@347 | 930 | |
paul@347 | 931 | def writeMonthTableHeading(self, year_month): |
paul@347 | 932 | page = self.page |
paul@347 | 933 | fmt = page.request.formatter |
paul@347 | 934 | |
paul@347 | 935 | output = [] |
paul@347 | 936 | append = output.append |
paul@347 | 937 | |
paul@368 | 938 | # Using a caption for accessibility reasons. |
paul@368 | 939 | |
paul@368 | 940 | append(fmt.rawHTML('<caption class="event-month-heading">')) |
paul@347 | 941 | append(self.writeMonthHeading(year_month)) |
paul@368 | 942 | append(fmt.rawHTML("</caption>")) |
paul@347 | 943 | |
paul@347 | 944 | return "".join(output) |
paul@347 | 945 | |
paul@347 | 946 | def writeWeekdayHeadings(self): |
paul@347 | 947 | page = self.page |
paul@347 | 948 | request = page.request |
paul@347 | 949 | fmt = request.formatter |
paul@347 | 950 | _ = request.getText |
paul@347 | 951 | |
paul@347 | 952 | output = [] |
paul@347 | 953 | append = output.append |
paul@347 | 954 | |
paul@347 | 955 | append(fmt.table_row(on=1)) |
paul@347 | 956 | |
paul@347 | 957 | for weekday in range(0, 7): |
paul@347 | 958 | append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"})) |
paul@347 | 959 | append(fmt.text(_(getDayLabel(weekday)))) |
paul@347 | 960 | append(fmt.table_cell(on=0)) |
paul@347 | 961 | |
paul@347 | 962 | append(fmt.table_row(on=0)) |
paul@347 | 963 | return "".join(output) |
paul@347 | 964 | |
paul@347 | 965 | def writeDayNumbers(self, first_day, number_of_days, month, coverage): |
paul@347 | 966 | page = self.page |
paul@347 | 967 | fmt = page.request.formatter |
paul@347 | 968 | |
paul@347 | 969 | output = [] |
paul@347 | 970 | append = output.append |
paul@347 | 971 | |
paul@347 | 972 | append(fmt.table_row(on=1)) |
paul@347 | 973 | |
paul@347 | 974 | for weekday in range(0, 7): |
paul@347 | 975 | day = first_day + weekday |
paul@347 | 976 | date = month.as_date(day) |
paul@347 | 977 | |
paul@347 | 978 | # Output out-of-month days. |
paul@347 | 979 | |
paul@347 | 980 | if day < 1 or day > number_of_days: |
paul@347 | 981 | append(fmt.table_cell(on=1, |
paul@347 | 982 | attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"})) |
paul@347 | 983 | append(fmt.table_cell(on=0)) |
paul@347 | 984 | |
paul@347 | 985 | # Output normal days. |
paul@347 | 986 | |
paul@347 | 987 | else: |
paul@347 | 988 | # Output the day heading, making a link to a new event |
paul@347 | 989 | # action. |
paul@347 | 990 | |
paul@347 | 991 | append(self.writeDayNumberHeading(date, date in coverage)) |
paul@347 | 992 | |
paul@347 | 993 | # End of day numbers. |
paul@347 | 994 | |
paul@347 | 995 | append(fmt.table_row(on=0)) |
paul@347 | 996 | return "".join(output) |
paul@347 | 997 | |
paul@347 | 998 | def writeEmptyWeek(self, first_day, number_of_days, month): |
paul@347 | 999 | page = self.page |
paul@347 | 1000 | fmt = page.request.formatter |
paul@347 | 1001 | |
paul@347 | 1002 | output = [] |
paul@347 | 1003 | append = output.append |
paul@347 | 1004 | |
paul@347 | 1005 | append(fmt.table_row(on=1)) |
paul@347 | 1006 | |
paul@347 | 1007 | for weekday in range(0, 7): |
paul@347 | 1008 | day = first_day + weekday |
paul@347 | 1009 | date = month.as_date(day) |
paul@347 | 1010 | |
paul@347 | 1011 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 1012 | |
paul@347 | 1013 | # Output out-of-month days. |
paul@347 | 1014 | |
paul@347 | 1015 | if day < 1 or day > number_of_days: |
paul@347 | 1016 | append(fmt.table_cell(on=1, |
paul@347 | 1017 | attrs={"class" : "event-day-content event-day-excluded %s" % today_attr, "colspan" : "3"})) |
paul@347 | 1018 | append(fmt.table_cell(on=0)) |
paul@347 | 1019 | |
paul@347 | 1020 | # Output empty days. |
paul@347 | 1021 | |
paul@347 | 1022 | else: |
paul@347 | 1023 | append(fmt.table_cell(on=1, |
paul@347 | 1024 | attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"})) |
paul@347 | 1025 | |
paul@347 | 1026 | append(fmt.table_row(on=0)) |
paul@347 | 1027 | return "".join(output) |
paul@347 | 1028 | |
paul@347 | 1029 | def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots): |
paul@347 | 1030 | output = [] |
paul@347 | 1031 | append = output.append |
paul@347 | 1032 | |
paul@347 | 1033 | locations = week_slots.keys() |
paul@347 | 1034 | locations.sort(sort_none_first) |
paul@347 | 1035 | |
paul@347 | 1036 | # Visit each slot corresponding to a location (or no location). |
paul@347 | 1037 | |
paul@347 | 1038 | for location in locations: |
paul@347 | 1039 | |
paul@347 | 1040 | # Visit each coverage span, presenting the events in the span. |
paul@347 | 1041 | |
paul@347 | 1042 | for events in week_slots[location]: |
paul@347 | 1043 | |
paul@347 | 1044 | # Output each set. |
paul@347 | 1045 | |
paul@347 | 1046 | append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events)) |
paul@347 | 1047 | |
paul@347 | 1048 | # Add a spacer. |
paul@347 | 1049 | |
paul@347 | 1050 | append(self.writeWeekSpacer(first_day, number_of_days, month)) |
paul@347 | 1051 | |
paul@347 | 1052 | return "".join(output) |
paul@347 | 1053 | |
paul@347 | 1054 | def writeWeekSlot(self, first_day, number_of_days, month, week_end, events): |
paul@347 | 1055 | page = self.page |
paul@347 | 1056 | request = page.request |
paul@347 | 1057 | fmt = request.formatter |
paul@347 | 1058 | |
paul@347 | 1059 | output = [] |
paul@347 | 1060 | append = output.append |
paul@347 | 1061 | |
paul@347 | 1062 | append(fmt.table_row(on=1)) |
paul@347 | 1063 | |
paul@347 | 1064 | # Then, output day details. |
paul@347 | 1065 | |
paul@347 | 1066 | for weekday in range(0, 7): |
paul@347 | 1067 | day = first_day + weekday |
paul@347 | 1068 | date = month.as_date(day) |
paul@347 | 1069 | |
paul@347 | 1070 | # Skip out-of-month days. |
paul@347 | 1071 | |
paul@347 | 1072 | if day < 1 or day > number_of_days: |
paul@347 | 1073 | append(fmt.table_cell(on=1, |
paul@347 | 1074 | attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"})) |
paul@347 | 1075 | append(fmt.table_cell(on=0)) |
paul@347 | 1076 | continue |
paul@347 | 1077 | |
paul@347 | 1078 | # Output the day. |
paul@347 | 1079 | # Where a day does not contain an event, a single cell is used. |
paul@347 | 1080 | # Otherwise, multiple cells are used to provide space before, during |
paul@347 | 1081 | # and after events. |
paul@347 | 1082 | |
paul@347 | 1083 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 1084 | |
paul@347 | 1085 | if date not in events: |
paul@347 | 1086 | append(fmt.table_cell(on=1, |
paul@347 | 1087 | attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"})) |
paul@347 | 1088 | |
paul@347 | 1089 | # Get event details for the current day. |
paul@347 | 1090 | |
paul@347 | 1091 | for event in events: |
paul@347 | 1092 | event_details = event.getDetails() |
paul@347 | 1093 | |
paul@347 | 1094 | if date not in event: |
paul@347 | 1095 | continue |
paul@347 | 1096 | |
paul@347 | 1097 | # Get basic properties of the event. |
paul@347 | 1098 | |
paul@347 | 1099 | starts_today = event_details["start"] == date |
paul@347 | 1100 | ends_today = event_details["end"] == date |
paul@347 | 1101 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1102 | |
paul@347 | 1103 | style = self.getEventStyle(event_summary) |
paul@347 | 1104 | |
paul@347 | 1105 | # Determine if the event name should be shown. |
paul@347 | 1106 | |
paul@347 | 1107 | start_of_period = starts_today or weekday == 0 or day == 1 |
paul@347 | 1108 | |
paul@347 | 1109 | if self.name_usage == "daily" or start_of_period: |
paul@347 | 1110 | hide_text = 0 |
paul@347 | 1111 | else: |
paul@347 | 1112 | hide_text = 1 |
paul@347 | 1113 | |
paul@347 | 1114 | # Output start of day gap and determine whether |
paul@347 | 1115 | # any event content should be explicitly output |
paul@347 | 1116 | # for this day. |
paul@347 | 1117 | |
paul@347 | 1118 | if starts_today: |
paul@347 | 1119 | |
paul@347 | 1120 | # Single day events... |
paul@347 | 1121 | |
paul@347 | 1122 | if ends_today: |
paul@347 | 1123 | colspan = 3 |
paul@347 | 1124 | event_day_type = "event-day-single" |
paul@347 | 1125 | |
paul@347 | 1126 | # Events starting today... |
paul@347 | 1127 | |
paul@347 | 1128 | else: |
paul@347 | 1129 | append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap %s" % today_attr})) |
paul@347 | 1130 | append(fmt.table_cell(on=0)) |
paul@347 | 1131 | |
paul@347 | 1132 | # Calculate the span of this cell. |
paul@347 | 1133 | # Events whose names appear on every day... |
paul@347 | 1134 | |
paul@347 | 1135 | if self.name_usage == "daily": |
paul@347 | 1136 | colspan = 2 |
paul@347 | 1137 | event_day_type = "event-day-starting" |
paul@347 | 1138 | |
paul@347 | 1139 | # Events whose names appear once per week... |
paul@347 | 1140 | |
paul@347 | 1141 | else: |
paul@347 | 1142 | if event_details["end"] <= week_end: |
paul@347 | 1143 | event_length = event_details["end"].day() - day + 1 |
paul@347 | 1144 | colspan = (event_length - 2) * 3 + 4 |
paul@347 | 1145 | else: |
paul@347 | 1146 | event_length = week_end.day() - day + 1 |
paul@347 | 1147 | colspan = (event_length - 1) * 3 + 2 |
paul@347 | 1148 | |
paul@347 | 1149 | event_day_type = "event-day-multiple" |
paul@347 | 1150 | |
paul@347 | 1151 | # Events continuing from a previous week... |
paul@347 | 1152 | |
paul@347 | 1153 | elif start_of_period: |
paul@347 | 1154 | |
paul@347 | 1155 | # End of continuing event... |
paul@347 | 1156 | |
paul@347 | 1157 | if ends_today: |
paul@347 | 1158 | colspan = 2 |
paul@347 | 1159 | event_day_type = "event-day-ending" |
paul@347 | 1160 | |
paul@347 | 1161 | # Events continuing for at least one more day... |
paul@347 | 1162 | |
paul@347 | 1163 | else: |
paul@347 | 1164 | |
paul@347 | 1165 | # Calculate the span of this cell. |
paul@347 | 1166 | # Events whose names appear on every day... |
paul@347 | 1167 | |
paul@347 | 1168 | if self.name_usage == "daily": |
paul@347 | 1169 | colspan = 3 |
paul@347 | 1170 | event_day_type = "event-day-full" |
paul@347 | 1171 | |
paul@347 | 1172 | # Events whose names appear once per week... |
paul@347 | 1173 | |
paul@347 | 1174 | else: |
paul@347 | 1175 | if event_details["end"] <= week_end: |
paul@347 | 1176 | event_length = event_details["end"].day() - day + 1 |
paul@347 | 1177 | colspan = (event_length - 1) * 3 + 2 |
paul@347 | 1178 | else: |
paul@347 | 1179 | event_length = week_end.day() - day + 1 |
paul@347 | 1180 | colspan = event_length * 3 |
paul@347 | 1181 | |
paul@347 | 1182 | event_day_type = "event-day-multiple" |
paul@347 | 1183 | |
paul@347 | 1184 | # Continuing events whose names appear on every day... |
paul@347 | 1185 | |
paul@347 | 1186 | elif self.name_usage == "daily": |
paul@347 | 1187 | if ends_today: |
paul@347 | 1188 | colspan = 2 |
paul@347 | 1189 | event_day_type = "event-day-ending" |
paul@347 | 1190 | else: |
paul@347 | 1191 | colspan = 3 |
paul@347 | 1192 | event_day_type = "event-day-full" |
paul@347 | 1193 | |
paul@347 | 1194 | # Continuing events whose names appear once per week... |
paul@347 | 1195 | |
paul@347 | 1196 | else: |
paul@347 | 1197 | colspan = None |
paul@347 | 1198 | |
paul@347 | 1199 | # Output the main content only if it is not |
paul@347 | 1200 | # continuing from a previous day. |
paul@347 | 1201 | |
paul@347 | 1202 | if colspan is not None: |
paul@347 | 1203 | |
paul@347 | 1204 | # Colour the cell for continuing events. |
paul@347 | 1205 | |
paul@347 | 1206 | attrs={ |
paul@347 | 1207 | "class" : "event-day-content event-day-busy %s %s" % (event_day_type, today_attr), |
paul@347 | 1208 | "colspan" : str(colspan) |
paul@347 | 1209 | } |
paul@347 | 1210 | |
paul@347 | 1211 | if not (starts_today and ends_today): |
paul@347 | 1212 | attrs["style"] = style |
paul@347 | 1213 | |
paul@347 | 1214 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1215 | |
paul@347 | 1216 | # Output the event. |
paul@347 | 1217 | |
paul@347 | 1218 | if starts_today and ends_today or not hide_text: |
paul@347 | 1219 | append(self.writeEventSummaryBox(event)) |
paul@347 | 1220 | |
paul@347 | 1221 | append(fmt.table_cell(on=0)) |
paul@347 | 1222 | |
paul@347 | 1223 | # Output end of day gap. |
paul@347 | 1224 | |
paul@347 | 1225 | if ends_today and not starts_today: |
paul@347 | 1226 | append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap %s" % today_attr})) |
paul@347 | 1227 | append(fmt.table_cell(on=0)) |
paul@347 | 1228 | |
paul@347 | 1229 | # End of set. |
paul@347 | 1230 | |
paul@347 | 1231 | append(fmt.table_row(on=0)) |
paul@347 | 1232 | return "".join(output) |
paul@347 | 1233 | |
paul@347 | 1234 | def writeWeekSpacer(self, first_day, number_of_days, month): |
paul@347 | 1235 | page = self.page |
paul@347 | 1236 | fmt = page.request.formatter |
paul@347 | 1237 | |
paul@347 | 1238 | output = [] |
paul@347 | 1239 | append = output.append |
paul@347 | 1240 | |
paul@347 | 1241 | append(fmt.table_row(on=1)) |
paul@347 | 1242 | |
paul@347 | 1243 | for weekday in range(0, 7): |
paul@347 | 1244 | day = first_day + weekday |
paul@347 | 1245 | date = month.as_date(day) |
paul@347 | 1246 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 1247 | |
paul@347 | 1248 | css_classes = "event-day-spacer %s" % today_attr |
paul@347 | 1249 | |
paul@347 | 1250 | # Skip out-of-month days. |
paul@347 | 1251 | |
paul@347 | 1252 | if day < 1 or day > number_of_days: |
paul@347 | 1253 | css_classes += " event-day-excluded" |
paul@347 | 1254 | |
paul@347 | 1255 | append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"})) |
paul@347 | 1256 | append(fmt.table_cell(on=0)) |
paul@347 | 1257 | |
paul@347 | 1258 | append(fmt.table_row(on=0)) |
paul@347 | 1259 | return "".join(output) |
paul@347 | 1260 | |
paul@347 | 1261 | # Day layout methods. |
paul@347 | 1262 | |
paul@347 | 1263 | def writeDayTableHeading(self, date, colspan=1): |
paul@347 | 1264 | page = self.page |
paul@347 | 1265 | fmt = page.request.formatter |
paul@347 | 1266 | |
paul@347 | 1267 | output = [] |
paul@347 | 1268 | append = output.append |
paul@347 | 1269 | |
paul@368 | 1270 | # Using a caption for accessibility reasons. |
paul@368 | 1271 | |
paul@368 | 1272 | append(fmt.rawHTML('<caption class="event-full-day-heading">')) |
paul@347 | 1273 | append(self.writeDayHeading(date)) |
paul@368 | 1274 | append(fmt.rawHTML("</caption>")) |
paul@368 | 1275 | |
paul@347 | 1276 | return "".join(output) |
paul@347 | 1277 | |
paul@347 | 1278 | def writeEmptyDay(self, date): |
paul@347 | 1279 | page = self.page |
paul@347 | 1280 | fmt = page.request.formatter |
paul@347 | 1281 | |
paul@347 | 1282 | output = [] |
paul@347 | 1283 | append = output.append |
paul@347 | 1284 | |
paul@347 | 1285 | append(fmt.table_row(on=1)) |
paul@347 | 1286 | |
paul@347 | 1287 | append(fmt.table_cell(on=1, |
paul@347 | 1288 | attrs={"class" : "event-day-content event-day-empty"})) |
paul@347 | 1289 | |
paul@347 | 1290 | append(fmt.table_row(on=0)) |
paul@347 | 1291 | return "".join(output) |
paul@347 | 1292 | |
paul@347 | 1293 | def writeDaySlots(self, date, full_coverage, day_slots): |
paul@347 | 1294 | |
paul@347 | 1295 | """ |
paul@347 | 1296 | Given a 'date', non-empty 'full_coverage' for the day concerned, and a |
paul@347 | 1297 | non-empty mapping of 'day_slots' (from locations to event collections), |
paul@347 | 1298 | output the day slots for the day. |
paul@347 | 1299 | """ |
paul@347 | 1300 | |
paul@347 | 1301 | page = self.page |
paul@347 | 1302 | fmt = page.request.formatter |
paul@347 | 1303 | |
paul@347 | 1304 | output = [] |
paul@347 | 1305 | append = output.append |
paul@347 | 1306 | |
paul@347 | 1307 | locations = day_slots.keys() |
paul@347 | 1308 | locations.sort(sort_none_first) |
paul@347 | 1309 | |
paul@347 | 1310 | # Traverse the time scale of the full coverage, visiting each slot to |
paul@347 | 1311 | # determine whether it provides content for each period. |
paul@347 | 1312 | |
paul@347 | 1313 | scale = getCoverageScale(full_coverage) |
paul@347 | 1314 | |
paul@347 | 1315 | # Define a mapping of events to rowspans. |
paul@347 | 1316 | |
paul@347 | 1317 | rowspans = {} |
paul@347 | 1318 | |
paul@347 | 1319 | # Populate each period with event details, recording how many periods |
paul@347 | 1320 | # each event populates. |
paul@347 | 1321 | |
paul@347 | 1322 | day_rows = [] |
paul@347 | 1323 | |
paul@355 | 1324 | for period, limit, times in scale: |
paul@347 | 1325 | |
paul@347 | 1326 | # Ignore timespans before this day. |
paul@347 | 1327 | |
paul@347 | 1328 | if period != date: |
paul@347 | 1329 | continue |
paul@347 | 1330 | |
paul@347 | 1331 | # Visit each slot corresponding to a location (or no location). |
paul@347 | 1332 | |
paul@347 | 1333 | day_row = [] |
paul@347 | 1334 | |
paul@347 | 1335 | for location in locations: |
paul@347 | 1336 | |
paul@347 | 1337 | # Visit each coverage span, presenting the events in the span. |
paul@347 | 1338 | |
paul@347 | 1339 | for events in day_slots[location]: |
paul@347 | 1340 | event = self.getActiveEvent(period, events) |
paul@347 | 1341 | if event is not None: |
paul@347 | 1342 | if not rowspans.has_key(event): |
paul@347 | 1343 | rowspans[event] = 1 |
paul@347 | 1344 | else: |
paul@347 | 1345 | rowspans[event] += 1 |
paul@347 | 1346 | day_row.append((location, event)) |
paul@347 | 1347 | |
paul@355 | 1348 | day_rows.append((period, day_row, times)) |
paul@347 | 1349 | |
paul@347 | 1350 | # Output the locations. |
paul@347 | 1351 | |
paul@347 | 1352 | append(fmt.table_row(on=1)) |
paul@347 | 1353 | |
paul@347 | 1354 | # Add a spacer. |
paul@347 | 1355 | |
paul@347 | 1356 | append(self.writeDaySpacer(colspan=2, cls="location")) |
paul@347 | 1357 | |
paul@347 | 1358 | for location in locations: |
paul@347 | 1359 | |
paul@347 | 1360 | # Add spacers to the column spans. |
paul@347 | 1361 | |
paul@347 | 1362 | columns = len(day_slots[location]) * 2 - 1 |
paul@347 | 1363 | append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)})) |
paul@347 | 1364 | append(fmt.text(location or "")) |
paul@347 | 1365 | append(fmt.table_cell(on=0)) |
paul@347 | 1366 | |
paul@347 | 1367 | # Add a trailing spacer. |
paul@347 | 1368 | |
paul@347 | 1369 | append(self.writeDaySpacer(cls="location")) |
paul@347 | 1370 | |
paul@347 | 1371 | append(fmt.table_row(on=0)) |
paul@347 | 1372 | |
paul@347 | 1373 | # Output the periods with event details. |
paul@347 | 1374 | |
paul@355 | 1375 | last_period = period = None |
paul@347 | 1376 | events_written = set() |
paul@347 | 1377 | |
paul@355 | 1378 | for period, day_row, times in day_rows: |
paul@355 | 1379 | |
paul@355 | 1380 | # Write a heading describing the time. |
paul@355 | 1381 | |
paul@355 | 1382 | append(fmt.table_row(on=1)) |
paul@355 | 1383 | |
paul@355 | 1384 | # Show times only for distinct periods. |
paul@355 | 1385 | |
paul@355 | 1386 | if not last_period or period.start != last_period.start: |
paul@355 | 1387 | append(self.writeDayScaleHeading(times)) |
paul@347 | 1388 | else: |
paul@355 | 1389 | append(self.writeDayScaleHeading([])) |
paul@347 | 1390 | |
paul@347 | 1391 | append(self.writeDaySpacer()) |
paul@347 | 1392 | |
paul@347 | 1393 | # Visit each slot corresponding to a location (or no location). |
paul@347 | 1394 | |
paul@347 | 1395 | for location, event in day_row: |
paul@347 | 1396 | |
paul@347 | 1397 | # Output each location slot's contribution. |
paul@347 | 1398 | |
paul@347 | 1399 | if event is None or event not in events_written: |
paul@347 | 1400 | append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event])) |
paul@347 | 1401 | if event is not None: |
paul@347 | 1402 | events_written.add(event) |
paul@347 | 1403 | |
paul@347 | 1404 | # Add a trailing spacer. |
paul@347 | 1405 | |
paul@347 | 1406 | append(self.writeDaySpacer()) |
paul@347 | 1407 | |
paul@347 | 1408 | append(fmt.table_row(on=0)) |
paul@347 | 1409 | |
paul@355 | 1410 | last_period = period |
paul@355 | 1411 | |
paul@347 | 1412 | # Write a final time heading if the last period ends in the current day. |
paul@347 | 1413 | |
paul@347 | 1414 | if period is not None: |
paul@347 | 1415 | if period.end == date: |
paul@347 | 1416 | append(fmt.table_row(on=1)) |
paul@355 | 1417 | append(self.writeDayScaleHeading(times)) |
paul@347 | 1418 | |
paul@347 | 1419 | for slot in day_row: |
paul@347 | 1420 | append(self.writeDaySpacer()) |
paul@347 | 1421 | append(self.writeEmptyDaySlot()) |
paul@347 | 1422 | |
paul@347 | 1423 | append(fmt.table_row(on=0)) |
paul@347 | 1424 | |
paul@347 | 1425 | return "".join(output) |
paul@347 | 1426 | |
paul@355 | 1427 | def writeDayScaleHeading(self, times): |
paul@347 | 1428 | page = self.page |
paul@347 | 1429 | fmt = page.request.formatter |
paul@347 | 1430 | |
paul@347 | 1431 | output = [] |
paul@347 | 1432 | append = output.append |
paul@347 | 1433 | |
paul@347 | 1434 | append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"})) |
paul@355 | 1435 | |
paul@355 | 1436 | first = 1 |
paul@355 | 1437 | for t in times: |
paul@355 | 1438 | if isinstance(t, DateTime): |
paul@355 | 1439 | if not first: |
paul@355 | 1440 | append(fmt.linebreak(0)) |
paul@355 | 1441 | append(fmt.text(t.time_string())) |
paul@355 | 1442 | first = 0 |
paul@355 | 1443 | |
paul@347 | 1444 | append(fmt.table_cell(on=0)) |
paul@347 | 1445 | |
paul@347 | 1446 | return "".join(output) |
paul@347 | 1447 | |
paul@347 | 1448 | def getActiveEvent(self, period, events): |
paul@347 | 1449 | for event in events: |
paul@347 | 1450 | if period not in event: |
paul@347 | 1451 | continue |
paul@347 | 1452 | return event |
paul@347 | 1453 | else: |
paul@347 | 1454 | return None |
paul@347 | 1455 | |
paul@347 | 1456 | def writeDaySlot(self, period, event, rowspan): |
paul@347 | 1457 | page = self.page |
paul@347 | 1458 | fmt = page.request.formatter |
paul@347 | 1459 | |
paul@347 | 1460 | output = [] |
paul@347 | 1461 | append = output.append |
paul@347 | 1462 | |
paul@347 | 1463 | if event is not None: |
paul@347 | 1464 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1465 | style = self.getEventStyle(event_summary) |
paul@347 | 1466 | |
paul@347 | 1467 | append(fmt.table_cell(on=1, attrs={ |
paul@347 | 1468 | "class" : "event-timespan-content event-timespan-busy", |
paul@347 | 1469 | "style" : style, |
paul@347 | 1470 | "rowspan" : str(rowspan) |
paul@347 | 1471 | })) |
paul@347 | 1472 | append(self.writeEventSummaryBox(event)) |
paul@347 | 1473 | append(fmt.table_cell(on=0)) |
paul@347 | 1474 | else: |
paul@347 | 1475 | append(self.writeEmptyDaySlot()) |
paul@347 | 1476 | |
paul@347 | 1477 | return "".join(output) |
paul@347 | 1478 | |
paul@347 | 1479 | def writeEmptyDaySlot(self): |
paul@347 | 1480 | page = self.page |
paul@347 | 1481 | fmt = page.request.formatter |
paul@347 | 1482 | |
paul@347 | 1483 | output = [] |
paul@347 | 1484 | append = output.append |
paul@347 | 1485 | |
paul@347 | 1486 | append(fmt.table_cell(on=1, |
paul@347 | 1487 | attrs={"class" : "event-timespan-content event-timespan-empty"})) |
paul@347 | 1488 | append(fmt.table_cell(on=0)) |
paul@347 | 1489 | |
paul@347 | 1490 | return "".join(output) |
paul@347 | 1491 | |
paul@347 | 1492 | def writeDaySpacer(self, colspan=1, cls="timespan"): |
paul@347 | 1493 | page = self.page |
paul@347 | 1494 | fmt = page.request.formatter |
paul@347 | 1495 | |
paul@347 | 1496 | output = [] |
paul@347 | 1497 | append = output.append |
paul@347 | 1498 | |
paul@347 | 1499 | append(fmt.table_cell(on=1, attrs={ |
paul@347 | 1500 | "class" : "event-%s-spacer" % cls, |
paul@347 | 1501 | "colspan" : str(colspan)})) |
paul@347 | 1502 | append(fmt.table_cell(on=0)) |
paul@347 | 1503 | return "".join(output) |
paul@347 | 1504 | |
paul@347 | 1505 | # Map layout methods. |
paul@347 | 1506 | |
paul@347 | 1507 | def writeMapTableHeading(self): |
paul@347 | 1508 | page = self.page |
paul@347 | 1509 | fmt = page.request.formatter |
paul@347 | 1510 | |
paul@347 | 1511 | output = [] |
paul@347 | 1512 | append = output.append |
paul@347 | 1513 | |
paul@368 | 1514 | # Using a caption for accessibility reasons. |
paul@368 | 1515 | |
paul@368 | 1516 | append(fmt.rawHTML('<caption class="event-map-heading">')) |
paul@347 | 1517 | append(self.writeMapHeading()) |
paul@368 | 1518 | append(fmt.rawHTML("</caption>")) |
paul@347 | 1519 | |
paul@347 | 1520 | return "".join(output) |
paul@347 | 1521 | |
paul@347 | 1522 | def showDictError(self, text, pagename): |
paul@347 | 1523 | page = self.page |
paul@347 | 1524 | request = page.request |
paul@347 | 1525 | fmt = request.formatter |
paul@347 | 1526 | |
paul@347 | 1527 | output = [] |
paul@347 | 1528 | append = output.append |
paul@347 | 1529 | |
paul@347 | 1530 | append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"})) |
paul@347 | 1531 | append(fmt.paragraph(on=1)) |
paul@347 | 1532 | append(fmt.text(text)) |
paul@347 | 1533 | append(fmt.paragraph(on=0)) |
paul@347 | 1534 | append(fmt.paragraph(on=1)) |
paul@347 | 1535 | append(linkToPage(request, Page(request, pagename), pagename)) |
paul@347 | 1536 | append(fmt.paragraph(on=0)) |
paul@347 | 1537 | |
paul@347 | 1538 | return "".join(output) |
paul@347 | 1539 | |
paul@347 | 1540 | def writeMapMarker(self, marker_x, marker_y, map_x_scale, map_y_scale, location, events): |
paul@347 | 1541 | |
paul@347 | 1542 | "Put a marker on the map." |
paul@347 | 1543 | |
paul@347 | 1544 | page = self.page |
paul@347 | 1545 | request = page.request |
paul@347 | 1546 | fmt = request.formatter |
paul@347 | 1547 | |
paul@347 | 1548 | output = [] |
paul@347 | 1549 | append = output.append |
paul@347 | 1550 | |
paul@347 | 1551 | append(fmt.listitem(on=1, css_class="event-map-label")) |
paul@347 | 1552 | |
paul@347 | 1553 | # Have a positioned marker for the print mode. |
paul@347 | 1554 | |
paul@347 | 1555 | append(fmt.div(on=1, css_class="event-map-label-only", |
paul@347 | 1556 | style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( |
paul@347 | 1557 | marker_x, marker_y, map_x_scale, map_y_scale)) |
paul@347 | 1558 | append(fmt.div(on=0)) |
paul@347 | 1559 | |
paul@347 | 1560 | # Have a marker containing a pop-up when using the screen mode, |
paul@347 | 1561 | # providing a normal block when using the print mode. |
paul@347 | 1562 | |
paul@373 | 1563 | location_text = to_plain_text(location, request) |
paul@373 | 1564 | label_target = "%s-maplabel-%s" % (self.getIdentifier(), location_text) |
paul@373 | 1565 | |
paul@373 | 1566 | append(fmt.div(on=1, css_class="event-map-label", id=label_target, |
paul@347 | 1567 | style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( |
paul@347 | 1568 | marker_x, marker_y, map_x_scale, map_y_scale)) |
paul@373 | 1569 | |
paul@373 | 1570 | label_target_url = page.url(request, anchor=label_target, relative=True) |
paul@373 | 1571 | append(fmt.url(1, label_target_url, "event-map-label-link")) |
paul@373 | 1572 | append(fmt.span(1)) |
paul@373 | 1573 | append(fmt.text(location_text)) |
paul@373 | 1574 | append(fmt.span(0)) |
paul@373 | 1575 | append(fmt.url(0)) |
paul@373 | 1576 | |
paul@347 | 1577 | append(fmt.div(on=1, css_class="event-map-details")) |
paul@347 | 1578 | append(fmt.div(on=1, css_class="event-map-shadow")) |
paul@347 | 1579 | append(fmt.div(on=1, css_class="event-map-location")) |
paul@347 | 1580 | |
paul@347 | 1581 | # The location may have been given as formatted text, but this will not |
paul@347 | 1582 | # be usable in a heading, so it must be first converted to plain text. |
paul@347 | 1583 | |
paul@347 | 1584 | append(fmt.heading(on=1, depth=2)) |
paul@373 | 1585 | append(fmt.text(location_text)) |
paul@347 | 1586 | append(fmt.heading(on=0, depth=2)) |
paul@347 | 1587 | |
paul@347 | 1588 | append(self.writeMapEventSummaries(events)) |
paul@347 | 1589 | |
paul@347 | 1590 | append(fmt.div(on=0)) |
paul@347 | 1591 | append(fmt.div(on=0)) |
paul@347 | 1592 | append(fmt.div(on=0)) |
paul@347 | 1593 | append(fmt.div(on=0)) |
paul@347 | 1594 | append(fmt.listitem(on=0)) |
paul@347 | 1595 | |
paul@347 | 1596 | return "".join(output) |
paul@347 | 1597 | |
paul@347 | 1598 | def writeMapEventSummaries(self, events): |
paul@347 | 1599 | |
paul@347 | 1600 | "Write summaries of the given 'events' for the map." |
paul@347 | 1601 | |
paul@347 | 1602 | page = self.page |
paul@347 | 1603 | request = page.request |
paul@347 | 1604 | fmt = request.formatter |
paul@347 | 1605 | |
paul@347 | 1606 | # Sort the events by date. |
paul@347 | 1607 | |
paul@347 | 1608 | events.sort(sort_start_first) |
paul@347 | 1609 | |
paul@347 | 1610 | # Write out a self-contained list of events. |
paul@347 | 1611 | |
paul@347 | 1612 | output = [] |
paul@347 | 1613 | append = output.append |
paul@347 | 1614 | |
paul@347 | 1615 | append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"})) |
paul@347 | 1616 | |
paul@347 | 1617 | for event in events: |
paul@347 | 1618 | |
paul@347 | 1619 | # Get the event details. |
paul@347 | 1620 | |
paul@347 | 1621 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1622 | start, end = event.as_limits() |
paul@347 | 1623 | event_period = self._getCalendarPeriod( |
paul@347 | 1624 | start and self.getFullDateLabel(start), |
paul@347 | 1625 | end and self.getFullDateLabel(end), |
paul@347 | 1626 | "") |
paul@347 | 1627 | |
paul@347 | 1628 | append(fmt.listitem(on=1)) |
paul@347 | 1629 | |
paul@347 | 1630 | # Link to the page using the summary. |
paul@347 | 1631 | |
paul@347 | 1632 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 1633 | |
paul@347 | 1634 | # Add the event period. |
paul@347 | 1635 | |
paul@347 | 1636 | append(fmt.text(" ")) |
paul@347 | 1637 | append(fmt.span(on=1, css_class="event-map-period")) |
paul@347 | 1638 | append(fmt.text(event_period)) |
paul@347 | 1639 | append(fmt.span(on=0)) |
paul@347 | 1640 | |
paul@347 | 1641 | append(fmt.listitem(on=0)) |
paul@347 | 1642 | |
paul@347 | 1643 | append(fmt.bullet_list(on=0)) |
paul@347 | 1644 | |
paul@347 | 1645 | return "".join(output) |
paul@347 | 1646 | |
paul@347 | 1647 | def render(self, all_shown_events): |
paul@347 | 1648 | |
paul@347 | 1649 | """ |
paul@347 | 1650 | Render the view, returning the rendered representation as a string. |
paul@347 | 1651 | The view will show a list of 'all_shown_events'. |
paul@347 | 1652 | """ |
paul@347 | 1653 | |
paul@347 | 1654 | page = self.page |
paul@347 | 1655 | request = page.request |
paul@347 | 1656 | fmt = request.formatter |
paul@347 | 1657 | _ = request.getText |
paul@347 | 1658 | |
paul@347 | 1659 | # Make a calendar. |
paul@347 | 1660 | |
paul@347 | 1661 | output = [] |
paul@347 | 1662 | append = output.append |
paul@347 | 1663 | |
paul@347 | 1664 | append(fmt.div(on=1, css_class="event-calendar", id=("EventAggregator-%s" % self.getIdentifier()))) |
paul@347 | 1665 | |
paul@347 | 1666 | # Output download controls. |
paul@347 | 1667 | |
paul@347 | 1668 | append(fmt.div(on=1, css_class="event-controls")) |
paul@347 | 1669 | append(self.writeDownloadControls()) |
paul@347 | 1670 | append(fmt.div(on=0)) |
paul@347 | 1671 | |
paul@347 | 1672 | # Output a table. |
paul@347 | 1673 | |
paul@347 | 1674 | if self.mode == "table": |
paul@347 | 1675 | |
paul@347 | 1676 | # Start of table view output. |
paul@347 | 1677 | |
paul@369 | 1678 | append(fmt.table(on=1, attrs={"tableclass" : "event-table", "summary" : _("A table of events")})) |
paul@347 | 1679 | |
paul@347 | 1680 | append(fmt.table_row(on=1)) |
paul@347 | 1681 | append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@347 | 1682 | append(fmt.text(_("Event dates"))) |
paul@347 | 1683 | append(fmt.table_cell(on=0)) |
paul@347 | 1684 | append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@347 | 1685 | append(fmt.text(_("Event location"))) |
paul@347 | 1686 | append(fmt.table_cell(on=0)) |
paul@347 | 1687 | append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@347 | 1688 | append(fmt.text(_("Event details"))) |
paul@347 | 1689 | append(fmt.table_cell(on=0)) |
paul@347 | 1690 | append(fmt.table_row(on=0)) |
paul@347 | 1691 | |
paul@347 | 1692 | # Show the events in order. |
paul@347 | 1693 | |
paul@347 | 1694 | all_shown_events.sort(sort_start_first) |
paul@347 | 1695 | |
paul@347 | 1696 | for event in all_shown_events: |
paul@347 | 1697 | event_page = event.getPage() |
paul@347 | 1698 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1699 | event_details = event.getDetails() |
paul@347 | 1700 | |
paul@347 | 1701 | # Prepare CSS classes with category-related styling. |
paul@347 | 1702 | |
paul@347 | 1703 | css_classes = ["event-table-details"] |
paul@347 | 1704 | |
paul@347 | 1705 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@347 | 1706 | |
paul@347 | 1707 | # Filter the category text to avoid illegal characters. |
paul@347 | 1708 | |
paul@347 | 1709 | css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic))) |
paul@347 | 1710 | |
paul@347 | 1711 | attrs = {"class" : " ".join(css_classes)} |
paul@347 | 1712 | |
paul@347 | 1713 | append(fmt.table_row(on=1)) |
paul@347 | 1714 | |
paul@347 | 1715 | # Start and end dates. |
paul@347 | 1716 | |
paul@347 | 1717 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1718 | append(fmt.span(on=1)) |
paul@347 | 1719 | append(fmt.text(str(event_details["start"]))) |
paul@347 | 1720 | append(fmt.span(on=0)) |
paul@347 | 1721 | |
paul@347 | 1722 | if event_details["start"] != event_details["end"]: |
paul@347 | 1723 | append(fmt.text(" - ")) |
paul@347 | 1724 | append(fmt.span(on=1)) |
paul@347 | 1725 | append(fmt.text(str(event_details["end"]))) |
paul@347 | 1726 | append(fmt.span(on=0)) |
paul@347 | 1727 | |
paul@347 | 1728 | append(fmt.table_cell(on=0)) |
paul@347 | 1729 | |
paul@347 | 1730 | # Location. |
paul@347 | 1731 | |
paul@347 | 1732 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1733 | |
paul@347 | 1734 | if event_details.has_key("location"): |
paul@347 | 1735 | append(event_page.formatText(event_details["location"], fmt)) |
paul@347 | 1736 | |
paul@347 | 1737 | append(fmt.table_cell(on=0)) |
paul@347 | 1738 | |
paul@347 | 1739 | # Link to the page using the summary. |
paul@347 | 1740 | |
paul@347 | 1741 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1742 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 1743 | append(fmt.table_cell(on=0)) |
paul@347 | 1744 | |
paul@347 | 1745 | append(fmt.table_row(on=0)) |
paul@347 | 1746 | |
paul@347 | 1747 | # End of table view output. |
paul@347 | 1748 | |
paul@347 | 1749 | append(fmt.table(on=0)) |
paul@347 | 1750 | |
paul@347 | 1751 | # Output a map view. |
paul@347 | 1752 | |
paul@347 | 1753 | elif self.mode == "map": |
paul@347 | 1754 | |
paul@347 | 1755 | # Special dictionary pages. |
paul@347 | 1756 | |
paul@347 | 1757 | maps_page = getMapsPage(request) |
paul@347 | 1758 | locations_page = getLocationsPage(request) |
paul@347 | 1759 | |
paul@347 | 1760 | map_image = None |
paul@347 | 1761 | |
paul@347 | 1762 | # Get the maps and locations. |
paul@347 | 1763 | |
paul@347 | 1764 | maps = getWikiDict(maps_page, request) |
paul@347 | 1765 | locations = getWikiDict(locations_page, request) |
paul@347 | 1766 | |
paul@347 | 1767 | # Get the map image definition. |
paul@347 | 1768 | |
paul@347 | 1769 | if maps is not None and self.map_name: |
paul@347 | 1770 | try: |
paul@347 | 1771 | map_details = maps[self.map_name].split() |
paul@347 | 1772 | |
paul@347 | 1773 | map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \ |
paul@347 | 1774 | map(getMapReference, map_details[:4]) |
paul@347 | 1775 | map_width, map_height = map(int, map_details[4:6]) |
paul@347 | 1776 | map_image = map_details[6] |
paul@347 | 1777 | |
paul@347 | 1778 | map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees() |
paul@347 | 1779 | map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees() |
paul@347 | 1780 | |
paul@347 | 1781 | except (KeyError, ValueError): |
paul@347 | 1782 | pass |
paul@347 | 1783 | |
paul@347 | 1784 | # Report errors. |
paul@347 | 1785 | |
paul@347 | 1786 | if maps is None: |
paul@347 | 1787 | append(self.showDictError( |
paul@347 | 1788 | _("You do not have read access to the maps page:"), |
paul@347 | 1789 | maps_page)) |
paul@347 | 1790 | |
paul@347 | 1791 | elif not self.map_name: |
paul@347 | 1792 | append(self.showDictError( |
paul@347 | 1793 | _("Please specify a valid map name corresponding to an entry on the following page:"), |
paul@347 | 1794 | maps_page)) |
paul@347 | 1795 | |
paul@347 | 1796 | elif map_image is None: |
paul@347 | 1797 | append(self.showDictError( |
paul@347 | 1798 | _("Please specify a valid entry for %s on the following page:") % self.map_name, |
paul@347 | 1799 | maps_page)) |
paul@347 | 1800 | |
paul@347 | 1801 | elif locations is None: |
paul@347 | 1802 | append(self.showDictError( |
paul@347 | 1803 | _("You do not have read access to the locations page:"), |
paul@347 | 1804 | locations_page)) |
paul@347 | 1805 | |
paul@347 | 1806 | # Attempt to show the map. |
paul@347 | 1807 | |
paul@347 | 1808 | else: |
paul@347 | 1809 | |
paul@347 | 1810 | # Get events by position. |
paul@347 | 1811 | |
paul@347 | 1812 | events_by_location = {} |
paul@347 | 1813 | event_locations = {} |
paul@347 | 1814 | |
paul@347 | 1815 | for event in all_shown_events: |
paul@347 | 1816 | event_details = event.getDetails() |
paul@347 | 1817 | |
paul@347 | 1818 | location = event_details.get("location") |
paul@347 | 1819 | geo = event_details.get("geo") |
paul@347 | 1820 | |
paul@347 | 1821 | # Make a temporary location if an explicit position is given |
paul@347 | 1822 | # but not a location name. |
paul@347 | 1823 | |
paul@347 | 1824 | if not location and geo: |
paul@347 | 1825 | location = "%s %s" % tuple(geo) |
paul@347 | 1826 | |
paul@347 | 1827 | # Map the location to a position. |
paul@347 | 1828 | |
paul@347 | 1829 | if location is not None and not event_locations.has_key(location): |
paul@347 | 1830 | |
paul@347 | 1831 | # Get any explicit position of an event. |
paul@347 | 1832 | |
paul@347 | 1833 | if geo: |
paul@347 | 1834 | latitude, longitude = geo |
paul@347 | 1835 | |
paul@347 | 1836 | # Or look up the position of a location using the locations |
paul@347 | 1837 | # page. |
paul@347 | 1838 | |
paul@347 | 1839 | else: |
paul@347 | 1840 | latitude, longitude = Location(location, locations).getPosition() |
paul@347 | 1841 | |
paul@347 | 1842 | # Use a normalised location if necessary. |
paul@347 | 1843 | |
paul@347 | 1844 | if latitude is None and longitude is None: |
paul@347 | 1845 | normalised_location = getNormalisedLocation(location) |
paul@347 | 1846 | if normalised_location is not None: |
paul@347 | 1847 | latitude, longitude = getLocationPosition(normalised_location, locations) |
paul@347 | 1848 | if latitude is not None and longitude is not None: |
paul@347 | 1849 | location = normalised_location |
paul@347 | 1850 | |
paul@347 | 1851 | # Only remember positioned locations. |
paul@347 | 1852 | |
paul@347 | 1853 | if latitude is not None and longitude is not None: |
paul@347 | 1854 | event_locations[location] = latitude, longitude |
paul@347 | 1855 | |
paul@347 | 1856 | # Record events according to location. |
paul@347 | 1857 | |
paul@347 | 1858 | if not events_by_location.has_key(location): |
paul@347 | 1859 | events_by_location[location] = [] |
paul@347 | 1860 | |
paul@347 | 1861 | events_by_location[location].append(event) |
paul@347 | 1862 | |
paul@347 | 1863 | # Get the map image URL. |
paul@347 | 1864 | |
paul@347 | 1865 | map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request) |
paul@347 | 1866 | |
paul@347 | 1867 | # Start of map view output. |
paul@347 | 1868 | |
paul@347 | 1869 | map_identifier = "map-%s" % self.getIdentifier() |
paul@347 | 1870 | append(fmt.div(on=1, css_class="event-map", id=map_identifier)) |
paul@347 | 1871 | |
paul@369 | 1872 | append(fmt.table(on=1, attrs={"summary" : _("A map showing events")})) |
paul@347 | 1873 | |
paul@347 | 1874 | append(self.writeMapTableHeading()) |
paul@347 | 1875 | |
paul@347 | 1876 | append(fmt.table_row(on=1)) |
paul@347 | 1877 | append(fmt.table_cell(on=1)) |
paul@347 | 1878 | |
paul@347 | 1879 | append(fmt.div(on=1, css_class="event-map-container")) |
paul@347 | 1880 | append(fmt.image(map_image_url)) |
paul@347 | 1881 | append(fmt.number_list(on=1)) |
paul@347 | 1882 | |
paul@347 | 1883 | # Events with no location are unpositioned. |
paul@347 | 1884 | |
paul@347 | 1885 | if events_by_location.has_key(None): |
paul@347 | 1886 | unpositioned_events = events_by_location[None] |
paul@347 | 1887 | del events_by_location[None] |
paul@347 | 1888 | else: |
paul@347 | 1889 | unpositioned_events = [] |
paul@347 | 1890 | |
paul@347 | 1891 | # Events whose location is unpositioned are themselves considered |
paul@347 | 1892 | # unpositioned. |
paul@347 | 1893 | |
paul@347 | 1894 | for location in set(events_by_location.keys()).difference(event_locations.keys()): |
paul@347 | 1895 | unpositioned_events += events_by_location[location] |
paul@347 | 1896 | |
paul@347 | 1897 | # Sort the locations before traversing them. |
paul@347 | 1898 | |
paul@347 | 1899 | event_locations = event_locations.items() |
paul@347 | 1900 | event_locations.sort() |
paul@347 | 1901 | |
paul@347 | 1902 | # Show the events in the map. |
paul@347 | 1903 | |
paul@347 | 1904 | for location, (latitude, longitude) in event_locations: |
paul@347 | 1905 | events = events_by_location[location] |
paul@347 | 1906 | |
paul@347 | 1907 | # Skip unpositioned locations and locations outside the map. |
paul@347 | 1908 | |
paul@347 | 1909 | if latitude is None or longitude is None or \ |
paul@347 | 1910 | latitude < map_bottom_left_latitude or \ |
paul@347 | 1911 | longitude < map_bottom_left_longitude or \ |
paul@347 | 1912 | latitude > map_top_right_latitude or \ |
paul@347 | 1913 | longitude > map_top_right_longitude: |
paul@347 | 1914 | |
paul@347 | 1915 | unpositioned_events += events |
paul@347 | 1916 | continue |
paul@347 | 1917 | |
paul@347 | 1918 | # Get the position and dimensions of the map marker. |
paul@347 | 1919 | # NOTE: Use one degree as the marker size. |
paul@347 | 1920 | |
paul@347 | 1921 | marker_x, marker_y = getPositionForCentrePoint( |
paul@347 | 1922 | getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude, |
paul@347 | 1923 | map_x_scale, map_y_scale), |
paul@347 | 1924 | map_x_scale, map_y_scale) |
paul@347 | 1925 | |
paul@347 | 1926 | # Add the map marker. |
paul@347 | 1927 | |
paul@347 | 1928 | append(self.writeMapMarker(marker_x, marker_y, map_x_scale, map_y_scale, location, events)) |
paul@347 | 1929 | |
paul@347 | 1930 | append(fmt.number_list(on=0)) |
paul@347 | 1931 | append(fmt.div(on=0)) |
paul@347 | 1932 | append(fmt.table_cell(on=0)) |
paul@347 | 1933 | append(fmt.table_row(on=0)) |
paul@347 | 1934 | |
paul@347 | 1935 | # Write unpositioned events. |
paul@347 | 1936 | |
paul@347 | 1937 | if unpositioned_events: |
paul@347 | 1938 | unpositioned_identifier = "unpositioned-%s" % self.getIdentifier() |
paul@347 | 1939 | |
paul@347 | 1940 | append(fmt.table_row(on=1, css_class="event-map-unpositioned", |
paul@347 | 1941 | id=unpositioned_identifier)) |
paul@347 | 1942 | append(fmt.table_cell(on=1)) |
paul@347 | 1943 | |
paul@347 | 1944 | append(fmt.heading(on=1, depth=2)) |
paul@347 | 1945 | append(fmt.text(_("Events not shown on the map"))) |
paul@347 | 1946 | append(fmt.heading(on=0, depth=2)) |
paul@347 | 1947 | |
paul@347 | 1948 | # Show and hide controls. |
paul@347 | 1949 | |
paul@347 | 1950 | append(fmt.div(on=1, css_class="event-map-show-control")) |
paul@347 | 1951 | append(fmt.anchorlink(on=1, name=unpositioned_identifier)) |
paul@347 | 1952 | append(fmt.text(_("Show unpositioned events"))) |
paul@347 | 1953 | append(fmt.anchorlink(on=0)) |
paul@347 | 1954 | append(fmt.div(on=0)) |
paul@347 | 1955 | |
paul@347 | 1956 | append(fmt.div(on=1, css_class="event-map-hide-control")) |
paul@347 | 1957 | append(fmt.anchorlink(on=1, name=map_identifier)) |
paul@347 | 1958 | append(fmt.text(_("Hide unpositioned events"))) |
paul@347 | 1959 | append(fmt.anchorlink(on=0)) |
paul@347 | 1960 | append(fmt.div(on=0)) |
paul@347 | 1961 | |
paul@347 | 1962 | append(self.writeMapEventSummaries(unpositioned_events)) |
paul@347 | 1963 | |
paul@347 | 1964 | # End of map view output. |
paul@347 | 1965 | |
paul@347 | 1966 | append(fmt.table_cell(on=0)) |
paul@347 | 1967 | append(fmt.table_row(on=0)) |
paul@347 | 1968 | append(fmt.table(on=0)) |
paul@347 | 1969 | append(fmt.div(on=0)) |
paul@347 | 1970 | |
paul@347 | 1971 | # Output a list. |
paul@347 | 1972 | |
paul@347 | 1973 | elif self.mode == "list": |
paul@347 | 1974 | |
paul@347 | 1975 | # Start of list view output. |
paul@347 | 1976 | |
paul@347 | 1977 | append(fmt.bullet_list(on=1, attr={"class" : "event-listings"})) |
paul@347 | 1978 | |
paul@347 | 1979 | # Output a list. |
paul@368 | 1980 | # NOTE: Make the heading depth configurable. |
paul@347 | 1981 | |
paul@347 | 1982 | for period in self.first.until(self.last): |
paul@347 | 1983 | |
paul@347 | 1984 | append(fmt.listitem(on=1, attr={"class" : "event-listings-period"})) |
paul@368 | 1985 | append(fmt.heading(on=1, depth=2, attr={"class" : "event-listings-heading"})) |
paul@347 | 1986 | |
paul@347 | 1987 | # Either write a date heading or produce links for navigable |
paul@347 | 1988 | # calendars. |
paul@347 | 1989 | |
paul@347 | 1990 | append(self.writeDateHeading(period)) |
paul@347 | 1991 | |
paul@368 | 1992 | append(fmt.heading(on=0, depth=2)) |
paul@347 | 1993 | |
paul@347 | 1994 | append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"})) |
paul@347 | 1995 | |
paul@347 | 1996 | # Show the events in order. |
paul@347 | 1997 | |
paul@347 | 1998 | events_in_period = getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period)) |
paul@347 | 1999 | events_in_period.sort(sort_start_first) |
paul@347 | 2000 | |
paul@347 | 2001 | for event in events_in_period: |
paul@347 | 2002 | event_page = event.getPage() |
paul@347 | 2003 | event_details = event.getDetails() |
paul@347 | 2004 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 2005 | |
paul@347 | 2006 | append(fmt.listitem(on=1, attr={"class" : "event-listing"})) |
paul@347 | 2007 | |
paul@347 | 2008 | # Link to the page using the summary. |
paul@347 | 2009 | |
paul@347 | 2010 | append(fmt.paragraph(on=1)) |
paul@347 | 2011 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 2012 | append(fmt.paragraph(on=0)) |
paul@347 | 2013 | |
paul@347 | 2014 | # Start and end dates. |
paul@347 | 2015 | |
paul@347 | 2016 | append(fmt.paragraph(on=1)) |
paul@347 | 2017 | append(fmt.span(on=1)) |
paul@347 | 2018 | append(fmt.text(str(event_details["start"]))) |
paul@347 | 2019 | append(fmt.span(on=0)) |
paul@347 | 2020 | append(fmt.text(" - ")) |
paul@347 | 2021 | append(fmt.span(on=1)) |
paul@347 | 2022 | append(fmt.text(str(event_details["end"]))) |
paul@347 | 2023 | append(fmt.span(on=0)) |
paul@347 | 2024 | append(fmt.paragraph(on=0)) |
paul@347 | 2025 | |
paul@347 | 2026 | # Location. |
paul@347 | 2027 | |
paul@347 | 2028 | if event_details.has_key("location"): |
paul@347 | 2029 | append(fmt.paragraph(on=1)) |
paul@347 | 2030 | append(event_page.formatText(event_details["location"], fmt)) |
paul@347 | 2031 | append(fmt.paragraph(on=1)) |
paul@347 | 2032 | |
paul@347 | 2033 | # Topics. |
paul@347 | 2034 | |
paul@347 | 2035 | if event_details.has_key("topics") or event_details.has_key("categories"): |
paul@347 | 2036 | append(fmt.bullet_list(on=1, attr={"class" : "event-topics"})) |
paul@347 | 2037 | |
paul@347 | 2038 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@347 | 2039 | append(fmt.listitem(on=1)) |
paul@347 | 2040 | append(event_page.formatText(topic, fmt)) |
paul@347 | 2041 | append(fmt.listitem(on=0)) |
paul@347 | 2042 | |
paul@347 | 2043 | append(fmt.bullet_list(on=0)) |
paul@347 | 2044 | |
paul@347 | 2045 | append(fmt.listitem(on=0)) |
paul@347 | 2046 | |
paul@347 | 2047 | append(fmt.bullet_list(on=0)) |
paul@347 | 2048 | |
paul@347 | 2049 | # End of list view output. |
paul@347 | 2050 | |
paul@347 | 2051 | append(fmt.bullet_list(on=0)) |
paul@347 | 2052 | |
paul@347 | 2053 | # Output a month calendar. This shows month-by-month data. |
paul@347 | 2054 | |
paul@347 | 2055 | elif self.mode == "calendar": |
paul@347 | 2056 | |
paul@347 | 2057 | # Visit all months in the requested range, or across known events. |
paul@347 | 2058 | |
paul@347 | 2059 | for month in self.first.months_until(self.last): |
paul@347 | 2060 | |
paul@347 | 2061 | # Output a month. |
paul@347 | 2062 | |
paul@370 | 2063 | append(fmt.table(on=1, attrs={"tableclass" : "event-month", "summary" : _("A table showing a calendar month")})) |
paul@347 | 2064 | |
paul@347 | 2065 | # Either write a month heading or produce links for navigable |
paul@347 | 2066 | # calendars. |
paul@347 | 2067 | |
paul@347 | 2068 | append(self.writeMonthTableHeading(month)) |
paul@347 | 2069 | |
paul@347 | 2070 | # Weekday headings. |
paul@347 | 2071 | |
paul@347 | 2072 | append(self.writeWeekdayHeadings()) |
paul@347 | 2073 | |
paul@347 | 2074 | # Process the days of the month. |
paul@347 | 2075 | |
paul@347 | 2076 | start_weekday, number_of_days = month.month_properties() |
paul@347 | 2077 | |
paul@347 | 2078 | # The start weekday is the weekday of day number 1. |
paul@347 | 2079 | # Find the first day of the week, counting from below zero, if |
paul@347 | 2080 | # necessary, in order to land on the first day of the month as |
paul@347 | 2081 | # day number 1. |
paul@347 | 2082 | |
paul@347 | 2083 | first_day = 1 - start_weekday |
paul@347 | 2084 | |
paul@347 | 2085 | while first_day <= number_of_days: |
paul@347 | 2086 | |
paul@347 | 2087 | # Find events in this week and determine how to mark them on the |
paul@347 | 2088 | # calendar. |
paul@347 | 2089 | |
paul@347 | 2090 | week_start = month.as_date(max(first_day, 1)) |
paul@347 | 2091 | week_end = month.as_date(min(first_day + 6, number_of_days)) |
paul@347 | 2092 | |
paul@347 | 2093 | full_coverage, week_slots = getCoverage( |
paul@347 | 2094 | getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end))) |
paul@347 | 2095 | |
paul@369 | 2096 | # Make a new table region. |
paul@369 | 2097 | # NOTE: Moin opens a "tbody" element in the table method. |
paul@369 | 2098 | |
paul@369 | 2099 | append(fmt.rawHTML("</tbody>")) |
paul@369 | 2100 | append(fmt.rawHTML("<tbody>")) |
paul@369 | 2101 | |
paul@347 | 2102 | # Output a week, starting with the day numbers. |
paul@347 | 2103 | |
paul@347 | 2104 | append(self.writeDayNumbers(first_day, number_of_days, month, full_coverage)) |
paul@347 | 2105 | |
paul@347 | 2106 | # Either generate empty days... |
paul@347 | 2107 | |
paul@347 | 2108 | if not week_slots: |
paul@347 | 2109 | append(self.writeEmptyWeek(first_day, number_of_days, month)) |
paul@347 | 2110 | |
paul@347 | 2111 | # Or generate each set of scheduled events... |
paul@347 | 2112 | |
paul@347 | 2113 | else: |
paul@347 | 2114 | append(self.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots)) |
paul@347 | 2115 | |
paul@347 | 2116 | # Process the next week... |
paul@347 | 2117 | |
paul@347 | 2118 | first_day += 7 |
paul@347 | 2119 | |
paul@347 | 2120 | # End of month. |
paul@369 | 2121 | # NOTE: Moin closes a "tbody" element in the table method. |
paul@347 | 2122 | |
paul@347 | 2123 | append(fmt.table(on=0)) |
paul@347 | 2124 | |
paul@347 | 2125 | # Output a day view. |
paul@347 | 2126 | |
paul@347 | 2127 | elif self.mode == "day": |
paul@347 | 2128 | |
paul@347 | 2129 | # Visit all days in the requested range, or across known events. |
paul@347 | 2130 | |
paul@347 | 2131 | for date in self.first.days_until(self.last): |
paul@347 | 2132 | |
paul@370 | 2133 | append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day", "summary" : _("A table showing a calendar day")})) |
paul@347 | 2134 | |
paul@347 | 2135 | full_coverage, day_slots = getCoverage( |
paul@347 | 2136 | getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime") |
paul@347 | 2137 | |
paul@347 | 2138 | # Work out how many columns the day title will need. |
paul@347 | 2139 | # Include spacers after the scale and each event column. |
paul@347 | 2140 | |
paul@347 | 2141 | colspan = sum(map(len, day_slots.values())) * 2 + 2 |
paul@347 | 2142 | |
paul@347 | 2143 | append(self.writeDayTableHeading(date, colspan)) |
paul@347 | 2144 | |
paul@347 | 2145 | # Either generate empty days... |
paul@347 | 2146 | |
paul@347 | 2147 | if not day_slots: |
paul@347 | 2148 | append(self.writeEmptyDay(date)) |
paul@347 | 2149 | |
paul@347 | 2150 | # Or generate each set of scheduled events... |
paul@347 | 2151 | |
paul@347 | 2152 | else: |
paul@347 | 2153 | append(self.writeDaySlots(date, full_coverage, day_slots)) |
paul@347 | 2154 | |
paul@347 | 2155 | # End of day. |
paul@347 | 2156 | |
paul@347 | 2157 | append(fmt.table(on=0)) |
paul@347 | 2158 | |
paul@347 | 2159 | # Output view controls. |
paul@347 | 2160 | |
paul@347 | 2161 | append(fmt.div(on=1, css_class="event-controls")) |
paul@347 | 2162 | append(self.writeViewControls()) |
paul@347 | 2163 | append(fmt.div(on=0)) |
paul@347 | 2164 | |
paul@347 | 2165 | # Close the calendar region. |
paul@347 | 2166 | |
paul@347 | 2167 | append(fmt.div(on=0)) |
paul@347 | 2168 | |
paul@347 | 2169 | # Add any scripts. |
paul@347 | 2170 | |
paul@347 | 2171 | if isinstance(fmt, request.html_formatter.__class__): |
paul@347 | 2172 | append(self.update_script) |
paul@347 | 2173 | |
paul@347 | 2174 | return ''.join(output) |
paul@347 | 2175 | |
paul@347 | 2176 | update_script = """\ |
paul@347 | 2177 | <script type="text/javascript"> |
paul@347 | 2178 | function replaceCalendar(name, url) { |
paul@347 | 2179 | var calendar = document.getElementById(name); |
paul@347 | 2180 | |
paul@347 | 2181 | if (calendar == null) { |
paul@347 | 2182 | return true; |
paul@347 | 2183 | } |
paul@347 | 2184 | |
paul@347 | 2185 | var xmlhttp = new XMLHttpRequest(); |
paul@347 | 2186 | xmlhttp.open("GET", url, false); |
paul@347 | 2187 | xmlhttp.send(null); |
paul@347 | 2188 | |
paul@347 | 2189 | var newCalendar = xmlhttp.responseText; |
paul@347 | 2190 | |
paul@347 | 2191 | if (newCalendar != null) { |
paul@347 | 2192 | calendar.innerHTML = newCalendar; |
paul@347 | 2193 | return false; |
paul@347 | 2194 | } |
paul@347 | 2195 | |
paul@347 | 2196 | return true; |
paul@347 | 2197 | } |
paul@347 | 2198 | </script> |
paul@347 | 2199 | """ |
paul@347 | 2200 | |
paul@347 | 2201 | # vim: tabstop=4 expandtab shiftwidth=4 |