paul@347 | 1 | # -*- coding: iso-8859-1 -*- |
paul@347 | 2 | """ |
paul@347 | 3 | MoinMoin - EventAggregator object types |
paul@347 | 4 | |
paul@391 | 5 | @copyright: 2008, 2009, 2010, 2011, 2012, 2013, 2014 by Paul Boddie <paul@boddie.org.uk> |
paul@347 | 6 | @copyright: 2000-2004 Juergen Hermann <jh@web.de>, |
paul@347 | 7 | 2005-2008 MoinMoin:ThomasWaldmann. |
paul@347 | 8 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@347 | 9 | """ |
paul@347 | 10 | |
paul@353 | 11 | from DateSupport import DateTime |
paul@347 | 12 | from GeneralSupport import to_list |
paul@397 | 13 | from LocationSupport import getMapReference, getMapReferenceFromDecimal |
paul@347 | 14 | from MoinSupport import * |
paul@395 | 15 | import vCalendar |
paul@347 | 16 | |
paul@395 | 17 | from codecs import getreader |
paul@412 | 18 | from email.parser import Parser |
paul@353 | 19 | from email.utils import parsedate |
paul@347 | 20 | import re |
paul@347 | 21 | |
paul@347 | 22 | try: |
paul@395 | 23 | from cStringIO import StringIO |
paul@395 | 24 | except ImportError: |
paul@395 | 25 | from StringIO import StringIO |
paul@395 | 26 | |
paul@395 | 27 | try: |
paul@347 | 28 | set |
paul@347 | 29 | except NameError: |
paul@347 | 30 | from sets import Set as set |
paul@347 | 31 | |
paul@408 | 32 | # Import libxml2dom for xCalendar parsing. |
paul@408 | 33 | |
paul@408 | 34 | try: |
paul@408 | 35 | import libxml2dom |
paul@408 | 36 | except ImportError: |
paul@408 | 37 | libxml2dom = None |
paul@408 | 38 | |
paul@347 | 39 | # Page parsing. |
paul@347 | 40 | |
paul@347 | 41 | definition_list_regexp = re.compile(ur'(?P<wholeterm>^(?P<optcomment>#*)\s+(?P<term>.*?):: )(?P<desc>.*?)$', re.UNICODE | re.MULTILINE) |
paul@347 | 42 | category_membership_regexp = re.compile(ur"^\s*(?:(Category\S+)(?:\s+(Category\S+))*)\s*$", re.MULTILINE | re.UNICODE) |
paul@347 | 43 | |
paul@347 | 44 | # Event parsing from page texts. |
paul@347 | 45 | |
paul@395 | 46 | def parseEventsInPage(text, page, fragment=None): |
paul@395 | 47 | |
paul@395 | 48 | """ |
paul@395 | 49 | Parse events in the given 'text' from the given 'page'. |
paul@395 | 50 | """ |
paul@395 | 51 | |
paul@395 | 52 | # Calendar-format pages are parsed directly by the iCalendar parser. |
paul@395 | 53 | |
paul@395 | 54 | if page.getFormat() == "calendar": |
paul@395 | 55 | return parseEventsInCalendar(text) |
paul@395 | 56 | |
paul@408 | 57 | # xCalendar-format pages are parsed directly by the iCalendar parser. |
paul@408 | 58 | |
paul@408 | 59 | elif page.getFormat() == "xcalendar": |
paul@408 | 60 | return parseEventsInXMLCalendar(text) |
paul@408 | 61 | |
paul@395 | 62 | # Wiki-format pages are parsed region-by-region using the special markup. |
paul@395 | 63 | |
paul@395 | 64 | elif page.getFormat() == "wiki": |
paul@395 | 65 | |
paul@395 | 66 | # Where a page contains events, potentially in regions, identify the page |
paul@395 | 67 | # regions and obtain the events within them. |
paul@395 | 68 | |
paul@395 | 69 | events = [] |
paul@395 | 70 | for format, attributes, region in getFragments(text, True): |
paul@395 | 71 | if format == "calendar": |
paul@395 | 72 | events += parseEventsInCalendar(region) |
paul@395 | 73 | else: |
paul@395 | 74 | events += parseEvents(region, page, attributes.get("fragment") or fragment) |
paul@395 | 75 | return events |
paul@395 | 76 | |
paul@395 | 77 | # Unsupported format pages return no events. |
paul@395 | 78 | |
paul@395 | 79 | else: |
paul@395 | 80 | return [] |
paul@395 | 81 | |
paul@395 | 82 | def parseEventsInCalendar(text): |
paul@395 | 83 | |
paul@405 | 84 | """ |
paul@405 | 85 | Parse events in iCalendar format from the given 'text'. |
paul@405 | 86 | """ |
paul@405 | 87 | |
paul@405 | 88 | # Fill the StringIO with encoded plain string data. |
paul@405 | 89 | |
paul@405 | 90 | encoding = "utf-8" |
paul@405 | 91 | calendar = parseEventsInCalendarFromResource(StringIO(text.encode(encoding)), encoding) |
paul@405 | 92 | return calendar.getEvents() |
paul@405 | 93 | |
paul@408 | 94 | def parseEventsInXMLCalendar(text): |
paul@408 | 95 | |
paul@408 | 96 | """ |
paul@408 | 97 | Parse events in xCalendar format from the given 'text'. |
paul@408 | 98 | """ |
paul@408 | 99 | |
paul@408 | 100 | # Fill the StringIO with encoded plain string data. |
paul@408 | 101 | |
paul@408 | 102 | encoding = "utf-8" |
paul@408 | 103 | calendar = parseEventsInXMLCalendarFromResource(StringIO(text.encode(encoding)), encoding) |
paul@408 | 104 | return calendar.getEvents() |
paul@408 | 105 | |
paul@405 | 106 | def parseEventsInCalendarFromResource(f, encoding=None, url=None, metadata=None): |
paul@395 | 107 | |
paul@405 | 108 | """ |
paul@405 | 109 | Parse events in iCalendar format from the given file-like object 'f', with |
paul@405 | 110 | content having any specified 'encoding' and being described by the given |
paul@405 | 111 | 'url' and 'metadata'. |
paul@405 | 112 | """ |
paul@405 | 113 | |
paul@405 | 114 | # Read Unicode from the resource. |
paul@405 | 115 | |
paul@405 | 116 | uf = getreader(encoding or "utf-8")(f) |
paul@405 | 117 | try: |
paul@405 | 118 | return EventCalendar(url or "", vCalendar.parse(uf), metadata or {}) |
paul@405 | 119 | finally: |
paul@405 | 120 | uf.close() |
paul@395 | 121 | |
paul@408 | 122 | def parseEventsInXMLCalendarFromResource(f, encoding=None, url=None, metadata=None): |
paul@408 | 123 | |
paul@408 | 124 | """ |
paul@408 | 125 | Parse events in xCalendar format from the given file-like object 'f', with |
paul@408 | 126 | content having any specified 'encoding' and being described by the given |
paul@408 | 127 | 'url' and 'metadata'. |
paul@408 | 128 | """ |
paul@408 | 129 | |
paul@408 | 130 | if libxml2dom is not None: |
paul@408 | 131 | return EventXMLCalendar(url or "", libxml2dom.parse(f), metadata or {}) |
paul@408 | 132 | else: |
paul@408 | 133 | return None |
paul@408 | 134 | |
paul@412 | 135 | def parseEventsInXMLCalendarsFromResource(f, encoding=None, url=None, metadata=None): |
paul@412 | 136 | |
paul@412 | 137 | """ |
paul@412 | 138 | Parse a collection of events in xCalendar format from the given file-like |
paul@412 | 139 | object 'f', with content having any specified 'encoding' and being described |
paul@412 | 140 | by the given 'url' and 'metadata'. |
paul@412 | 141 | """ |
paul@412 | 142 | |
paul@413 | 143 | new_url = "" # hide the IMAP URL |
paul@413 | 144 | |
paul@412 | 145 | message = Parser().parse(f) |
paul@413 | 146 | resources = EventResourceCollection(new_url, metadata or {}) |
paul@412 | 147 | |
paul@412 | 148 | for data in message.get_payload(): |
paul@412 | 149 | |
paul@412 | 150 | # Find the calendar data. |
paul@412 | 151 | |
paul@412 | 152 | if data.is_multipart(): |
paul@412 | 153 | for part in data.get_payload(): |
paul@412 | 154 | if part.get_content_type() == "application/calendar+xml": |
paul@412 | 155 | text = part |
paul@412 | 156 | else: |
paul@412 | 157 | text = data |
paul@412 | 158 | |
paul@412 | 159 | # Obtain a calendar and merge it into the collection. |
paul@412 | 160 | |
paul@413 | 161 | resources.append(parseEventsInXMLCalendarFromResource(StringIO(text.get_payload(decode=True)), part.get_charset(), new_url)) |
paul@412 | 162 | |
paul@412 | 163 | return resources |
paul@412 | 164 | |
paul@347 | 165 | def parseEvents(text, event_page, fragment=None): |
paul@347 | 166 | |
paul@347 | 167 | """ |
paul@347 | 168 | Parse events in the given 'text', returning a list of event objects for the |
paul@347 | 169 | given 'event_page'. An optional 'fragment' can be specified to indicate a |
paul@347 | 170 | specific region of the event page. |
paul@347 | 171 | |
paul@347 | 172 | If the optional 'fragment' identifier is provided, the first heading may |
paul@347 | 173 | also be used to provide an event summary/title. |
paul@347 | 174 | """ |
paul@347 | 175 | |
paul@347 | 176 | template_details = {} |
paul@347 | 177 | if fragment: |
paul@347 | 178 | template_details["fragment"] = fragment |
paul@347 | 179 | |
paul@347 | 180 | details = {} |
paul@347 | 181 | details.update(template_details) |
paul@347 | 182 | raw_details = {} |
paul@347 | 183 | |
paul@347 | 184 | # Obtain a heading, if requested. |
paul@347 | 185 | |
paul@347 | 186 | if fragment: |
paul@347 | 187 | for level, title, (start, end) in getHeadings(text): |
paul@347 | 188 | raw_details["title"] = text[start:end] |
paul@347 | 189 | details["title"] = getSimpleWikiText(title.strip()) |
paul@347 | 190 | break |
paul@347 | 191 | |
paul@347 | 192 | # Start populating events. |
paul@347 | 193 | |
paul@347 | 194 | events = [Event(event_page, details, raw_details)] |
paul@347 | 195 | |
paul@380 | 196 | # Get any default raw details to modify. |
paul@380 | 197 | |
paul@380 | 198 | raw_details = events[-1].getRawDetails() |
paul@380 | 199 | |
paul@347 | 200 | for match in definition_list_regexp.finditer(text): |
paul@347 | 201 | |
paul@347 | 202 | # Skip commented-out items. |
paul@347 | 203 | |
paul@347 | 204 | if match.group("optcomment"): |
paul@347 | 205 | continue |
paul@347 | 206 | |
paul@347 | 207 | # Permit case-insensitive list terms. |
paul@347 | 208 | |
paul@347 | 209 | term = match.group("term").lower() |
paul@347 | 210 | raw_desc = match.group("desc") |
paul@347 | 211 | |
paul@347 | 212 | # Special value type handling. |
paul@347 | 213 | |
paul@347 | 214 | # Dates. |
paul@347 | 215 | |
paul@347 | 216 | if term in Event.date_terms: |
paul@347 | 217 | desc = getDateTime(raw_desc) |
paul@347 | 218 | |
paul@347 | 219 | # Lists (whose elements may be quoted). |
paul@347 | 220 | |
paul@347 | 221 | elif term in Event.list_terms: |
paul@347 | 222 | desc = map(getSimpleWikiText, to_list(raw_desc, ",")) |
paul@347 | 223 | |
paul@347 | 224 | # Position details. |
paul@347 | 225 | |
paul@347 | 226 | elif term == "geo": |
paul@347 | 227 | try: |
paul@347 | 228 | desc = map(getMapReference, to_list(raw_desc, None)) |
paul@347 | 229 | if len(desc) != 2: |
paul@347 | 230 | continue |
paul@347 | 231 | except (KeyError, ValueError): |
paul@347 | 232 | continue |
paul@347 | 233 | |
paul@347 | 234 | # Labels which may well be quoted. |
paul@347 | 235 | |
paul@347 | 236 | elif term in Event.title_terms: |
paul@347 | 237 | desc = getSimpleWikiText(raw_desc.strip()) |
paul@347 | 238 | |
paul@347 | 239 | # Plain Wiki text terms. |
paul@347 | 240 | |
paul@347 | 241 | elif term in Event.other_terms: |
paul@347 | 242 | desc = raw_desc.strip() |
paul@347 | 243 | |
paul@347 | 244 | else: |
paul@347 | 245 | desc = raw_desc |
paul@347 | 246 | |
paul@347 | 247 | if desc is not None: |
paul@347 | 248 | |
paul@347 | 249 | # Handle apparent duplicates by creating a new set of |
paul@347 | 250 | # details. |
paul@347 | 251 | |
paul@347 | 252 | if details.has_key(term): |
paul@347 | 253 | |
paul@347 | 254 | # Make a new event. |
paul@347 | 255 | |
paul@347 | 256 | details = {} |
paul@347 | 257 | details.update(template_details) |
paul@347 | 258 | raw_details = {} |
paul@347 | 259 | events.append(Event(event_page, details, raw_details)) |
paul@380 | 260 | raw_details = events[-1].getRawDetails() |
paul@347 | 261 | |
paul@347 | 262 | details[term] = desc |
paul@347 | 263 | raw_details[term] = raw_desc |
paul@347 | 264 | |
paul@347 | 265 | return events |
paul@347 | 266 | |
paul@347 | 267 | # Event resources providing collections of events. |
paul@347 | 268 | |
paul@347 | 269 | class EventResource: |
paul@347 | 270 | |
paul@347 | 271 | "A resource providing event information." |
paul@347 | 272 | |
paul@412 | 273 | def __init__(self, url, metadata=None): |
paul@347 | 274 | self.url = url |
paul@412 | 275 | self.metadata = metadata |
paul@412 | 276 | self.events = None |
paul@347 | 277 | |
paul@347 | 278 | def getPageURL(self): |
paul@347 | 279 | |
paul@347 | 280 | "Return the URL of this page." |
paul@347 | 281 | |
paul@347 | 282 | return self.url |
paul@347 | 283 | |
paul@347 | 284 | def getFormat(self): |
paul@347 | 285 | |
paul@347 | 286 | "Get the format used by this resource." |
paul@347 | 287 | |
paul@347 | 288 | return "plain" |
paul@347 | 289 | |
paul@347 | 290 | def getMetadata(self): |
paul@347 | 291 | |
paul@347 | 292 | """ |
paul@347 | 293 | Return a dictionary containing items describing the page's "created" |
paul@347 | 294 | time, "last-modified" time, "sequence" (or revision number) and the |
paul@347 | 295 | "last-comment" made about the last edit. |
paul@347 | 296 | """ |
paul@347 | 297 | |
paul@412 | 298 | return self.metadata or {} |
paul@347 | 299 | |
paul@347 | 300 | def getEvents(self): |
paul@347 | 301 | |
paul@347 | 302 | "Return a list of events from this resource." |
paul@347 | 303 | |
paul@412 | 304 | return self.events or [] |
paul@347 | 305 | |
paul@347 | 306 | def linkToPage(self, request, text, query_string=None, anchor=None): |
paul@347 | 307 | |
paul@347 | 308 | """ |
paul@347 | 309 | Using 'request', return a link to this page with the given link 'text' |
paul@347 | 310 | and optional 'query_string' and 'anchor'. |
paul@347 | 311 | """ |
paul@347 | 312 | |
paul@347 | 313 | return linkToResource(self.url, request, text, query_string, anchor) |
paul@347 | 314 | |
paul@347 | 315 | # Formatting-related functions. |
paul@347 | 316 | |
paul@347 | 317 | def formatText(self, text, fmt): |
paul@347 | 318 | |
paul@347 | 319 | """ |
paul@347 | 320 | Format the given 'text' using the specified formatter 'fmt'. |
paul@347 | 321 | """ |
paul@347 | 322 | |
paul@347 | 323 | # Assume plain text which is then formatted appropriately. |
paul@347 | 324 | |
paul@347 | 325 | return fmt.text(text) |
paul@347 | 326 | |
paul@412 | 327 | class EventResourceCollection(EventResource): |
paul@412 | 328 | |
paul@412 | 329 | "A collection of resources." |
paul@412 | 330 | |
paul@412 | 331 | def __init__(self, url, metadata=None): |
paul@412 | 332 | self.url = url |
paul@412 | 333 | self.metadata = metadata |
paul@412 | 334 | self.resources = [] |
paul@412 | 335 | |
paul@412 | 336 | def append(self, resource): |
paul@412 | 337 | self.resources.append(resource) |
paul@412 | 338 | |
paul@412 | 339 | def getEvents(self): |
paul@412 | 340 | events = [] |
paul@412 | 341 | for resource in self.resources: |
paul@412 | 342 | events += resource.getEvents() |
paul@412 | 343 | return events |
paul@412 | 344 | |
paul@408 | 345 | class EventCalendarResource(EventResource): |
paul@347 | 346 | |
paul@408 | 347 | "A generic calendar resource." |
paul@408 | 348 | |
paul@408 | 349 | def __init__(self, url, metadata): |
paul@412 | 350 | EventResource.__init__(self, url, metadata) |
paul@347 | 351 | |
paul@353 | 352 | if not self.metadata.has_key("created") and self.metadata.has_key("date"): |
paul@353 | 353 | self.metadata["created"] = DateTime(parsedate(self.metadata["date"])[:7]) |
paul@353 | 354 | |
paul@353 | 355 | if self.metadata.has_key("last-modified") and not isinstance(self.metadata["last-modified"], DateTime): |
paul@353 | 356 | self.metadata["last-modified"] = DateTime(parsedate(self.metadata["last-modified"])[:7]) |
paul@353 | 357 | |
paul@408 | 358 | class EventCalendar(EventCalendarResource): |
paul@408 | 359 | |
paul@408 | 360 | "An iCalendar resource." |
paul@408 | 361 | |
paul@408 | 362 | def __init__(self, url, calendar, metadata): |
paul@408 | 363 | EventCalendarResource.__init__(self, url, metadata) |
paul@408 | 364 | self.calendar = calendar |
paul@408 | 365 | |
paul@347 | 366 | def getEvents(self): |
paul@347 | 367 | |
paul@347 | 368 | "Return a list of events from this resource." |
paul@347 | 369 | |
paul@347 | 370 | if self.events is None: |
paul@347 | 371 | self.events = [] |
paul@347 | 372 | |
paul@347 | 373 | _calendar, _empty, calendar = self.calendar |
paul@347 | 374 | |
paul@347 | 375 | for objtype, attrs, obj in calendar: |
paul@347 | 376 | |
paul@347 | 377 | # Read events. |
paul@347 | 378 | |
paul@347 | 379 | if objtype == "VEVENT": |
paul@347 | 380 | details = {} |
paul@347 | 381 | |
paul@347 | 382 | for property, attrs, value in obj: |
paul@347 | 383 | |
paul@347 | 384 | # Convert dates. |
paul@347 | 385 | |
paul@347 | 386 | if property in ("DTSTART", "DTEND", "CREATED", "DTSTAMP", "LAST-MODIFIED"): |
paul@347 | 387 | if property in ("DTSTART", "DTEND"): |
paul@347 | 388 | property = property[2:] |
paul@347 | 389 | if attrs.get("VALUE") == "DATE": |
paul@347 | 390 | value = getDateFromCalendar(value) |
paul@347 | 391 | if value and property == "END": |
paul@347 | 392 | value = value.previous_day() |
paul@347 | 393 | else: |
paul@347 | 394 | value = getDateTimeFromCalendar(value) |
paul@347 | 395 | |
paul@347 | 396 | # Convert numeric data. |
paul@347 | 397 | |
paul@347 | 398 | elif property == "SEQUENCE": |
paul@347 | 399 | value = int(value) |
paul@347 | 400 | |
paul@347 | 401 | # Convert lists. |
paul@347 | 402 | |
paul@347 | 403 | elif property == "CATEGORIES": |
paul@391 | 404 | if not isinstance(value, list): |
paul@391 | 405 | value = to_list(value, ",") |
paul@347 | 406 | |
paul@347 | 407 | # Convert positions (using decimal values). |
paul@347 | 408 | |
paul@347 | 409 | elif property == "GEO": |
paul@347 | 410 | try: |
paul@347 | 411 | value = map(getMapReferenceFromDecimal, to_list(value, ";")) |
paul@347 | 412 | if len(value) != 2: |
paul@347 | 413 | continue |
paul@347 | 414 | except (KeyError, ValueError): |
paul@347 | 415 | continue |
paul@347 | 416 | |
paul@347 | 417 | # Accept other textual data as it is. |
paul@347 | 418 | |
paul@347 | 419 | elif property in ("LOCATION", "SUMMARY", "URL"): |
paul@347 | 420 | value = value or None |
paul@347 | 421 | |
paul@347 | 422 | # Ignore other properties. |
paul@347 | 423 | |
paul@347 | 424 | else: |
paul@347 | 425 | continue |
paul@347 | 426 | |
paul@347 | 427 | property = property.lower() |
paul@347 | 428 | details[property] = value |
paul@347 | 429 | |
paul@347 | 430 | self.events.append(CalendarEvent(self, details)) |
paul@347 | 431 | |
paul@347 | 432 | return self.events |
paul@347 | 433 | |
paul@408 | 434 | class EventXMLCalendar(EventCalendarResource): |
paul@408 | 435 | |
paul@408 | 436 | "An xCalendar resource." |
paul@408 | 437 | |
paul@408 | 438 | XCAL = {"xcal" : "urn:ietf:params:xml:ns:icalendar-2.0"} |
paul@408 | 439 | |
paul@408 | 440 | # See: http://tools.ietf.org/html/draft-daboo-et-al-icalendar-in-xml-11#section-3.4 |
paul@408 | 441 | |
paul@408 | 442 | properties = [ |
paul@408 | 443 | ("summary", "xcal:properties/xcal:summary", "getText"), |
paul@408 | 444 | ("location", "xcal:properties/xcal:location", "getText"), |
paul@408 | 445 | ("start", "xcal:properties/xcal:dtstart", "getDateTime"), |
paul@408 | 446 | ("end", "xcal:properties/xcal:dtend", "getDateTime"), |
paul@408 | 447 | ("created", "xcal:properties/xcal:created", "getDateTime"), |
paul@408 | 448 | ("dtstamp", "xcal:properties/xcal:dtstamp", "getDateTime"), |
paul@408 | 449 | ("last-modified", "xcal:properties/xcal:last-modified", "getDateTime"), |
paul@408 | 450 | ("sequence", "xcal:properties/xcal:sequence", "getInteger"), |
paul@408 | 451 | ("categories", "xcal:properties/xcal:categories", "getCollection"), |
paul@408 | 452 | ("geo", "xcal:properties/xcal:geo", "getGeo"), |
paul@408 | 453 | ("url", "xcal:properties/xcal:url", "getURI"), |
paul@408 | 454 | ] |
paul@408 | 455 | |
paul@408 | 456 | def __init__(self, url, doc, metadata): |
paul@408 | 457 | EventCalendarResource.__init__(self, url, metadata) |
paul@408 | 458 | self.doc = doc |
paul@408 | 459 | |
paul@408 | 460 | def getEvents(self): |
paul@408 | 461 | |
paul@408 | 462 | "Return a list of events from this resource." |
paul@408 | 463 | |
paul@408 | 464 | if self.events is None: |
paul@408 | 465 | self.events = [] |
paul@408 | 466 | |
paul@408 | 467 | for event in self.doc.xpath("//xcal:vevent", namespaces=self.XCAL): |
paul@408 | 468 | details = {} |
paul@408 | 469 | |
paul@408 | 470 | for property, path, converter in self.properties: |
paul@408 | 471 | values = event.xpath(path, namespaces=self.XCAL) |
paul@408 | 472 | |
paul@408 | 473 | try: |
paul@408 | 474 | value = getattr(self, converter)(property, values) |
paul@408 | 475 | details[property] = value |
paul@408 | 476 | except (IndexError, ValueError): |
paul@408 | 477 | pass |
paul@408 | 478 | |
paul@408 | 479 | self.events.append(CalendarEvent(self, details)) |
paul@408 | 480 | |
paul@408 | 481 | return self.events |
paul@408 | 482 | |
paul@412 | 483 | # Parsing methods. |
paul@412 | 484 | |
paul@408 | 485 | def _getValue(self, values, type): |
paul@408 | 486 | for element in values[0].xpath("xcal:%s" % type, namespaces=self.XCAL): |
paul@408 | 487 | return element.textContent |
paul@408 | 488 | else: |
paul@408 | 489 | return None |
paul@408 | 490 | |
paul@408 | 491 | def getText(self, property, values): |
paul@408 | 492 | return self._getValue(values, "text") |
paul@408 | 493 | |
paul@408 | 494 | def getDateTime(self, property, values): |
paul@408 | 495 | element = values[0] |
paul@408 | 496 | for dtelement in element.xpath("xcal:date-time|xcal:date", namespaces=self.XCAL): |
paul@408 | 497 | dt = getDateTimeFromISO8601(dtelement.textContent) |
paul@408 | 498 | break |
paul@408 | 499 | else: |
paul@408 | 500 | return None |
paul@408 | 501 | |
paul@408 | 502 | tzid = self._getValue(element.xpath("xcal:parameters", namespaces=self.XCAL), "tzid") |
paul@408 | 503 | if tzid and isinstance(dt, DateTime): |
paul@408 | 504 | zone = "/".join(tzid.rsplit("/", 2)[-2:]) |
paul@408 | 505 | dt.set_time_zone(zone) |
paul@408 | 506 | |
paul@408 | 507 | if dtelement.localName == "date" and property == "end": |
paul@408 | 508 | dt = dt.previous_day() |
paul@408 | 509 | |
paul@408 | 510 | return dt |
paul@408 | 511 | |
paul@408 | 512 | def getInteger(self, property, values): |
paul@408 | 513 | value = self._getValue(values, "integer") |
paul@408 | 514 | if value is not None: |
paul@408 | 515 | return int(value) |
paul@408 | 516 | else: |
paul@408 | 517 | return None |
paul@408 | 518 | |
paul@408 | 519 | def getCollection(self, property, values): |
paul@408 | 520 | return [n.textContent for n in values[0].xpath("xcal:text", namespaces=self.XCAL)] |
paul@408 | 521 | |
paul@408 | 522 | def getGeo(self, property, values): |
paul@408 | 523 | geo = [None, None] |
paul@408 | 524 | |
paul@408 | 525 | for geoelement in values[0].xpath("xcal:latitude|xcal:longitude", namespaces=self.XCAL): |
paul@408 | 526 | value = geoelement.textContent |
paul@408 | 527 | if geoelement.localName == "latitude": |
paul@408 | 528 | geo[0] = value |
paul@408 | 529 | else: |
paul@408 | 530 | geo[1] = value |
paul@408 | 531 | |
paul@408 | 532 | if None not in geo: |
paul@408 | 533 | return map(getMapReferenceFromDecimal, geo) |
paul@408 | 534 | else: |
paul@408 | 535 | return None |
paul@408 | 536 | |
paul@408 | 537 | def getURI(self, property, values): |
paul@408 | 538 | return self._getValue(values, "uri") |
paul@408 | 539 | |
paul@347 | 540 | class EventPage: |
paul@347 | 541 | |
paul@347 | 542 | "An event page acting as an event resource." |
paul@347 | 543 | |
paul@347 | 544 | def __init__(self, page): |
paul@347 | 545 | self.page = page |
paul@347 | 546 | self.events = None |
paul@347 | 547 | self.body = None |
paul@347 | 548 | self.categories = None |
paul@347 | 549 | self.metadata = None |
paul@347 | 550 | |
paul@347 | 551 | def copyPage(self, page): |
paul@347 | 552 | |
paul@347 | 553 | "Copy the body of the given 'page'." |
paul@347 | 554 | |
paul@347 | 555 | self.body = page.getBody() |
paul@347 | 556 | |
paul@347 | 557 | def getPageURL(self): |
paul@347 | 558 | |
paul@347 | 559 | "Return the URL of this page." |
paul@347 | 560 | |
paul@347 | 561 | return getPageURL(self.page) |
paul@347 | 562 | |
paul@347 | 563 | def getFormat(self): |
paul@347 | 564 | |
paul@347 | 565 | "Get the format used on this page." |
paul@347 | 566 | |
paul@347 | 567 | return getFormat(self.page) |
paul@347 | 568 | |
paul@347 | 569 | def getMetadata(self): |
paul@347 | 570 | |
paul@347 | 571 | """ |
paul@347 | 572 | Return a dictionary containing items describing the page's "created" |
paul@347 | 573 | time, "last-modified" time, "sequence" (or revision number) and the |
paul@347 | 574 | "last-comment" made about the last edit. |
paul@347 | 575 | """ |
paul@347 | 576 | |
paul@347 | 577 | if self.metadata is None: |
paul@347 | 578 | self.metadata = getMetadata(self.page) |
paul@347 | 579 | return self.metadata |
paul@347 | 580 | |
paul@347 | 581 | def getRevisions(self): |
paul@347 | 582 | |
paul@347 | 583 | "Return a list of page revisions." |
paul@347 | 584 | |
paul@347 | 585 | return self.page.getRevList() |
paul@347 | 586 | |
paul@347 | 587 | def getPageRevision(self): |
paul@347 | 588 | |
paul@347 | 589 | "Return the revision details dictionary for this page." |
paul@347 | 590 | |
paul@347 | 591 | return getPageRevision(self.page) |
paul@347 | 592 | |
paul@347 | 593 | def getPageName(self): |
paul@347 | 594 | |
paul@347 | 595 | "Return the page name." |
paul@347 | 596 | |
paul@347 | 597 | return self.page.page_name |
paul@347 | 598 | |
paul@347 | 599 | def getPrettyPageName(self): |
paul@347 | 600 | |
paul@347 | 601 | "Return a nicely formatted title/name for this page." |
paul@347 | 602 | |
paul@347 | 603 | return getPrettyPageName(self.page) |
paul@347 | 604 | |
paul@347 | 605 | def getBody(self): |
paul@347 | 606 | |
paul@347 | 607 | "Get the current page body." |
paul@347 | 608 | |
paul@347 | 609 | if self.body is None: |
paul@347 | 610 | self.body = self.page.get_raw_body() |
paul@347 | 611 | return self.body |
paul@347 | 612 | |
paul@347 | 613 | def getEvents(self): |
paul@347 | 614 | |
paul@347 | 615 | "Return a list of events from this page." |
paul@347 | 616 | |
paul@347 | 617 | if self.events is None: |
paul@395 | 618 | self.events = parseEventsInPage(self.page.data, self) |
paul@347 | 619 | |
paul@347 | 620 | return self.events |
paul@347 | 621 | |
paul@347 | 622 | def setEvents(self, events): |
paul@347 | 623 | |
paul@347 | 624 | "Set the given 'events' on this page." |
paul@347 | 625 | |
paul@347 | 626 | self.events = events |
paul@347 | 627 | |
paul@347 | 628 | def getCategoryMembership(self): |
paul@347 | 629 | |
paul@347 | 630 | "Get the category names from this page." |
paul@347 | 631 | |
paul@347 | 632 | if self.categories is None: |
paul@347 | 633 | body = self.getBody() |
paul@347 | 634 | match = category_membership_regexp.search(body) |
paul@347 | 635 | self.categories = match and [x for x in match.groups() if x] or [] |
paul@347 | 636 | |
paul@347 | 637 | return self.categories |
paul@347 | 638 | |
paul@347 | 639 | def setCategoryMembership(self, category_names): |
paul@347 | 640 | |
paul@347 | 641 | """ |
paul@347 | 642 | Set the category membership for the page using the specified |
paul@347 | 643 | 'category_names'. |
paul@347 | 644 | """ |
paul@347 | 645 | |
paul@347 | 646 | self.categories = category_names |
paul@347 | 647 | |
paul@347 | 648 | def flushEventDetails(self): |
paul@347 | 649 | |
paul@347 | 650 | "Flush the current event details to this page's body text." |
paul@347 | 651 | |
paul@347 | 652 | new_body_parts = [] |
paul@347 | 653 | end_of_last_match = 0 |
paul@347 | 654 | body = self.getBody() |
paul@347 | 655 | |
paul@347 | 656 | events = iter(self.getEvents()) |
paul@347 | 657 | |
paul@347 | 658 | event = events.next() |
paul@347 | 659 | event_details = event.getDetails() |
paul@347 | 660 | replaced_terms = set() |
paul@347 | 661 | |
paul@347 | 662 | for match in definition_list_regexp.finditer(body): |
paul@347 | 663 | |
paul@347 | 664 | # Permit case-insensitive list terms. |
paul@347 | 665 | |
paul@347 | 666 | term = match.group("term").lower() |
paul@347 | 667 | desc = match.group("desc") |
paul@347 | 668 | |
paul@347 | 669 | # Check that the term has not already been substituted. If so, |
paul@347 | 670 | # get the next event. |
paul@347 | 671 | |
paul@347 | 672 | if term in replaced_terms: |
paul@347 | 673 | try: |
paul@347 | 674 | event = events.next() |
paul@347 | 675 | |
paul@347 | 676 | # No more events. |
paul@347 | 677 | |
paul@347 | 678 | except StopIteration: |
paul@347 | 679 | break |
paul@347 | 680 | |
paul@347 | 681 | event_details = event.getDetails() |
paul@347 | 682 | replaced_terms = set() |
paul@347 | 683 | |
paul@347 | 684 | # Add preceding text to the new body. |
paul@347 | 685 | |
paul@347 | 686 | new_body_parts.append(body[end_of_last_match:match.start()]) |
paul@347 | 687 | |
paul@347 | 688 | # Get the matching regions, adding the term to the new body. |
paul@347 | 689 | |
paul@347 | 690 | new_body_parts.append(match.group("wholeterm")) |
paul@347 | 691 | |
paul@347 | 692 | # Special value type handling. |
paul@347 | 693 | |
paul@347 | 694 | if event_details.has_key(term): |
paul@347 | 695 | |
paul@347 | 696 | # Dates. |
paul@347 | 697 | |
paul@347 | 698 | if term in event.date_terms: |
paul@347 | 699 | desc = desc.replace("YYYY-MM-DD", str(event_details[term])) |
paul@347 | 700 | |
paul@347 | 701 | # Lists (whose elements may be quoted). |
paul@347 | 702 | |
paul@347 | 703 | elif term in event.list_terms: |
paul@347 | 704 | desc = ", ".join([getEncodedWikiText(item) for item in event_details[term]]) |
paul@347 | 705 | |
paul@347 | 706 | # Labels which must be quoted. |
paul@347 | 707 | |
paul@347 | 708 | elif term in event.title_terms: |
paul@347 | 709 | desc = getEncodedWikiText(event_details[term]) |
paul@347 | 710 | |
paul@347 | 711 | # Position details. |
paul@347 | 712 | |
paul@347 | 713 | elif term == "geo": |
paul@347 | 714 | desc = " ".join(map(str, event_details[term])) |
paul@347 | 715 | |
paul@347 | 716 | # Text which need not be quoted, but it will be Wiki text. |
paul@347 | 717 | |
paul@347 | 718 | elif term in event.other_terms: |
paul@347 | 719 | desc = event_details[term] |
paul@347 | 720 | |
paul@347 | 721 | replaced_terms.add(term) |
paul@347 | 722 | |
paul@347 | 723 | # Add the replaced value. |
paul@347 | 724 | |
paul@347 | 725 | new_body_parts.append(desc) |
paul@347 | 726 | |
paul@347 | 727 | # Remember where in the page has been processed. |
paul@347 | 728 | |
paul@347 | 729 | end_of_last_match = match.end() |
paul@347 | 730 | |
paul@347 | 731 | # Write the rest of the page. |
paul@347 | 732 | |
paul@347 | 733 | new_body_parts.append(body[end_of_last_match:]) |
paul@347 | 734 | |
paul@347 | 735 | self.body = "".join(new_body_parts) |
paul@347 | 736 | |
paul@347 | 737 | def flushCategoryMembership(self): |
paul@347 | 738 | |
paul@347 | 739 | "Flush the category membership to the page body." |
paul@347 | 740 | |
paul@347 | 741 | body = self.getBody() |
paul@347 | 742 | category_names = self.getCategoryMembership() |
paul@347 | 743 | match = category_membership_regexp.search(body) |
paul@347 | 744 | |
paul@347 | 745 | if match: |
paul@347 | 746 | self.body = "".join([body[:match.start()], " ".join(category_names), body[match.end():]]) |
paul@347 | 747 | |
paul@347 | 748 | def saveChanges(self): |
paul@347 | 749 | |
paul@347 | 750 | "Save changes to the event." |
paul@347 | 751 | |
paul@347 | 752 | self.flushEventDetails() |
paul@347 | 753 | self.flushCategoryMembership() |
paul@347 | 754 | self.page.saveText(self.getBody(), 0) |
paul@347 | 755 | |
paul@347 | 756 | def linkToPage(self, request, text, query_string=None, anchor=None): |
paul@347 | 757 | |
paul@347 | 758 | """ |
paul@347 | 759 | Using 'request', return a link to this page with the given link 'text' |
paul@347 | 760 | and optional 'query_string' and 'anchor'. |
paul@347 | 761 | """ |
paul@347 | 762 | |
paul@347 | 763 | return linkToPage(request, self.page, text, query_string, anchor) |
paul@347 | 764 | |
paul@347 | 765 | # Formatting-related functions. |
paul@347 | 766 | |
paul@347 | 767 | def getParserClass(self, format): |
paul@347 | 768 | |
paul@347 | 769 | """ |
paul@347 | 770 | Return a parser class for the given 'format', returning a plain text |
paul@347 | 771 | parser if no parser can be found for the specified 'format'. |
paul@347 | 772 | """ |
paul@347 | 773 | |
paul@347 | 774 | return getParserClass(self.page.request, format) |
paul@347 | 775 | |
paul@347 | 776 | def formatText(self, text, fmt): |
paul@347 | 777 | |
paul@347 | 778 | """ |
paul@347 | 779 | Format the given 'text' using the specified formatter 'fmt'. |
paul@347 | 780 | """ |
paul@347 | 781 | |
paul@347 | 782 | fmt.page = page = self.page |
paul@347 | 783 | request = page.request |
paul@347 | 784 | |
paul@395 | 785 | if self.getFormat() == "calendar": |
paul@395 | 786 | parser_cls = RawParser |
paul@395 | 787 | else: |
paul@395 | 788 | parser_cls = self.getParserClass(self.getFormat()) |
paul@395 | 789 | |
paul@347 | 790 | return formatText(text, request, fmt, parser_cls) |
paul@347 | 791 | |
paul@347 | 792 | # Event details. |
paul@347 | 793 | |
paul@347 | 794 | class Event(ActsAsTimespan): |
paul@347 | 795 | |
paul@347 | 796 | "A description of an event." |
paul@347 | 797 | |
paul@347 | 798 | title_terms = "title", "summary" |
paul@347 | 799 | date_terms = "start", "end" |
paul@347 | 800 | list_terms = "topics", "categories" |
paul@347 | 801 | other_terms = "description", "location", "link" |
paul@347 | 802 | geo_terms = "geo", |
paul@347 | 803 | all_terms = title_terms + date_terms + list_terms + other_terms + geo_terms |
paul@347 | 804 | |
paul@347 | 805 | def __init__(self, page, details, raw_details=None): |
paul@347 | 806 | self.page = page |
paul@347 | 807 | self.details = details |
paul@366 | 808 | self.raw_details = raw_details or {} |
paul@347 | 809 | |
paul@347 | 810 | # Permit omission of the end of the event by duplicating the start. |
paul@347 | 811 | |
paul@347 | 812 | if self.details.has_key("start") and not self.details.get("end"): |
paul@347 | 813 | end = self.details["start"] |
paul@347 | 814 | |
paul@347 | 815 | # Make any end time refer to the day instead. |
paul@347 | 816 | |
paul@347 | 817 | if isinstance(end, DateTime): |
paul@347 | 818 | end = end.as_date() |
paul@347 | 819 | |
paul@347 | 820 | self.details["end"] = end |
paul@347 | 821 | |
paul@347 | 822 | def __repr__(self): |
paul@347 | 823 | return "<Event %r %r>" % (self.getSummary(), self.as_limits()) |
paul@347 | 824 | |
paul@347 | 825 | def __hash__(self): |
paul@347 | 826 | |
paul@347 | 827 | """ |
paul@347 | 828 | Return a dictionary hash, avoiding mistaken equality of events in some |
paul@347 | 829 | situations (notably membership tests) by including the URL as well as |
paul@347 | 830 | the summary. |
paul@347 | 831 | """ |
paul@347 | 832 | |
paul@347 | 833 | return hash(self.getSummary() + self.getEventURL()) |
paul@347 | 834 | |
paul@347 | 835 | def getPage(self): |
paul@347 | 836 | |
paul@347 | 837 | "Return the page describing this event." |
paul@347 | 838 | |
paul@347 | 839 | return self.page |
paul@347 | 840 | |
paul@347 | 841 | def setPage(self, page): |
paul@347 | 842 | |
paul@347 | 843 | "Set the 'page' describing this event." |
paul@347 | 844 | |
paul@347 | 845 | self.page = page |
paul@347 | 846 | |
paul@347 | 847 | def getEventURL(self): |
paul@347 | 848 | |
paul@347 | 849 | "Return the URL of this event." |
paul@347 | 850 | |
paul@347 | 851 | fragment = self.details.get("fragment") |
paul@347 | 852 | return self.page.getPageURL() + (fragment and "#" + fragment or "") |
paul@347 | 853 | |
paul@347 | 854 | def linkToEvent(self, request, text, query_string=None): |
paul@347 | 855 | |
paul@347 | 856 | """ |
paul@347 | 857 | Using 'request', return a link to this event with the given link 'text' |
paul@347 | 858 | and optional 'query_string'. |
paul@347 | 859 | """ |
paul@347 | 860 | |
paul@347 | 861 | return self.page.linkToPage(request, text, query_string, self.details.get("fragment")) |
paul@347 | 862 | |
paul@347 | 863 | def getMetadata(self): |
paul@347 | 864 | |
paul@347 | 865 | """ |
paul@347 | 866 | Return a dictionary containing items describing the event's "created" |
paul@347 | 867 | time, "last-modified" time, "sequence" (or revision number) and the |
paul@347 | 868 | "last-comment" made about the last edit. |
paul@347 | 869 | """ |
paul@347 | 870 | |
paul@347 | 871 | # Delegate this to the page. |
paul@347 | 872 | |
paul@347 | 873 | return self.page.getMetadata() |
paul@347 | 874 | |
paul@347 | 875 | def getSummary(self, event_parent=None): |
paul@347 | 876 | |
paul@347 | 877 | """ |
paul@347 | 878 | Return either the given title or summary of the event according to the |
paul@347 | 879 | event details, or a summary made from using the pretty version of the |
paul@347 | 880 | page name. |
paul@347 | 881 | |
paul@347 | 882 | If the optional 'event_parent' is specified, any page beneath the given |
paul@347 | 883 | 'event_parent' page in the page hierarchy will omit this parent information |
paul@347 | 884 | if its name is used as the summary. |
paul@347 | 885 | """ |
paul@347 | 886 | |
paul@347 | 887 | event_details = self.details |
paul@347 | 888 | |
paul@347 | 889 | if event_details.has_key("title"): |
paul@347 | 890 | return event_details["title"] |
paul@347 | 891 | elif event_details.has_key("summary"): |
paul@347 | 892 | return event_details["summary"] |
paul@347 | 893 | else: |
paul@347 | 894 | # If appropriate, remove the parent details and "/" character. |
paul@347 | 895 | |
paul@347 | 896 | title = self.page.getPageName() |
paul@347 | 897 | |
paul@347 | 898 | if event_parent and title.startswith(event_parent): |
paul@347 | 899 | title = title[len(event_parent.rstrip("/")) + 1:] |
paul@347 | 900 | |
paul@347 | 901 | return getPrettyTitle(title) |
paul@347 | 902 | |
paul@347 | 903 | def getDetails(self): |
paul@347 | 904 | |
paul@347 | 905 | "Return the details for this event." |
paul@347 | 906 | |
paul@347 | 907 | return self.details |
paul@347 | 908 | |
paul@347 | 909 | def setDetails(self, event_details): |
paul@347 | 910 | |
paul@347 | 911 | "Set the 'event_details' for this event." |
paul@347 | 912 | |
paul@347 | 913 | self.details = event_details |
paul@347 | 914 | |
paul@347 | 915 | def getRawDetails(self): |
paul@347 | 916 | |
paul@347 | 917 | "Return the details for this event as they were written in a page." |
paul@347 | 918 | |
paul@347 | 919 | return self.raw_details |
paul@347 | 920 | |
paul@347 | 921 | # Timespan-related methods. |
paul@347 | 922 | |
paul@347 | 923 | def __contains__(self, other): |
paul@347 | 924 | return self == other |
paul@347 | 925 | |
paul@347 | 926 | def __eq__(self, other): |
paul@347 | 927 | if isinstance(other, Event): |
paul@347 | 928 | return self.getSummary() == other.getSummary() and self.getEventURL() == other.getEventURL() and self._cmp(other) |
paul@347 | 929 | else: |
paul@347 | 930 | return self._cmp(other) == 0 |
paul@347 | 931 | |
paul@347 | 932 | def __ne__(self, other): |
paul@347 | 933 | return not self.__eq__(other) |
paul@347 | 934 | |
paul@347 | 935 | def __lt__(self, other): |
paul@347 | 936 | return self._cmp(other) == -1 |
paul@347 | 937 | |
paul@347 | 938 | def __le__(self, other): |
paul@347 | 939 | return self._cmp(other) in (-1, 0) |
paul@347 | 940 | |
paul@347 | 941 | def __gt__(self, other): |
paul@347 | 942 | return self._cmp(other) == 1 |
paul@347 | 943 | |
paul@347 | 944 | def __ge__(self, other): |
paul@347 | 945 | return self._cmp(other) in (0, 1) |
paul@347 | 946 | |
paul@347 | 947 | def _cmp(self, other): |
paul@347 | 948 | |
paul@347 | 949 | "Compare this event to an 'other' event purely by their timespans." |
paul@347 | 950 | |
paul@347 | 951 | if isinstance(other, Event): |
paul@347 | 952 | return cmp(self.as_timespan(), other.as_timespan()) |
paul@347 | 953 | else: |
paul@347 | 954 | return cmp(self.as_timespan(), other) |
paul@347 | 955 | |
paul@347 | 956 | def as_timespan(self): |
paul@347 | 957 | details = self.details |
paul@347 | 958 | if details.has_key("start") and details.has_key("end"): |
paul@347 | 959 | return Timespan(details["start"], details["end"]) |
paul@347 | 960 | else: |
paul@347 | 961 | return None |
paul@347 | 962 | |
paul@347 | 963 | def as_limits(self): |
paul@347 | 964 | ts = self.as_timespan() |
paul@347 | 965 | return ts and ts.as_limits() |
paul@347 | 966 | |
paul@347 | 967 | class CalendarEvent(Event): |
paul@347 | 968 | |
paul@347 | 969 | "An event from a remote calendar." |
paul@347 | 970 | |
paul@347 | 971 | def getEventURL(self): |
paul@347 | 972 | |
paul@354 | 973 | """ |
paul@354 | 974 | Return the URL of this event, fixing any misinterpreted or incorrectly |
paul@354 | 975 | formatted value in the event definition or returning the resource URL in |
paul@354 | 976 | the absence of any URL in the event details. |
paul@354 | 977 | """ |
paul@354 | 978 | |
paul@413 | 979 | # NOTE: Redirect empty URLs to an action showing the resource details. |
paul@413 | 980 | |
paul@354 | 981 | return self.details.get("url") and \ |
paul@354 | 982 | self.valueToString(self.details["url"]) or \ |
paul@354 | 983 | self.page.getPageURL() |
paul@354 | 984 | |
paul@354 | 985 | def getSummary(self, event_parent=None): |
paul@347 | 986 | |
paul@354 | 987 | """ |
paul@354 | 988 | Return the event summary, fixing any misinterpreted or incorrectly |
paul@354 | 989 | formatted value in the event definition. |
paul@354 | 990 | """ |
paul@354 | 991 | |
paul@354 | 992 | return self.valueToString(self.details["summary"]) |
paul@354 | 993 | |
paul@354 | 994 | def valueToString(self, value): |
paul@354 | 995 | |
paul@354 | 996 | "Return the given 'value' converted to a string." |
paul@354 | 997 | |
paul@354 | 998 | if isinstance(value, list): |
paul@354 | 999 | return ",".join(value) |
paul@354 | 1000 | elif isinstance(value, tuple): |
paul@354 | 1001 | return ";".join(value) |
paul@354 | 1002 | else: |
paul@354 | 1003 | return value |
paul@347 | 1004 | |
paul@347 | 1005 | def linkToEvent(self, request, text, query_string=None, anchor=None): |
paul@347 | 1006 | |
paul@347 | 1007 | """ |
paul@347 | 1008 | Using 'request', return a link to this event with the given link 'text' |
paul@347 | 1009 | and optional 'query_string' and 'anchor'. |
paul@347 | 1010 | """ |
paul@347 | 1011 | |
paul@347 | 1012 | return linkToResource(self.getEventURL(), request, text, query_string, anchor) |
paul@347 | 1013 | |
paul@347 | 1014 | def getMetadata(self): |
paul@347 | 1015 | |
paul@347 | 1016 | """ |
paul@347 | 1017 | Return a dictionary containing items describing the event's "created" |
paul@347 | 1018 | time, "last-modified" time, "sequence" (or revision number) and the |
paul@347 | 1019 | "last-comment" made about the last edit. |
paul@347 | 1020 | """ |
paul@347 | 1021 | |
paul@353 | 1022 | metadata = self.page.getMetadata() |
paul@353 | 1023 | |
paul@347 | 1024 | return { |
paul@353 | 1025 | "created" : self.details.get("created") or self.details.get("dtstamp") or metadata["created"], |
paul@353 | 1026 | "last-modified" : self.details.get("last-modified") or self.details.get("dtstamp") or metadata["last-modified"], |
paul@347 | 1027 | "sequence" : self.details.get("sequence") or 0, |
paul@347 | 1028 | "last-comment" : "" |
paul@347 | 1029 | } |
paul@347 | 1030 | |
paul@347 | 1031 | # vim: tabstop=4 expandtab shiftwidth=4 |