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