EventAggregator

Changeset

438:c3696d680f22
2014-04-08 Paul Boddie raw files shortlog changelog graph Obtain UID and SEQUENCE details in order to select active event revisions.
EventAggregatorSupport/Resources.py (file) EventAggregatorSupport/Types.py (file)
     1.1 --- a/EventAggregatorSupport/Resources.py	Mon Apr 07 23:16:49 2014 +0200
     1.2 +++ b/EventAggregatorSupport/Resources.py	Tue Apr 08 00:26:33 2014 +0200
     1.3 @@ -213,6 +213,26 @@
     1.4  
     1.5      return new_event_page.getBody()
     1.6  
     1.7 +# Event selection using UID and SEQUENCE information.
     1.8 +
     1.9 +def getActiveRevisions(events):
    1.10 +
    1.11 +    """
    1.12 +    Get the event instances with the greatest SEQUENCE number for each UID in
    1.13 +    the given 'events'.
    1.14 +    """
    1.15 +
    1.16 +    active = {}
    1.17 +
    1.18 +    for event in events:
    1.19 +        uid = event.getEventUID()
    1.20 +
    1.21 +        if not active.has_key(uid) or \
    1.22 +            event.getSequence() > active[uid].getSequence():
    1.23 +            active[uid] = event
    1.24 +
    1.25 +    return active.values()
    1.26 +
    1.27  # Event selection from request parameters.
    1.28  
    1.29  def getEventsUsingParameters(category_names, search_pattern, remote_sources,
    1.30 @@ -229,6 +249,7 @@
    1.31      pages               = getPagesFromResults(results, request)
    1.32      events              = getEventPages(pages).getEvents()
    1.33      events             += getEventResources(remote_sources, calendar_start, calendar_end, request).getEvents()
    1.34 +    events              = getActiveRevisions(events)
    1.35      all_shown_events    = getEventsInPeriod(events, getCalendarPeriod(calendar_start, calendar_end))
    1.36      earliest, latest    = getEventLimits(all_shown_events)
    1.37  
     2.1 --- a/EventAggregatorSupport/Types.py	Mon Apr 07 23:16:49 2014 +0200
     2.2 +++ b/EventAggregatorSupport/Types.py	Tue Apr 08 00:26:33 2014 +0200
     2.3 @@ -481,7 +481,7 @@
     2.4  
     2.5                          # Accept other textual data as it is.
     2.6  
     2.7 -                        elif property in ("LOCATION", "SUMMARY", "URL"):
     2.8 +                        elif property in ("LOCATION", "SUMMARY", "URL", "UID"):
     2.9                              value = value or None
    2.10  
    2.11                          # Ignore other properties.
    2.12 @@ -525,6 +525,7 @@
    2.13          ("categories",      "xcal:properties/xcal:categories",      "getCollection"),
    2.14          ("geo",             "xcal:properties/xcal:geo",             "getGeo"),
    2.15          ("url",             "xcal:properties/xcal:url",             "getURI"),
    2.16 +        ("uid",             "xcal:properties/xcal:uid",             "getText"),
    2.17          ]
    2.18  
    2.19      def __init__(self, url, doc, metadata):
    2.20 @@ -928,6 +929,18 @@
    2.21  
    2.22          self.page = page
    2.23  
    2.24 +    def getEventUID(self):
    2.25 +
    2.26 +        "Return the UID of this event."
    2.27 +
    2.28 +        return self.details.get("uid") or self.getEventURL()
    2.29 +
    2.30 +    def getSequence(self):
    2.31 +
    2.32 +        "Return the sequence number of this event."
    2.33 +
    2.34 +        return self.details.get("sequence") or 0
    2.35 +
    2.36      def getEventURL(self):
    2.37  
    2.38          "Return the URL of this event."
    2.39 @@ -1108,7 +1121,7 @@
    2.40          return {
    2.41              "created" : self.details.get("created") or self.details.get("dtstamp") or metadata["created"],
    2.42              "last-modified" : self.details.get("last-modified") or self.details.get("dtstamp") or metadata["last-modified"],
    2.43 -            "sequence" : self.details.get("sequence") or 0,
    2.44 +            "sequence" : self.getSequence(),
    2.45              "last-comment" : ""
    2.46              }
    2.47