# HG changeset patch # User Paul Boddie # Date 1396909593 -7200 # Node ID c3696d680f22fc4bbd1a2ceee361ce57728eadea # Parent 62f611b64ff264a30911927298b33059790b8e89 Obtain UID and SEQUENCE details in order to select active event revisions. diff -r 62f611b64ff2 -r c3696d680f22 EventAggregatorSupport/Resources.py --- a/EventAggregatorSupport/Resources.py Mon Apr 07 23:16:49 2014 +0200 +++ b/EventAggregatorSupport/Resources.py Tue Apr 08 00:26:33 2014 +0200 @@ -213,6 +213,26 @@ return new_event_page.getBody() +# Event selection using UID and SEQUENCE information. + +def getActiveRevisions(events): + + """ + Get the event instances with the greatest SEQUENCE number for each UID in + the given 'events'. + """ + + active = {} + + for event in events: + uid = event.getEventUID() + + if not active.has_key(uid) or \ + event.getSequence() > active[uid].getSequence(): + active[uid] = event + + return active.values() + # Event selection from request parameters. def getEventsUsingParameters(category_names, search_pattern, remote_sources, @@ -229,6 +249,7 @@ pages = getPagesFromResults(results, request) events = getEventPages(pages).getEvents() events += getEventResources(remote_sources, calendar_start, calendar_end, request).getEvents() + events = getActiveRevisions(events) all_shown_events = getEventsInPeriod(events, getCalendarPeriod(calendar_start, calendar_end)) earliest, latest = getEventLimits(all_shown_events) diff -r 62f611b64ff2 -r c3696d680f22 EventAggregatorSupport/Types.py --- a/EventAggregatorSupport/Types.py Mon Apr 07 23:16:49 2014 +0200 +++ b/EventAggregatorSupport/Types.py Tue Apr 08 00:26:33 2014 +0200 @@ -481,7 +481,7 @@ # Accept other textual data as it is. - elif property in ("LOCATION", "SUMMARY", "URL"): + elif property in ("LOCATION", "SUMMARY", "URL", "UID"): value = value or None # Ignore other properties. @@ -525,6 +525,7 @@ ("categories", "xcal:properties/xcal:categories", "getCollection"), ("geo", "xcal:properties/xcal:geo", "getGeo"), ("url", "xcal:properties/xcal:url", "getURI"), + ("uid", "xcal:properties/xcal:uid", "getText"), ] def __init__(self, url, doc, metadata): @@ -928,6 +929,18 @@ self.page = page + def getEventUID(self): + + "Return the UID of this event." + + return self.details.get("uid") or self.getEventURL() + + def getSequence(self): + + "Return the sequence number of this event." + + return self.details.get("sequence") or 0 + def getEventURL(self): "Return the URL of this event." @@ -1108,7 +1121,7 @@ return { "created" : self.details.get("created") or self.details.get("dtstamp") or metadata["created"], "last-modified" : self.details.get("last-modified") or self.details.get("dtstamp") or metadata["last-modified"], - "sequence" : self.details.get("sequence") or 0, + "sequence" : self.getSequence(), "last-comment" : "" }