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@347 | 453 | append(fmt.div(on=1, css_class="event-download-controls")) |
paul@347 | 454 | |
paul@347 | 455 | append(fmt.span(on=1, css_class="event-download")) |
paul@347 | 456 | append(fmt.text(_("Download..."))) |
paul@347 | 457 | append(fmt.div(on=1, css_class="event-download-popup")) |
paul@347 | 458 | |
paul@347 | 459 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 460 | append(fmt.span(on=1, css_class="event-download-types")) |
paul@347 | 461 | append(fmt.span(on=1, css_class="event-download-webcal")) |
paul@347 | 462 | append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_link)) |
paul@347 | 463 | append(fmt.span(on=0)) |
paul@347 | 464 | append(fmt.span(on=1, css_class="event-download-http")) |
paul@347 | 465 | append(linkToPage(request, page, _("http"), download_link)) |
paul@347 | 466 | append(fmt.span(on=0)) |
paul@347 | 467 | append(fmt.span(on=0)) # end types |
paul@347 | 468 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 469 | append(fmt.text(_("Download this view"))) |
paul@347 | 470 | append(fmt.span(on=0)) # end label |
paul@347 | 471 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@352 | 472 | append(fmt.text(shown_calendar_period)) |
paul@347 | 473 | append(fmt.span(on=0)) |
paul@347 | 474 | append(fmt.div(on=0)) |
paul@347 | 475 | |
paul@347 | 476 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 477 | append(fmt.span(on=1, css_class="event-download-types")) |
paul@347 | 478 | append(fmt.span(on=1, css_class="event-download-webcal")) |
paul@347 | 479 | append(linkToResource(full_url.replace("http", "webcal", 1), request, _("webcal"), download_all_link)) |
paul@347 | 480 | append(fmt.span(on=0)) |
paul@347 | 481 | append(fmt.span(on=1, css_class="event-download-http")) |
paul@347 | 482 | append(linkToPage(request, page, _("http"), download_all_link)) |
paul@347 | 483 | append(fmt.span(on=0)) |
paul@347 | 484 | append(fmt.span(on=0)) # end types |
paul@347 | 485 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 486 | append(fmt.text(_("Download this calendar"))) |
paul@347 | 487 | append(fmt.span(on=0)) # end label |
paul@347 | 488 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@347 | 489 | append(fmt.text(original_calendar_period)) |
paul@347 | 490 | append(fmt.span(on=0)) |
paul@347 | 491 | append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@347 | 492 | append(fmt.text(raw_calendar_period)) |
paul@347 | 493 | append(fmt.span(on=0)) |
paul@347 | 494 | append(fmt.div(on=0)) |
paul@347 | 495 | |
paul@347 | 496 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 497 | append(fmt.span(on=1, css_class="event-download-link")) |
paul@347 | 498 | append(linkToPage(request, page, _("Edit download options..."), download_dialogue_link)) |
paul@347 | 499 | append(fmt.span(on=0)) # end label |
paul@347 | 500 | append(fmt.div(on=0)) |
paul@347 | 501 | |
paul@347 | 502 | append(fmt.div(on=0)) # end of pop-up |
paul@347 | 503 | append(fmt.span(on=0)) # end of download |
paul@347 | 504 | |
paul@347 | 505 | # Subscription controls. |
paul@347 | 506 | |
paul@347 | 507 | append(fmt.span(on=1, css_class="event-download")) |
paul@347 | 508 | append(fmt.text(_("Subscribe..."))) |
paul@347 | 509 | append(fmt.div(on=1, css_class="event-download-popup")) |
paul@347 | 510 | |
paul@347 | 511 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 512 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 513 | append(linkToPage(request, page, _("Subscribe to this view"), subscribe_link)) |
paul@347 | 514 | append(fmt.span(on=0)) # end label |
paul@347 | 515 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@352 | 516 | append(fmt.text(shown_calendar_period)) |
paul@347 | 517 | append(fmt.span(on=0)) |
paul@347 | 518 | append(fmt.div(on=0)) |
paul@347 | 519 | |
paul@347 | 520 | append(fmt.div(on=1, css_class="event-download-item")) |
paul@347 | 521 | append(fmt.span(on=1, css_class="event-download-label")) |
paul@347 | 522 | append(linkToPage(request, page, _("Subscribe to this calendar"), subscribe_all_link)) |
paul@347 | 523 | append(fmt.span(on=0)) # end label |
paul@347 | 524 | append(fmt.span(on=1, css_class="event-download-period")) |
paul@347 | 525 | append(fmt.text(original_calendar_period)) |
paul@347 | 526 | append(fmt.span(on=0)) |
paul@347 | 527 | append(fmt.span(on=1, css_class="event-download-period-raw")) |
paul@347 | 528 | append(fmt.text(raw_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-link")) |
paul@347 | 534 | append(linkToPage(request, page, _("Edit subscription options..."), subscribe_dialogue_link)) |
paul@347 | 535 | append(fmt.span(on=0)) # end label |
paul@347 | 536 | append(fmt.div(on=0)) |
paul@347 | 537 | |
paul@347 | 538 | append(fmt.div(on=0)) # end of pop-up |
paul@347 | 539 | append(fmt.span(on=0)) # end of download |
paul@347 | 540 | |
paul@347 | 541 | append(fmt.div(on=0)) # end of controls |
paul@347 | 542 | |
paul@347 | 543 | return "".join(output) |
paul@347 | 544 | |
paul@347 | 545 | def writeViewControls(self): |
paul@347 | 546 | |
paul@347 | 547 | """ |
paul@347 | 548 | Return a representation of the view mode controls, permitting viewing of |
paul@347 | 549 | aggregated events in calendar, list or table form. |
paul@347 | 550 | """ |
paul@347 | 551 | |
paul@347 | 552 | page = self.page |
paul@347 | 553 | request = page.request |
paul@347 | 554 | fmt = request.formatter |
paul@347 | 555 | _ = request.getText |
paul@347 | 556 | |
paul@347 | 557 | output = [] |
paul@347 | 558 | append = output.append |
paul@347 | 559 | |
paul@347 | 560 | # For day view links to other views, the wider view parameters should |
paul@347 | 561 | # be used in order to be able to return to those other views. |
paul@347 | 562 | |
paul@347 | 563 | specific_start = self.calendar_start |
paul@347 | 564 | specific_end = self.calendar_end |
paul@347 | 565 | |
paul@347 | 566 | start = self.wider_calendar_start or self.original_calendar_start and specific_start |
paul@347 | 567 | end = self.wider_calendar_end or self.original_calendar_end and specific_end |
paul@347 | 568 | |
paul@347 | 569 | help_page = Page(request, "HelpOnEventAggregator") |
paul@347 | 570 | |
paul@347 | 571 | calendar_link = self.getNavigationLink(start and start.as_month(), end and end.as_month(), "calendar", "month") |
paul@347 | 572 | calendar_update_link = self.getUpdateLink(start and start.as_month(), end and end.as_month(), "calendar", "month") |
paul@347 | 573 | list_link = self.getNavigationLink(start, end, "list", "month") |
paul@347 | 574 | list_update_link = self.getUpdateLink(start, end, "list", "month") |
paul@347 | 575 | table_link = self.getNavigationLink(start, end, "table", "month") |
paul@347 | 576 | table_update_link = self.getUpdateLink(start, end, "table", "month") |
paul@347 | 577 | map_link = self.getNavigationLink(start, end, "map", "month") |
paul@347 | 578 | map_update_link = self.getUpdateLink(start, end, "map", "month") |
paul@347 | 579 | |
paul@347 | 580 | # Specific links permit date-level navigation. |
paul@347 | 581 | |
paul@347 | 582 | specific_day_link = self.getNavigationLink(specific_start, specific_end, "day", wider_start=start, wider_end=end) |
paul@347 | 583 | specific_day_update_link = self.getUpdateLink(specific_start, specific_end, "day", wider_start=start, wider_end=end) |
paul@347 | 584 | specific_list_link = self.getNavigationLink(specific_start, specific_end, "list", wider_start=start, wider_end=end) |
paul@347 | 585 | specific_list_update_link = self.getUpdateLink(specific_start, specific_end, "list", wider_start=start, wider_end=end) |
paul@347 | 586 | specific_table_link = self.getNavigationLink(specific_start, specific_end, "table", wider_start=start, wider_end=end) |
paul@347 | 587 | specific_table_update_link = self.getUpdateLink(specific_start, specific_end, "table", wider_start=start, wider_end=end) |
paul@347 | 588 | specific_map_link = self.getNavigationLink(specific_start, specific_end, "map", wider_start=start, wider_end=end) |
paul@347 | 589 | specific_map_update_link = self.getUpdateLink(specific_start, specific_end, "map", wider_start=start, wider_end=end) |
paul@347 | 590 | |
paul@347 | 591 | new_event_link = self.getNewEventLink(start) |
paul@347 | 592 | |
paul@347 | 593 | # Write the controls. |
paul@347 | 594 | |
paul@347 | 595 | append(fmt.div(on=1, css_class="event-view-controls")) |
paul@347 | 596 | |
paul@347 | 597 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 598 | append(linkToPage(request, help_page, _("Help"))) |
paul@347 | 599 | append(fmt.span(on=0)) |
paul@347 | 600 | |
paul@347 | 601 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 602 | append(linkToPage(request, page, _("New event"), new_event_link)) |
paul@347 | 603 | append(fmt.span(on=0)) |
paul@347 | 604 | |
paul@347 | 605 | if self.mode != "calendar": |
paul@347 | 606 | view_label = self.resolution == "date" and _("View day in calendar") or _("View as calendar") |
paul@347 | 607 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 608 | append(linkToPage(request, page, view_label, calendar_link, onclick=calendar_update_link)) |
paul@347 | 609 | append(fmt.span(on=0)) |
paul@347 | 610 | |
paul@347 | 611 | if self.resolution == "date" and self.mode != "day": |
paul@347 | 612 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 613 | append(linkToPage(request, page, _("View day as calendar"), specific_day_link, onclick=specific_day_update_link)) |
paul@347 | 614 | append(fmt.span(on=0)) |
paul@347 | 615 | |
paul@347 | 616 | if self.resolution != "date" and self.mode != "list" or self.resolution == "date": |
paul@347 | 617 | view_label = self.resolution == "date" and _("View day in list") or _("View as list") |
paul@347 | 618 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 619 | append(linkToPage(request, page, view_label, list_link, onclick=list_update_link)) |
paul@347 | 620 | append(fmt.span(on=0)) |
paul@347 | 621 | |
paul@347 | 622 | if self.resolution == "date" and self.mode != "list": |
paul@347 | 623 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 624 | append(linkToPage(request, page, _("View day as list"), |
paul@347 | 625 | specific_list_link, onclick=specific_list_update_link |
paul@347 | 626 | )) |
paul@347 | 627 | append(fmt.span(on=0)) |
paul@347 | 628 | |
paul@347 | 629 | if self.resolution != "date" and self.mode != "table" or self.resolution == "date": |
paul@347 | 630 | view_label = self.resolution == "date" and _("View day in table") or _("View as table") |
paul@347 | 631 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 632 | append(linkToPage(request, page, view_label, table_link, onclick=table_update_link)) |
paul@347 | 633 | append(fmt.span(on=0)) |
paul@347 | 634 | |
paul@347 | 635 | if self.resolution == "date" and self.mode != "table": |
paul@347 | 636 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 637 | append(linkToPage(request, page, _("View day as table"), |
paul@347 | 638 | specific_table_link, onclick=specific_table_update_link |
paul@347 | 639 | )) |
paul@347 | 640 | append(fmt.span(on=0)) |
paul@347 | 641 | |
paul@347 | 642 | if self.map_name: |
paul@347 | 643 | if self.resolution != "date" and self.mode != "map" or self.resolution == "date": |
paul@347 | 644 | view_label = self.resolution == "date" and _("View day in map") or _("View as map") |
paul@347 | 645 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 646 | append(linkToPage(request, page, view_label, map_link, onclick=map_update_link)) |
paul@347 | 647 | append(fmt.span(on=0)) |
paul@347 | 648 | |
paul@347 | 649 | if self.resolution == "date" and self.mode != "map": |
paul@347 | 650 | append(fmt.span(on=1, css_class="event-view")) |
paul@347 | 651 | append(linkToPage(request, page, _("View day as map"), |
paul@347 | 652 | specific_map_link, onclick=specific_map_update_link |
paul@347 | 653 | )) |
paul@347 | 654 | append(fmt.span(on=0)) |
paul@347 | 655 | |
paul@347 | 656 | append(fmt.div(on=0)) |
paul@347 | 657 | |
paul@347 | 658 | return "".join(output) |
paul@347 | 659 | |
paul@347 | 660 | def writeMapHeading(self): |
paul@347 | 661 | |
paul@347 | 662 | """ |
paul@347 | 663 | Return the calendar heading for the current calendar, providing links |
paul@347 | 664 | permitting navigation to other periods. |
paul@347 | 665 | """ |
paul@347 | 666 | |
paul@347 | 667 | label = self.getCalendarPeriod() |
paul@347 | 668 | |
paul@347 | 669 | if self.raw_calendar_start is None or self.raw_calendar_end is None: |
paul@347 | 670 | fmt = self.page.request.formatter |
paul@347 | 671 | output = [] |
paul@347 | 672 | append = output.append |
paul@347 | 673 | append(fmt.span(on=1)) |
paul@347 | 674 | append(fmt.text(label)) |
paul@347 | 675 | append(fmt.span(on=0)) |
paul@347 | 676 | return "".join(output) |
paul@347 | 677 | else: |
paul@347 | 678 | return self._writeCalendarHeading(label, self.calendar_start, self.calendar_end) |
paul@347 | 679 | |
paul@347 | 680 | def writeDateHeading(self, date): |
paul@347 | 681 | if isinstance(date, Date): |
paul@347 | 682 | return self.writeDayHeading(date) |
paul@347 | 683 | else: |
paul@347 | 684 | return self.writeMonthHeading(date) |
paul@347 | 685 | |
paul@347 | 686 | def writeMonthHeading(self, year_month): |
paul@347 | 687 | |
paul@347 | 688 | """ |
paul@347 | 689 | Return the calendar heading for the given 'year_month' (a Month object) |
paul@347 | 690 | providing links permitting navigation to other months. |
paul@347 | 691 | """ |
paul@347 | 692 | |
paul@347 | 693 | full_month_label = self.getFullMonthLabel(year_month) |
paul@347 | 694 | end_month = year_month.update(self.duration - 1) |
paul@347 | 695 | return self._writeCalendarHeading(full_month_label, year_month, end_month) |
paul@347 | 696 | |
paul@347 | 697 | def writeDayHeading(self, date): |
paul@347 | 698 | |
paul@347 | 699 | """ |
paul@347 | 700 | Return the calendar heading for the given 'date' (a Date object) |
paul@347 | 701 | providing links permitting navigation to other dates. |
paul@347 | 702 | """ |
paul@347 | 703 | |
paul@347 | 704 | full_date_label = self.getFullDateLabel(date) |
paul@347 | 705 | end_date = date.update(self.duration - 1) |
paul@347 | 706 | return self._writeCalendarHeading(full_date_label, date, end_date) |
paul@347 | 707 | |
paul@347 | 708 | def _writeCalendarHeading(self, label, start, end): |
paul@347 | 709 | |
paul@347 | 710 | """ |
paul@347 | 711 | Write a calendar heading providing links permitting navigation to other |
paul@347 | 712 | periods, using the given 'label' along with the 'start' and 'end' dates |
paul@347 | 713 | to provide a link to a particular period. |
paul@347 | 714 | """ |
paul@347 | 715 | |
paul@347 | 716 | page = self.page |
paul@347 | 717 | request = page.request |
paul@347 | 718 | fmt = request.formatter |
paul@347 | 719 | _ = request.getText |
paul@347 | 720 | |
paul@347 | 721 | output = [] |
paul@347 | 722 | append = output.append |
paul@347 | 723 | |
paul@347 | 724 | # Prepare navigation links. |
paul@347 | 725 | |
paul@347 | 726 | if self.calendar_name: |
paul@347 | 727 | calendar_name = self.calendar_name |
paul@347 | 728 | |
paul@347 | 729 | # Links to the previous set of months and to a calendar shifted |
paul@347 | 730 | # back one month. |
paul@347 | 731 | |
paul@347 | 732 | previous_set_link = self.getNavigationLink( |
paul@347 | 733 | self.previous_set_start, self.previous_set_end |
paul@347 | 734 | ) |
paul@347 | 735 | previous_link = self.getNavigationLink( |
paul@347 | 736 | self.previous_start, self.previous_end |
paul@347 | 737 | ) |
paul@347 | 738 | previous_set_update_link = self.getUpdateLink( |
paul@347 | 739 | self.previous_set_start, self.previous_set_end |
paul@347 | 740 | ) |
paul@347 | 741 | previous_update_link = self.getUpdateLink( |
paul@347 | 742 | self.previous_start, self.previous_end |
paul@347 | 743 | ) |
paul@347 | 744 | |
paul@347 | 745 | # Links to the next set of months and to a calendar shifted |
paul@347 | 746 | # forward one month. |
paul@347 | 747 | |
paul@347 | 748 | next_set_link = self.getNavigationLink( |
paul@347 | 749 | self.next_set_start, self.next_set_end |
paul@347 | 750 | ) |
paul@347 | 751 | next_link = self.getNavigationLink( |
paul@347 | 752 | self.next_start, self.next_end |
paul@347 | 753 | ) |
paul@347 | 754 | next_set_update_link = self.getUpdateLink( |
paul@347 | 755 | self.next_set_start, self.next_set_end |
paul@347 | 756 | ) |
paul@347 | 757 | next_update_link = self.getUpdateLink( |
paul@347 | 758 | self.next_start, self.next_end |
paul@347 | 759 | ) |
paul@347 | 760 | |
paul@347 | 761 | # A link leading to this date being at the top of the calendar. |
paul@347 | 762 | |
paul@347 | 763 | date_link = self.getNavigationLink(start, end) |
paul@347 | 764 | date_update_link = self.getUpdateLink(start, end) |
paul@347 | 765 | |
paul@347 | 766 | append(fmt.span(on=1, css_class="previous")) |
paul@347 | 767 | append(linkToPage(request, page, "<<", previous_set_link, onclick=previous_set_update_link)) |
paul@347 | 768 | append(fmt.text(" ")) |
paul@347 | 769 | append(linkToPage(request, page, "<", previous_link, onclick=previous_update_link)) |
paul@347 | 770 | append(fmt.span(on=0)) |
paul@347 | 771 | |
paul@347 | 772 | append(fmt.span(on=1, css_class="next")) |
paul@347 | 773 | append(linkToPage(request, page, ">", next_link, onclick=next_update_link)) |
paul@347 | 774 | append(fmt.text(" ")) |
paul@347 | 775 | append(linkToPage(request, page, ">>", next_set_link, onclick=next_set_update_link)) |
paul@347 | 776 | append(fmt.span(on=0)) |
paul@347 | 777 | |
paul@347 | 778 | append(linkToPage(request, page, label, date_link, onclick=date_update_link)) |
paul@347 | 779 | |
paul@347 | 780 | else: |
paul@347 | 781 | append(fmt.span(on=1)) |
paul@347 | 782 | append(fmt.text(label)) |
paul@347 | 783 | append(fmt.span(on=0)) |
paul@347 | 784 | |
paul@347 | 785 | return "".join(output) |
paul@347 | 786 | |
paul@347 | 787 | def writeDayNumberHeading(self, date, busy): |
paul@347 | 788 | |
paul@347 | 789 | """ |
paul@347 | 790 | Return a link for the given 'date' which will activate the new event |
paul@347 | 791 | action for the given day. If 'busy' is given as a true value, the |
paul@347 | 792 | heading will be marked as busy. |
paul@347 | 793 | """ |
paul@347 | 794 | |
paul@347 | 795 | page = self.page |
paul@347 | 796 | request = page.request |
paul@347 | 797 | fmt = request.formatter |
paul@347 | 798 | _ = request.getText |
paul@347 | 799 | |
paul@347 | 800 | output = [] |
paul@347 | 801 | append = output.append |
paul@347 | 802 | |
paul@347 | 803 | year, month, day = date.as_tuple() |
paul@347 | 804 | new_event_link = self.getNewEventLink(date) |
paul@347 | 805 | |
paul@347 | 806 | # Prepare a link to the day view for this day. |
paul@347 | 807 | |
paul@347 | 808 | day_view_link = self.getNavigationLink(date, date, "day", "date", self.calendar_start, self.calendar_end) |
paul@347 | 809 | day_view_update_link = self.getUpdateLink(date, date, "day", "date", self.calendar_start, self.calendar_end) |
paul@347 | 810 | |
paul@347 | 811 | # Output the heading class. |
paul@347 | 812 | |
paul@347 | 813 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 814 | |
paul@347 | 815 | append( |
paul@347 | 816 | fmt.table_cell(on=1, attrs={ |
paul@347 | 817 | "class" : "event-day-heading event-day-%s %s" % (busy and "busy" or "empty", today_attr), |
paul@347 | 818 | "colspan" : "3" |
paul@347 | 819 | })) |
paul@347 | 820 | |
paul@347 | 821 | # Output the number and pop-up menu. |
paul@347 | 822 | |
paul@347 | 823 | append(fmt.div(on=1, css_class="event-day-box")) |
paul@347 | 824 | |
paul@347 | 825 | append(fmt.span(on=1, css_class="event-day-number-popup")) |
paul@347 | 826 | append(fmt.span(on=1, css_class="event-day-number-link")) |
paul@347 | 827 | append(linkToPage(request, page, _("View day"), day_view_link, onclick=day_view_update_link)) |
paul@347 | 828 | append(fmt.span(on=0)) |
paul@347 | 829 | append(fmt.span(on=1, css_class="event-day-number-link")) |
paul@347 | 830 | append(linkToPage(request, page, _("New event"), new_event_link)) |
paul@347 | 831 | append(fmt.span(on=0)) |
paul@347 | 832 | append(fmt.span(on=0)) |
paul@347 | 833 | |
paul@347 | 834 | append(fmt.span(on=1, css_class="event-day-number")) |
paul@347 | 835 | append(fmt.text(unicode(day))) |
paul@347 | 836 | append(fmt.span(on=0)) |
paul@347 | 837 | |
paul@347 | 838 | append(fmt.div(on=0)) |
paul@347 | 839 | |
paul@347 | 840 | # End of heading. |
paul@347 | 841 | |
paul@347 | 842 | append(fmt.table_cell(on=0)) |
paul@347 | 843 | |
paul@347 | 844 | return "".join(output) |
paul@347 | 845 | |
paul@347 | 846 | # Common layout methods. |
paul@347 | 847 | |
paul@347 | 848 | def getEventStyle(self, colour_seed): |
paul@347 | 849 | |
paul@347 | 850 | "Generate colour style information using the given 'colour_seed'." |
paul@347 | 851 | |
paul@347 | 852 | bg = getColour(colour_seed) |
paul@347 | 853 | fg = getBlackOrWhite(bg) |
paul@347 | 854 | return "background-color: rgb(%d, %d, %d); color: rgb(%d, %d, %d);" % (bg + fg) |
paul@347 | 855 | |
paul@347 | 856 | def writeEventSummaryBox(self, event): |
paul@347 | 857 | |
paul@347 | 858 | "Return an event summary box linking to the given 'event'." |
paul@347 | 859 | |
paul@347 | 860 | page = self.page |
paul@347 | 861 | request = page.request |
paul@347 | 862 | fmt = request.formatter |
paul@347 | 863 | |
paul@347 | 864 | output = [] |
paul@347 | 865 | append = output.append |
paul@347 | 866 | |
paul@347 | 867 | event_details = event.getDetails() |
paul@347 | 868 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 869 | |
paul@347 | 870 | is_ambiguous = event.as_timespan().ambiguous() |
paul@347 | 871 | style = self.getEventStyle(event_summary) |
paul@347 | 872 | |
paul@347 | 873 | # The event box contains the summary, alongside |
paul@347 | 874 | # other elements. |
paul@347 | 875 | |
paul@347 | 876 | append(fmt.div(on=1, css_class="event-summary-box")) |
paul@347 | 877 | append(fmt.div(on=1, css_class="event-summary", style=style)) |
paul@347 | 878 | |
paul@347 | 879 | if is_ambiguous: |
paul@347 | 880 | append(fmt.icon("/!\\")) |
paul@347 | 881 | |
paul@347 | 882 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 883 | append(fmt.div(on=0)) |
paul@347 | 884 | |
paul@347 | 885 | # Add a pop-up element for long summaries. |
paul@347 | 886 | |
paul@347 | 887 | append(fmt.div(on=1, css_class="event-summary-popup", style=style)) |
paul@347 | 888 | |
paul@347 | 889 | if is_ambiguous: |
paul@347 | 890 | append(fmt.icon("/!\\")) |
paul@347 | 891 | |
paul@347 | 892 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 893 | append(fmt.div(on=0)) |
paul@347 | 894 | |
paul@347 | 895 | append(fmt.div(on=0)) |
paul@347 | 896 | |
paul@347 | 897 | return "".join(output) |
paul@347 | 898 | |
paul@347 | 899 | # Calendar layout methods. |
paul@347 | 900 | |
paul@347 | 901 | def writeMonthTableHeading(self, year_month): |
paul@347 | 902 | page = self.page |
paul@347 | 903 | fmt = page.request.formatter |
paul@347 | 904 | |
paul@347 | 905 | output = [] |
paul@347 | 906 | append = output.append |
paul@347 | 907 | |
paul@347 | 908 | append(fmt.table_row(on=1)) |
paul@347 | 909 | append(fmt.table_cell(on=1, attrs={"class" : "event-month-heading", "colspan" : "21"})) |
paul@347 | 910 | |
paul@347 | 911 | append(self.writeMonthHeading(year_month)) |
paul@347 | 912 | |
paul@347 | 913 | append(fmt.table_cell(on=0)) |
paul@347 | 914 | append(fmt.table_row(on=0)) |
paul@347 | 915 | |
paul@347 | 916 | return "".join(output) |
paul@347 | 917 | |
paul@347 | 918 | def writeWeekdayHeadings(self): |
paul@347 | 919 | page = self.page |
paul@347 | 920 | request = page.request |
paul@347 | 921 | fmt = request.formatter |
paul@347 | 922 | _ = request.getText |
paul@347 | 923 | |
paul@347 | 924 | output = [] |
paul@347 | 925 | append = output.append |
paul@347 | 926 | |
paul@347 | 927 | append(fmt.table_row(on=1)) |
paul@347 | 928 | |
paul@347 | 929 | for weekday in range(0, 7): |
paul@347 | 930 | append(fmt.table_cell(on=1, attrs={"class" : "event-weekday-heading", "colspan" : "3"})) |
paul@347 | 931 | append(fmt.text(_(getDayLabel(weekday)))) |
paul@347 | 932 | append(fmt.table_cell(on=0)) |
paul@347 | 933 | |
paul@347 | 934 | append(fmt.table_row(on=0)) |
paul@347 | 935 | return "".join(output) |
paul@347 | 936 | |
paul@347 | 937 | def writeDayNumbers(self, first_day, number_of_days, month, coverage): |
paul@347 | 938 | page = self.page |
paul@347 | 939 | fmt = page.request.formatter |
paul@347 | 940 | |
paul@347 | 941 | output = [] |
paul@347 | 942 | append = output.append |
paul@347 | 943 | |
paul@347 | 944 | append(fmt.table_row(on=1)) |
paul@347 | 945 | |
paul@347 | 946 | for weekday in range(0, 7): |
paul@347 | 947 | day = first_day + weekday |
paul@347 | 948 | date = month.as_date(day) |
paul@347 | 949 | |
paul@347 | 950 | # Output out-of-month days. |
paul@347 | 951 | |
paul@347 | 952 | if day < 1 or day > number_of_days: |
paul@347 | 953 | append(fmt.table_cell(on=1, |
paul@347 | 954 | attrs={"class" : "event-day-heading event-day-excluded", "colspan" : "3"})) |
paul@347 | 955 | append(fmt.table_cell(on=0)) |
paul@347 | 956 | |
paul@347 | 957 | # Output normal days. |
paul@347 | 958 | |
paul@347 | 959 | else: |
paul@347 | 960 | # Output the day heading, making a link to a new event |
paul@347 | 961 | # action. |
paul@347 | 962 | |
paul@347 | 963 | append(self.writeDayNumberHeading(date, date in coverage)) |
paul@347 | 964 | |
paul@347 | 965 | # End of day numbers. |
paul@347 | 966 | |
paul@347 | 967 | append(fmt.table_row(on=0)) |
paul@347 | 968 | return "".join(output) |
paul@347 | 969 | |
paul@347 | 970 | def writeEmptyWeek(self, first_day, number_of_days, month): |
paul@347 | 971 | page = self.page |
paul@347 | 972 | fmt = page.request.formatter |
paul@347 | 973 | |
paul@347 | 974 | output = [] |
paul@347 | 975 | append = output.append |
paul@347 | 976 | |
paul@347 | 977 | append(fmt.table_row(on=1)) |
paul@347 | 978 | |
paul@347 | 979 | for weekday in range(0, 7): |
paul@347 | 980 | day = first_day + weekday |
paul@347 | 981 | date = month.as_date(day) |
paul@347 | 982 | |
paul@347 | 983 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 984 | |
paul@347 | 985 | # Output out-of-month days. |
paul@347 | 986 | |
paul@347 | 987 | if day < 1 or day > number_of_days: |
paul@347 | 988 | append(fmt.table_cell(on=1, |
paul@347 | 989 | attrs={"class" : "event-day-content event-day-excluded %s" % today_attr, "colspan" : "3"})) |
paul@347 | 990 | append(fmt.table_cell(on=0)) |
paul@347 | 991 | |
paul@347 | 992 | # Output empty days. |
paul@347 | 993 | |
paul@347 | 994 | else: |
paul@347 | 995 | append(fmt.table_cell(on=1, |
paul@347 | 996 | attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"})) |
paul@347 | 997 | |
paul@347 | 998 | append(fmt.table_row(on=0)) |
paul@347 | 999 | return "".join(output) |
paul@347 | 1000 | |
paul@347 | 1001 | def writeWeekSlots(self, first_day, number_of_days, month, week_end, week_slots): |
paul@347 | 1002 | output = [] |
paul@347 | 1003 | append = output.append |
paul@347 | 1004 | |
paul@347 | 1005 | locations = week_slots.keys() |
paul@347 | 1006 | locations.sort(sort_none_first) |
paul@347 | 1007 | |
paul@347 | 1008 | # Visit each slot corresponding to a location (or no location). |
paul@347 | 1009 | |
paul@347 | 1010 | for location in locations: |
paul@347 | 1011 | |
paul@347 | 1012 | # Visit each coverage span, presenting the events in the span. |
paul@347 | 1013 | |
paul@347 | 1014 | for events in week_slots[location]: |
paul@347 | 1015 | |
paul@347 | 1016 | # Output each set. |
paul@347 | 1017 | |
paul@347 | 1018 | append(self.writeWeekSlot(first_day, number_of_days, month, week_end, events)) |
paul@347 | 1019 | |
paul@347 | 1020 | # Add a spacer. |
paul@347 | 1021 | |
paul@347 | 1022 | append(self.writeWeekSpacer(first_day, number_of_days, month)) |
paul@347 | 1023 | |
paul@347 | 1024 | return "".join(output) |
paul@347 | 1025 | |
paul@347 | 1026 | def writeWeekSlot(self, first_day, number_of_days, month, week_end, events): |
paul@347 | 1027 | page = self.page |
paul@347 | 1028 | request = page.request |
paul@347 | 1029 | fmt = request.formatter |
paul@347 | 1030 | |
paul@347 | 1031 | output = [] |
paul@347 | 1032 | append = output.append |
paul@347 | 1033 | |
paul@347 | 1034 | append(fmt.table_row(on=1)) |
paul@347 | 1035 | |
paul@347 | 1036 | # Then, output day details. |
paul@347 | 1037 | |
paul@347 | 1038 | for weekday in range(0, 7): |
paul@347 | 1039 | day = first_day + weekday |
paul@347 | 1040 | date = month.as_date(day) |
paul@347 | 1041 | |
paul@347 | 1042 | # Skip out-of-month days. |
paul@347 | 1043 | |
paul@347 | 1044 | if day < 1 or day > number_of_days: |
paul@347 | 1045 | append(fmt.table_cell(on=1, |
paul@347 | 1046 | attrs={"class" : "event-day-content event-day-excluded", "colspan" : "3"})) |
paul@347 | 1047 | append(fmt.table_cell(on=0)) |
paul@347 | 1048 | continue |
paul@347 | 1049 | |
paul@347 | 1050 | # Output the day. |
paul@347 | 1051 | # Where a day does not contain an event, a single cell is used. |
paul@347 | 1052 | # Otherwise, multiple cells are used to provide space before, during |
paul@347 | 1053 | # and after events. |
paul@347 | 1054 | |
paul@347 | 1055 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 1056 | |
paul@347 | 1057 | if date not in events: |
paul@347 | 1058 | append(fmt.table_cell(on=1, |
paul@347 | 1059 | attrs={"class" : "event-day-content event-day-empty %s" % today_attr, "colspan" : "3"})) |
paul@347 | 1060 | |
paul@347 | 1061 | # Get event details for the current day. |
paul@347 | 1062 | |
paul@347 | 1063 | for event in events: |
paul@347 | 1064 | event_details = event.getDetails() |
paul@347 | 1065 | |
paul@347 | 1066 | if date not in event: |
paul@347 | 1067 | continue |
paul@347 | 1068 | |
paul@347 | 1069 | # Get basic properties of the event. |
paul@347 | 1070 | |
paul@347 | 1071 | starts_today = event_details["start"] == date |
paul@347 | 1072 | ends_today = event_details["end"] == date |
paul@347 | 1073 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1074 | |
paul@347 | 1075 | style = self.getEventStyle(event_summary) |
paul@347 | 1076 | |
paul@347 | 1077 | # Determine if the event name should be shown. |
paul@347 | 1078 | |
paul@347 | 1079 | start_of_period = starts_today or weekday == 0 or day == 1 |
paul@347 | 1080 | |
paul@347 | 1081 | if self.name_usage == "daily" or start_of_period: |
paul@347 | 1082 | hide_text = 0 |
paul@347 | 1083 | else: |
paul@347 | 1084 | hide_text = 1 |
paul@347 | 1085 | |
paul@347 | 1086 | # Output start of day gap and determine whether |
paul@347 | 1087 | # any event content should be explicitly output |
paul@347 | 1088 | # for this day. |
paul@347 | 1089 | |
paul@347 | 1090 | if starts_today: |
paul@347 | 1091 | |
paul@347 | 1092 | # Single day events... |
paul@347 | 1093 | |
paul@347 | 1094 | if ends_today: |
paul@347 | 1095 | colspan = 3 |
paul@347 | 1096 | event_day_type = "event-day-single" |
paul@347 | 1097 | |
paul@347 | 1098 | # Events starting today... |
paul@347 | 1099 | |
paul@347 | 1100 | else: |
paul@347 | 1101 | append(fmt.table_cell(on=1, attrs={"class" : "event-day-start-gap %s" % today_attr})) |
paul@347 | 1102 | append(fmt.table_cell(on=0)) |
paul@347 | 1103 | |
paul@347 | 1104 | # Calculate the span of this cell. |
paul@347 | 1105 | # Events whose names appear on every day... |
paul@347 | 1106 | |
paul@347 | 1107 | if self.name_usage == "daily": |
paul@347 | 1108 | colspan = 2 |
paul@347 | 1109 | event_day_type = "event-day-starting" |
paul@347 | 1110 | |
paul@347 | 1111 | # Events whose names appear once per week... |
paul@347 | 1112 | |
paul@347 | 1113 | else: |
paul@347 | 1114 | if event_details["end"] <= week_end: |
paul@347 | 1115 | event_length = event_details["end"].day() - day + 1 |
paul@347 | 1116 | colspan = (event_length - 2) * 3 + 4 |
paul@347 | 1117 | else: |
paul@347 | 1118 | event_length = week_end.day() - day + 1 |
paul@347 | 1119 | colspan = (event_length - 1) * 3 + 2 |
paul@347 | 1120 | |
paul@347 | 1121 | event_day_type = "event-day-multiple" |
paul@347 | 1122 | |
paul@347 | 1123 | # Events continuing from a previous week... |
paul@347 | 1124 | |
paul@347 | 1125 | elif start_of_period: |
paul@347 | 1126 | |
paul@347 | 1127 | # End of continuing event... |
paul@347 | 1128 | |
paul@347 | 1129 | if ends_today: |
paul@347 | 1130 | colspan = 2 |
paul@347 | 1131 | event_day_type = "event-day-ending" |
paul@347 | 1132 | |
paul@347 | 1133 | # Events continuing for at least one more day... |
paul@347 | 1134 | |
paul@347 | 1135 | else: |
paul@347 | 1136 | |
paul@347 | 1137 | # Calculate the span of this cell. |
paul@347 | 1138 | # Events whose names appear on every day... |
paul@347 | 1139 | |
paul@347 | 1140 | if self.name_usage == "daily": |
paul@347 | 1141 | colspan = 3 |
paul@347 | 1142 | event_day_type = "event-day-full" |
paul@347 | 1143 | |
paul@347 | 1144 | # Events whose names appear once per week... |
paul@347 | 1145 | |
paul@347 | 1146 | else: |
paul@347 | 1147 | if event_details["end"] <= week_end: |
paul@347 | 1148 | event_length = event_details["end"].day() - day + 1 |
paul@347 | 1149 | colspan = (event_length - 1) * 3 + 2 |
paul@347 | 1150 | else: |
paul@347 | 1151 | event_length = week_end.day() - day + 1 |
paul@347 | 1152 | colspan = event_length * 3 |
paul@347 | 1153 | |
paul@347 | 1154 | event_day_type = "event-day-multiple" |
paul@347 | 1155 | |
paul@347 | 1156 | # Continuing events whose names appear on every day... |
paul@347 | 1157 | |
paul@347 | 1158 | elif self.name_usage == "daily": |
paul@347 | 1159 | if ends_today: |
paul@347 | 1160 | colspan = 2 |
paul@347 | 1161 | event_day_type = "event-day-ending" |
paul@347 | 1162 | else: |
paul@347 | 1163 | colspan = 3 |
paul@347 | 1164 | event_day_type = "event-day-full" |
paul@347 | 1165 | |
paul@347 | 1166 | # Continuing events whose names appear once per week... |
paul@347 | 1167 | |
paul@347 | 1168 | else: |
paul@347 | 1169 | colspan = None |
paul@347 | 1170 | |
paul@347 | 1171 | # Output the main content only if it is not |
paul@347 | 1172 | # continuing from a previous day. |
paul@347 | 1173 | |
paul@347 | 1174 | if colspan is not None: |
paul@347 | 1175 | |
paul@347 | 1176 | # Colour the cell for continuing events. |
paul@347 | 1177 | |
paul@347 | 1178 | attrs={ |
paul@347 | 1179 | "class" : "event-day-content event-day-busy %s %s" % (event_day_type, today_attr), |
paul@347 | 1180 | "colspan" : str(colspan) |
paul@347 | 1181 | } |
paul@347 | 1182 | |
paul@347 | 1183 | if not (starts_today and ends_today): |
paul@347 | 1184 | attrs["style"] = style |
paul@347 | 1185 | |
paul@347 | 1186 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1187 | |
paul@347 | 1188 | # Output the event. |
paul@347 | 1189 | |
paul@347 | 1190 | if starts_today and ends_today or not hide_text: |
paul@347 | 1191 | append(self.writeEventSummaryBox(event)) |
paul@347 | 1192 | |
paul@347 | 1193 | append(fmt.table_cell(on=0)) |
paul@347 | 1194 | |
paul@347 | 1195 | # Output end of day gap. |
paul@347 | 1196 | |
paul@347 | 1197 | if ends_today and not starts_today: |
paul@347 | 1198 | append(fmt.table_cell(on=1, attrs={"class" : "event-day-end-gap %s" % today_attr})) |
paul@347 | 1199 | append(fmt.table_cell(on=0)) |
paul@347 | 1200 | |
paul@347 | 1201 | # End of set. |
paul@347 | 1202 | |
paul@347 | 1203 | append(fmt.table_row(on=0)) |
paul@347 | 1204 | return "".join(output) |
paul@347 | 1205 | |
paul@347 | 1206 | def writeWeekSpacer(self, first_day, number_of_days, month): |
paul@347 | 1207 | page = self.page |
paul@347 | 1208 | fmt = page.request.formatter |
paul@347 | 1209 | |
paul@347 | 1210 | output = [] |
paul@347 | 1211 | append = output.append |
paul@347 | 1212 | |
paul@347 | 1213 | append(fmt.table_row(on=1)) |
paul@347 | 1214 | |
paul@347 | 1215 | for weekday in range(0, 7): |
paul@347 | 1216 | day = first_day + weekday |
paul@347 | 1217 | date = month.as_date(day) |
paul@347 | 1218 | today_attr = date == getCurrentDate() and "event-day-current" or "" |
paul@347 | 1219 | |
paul@347 | 1220 | css_classes = "event-day-spacer %s" % today_attr |
paul@347 | 1221 | |
paul@347 | 1222 | # Skip out-of-month days. |
paul@347 | 1223 | |
paul@347 | 1224 | if day < 1 or day > number_of_days: |
paul@347 | 1225 | css_classes += " event-day-excluded" |
paul@347 | 1226 | |
paul@347 | 1227 | append(fmt.table_cell(on=1, attrs={"class" : css_classes, "colspan" : "3"})) |
paul@347 | 1228 | append(fmt.table_cell(on=0)) |
paul@347 | 1229 | |
paul@347 | 1230 | append(fmt.table_row(on=0)) |
paul@347 | 1231 | return "".join(output) |
paul@347 | 1232 | |
paul@347 | 1233 | # Day layout methods. |
paul@347 | 1234 | |
paul@347 | 1235 | def writeDayTableHeading(self, date, colspan=1): |
paul@347 | 1236 | page = self.page |
paul@347 | 1237 | fmt = page.request.formatter |
paul@347 | 1238 | |
paul@347 | 1239 | output = [] |
paul@347 | 1240 | append = output.append |
paul@347 | 1241 | |
paul@347 | 1242 | append(fmt.table_row(on=1)) |
paul@347 | 1243 | |
paul@347 | 1244 | append(fmt.table_cell(on=1, attrs={"class" : "event-full-day-heading", "colspan" : str(colspan)})) |
paul@347 | 1245 | append(self.writeDayHeading(date)) |
paul@347 | 1246 | append(fmt.table_cell(on=0)) |
paul@347 | 1247 | |
paul@347 | 1248 | append(fmt.table_row(on=0)) |
paul@347 | 1249 | return "".join(output) |
paul@347 | 1250 | |
paul@347 | 1251 | def writeEmptyDay(self, date): |
paul@347 | 1252 | page = self.page |
paul@347 | 1253 | fmt = page.request.formatter |
paul@347 | 1254 | |
paul@347 | 1255 | output = [] |
paul@347 | 1256 | append = output.append |
paul@347 | 1257 | |
paul@347 | 1258 | append(fmt.table_row(on=1)) |
paul@347 | 1259 | |
paul@347 | 1260 | append(fmt.table_cell(on=1, |
paul@347 | 1261 | attrs={"class" : "event-day-content event-day-empty"})) |
paul@347 | 1262 | |
paul@347 | 1263 | append(fmt.table_row(on=0)) |
paul@347 | 1264 | return "".join(output) |
paul@347 | 1265 | |
paul@347 | 1266 | def writeDaySlots(self, date, full_coverage, day_slots): |
paul@347 | 1267 | |
paul@347 | 1268 | """ |
paul@347 | 1269 | Given a 'date', non-empty 'full_coverage' for the day concerned, and a |
paul@347 | 1270 | non-empty mapping of 'day_slots' (from locations to event collections), |
paul@347 | 1271 | output the day slots for the day. |
paul@347 | 1272 | """ |
paul@347 | 1273 | |
paul@347 | 1274 | page = self.page |
paul@347 | 1275 | fmt = page.request.formatter |
paul@347 | 1276 | |
paul@347 | 1277 | output = [] |
paul@347 | 1278 | append = output.append |
paul@347 | 1279 | |
paul@347 | 1280 | locations = day_slots.keys() |
paul@347 | 1281 | locations.sort(sort_none_first) |
paul@347 | 1282 | |
paul@347 | 1283 | # Traverse the time scale of the full coverage, visiting each slot to |
paul@347 | 1284 | # determine whether it provides content for each period. |
paul@347 | 1285 | |
paul@347 | 1286 | scale = getCoverageScale(full_coverage) |
paul@347 | 1287 | |
paul@347 | 1288 | # Define a mapping of events to rowspans. |
paul@347 | 1289 | |
paul@347 | 1290 | rowspans = {} |
paul@347 | 1291 | |
paul@347 | 1292 | # Populate each period with event details, recording how many periods |
paul@347 | 1293 | # each event populates. |
paul@347 | 1294 | |
paul@347 | 1295 | day_rows = [] |
paul@347 | 1296 | |
paul@347 | 1297 | for period in scale: |
paul@347 | 1298 | |
paul@347 | 1299 | # Ignore timespans before this day. |
paul@347 | 1300 | |
paul@347 | 1301 | if period != date: |
paul@347 | 1302 | continue |
paul@347 | 1303 | |
paul@347 | 1304 | # Visit each slot corresponding to a location (or no location). |
paul@347 | 1305 | |
paul@347 | 1306 | day_row = [] |
paul@347 | 1307 | |
paul@347 | 1308 | for location in locations: |
paul@347 | 1309 | |
paul@347 | 1310 | # Visit each coverage span, presenting the events in the span. |
paul@347 | 1311 | |
paul@347 | 1312 | for events in day_slots[location]: |
paul@347 | 1313 | event = self.getActiveEvent(period, events) |
paul@347 | 1314 | if event is not None: |
paul@347 | 1315 | if not rowspans.has_key(event): |
paul@347 | 1316 | rowspans[event] = 1 |
paul@347 | 1317 | else: |
paul@347 | 1318 | rowspans[event] += 1 |
paul@347 | 1319 | day_row.append((location, event)) |
paul@347 | 1320 | |
paul@347 | 1321 | day_rows.append((period, day_row)) |
paul@347 | 1322 | |
paul@347 | 1323 | # Output the locations. |
paul@347 | 1324 | |
paul@347 | 1325 | append(fmt.table_row(on=1)) |
paul@347 | 1326 | |
paul@347 | 1327 | # Add a spacer. |
paul@347 | 1328 | |
paul@347 | 1329 | append(self.writeDaySpacer(colspan=2, cls="location")) |
paul@347 | 1330 | |
paul@347 | 1331 | for location in locations: |
paul@347 | 1332 | |
paul@347 | 1333 | # Add spacers to the column spans. |
paul@347 | 1334 | |
paul@347 | 1335 | columns = len(day_slots[location]) * 2 - 1 |
paul@347 | 1336 | append(fmt.table_cell(on=1, attrs={"class" : "event-location-heading", "colspan" : str(columns)})) |
paul@347 | 1337 | append(fmt.text(location or "")) |
paul@347 | 1338 | append(fmt.table_cell(on=0)) |
paul@347 | 1339 | |
paul@347 | 1340 | # Add a trailing spacer. |
paul@347 | 1341 | |
paul@347 | 1342 | append(self.writeDaySpacer(cls="location")) |
paul@347 | 1343 | |
paul@347 | 1344 | append(fmt.table_row(on=0)) |
paul@347 | 1345 | |
paul@347 | 1346 | # Output the periods with event details. |
paul@347 | 1347 | |
paul@347 | 1348 | period = None |
paul@347 | 1349 | events_written = set() |
paul@347 | 1350 | |
paul@347 | 1351 | for period, day_row in day_rows: |
paul@347 | 1352 | |
paul@347 | 1353 | # Write an empty heading for the start of the day where the first |
paul@347 | 1354 | # applicable timespan starts before this day. |
paul@347 | 1355 | |
paul@347 | 1356 | if period.start < date: |
paul@347 | 1357 | append(fmt.table_row(on=1)) |
paul@347 | 1358 | append(self.writeDayScaleHeading("")) |
paul@347 | 1359 | |
paul@347 | 1360 | # Otherwise, write a heading describing the time. |
paul@347 | 1361 | |
paul@347 | 1362 | else: |
paul@347 | 1363 | append(fmt.table_row(on=1)) |
paul@347 | 1364 | append(self.writeDayScaleHeading(period.start.time_string())) |
paul@347 | 1365 | |
paul@347 | 1366 | append(self.writeDaySpacer()) |
paul@347 | 1367 | |
paul@347 | 1368 | # Visit each slot corresponding to a location (or no location). |
paul@347 | 1369 | |
paul@347 | 1370 | for location, event in day_row: |
paul@347 | 1371 | |
paul@347 | 1372 | # Output each location slot's contribution. |
paul@347 | 1373 | |
paul@347 | 1374 | if event is None or event not in events_written: |
paul@347 | 1375 | append(self.writeDaySlot(period, event, event is None and 1 or rowspans[event])) |
paul@347 | 1376 | if event is not None: |
paul@347 | 1377 | events_written.add(event) |
paul@347 | 1378 | |
paul@347 | 1379 | # Add a trailing spacer. |
paul@347 | 1380 | |
paul@347 | 1381 | append(self.writeDaySpacer()) |
paul@347 | 1382 | |
paul@347 | 1383 | append(fmt.table_row(on=0)) |
paul@347 | 1384 | |
paul@347 | 1385 | # Write a final time heading if the last period ends in the current day. |
paul@347 | 1386 | |
paul@347 | 1387 | if period is not None: |
paul@347 | 1388 | if period.end == date: |
paul@347 | 1389 | append(fmt.table_row(on=1)) |
paul@347 | 1390 | append(self.writeDayScaleHeading(period.end.time_string())) |
paul@347 | 1391 | |
paul@347 | 1392 | for slot in day_row: |
paul@347 | 1393 | append(self.writeDaySpacer()) |
paul@347 | 1394 | append(self.writeEmptyDaySlot()) |
paul@347 | 1395 | |
paul@347 | 1396 | append(fmt.table_row(on=0)) |
paul@347 | 1397 | |
paul@347 | 1398 | return "".join(output) |
paul@347 | 1399 | |
paul@347 | 1400 | def writeDayScaleHeading(self, heading): |
paul@347 | 1401 | page = self.page |
paul@347 | 1402 | fmt = page.request.formatter |
paul@347 | 1403 | |
paul@347 | 1404 | output = [] |
paul@347 | 1405 | append = output.append |
paul@347 | 1406 | |
paul@347 | 1407 | append(fmt.table_cell(on=1, attrs={"class" : "event-scale-heading"})) |
paul@347 | 1408 | append(fmt.text(heading)) |
paul@347 | 1409 | append(fmt.table_cell(on=0)) |
paul@347 | 1410 | |
paul@347 | 1411 | return "".join(output) |
paul@347 | 1412 | |
paul@347 | 1413 | def getActiveEvent(self, period, events): |
paul@347 | 1414 | for event in events: |
paul@347 | 1415 | if period not in event: |
paul@347 | 1416 | continue |
paul@347 | 1417 | return event |
paul@347 | 1418 | else: |
paul@347 | 1419 | return None |
paul@347 | 1420 | |
paul@347 | 1421 | def writeDaySlot(self, period, event, rowspan): |
paul@347 | 1422 | page = self.page |
paul@347 | 1423 | fmt = page.request.formatter |
paul@347 | 1424 | |
paul@347 | 1425 | output = [] |
paul@347 | 1426 | append = output.append |
paul@347 | 1427 | |
paul@347 | 1428 | if event is not None: |
paul@347 | 1429 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1430 | style = self.getEventStyle(event_summary) |
paul@347 | 1431 | |
paul@347 | 1432 | append(fmt.table_cell(on=1, attrs={ |
paul@347 | 1433 | "class" : "event-timespan-content event-timespan-busy", |
paul@347 | 1434 | "style" : style, |
paul@347 | 1435 | "rowspan" : str(rowspan) |
paul@347 | 1436 | })) |
paul@347 | 1437 | append(self.writeEventSummaryBox(event)) |
paul@347 | 1438 | append(fmt.table_cell(on=0)) |
paul@347 | 1439 | else: |
paul@347 | 1440 | append(self.writeEmptyDaySlot()) |
paul@347 | 1441 | |
paul@347 | 1442 | return "".join(output) |
paul@347 | 1443 | |
paul@347 | 1444 | def writeEmptyDaySlot(self): |
paul@347 | 1445 | page = self.page |
paul@347 | 1446 | fmt = page.request.formatter |
paul@347 | 1447 | |
paul@347 | 1448 | output = [] |
paul@347 | 1449 | append = output.append |
paul@347 | 1450 | |
paul@347 | 1451 | append(fmt.table_cell(on=1, |
paul@347 | 1452 | attrs={"class" : "event-timespan-content event-timespan-empty"})) |
paul@347 | 1453 | append(fmt.table_cell(on=0)) |
paul@347 | 1454 | |
paul@347 | 1455 | return "".join(output) |
paul@347 | 1456 | |
paul@347 | 1457 | def writeDaySpacer(self, colspan=1, cls="timespan"): |
paul@347 | 1458 | page = self.page |
paul@347 | 1459 | fmt = page.request.formatter |
paul@347 | 1460 | |
paul@347 | 1461 | output = [] |
paul@347 | 1462 | append = output.append |
paul@347 | 1463 | |
paul@347 | 1464 | append(fmt.table_cell(on=1, attrs={ |
paul@347 | 1465 | "class" : "event-%s-spacer" % cls, |
paul@347 | 1466 | "colspan" : str(colspan)})) |
paul@347 | 1467 | append(fmt.table_cell(on=0)) |
paul@347 | 1468 | return "".join(output) |
paul@347 | 1469 | |
paul@347 | 1470 | # Map layout methods. |
paul@347 | 1471 | |
paul@347 | 1472 | def writeMapTableHeading(self): |
paul@347 | 1473 | page = self.page |
paul@347 | 1474 | fmt = page.request.formatter |
paul@347 | 1475 | |
paul@347 | 1476 | output = [] |
paul@347 | 1477 | append = output.append |
paul@347 | 1478 | |
paul@347 | 1479 | append(fmt.table_cell(on=1, attrs={"class" : "event-map-heading"})) |
paul@347 | 1480 | append(self.writeMapHeading()) |
paul@347 | 1481 | append(fmt.table_cell(on=0)) |
paul@347 | 1482 | |
paul@347 | 1483 | return "".join(output) |
paul@347 | 1484 | |
paul@347 | 1485 | def showDictError(self, text, pagename): |
paul@347 | 1486 | page = self.page |
paul@347 | 1487 | request = page.request |
paul@347 | 1488 | fmt = request.formatter |
paul@347 | 1489 | |
paul@347 | 1490 | output = [] |
paul@347 | 1491 | append = output.append |
paul@347 | 1492 | |
paul@347 | 1493 | append(fmt.div(on=1, attrs={"class" : "event-aggregator-error"})) |
paul@347 | 1494 | append(fmt.paragraph(on=1)) |
paul@347 | 1495 | append(fmt.text(text)) |
paul@347 | 1496 | append(fmt.paragraph(on=0)) |
paul@347 | 1497 | append(fmt.paragraph(on=1)) |
paul@347 | 1498 | append(linkToPage(request, Page(request, pagename), pagename)) |
paul@347 | 1499 | append(fmt.paragraph(on=0)) |
paul@347 | 1500 | |
paul@347 | 1501 | return "".join(output) |
paul@347 | 1502 | |
paul@347 | 1503 | def writeMapMarker(self, marker_x, marker_y, map_x_scale, map_y_scale, location, events): |
paul@347 | 1504 | |
paul@347 | 1505 | "Put a marker on the map." |
paul@347 | 1506 | |
paul@347 | 1507 | page = self.page |
paul@347 | 1508 | request = page.request |
paul@347 | 1509 | fmt = request.formatter |
paul@347 | 1510 | |
paul@347 | 1511 | output = [] |
paul@347 | 1512 | append = output.append |
paul@347 | 1513 | |
paul@347 | 1514 | append(fmt.listitem(on=1, css_class="event-map-label")) |
paul@347 | 1515 | |
paul@347 | 1516 | # Have a positioned marker for the print mode. |
paul@347 | 1517 | |
paul@347 | 1518 | append(fmt.div(on=1, css_class="event-map-label-only", |
paul@347 | 1519 | style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( |
paul@347 | 1520 | marker_x, marker_y, map_x_scale, map_y_scale)) |
paul@347 | 1521 | append(fmt.div(on=0)) |
paul@347 | 1522 | |
paul@347 | 1523 | # Have a marker containing a pop-up when using the screen mode, |
paul@347 | 1524 | # providing a normal block when using the print mode. |
paul@347 | 1525 | |
paul@347 | 1526 | append(fmt.div(on=1, css_class="event-map-label", |
paul@347 | 1527 | style="left:%dpx; top:%dpx; min-width:%dpx; min-height:%dpx") % ( |
paul@347 | 1528 | marker_x, marker_y, map_x_scale, map_y_scale)) |
paul@347 | 1529 | append(fmt.div(on=1, css_class="event-map-details")) |
paul@347 | 1530 | append(fmt.div(on=1, css_class="event-map-shadow")) |
paul@347 | 1531 | append(fmt.div(on=1, css_class="event-map-location")) |
paul@347 | 1532 | |
paul@347 | 1533 | # The location may have been given as formatted text, but this will not |
paul@347 | 1534 | # be usable in a heading, so it must be first converted to plain text. |
paul@347 | 1535 | |
paul@347 | 1536 | append(fmt.heading(on=1, depth=2)) |
paul@347 | 1537 | append(fmt.text(to_plain_text(location, request))) |
paul@347 | 1538 | append(fmt.heading(on=0, depth=2)) |
paul@347 | 1539 | |
paul@347 | 1540 | append(self.writeMapEventSummaries(events)) |
paul@347 | 1541 | |
paul@347 | 1542 | append(fmt.div(on=0)) |
paul@347 | 1543 | append(fmt.div(on=0)) |
paul@347 | 1544 | append(fmt.div(on=0)) |
paul@347 | 1545 | append(fmt.div(on=0)) |
paul@347 | 1546 | append(fmt.listitem(on=0)) |
paul@347 | 1547 | |
paul@347 | 1548 | return "".join(output) |
paul@347 | 1549 | |
paul@347 | 1550 | def writeMapEventSummaries(self, events): |
paul@347 | 1551 | |
paul@347 | 1552 | "Write summaries of the given 'events' for the map." |
paul@347 | 1553 | |
paul@347 | 1554 | page = self.page |
paul@347 | 1555 | request = page.request |
paul@347 | 1556 | fmt = request.formatter |
paul@347 | 1557 | |
paul@347 | 1558 | # Sort the events by date. |
paul@347 | 1559 | |
paul@347 | 1560 | events.sort(sort_start_first) |
paul@347 | 1561 | |
paul@347 | 1562 | # Write out a self-contained list of events. |
paul@347 | 1563 | |
paul@347 | 1564 | output = [] |
paul@347 | 1565 | append = output.append |
paul@347 | 1566 | |
paul@347 | 1567 | append(fmt.bullet_list(on=1, attr={"class" : "event-map-location-events"})) |
paul@347 | 1568 | |
paul@347 | 1569 | for event in events: |
paul@347 | 1570 | |
paul@347 | 1571 | # Get the event details. |
paul@347 | 1572 | |
paul@347 | 1573 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1574 | start, end = event.as_limits() |
paul@347 | 1575 | event_period = self._getCalendarPeriod( |
paul@347 | 1576 | start and self.getFullDateLabel(start), |
paul@347 | 1577 | end and self.getFullDateLabel(end), |
paul@347 | 1578 | "") |
paul@347 | 1579 | |
paul@347 | 1580 | append(fmt.listitem(on=1)) |
paul@347 | 1581 | |
paul@347 | 1582 | # Link to the page using the summary. |
paul@347 | 1583 | |
paul@347 | 1584 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 1585 | |
paul@347 | 1586 | # Add the event period. |
paul@347 | 1587 | |
paul@347 | 1588 | append(fmt.text(" ")) |
paul@347 | 1589 | append(fmt.span(on=1, css_class="event-map-period")) |
paul@347 | 1590 | append(fmt.text(event_period)) |
paul@347 | 1591 | append(fmt.span(on=0)) |
paul@347 | 1592 | |
paul@347 | 1593 | append(fmt.listitem(on=0)) |
paul@347 | 1594 | |
paul@347 | 1595 | append(fmt.bullet_list(on=0)) |
paul@347 | 1596 | |
paul@347 | 1597 | return "".join(output) |
paul@347 | 1598 | |
paul@347 | 1599 | def render(self, all_shown_events): |
paul@347 | 1600 | |
paul@347 | 1601 | """ |
paul@347 | 1602 | Render the view, returning the rendered representation as a string. |
paul@347 | 1603 | The view will show a list of 'all_shown_events'. |
paul@347 | 1604 | """ |
paul@347 | 1605 | |
paul@347 | 1606 | page = self.page |
paul@347 | 1607 | request = page.request |
paul@347 | 1608 | fmt = request.formatter |
paul@347 | 1609 | _ = request.getText |
paul@347 | 1610 | |
paul@347 | 1611 | # Make a calendar. |
paul@347 | 1612 | |
paul@347 | 1613 | output = [] |
paul@347 | 1614 | append = output.append |
paul@347 | 1615 | |
paul@347 | 1616 | append(fmt.div(on=1, css_class="event-calendar", id=("EventAggregator-%s" % self.getIdentifier()))) |
paul@347 | 1617 | |
paul@347 | 1618 | # Output download controls. |
paul@347 | 1619 | |
paul@347 | 1620 | append(fmt.div(on=1, css_class="event-controls")) |
paul@347 | 1621 | append(self.writeDownloadControls()) |
paul@347 | 1622 | append(fmt.div(on=0)) |
paul@347 | 1623 | |
paul@347 | 1624 | # Output a table. |
paul@347 | 1625 | |
paul@347 | 1626 | if self.mode == "table": |
paul@347 | 1627 | |
paul@347 | 1628 | # Start of table view output. |
paul@347 | 1629 | |
paul@347 | 1630 | append(fmt.table(on=1, attrs={"tableclass" : "event-table"})) |
paul@347 | 1631 | |
paul@347 | 1632 | append(fmt.table_row(on=1)) |
paul@347 | 1633 | append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@347 | 1634 | append(fmt.text(_("Event dates"))) |
paul@347 | 1635 | append(fmt.table_cell(on=0)) |
paul@347 | 1636 | append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@347 | 1637 | append(fmt.text(_("Event location"))) |
paul@347 | 1638 | append(fmt.table_cell(on=0)) |
paul@347 | 1639 | append(fmt.table_cell(on=1, attrs={"class" : "event-table-heading"})) |
paul@347 | 1640 | append(fmt.text(_("Event details"))) |
paul@347 | 1641 | append(fmt.table_cell(on=0)) |
paul@347 | 1642 | append(fmt.table_row(on=0)) |
paul@347 | 1643 | |
paul@347 | 1644 | # Show the events in order. |
paul@347 | 1645 | |
paul@347 | 1646 | all_shown_events.sort(sort_start_first) |
paul@347 | 1647 | |
paul@347 | 1648 | for event in all_shown_events: |
paul@347 | 1649 | event_page = event.getPage() |
paul@347 | 1650 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1651 | event_details = event.getDetails() |
paul@347 | 1652 | |
paul@347 | 1653 | # Prepare CSS classes with category-related styling. |
paul@347 | 1654 | |
paul@347 | 1655 | css_classes = ["event-table-details"] |
paul@347 | 1656 | |
paul@347 | 1657 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@347 | 1658 | |
paul@347 | 1659 | # Filter the category text to avoid illegal characters. |
paul@347 | 1660 | |
paul@347 | 1661 | css_classes.append("event-table-category-%s" % "".join(filter(lambda c: c.isalnum(), topic))) |
paul@347 | 1662 | |
paul@347 | 1663 | attrs = {"class" : " ".join(css_classes)} |
paul@347 | 1664 | |
paul@347 | 1665 | append(fmt.table_row(on=1)) |
paul@347 | 1666 | |
paul@347 | 1667 | # Start and end dates. |
paul@347 | 1668 | |
paul@347 | 1669 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1670 | append(fmt.span(on=1)) |
paul@347 | 1671 | append(fmt.text(str(event_details["start"]))) |
paul@347 | 1672 | append(fmt.span(on=0)) |
paul@347 | 1673 | |
paul@347 | 1674 | if event_details["start"] != event_details["end"]: |
paul@347 | 1675 | append(fmt.text(" - ")) |
paul@347 | 1676 | append(fmt.span(on=1)) |
paul@347 | 1677 | append(fmt.text(str(event_details["end"]))) |
paul@347 | 1678 | append(fmt.span(on=0)) |
paul@347 | 1679 | |
paul@347 | 1680 | append(fmt.table_cell(on=0)) |
paul@347 | 1681 | |
paul@347 | 1682 | # Location. |
paul@347 | 1683 | |
paul@347 | 1684 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1685 | |
paul@347 | 1686 | if event_details.has_key("location"): |
paul@347 | 1687 | append(event_page.formatText(event_details["location"], fmt)) |
paul@347 | 1688 | |
paul@347 | 1689 | append(fmt.table_cell(on=0)) |
paul@347 | 1690 | |
paul@347 | 1691 | # Link to the page using the summary. |
paul@347 | 1692 | |
paul@347 | 1693 | append(fmt.table_cell(on=1, attrs=attrs)) |
paul@347 | 1694 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 1695 | append(fmt.table_cell(on=0)) |
paul@347 | 1696 | |
paul@347 | 1697 | append(fmt.table_row(on=0)) |
paul@347 | 1698 | |
paul@347 | 1699 | # End of table view output. |
paul@347 | 1700 | |
paul@347 | 1701 | append(fmt.table(on=0)) |
paul@347 | 1702 | |
paul@347 | 1703 | # Output a map view. |
paul@347 | 1704 | |
paul@347 | 1705 | elif self.mode == "map": |
paul@347 | 1706 | |
paul@347 | 1707 | # Special dictionary pages. |
paul@347 | 1708 | |
paul@347 | 1709 | maps_page = getMapsPage(request) |
paul@347 | 1710 | locations_page = getLocationsPage(request) |
paul@347 | 1711 | |
paul@347 | 1712 | map_image = None |
paul@347 | 1713 | |
paul@347 | 1714 | # Get the maps and locations. |
paul@347 | 1715 | |
paul@347 | 1716 | maps = getWikiDict(maps_page, request) |
paul@347 | 1717 | locations = getWikiDict(locations_page, request) |
paul@347 | 1718 | |
paul@347 | 1719 | # Get the map image definition. |
paul@347 | 1720 | |
paul@347 | 1721 | if maps is not None and self.map_name: |
paul@347 | 1722 | try: |
paul@347 | 1723 | map_details = maps[self.map_name].split() |
paul@347 | 1724 | |
paul@347 | 1725 | map_bottom_left_latitude, map_bottom_left_longitude, map_top_right_latitude, map_top_right_longitude = \ |
paul@347 | 1726 | map(getMapReference, map_details[:4]) |
paul@347 | 1727 | map_width, map_height = map(int, map_details[4:6]) |
paul@347 | 1728 | map_image = map_details[6] |
paul@347 | 1729 | |
paul@347 | 1730 | map_x_scale = map_width / (map_top_right_longitude - map_bottom_left_longitude).to_degrees() |
paul@347 | 1731 | map_y_scale = map_height / (map_top_right_latitude - map_bottom_left_latitude).to_degrees() |
paul@347 | 1732 | |
paul@347 | 1733 | except (KeyError, ValueError): |
paul@347 | 1734 | pass |
paul@347 | 1735 | |
paul@347 | 1736 | # Report errors. |
paul@347 | 1737 | |
paul@347 | 1738 | if maps is None: |
paul@347 | 1739 | append(self.showDictError( |
paul@347 | 1740 | _("You do not have read access to the maps page:"), |
paul@347 | 1741 | maps_page)) |
paul@347 | 1742 | |
paul@347 | 1743 | elif not self.map_name: |
paul@347 | 1744 | append(self.showDictError( |
paul@347 | 1745 | _("Please specify a valid map name corresponding to an entry on the following page:"), |
paul@347 | 1746 | maps_page)) |
paul@347 | 1747 | |
paul@347 | 1748 | elif map_image is None: |
paul@347 | 1749 | append(self.showDictError( |
paul@347 | 1750 | _("Please specify a valid entry for %s on the following page:") % self.map_name, |
paul@347 | 1751 | maps_page)) |
paul@347 | 1752 | |
paul@347 | 1753 | elif locations is None: |
paul@347 | 1754 | append(self.showDictError( |
paul@347 | 1755 | _("You do not have read access to the locations page:"), |
paul@347 | 1756 | locations_page)) |
paul@347 | 1757 | |
paul@347 | 1758 | # Attempt to show the map. |
paul@347 | 1759 | |
paul@347 | 1760 | else: |
paul@347 | 1761 | |
paul@347 | 1762 | # Get events by position. |
paul@347 | 1763 | |
paul@347 | 1764 | events_by_location = {} |
paul@347 | 1765 | event_locations = {} |
paul@347 | 1766 | |
paul@347 | 1767 | for event in all_shown_events: |
paul@347 | 1768 | event_details = event.getDetails() |
paul@347 | 1769 | |
paul@347 | 1770 | location = event_details.get("location") |
paul@347 | 1771 | geo = event_details.get("geo") |
paul@347 | 1772 | |
paul@347 | 1773 | # Make a temporary location if an explicit position is given |
paul@347 | 1774 | # but not a location name. |
paul@347 | 1775 | |
paul@347 | 1776 | if not location and geo: |
paul@347 | 1777 | location = "%s %s" % tuple(geo) |
paul@347 | 1778 | |
paul@347 | 1779 | # Map the location to a position. |
paul@347 | 1780 | |
paul@347 | 1781 | if location is not None and not event_locations.has_key(location): |
paul@347 | 1782 | |
paul@347 | 1783 | # Get any explicit position of an event. |
paul@347 | 1784 | |
paul@347 | 1785 | if geo: |
paul@347 | 1786 | latitude, longitude = geo |
paul@347 | 1787 | |
paul@347 | 1788 | # Or look up the position of a location using the locations |
paul@347 | 1789 | # page. |
paul@347 | 1790 | |
paul@347 | 1791 | else: |
paul@347 | 1792 | latitude, longitude = Location(location, locations).getPosition() |
paul@347 | 1793 | |
paul@347 | 1794 | # Use a normalised location if necessary. |
paul@347 | 1795 | |
paul@347 | 1796 | if latitude is None and longitude is None: |
paul@347 | 1797 | normalised_location = getNormalisedLocation(location) |
paul@347 | 1798 | if normalised_location is not None: |
paul@347 | 1799 | latitude, longitude = getLocationPosition(normalised_location, locations) |
paul@347 | 1800 | if latitude is not None and longitude is not None: |
paul@347 | 1801 | location = normalised_location |
paul@347 | 1802 | |
paul@347 | 1803 | # Only remember positioned locations. |
paul@347 | 1804 | |
paul@347 | 1805 | if latitude is not None and longitude is not None: |
paul@347 | 1806 | event_locations[location] = latitude, longitude |
paul@347 | 1807 | |
paul@347 | 1808 | # Record events according to location. |
paul@347 | 1809 | |
paul@347 | 1810 | if not events_by_location.has_key(location): |
paul@347 | 1811 | events_by_location[location] = [] |
paul@347 | 1812 | |
paul@347 | 1813 | events_by_location[location].append(event) |
paul@347 | 1814 | |
paul@347 | 1815 | # Get the map image URL. |
paul@347 | 1816 | |
paul@347 | 1817 | map_image_url = AttachFile.getAttachUrl(maps_page, map_image, request) |
paul@347 | 1818 | |
paul@347 | 1819 | # Start of map view output. |
paul@347 | 1820 | |
paul@347 | 1821 | map_identifier = "map-%s" % self.getIdentifier() |
paul@347 | 1822 | append(fmt.div(on=1, css_class="event-map", id=map_identifier)) |
paul@347 | 1823 | |
paul@347 | 1824 | append(fmt.table(on=1)) |
paul@347 | 1825 | |
paul@347 | 1826 | append(fmt.table_row(on=1)) |
paul@347 | 1827 | append(self.writeMapTableHeading()) |
paul@347 | 1828 | append(fmt.table_row(on=0)) |
paul@347 | 1829 | |
paul@347 | 1830 | append(fmt.table_row(on=1)) |
paul@347 | 1831 | append(fmt.table_cell(on=1)) |
paul@347 | 1832 | |
paul@347 | 1833 | append(fmt.div(on=1, css_class="event-map-container")) |
paul@347 | 1834 | append(fmt.image(map_image_url)) |
paul@347 | 1835 | append(fmt.number_list(on=1)) |
paul@347 | 1836 | |
paul@347 | 1837 | # Events with no location are unpositioned. |
paul@347 | 1838 | |
paul@347 | 1839 | if events_by_location.has_key(None): |
paul@347 | 1840 | unpositioned_events = events_by_location[None] |
paul@347 | 1841 | del events_by_location[None] |
paul@347 | 1842 | else: |
paul@347 | 1843 | unpositioned_events = [] |
paul@347 | 1844 | |
paul@347 | 1845 | # Events whose location is unpositioned are themselves considered |
paul@347 | 1846 | # unpositioned. |
paul@347 | 1847 | |
paul@347 | 1848 | for location in set(events_by_location.keys()).difference(event_locations.keys()): |
paul@347 | 1849 | unpositioned_events += events_by_location[location] |
paul@347 | 1850 | |
paul@347 | 1851 | # Sort the locations before traversing them. |
paul@347 | 1852 | |
paul@347 | 1853 | event_locations = event_locations.items() |
paul@347 | 1854 | event_locations.sort() |
paul@347 | 1855 | |
paul@347 | 1856 | # Show the events in the map. |
paul@347 | 1857 | |
paul@347 | 1858 | for location, (latitude, longitude) in event_locations: |
paul@347 | 1859 | events = events_by_location[location] |
paul@347 | 1860 | |
paul@347 | 1861 | # Skip unpositioned locations and locations outside the map. |
paul@347 | 1862 | |
paul@347 | 1863 | if latitude is None or longitude is None or \ |
paul@347 | 1864 | latitude < map_bottom_left_latitude or \ |
paul@347 | 1865 | longitude < map_bottom_left_longitude or \ |
paul@347 | 1866 | latitude > map_top_right_latitude or \ |
paul@347 | 1867 | longitude > map_top_right_longitude: |
paul@347 | 1868 | |
paul@347 | 1869 | unpositioned_events += events |
paul@347 | 1870 | continue |
paul@347 | 1871 | |
paul@347 | 1872 | # Get the position and dimensions of the map marker. |
paul@347 | 1873 | # NOTE: Use one degree as the marker size. |
paul@347 | 1874 | |
paul@347 | 1875 | marker_x, marker_y = getPositionForCentrePoint( |
paul@347 | 1876 | getPositionForReference(map_top_right_latitude, longitude, latitude, map_bottom_left_longitude, |
paul@347 | 1877 | map_x_scale, map_y_scale), |
paul@347 | 1878 | map_x_scale, map_y_scale) |
paul@347 | 1879 | |
paul@347 | 1880 | # Add the map marker. |
paul@347 | 1881 | |
paul@347 | 1882 | append(self.writeMapMarker(marker_x, marker_y, map_x_scale, map_y_scale, location, events)) |
paul@347 | 1883 | |
paul@347 | 1884 | append(fmt.number_list(on=0)) |
paul@347 | 1885 | append(fmt.div(on=0)) |
paul@347 | 1886 | append(fmt.table_cell(on=0)) |
paul@347 | 1887 | append(fmt.table_row(on=0)) |
paul@347 | 1888 | |
paul@347 | 1889 | # Write unpositioned events. |
paul@347 | 1890 | |
paul@347 | 1891 | if unpositioned_events: |
paul@347 | 1892 | unpositioned_identifier = "unpositioned-%s" % self.getIdentifier() |
paul@347 | 1893 | |
paul@347 | 1894 | append(fmt.table_row(on=1, css_class="event-map-unpositioned", |
paul@347 | 1895 | id=unpositioned_identifier)) |
paul@347 | 1896 | append(fmt.table_cell(on=1)) |
paul@347 | 1897 | |
paul@347 | 1898 | append(fmt.heading(on=1, depth=2)) |
paul@347 | 1899 | append(fmt.text(_("Events not shown on the map"))) |
paul@347 | 1900 | append(fmt.heading(on=0, depth=2)) |
paul@347 | 1901 | |
paul@347 | 1902 | # Show and hide controls. |
paul@347 | 1903 | |
paul@347 | 1904 | append(fmt.div(on=1, css_class="event-map-show-control")) |
paul@347 | 1905 | append(fmt.anchorlink(on=1, name=unpositioned_identifier)) |
paul@347 | 1906 | append(fmt.text(_("Show unpositioned events"))) |
paul@347 | 1907 | append(fmt.anchorlink(on=0)) |
paul@347 | 1908 | append(fmt.div(on=0)) |
paul@347 | 1909 | |
paul@347 | 1910 | append(fmt.div(on=1, css_class="event-map-hide-control")) |
paul@347 | 1911 | append(fmt.anchorlink(on=1, name=map_identifier)) |
paul@347 | 1912 | append(fmt.text(_("Hide unpositioned events"))) |
paul@347 | 1913 | append(fmt.anchorlink(on=0)) |
paul@347 | 1914 | append(fmt.div(on=0)) |
paul@347 | 1915 | |
paul@347 | 1916 | append(self.writeMapEventSummaries(unpositioned_events)) |
paul@347 | 1917 | |
paul@347 | 1918 | # End of map view output. |
paul@347 | 1919 | |
paul@347 | 1920 | append(fmt.table_cell(on=0)) |
paul@347 | 1921 | append(fmt.table_row(on=0)) |
paul@347 | 1922 | append(fmt.table(on=0)) |
paul@347 | 1923 | append(fmt.div(on=0)) |
paul@347 | 1924 | |
paul@347 | 1925 | # Output a list. |
paul@347 | 1926 | |
paul@347 | 1927 | elif self.mode == "list": |
paul@347 | 1928 | |
paul@347 | 1929 | # Start of list view output. |
paul@347 | 1930 | |
paul@347 | 1931 | append(fmt.bullet_list(on=1, attr={"class" : "event-listings"})) |
paul@347 | 1932 | |
paul@347 | 1933 | # Output a list. |
paul@347 | 1934 | |
paul@347 | 1935 | for period in self.first.until(self.last): |
paul@347 | 1936 | |
paul@347 | 1937 | append(fmt.listitem(on=1, attr={"class" : "event-listings-period"})) |
paul@347 | 1938 | append(fmt.div(on=1, attr={"class" : "event-listings-heading"})) |
paul@347 | 1939 | |
paul@347 | 1940 | # Either write a date heading or produce links for navigable |
paul@347 | 1941 | # calendars. |
paul@347 | 1942 | |
paul@347 | 1943 | append(self.writeDateHeading(period)) |
paul@347 | 1944 | |
paul@347 | 1945 | append(fmt.div(on=0)) |
paul@347 | 1946 | |
paul@347 | 1947 | append(fmt.bullet_list(on=1, attr={"class" : "event-period-listings"})) |
paul@347 | 1948 | |
paul@347 | 1949 | # Show the events in order. |
paul@347 | 1950 | |
paul@347 | 1951 | events_in_period = getEventsInPeriod(all_shown_events, getCalendarPeriod(period, period)) |
paul@347 | 1952 | events_in_period.sort(sort_start_first) |
paul@347 | 1953 | |
paul@347 | 1954 | for event in events_in_period: |
paul@347 | 1955 | event_page = event.getPage() |
paul@347 | 1956 | event_details = event.getDetails() |
paul@347 | 1957 | event_summary = event.getSummary(self.parent_name) |
paul@347 | 1958 | |
paul@347 | 1959 | append(fmt.listitem(on=1, attr={"class" : "event-listing"})) |
paul@347 | 1960 | |
paul@347 | 1961 | # Link to the page using the summary. |
paul@347 | 1962 | |
paul@347 | 1963 | append(fmt.paragraph(on=1)) |
paul@347 | 1964 | append(event.linkToEvent(request, event_summary)) |
paul@347 | 1965 | append(fmt.paragraph(on=0)) |
paul@347 | 1966 | |
paul@347 | 1967 | # Start and end dates. |
paul@347 | 1968 | |
paul@347 | 1969 | append(fmt.paragraph(on=1)) |
paul@347 | 1970 | append(fmt.span(on=1)) |
paul@347 | 1971 | append(fmt.text(str(event_details["start"]))) |
paul@347 | 1972 | append(fmt.span(on=0)) |
paul@347 | 1973 | append(fmt.text(" - ")) |
paul@347 | 1974 | append(fmt.span(on=1)) |
paul@347 | 1975 | append(fmt.text(str(event_details["end"]))) |
paul@347 | 1976 | append(fmt.span(on=0)) |
paul@347 | 1977 | append(fmt.paragraph(on=0)) |
paul@347 | 1978 | |
paul@347 | 1979 | # Location. |
paul@347 | 1980 | |
paul@347 | 1981 | if event_details.has_key("location"): |
paul@347 | 1982 | append(fmt.paragraph(on=1)) |
paul@347 | 1983 | append(event_page.formatText(event_details["location"], fmt)) |
paul@347 | 1984 | append(fmt.paragraph(on=1)) |
paul@347 | 1985 | |
paul@347 | 1986 | # Topics. |
paul@347 | 1987 | |
paul@347 | 1988 | if event_details.has_key("topics") or event_details.has_key("categories"): |
paul@347 | 1989 | append(fmt.bullet_list(on=1, attr={"class" : "event-topics"})) |
paul@347 | 1990 | |
paul@347 | 1991 | for topic in event_details.get("topics") or event_details.get("categories") or []: |
paul@347 | 1992 | append(fmt.listitem(on=1)) |
paul@347 | 1993 | append(event_page.formatText(topic, fmt)) |
paul@347 | 1994 | append(fmt.listitem(on=0)) |
paul@347 | 1995 | |
paul@347 | 1996 | append(fmt.bullet_list(on=0)) |
paul@347 | 1997 | |
paul@347 | 1998 | append(fmt.listitem(on=0)) |
paul@347 | 1999 | |
paul@347 | 2000 | append(fmt.bullet_list(on=0)) |
paul@347 | 2001 | |
paul@347 | 2002 | # End of list view output. |
paul@347 | 2003 | |
paul@347 | 2004 | append(fmt.bullet_list(on=0)) |
paul@347 | 2005 | |
paul@347 | 2006 | # Output a month calendar. This shows month-by-month data. |
paul@347 | 2007 | |
paul@347 | 2008 | elif self.mode == "calendar": |
paul@347 | 2009 | |
paul@347 | 2010 | # Visit all months in the requested range, or across known events. |
paul@347 | 2011 | |
paul@347 | 2012 | for month in self.first.months_until(self.last): |
paul@347 | 2013 | |
paul@347 | 2014 | # Output a month. |
paul@347 | 2015 | |
paul@347 | 2016 | append(fmt.table(on=1, attrs={"tableclass" : "event-month"})) |
paul@347 | 2017 | |
paul@347 | 2018 | # Either write a month heading or produce links for navigable |
paul@347 | 2019 | # calendars. |
paul@347 | 2020 | |
paul@347 | 2021 | append(self.writeMonthTableHeading(month)) |
paul@347 | 2022 | |
paul@347 | 2023 | # Weekday headings. |
paul@347 | 2024 | |
paul@347 | 2025 | append(self.writeWeekdayHeadings()) |
paul@347 | 2026 | |
paul@347 | 2027 | # Process the days of the month. |
paul@347 | 2028 | |
paul@347 | 2029 | start_weekday, number_of_days = month.month_properties() |
paul@347 | 2030 | |
paul@347 | 2031 | # The start weekday is the weekday of day number 1. |
paul@347 | 2032 | # Find the first day of the week, counting from below zero, if |
paul@347 | 2033 | # necessary, in order to land on the first day of the month as |
paul@347 | 2034 | # day number 1. |
paul@347 | 2035 | |
paul@347 | 2036 | first_day = 1 - start_weekday |
paul@347 | 2037 | |
paul@347 | 2038 | while first_day <= number_of_days: |
paul@347 | 2039 | |
paul@347 | 2040 | # Find events in this week and determine how to mark them on the |
paul@347 | 2041 | # calendar. |
paul@347 | 2042 | |
paul@347 | 2043 | week_start = month.as_date(max(first_day, 1)) |
paul@347 | 2044 | week_end = month.as_date(min(first_day + 6, number_of_days)) |
paul@347 | 2045 | |
paul@347 | 2046 | full_coverage, week_slots = getCoverage( |
paul@347 | 2047 | getEventsInPeriod(all_shown_events, getCalendarPeriod(week_start, week_end))) |
paul@347 | 2048 | |
paul@347 | 2049 | # Output a week, starting with the day numbers. |
paul@347 | 2050 | |
paul@347 | 2051 | append(self.writeDayNumbers(first_day, number_of_days, month, full_coverage)) |
paul@347 | 2052 | |
paul@347 | 2053 | # Either generate empty days... |
paul@347 | 2054 | |
paul@347 | 2055 | if not week_slots: |
paul@347 | 2056 | append(self.writeEmptyWeek(first_day, number_of_days, month)) |
paul@347 | 2057 | |
paul@347 | 2058 | # Or generate each set of scheduled events... |
paul@347 | 2059 | |
paul@347 | 2060 | else: |
paul@347 | 2061 | append(self.writeWeekSlots(first_day, number_of_days, month, week_end, week_slots)) |
paul@347 | 2062 | |
paul@347 | 2063 | # Process the next week... |
paul@347 | 2064 | |
paul@347 | 2065 | first_day += 7 |
paul@347 | 2066 | |
paul@347 | 2067 | # End of month. |
paul@347 | 2068 | |
paul@347 | 2069 | append(fmt.table(on=0)) |
paul@347 | 2070 | |
paul@347 | 2071 | # Output a day view. |
paul@347 | 2072 | |
paul@347 | 2073 | elif self.mode == "day": |
paul@347 | 2074 | |
paul@347 | 2075 | # Visit all days in the requested range, or across known events. |
paul@347 | 2076 | |
paul@347 | 2077 | for date in self.first.days_until(self.last): |
paul@347 | 2078 | |
paul@347 | 2079 | append(fmt.table(on=1, attrs={"tableclass" : "event-calendar-day"})) |
paul@347 | 2080 | |
paul@347 | 2081 | full_coverage, day_slots = getCoverage( |
paul@347 | 2082 | getEventsInPeriod(all_shown_events, getCalendarPeriod(date, date)), "datetime") |
paul@347 | 2083 | |
paul@347 | 2084 | # Work out how many columns the day title will need. |
paul@347 | 2085 | # Include spacers after the scale and each event column. |
paul@347 | 2086 | |
paul@347 | 2087 | colspan = sum(map(len, day_slots.values())) * 2 + 2 |
paul@347 | 2088 | |
paul@347 | 2089 | append(self.writeDayTableHeading(date, colspan)) |
paul@347 | 2090 | |
paul@347 | 2091 | # Either generate empty days... |
paul@347 | 2092 | |
paul@347 | 2093 | if not day_slots: |
paul@347 | 2094 | append(self.writeEmptyDay(date)) |
paul@347 | 2095 | |
paul@347 | 2096 | # Or generate each set of scheduled events... |
paul@347 | 2097 | |
paul@347 | 2098 | else: |
paul@347 | 2099 | append(self.writeDaySlots(date, full_coverage, day_slots)) |
paul@347 | 2100 | |
paul@347 | 2101 | # End of day. |
paul@347 | 2102 | |
paul@347 | 2103 | append(fmt.table(on=0)) |
paul@347 | 2104 | |
paul@347 | 2105 | # Output view controls. |
paul@347 | 2106 | |
paul@347 | 2107 | append(fmt.div(on=1, css_class="event-controls")) |
paul@347 | 2108 | append(self.writeViewControls()) |
paul@347 | 2109 | append(fmt.div(on=0)) |
paul@347 | 2110 | |
paul@347 | 2111 | # Close the calendar region. |
paul@347 | 2112 | |
paul@347 | 2113 | append(fmt.div(on=0)) |
paul@347 | 2114 | |
paul@347 | 2115 | # Add any scripts. |
paul@347 | 2116 | |
paul@347 | 2117 | if isinstance(fmt, request.html_formatter.__class__): |
paul@347 | 2118 | append(self.update_script) |
paul@347 | 2119 | |
paul@347 | 2120 | return ''.join(output) |
paul@347 | 2121 | |
paul@347 | 2122 | update_script = """\ |
paul@347 | 2123 | <script type="text/javascript"> |
paul@347 | 2124 | function replaceCalendar(name, url) { |
paul@347 | 2125 | var calendar = document.getElementById(name); |
paul@347 | 2126 | |
paul@347 | 2127 | if (calendar == null) { |
paul@347 | 2128 | return true; |
paul@347 | 2129 | } |
paul@347 | 2130 | |
paul@347 | 2131 | var xmlhttp = new XMLHttpRequest(); |
paul@347 | 2132 | xmlhttp.open("GET", url, false); |
paul@347 | 2133 | xmlhttp.send(null); |
paul@347 | 2134 | |
paul@347 | 2135 | var newCalendar = xmlhttp.responseText; |
paul@347 | 2136 | |
paul@347 | 2137 | if (newCalendar != null) { |
paul@347 | 2138 | calendar.innerHTML = newCalendar; |
paul@347 | 2139 | return false; |
paul@347 | 2140 | } |
paul@347 | 2141 | |
paul@347 | 2142 | return true; |
paul@347 | 2143 | } |
paul@347 | 2144 | </script> |
paul@347 | 2145 | """ |
paul@347 | 2146 | |
paul@347 | 2147 | # vim: tabstop=4 expandtab shiftwidth=4 |