diff --git a/tabellio/icalimport/icalimport.py b/tabellio/icalimport/icalimport.py index 74b2245..884b9bd 100644 --- a/tabellio/icalimport/icalimport.py +++ b/tabellio/icalimport/icalimport.py @@ -32,6 +32,9 @@ class IcalImport(BrowserView): urlopen = urllib2.urlopen content = urlopen(url).read() parsed_cal = vobject.readOne(content) + seen_ids = [] + created = 0 + updated = 0 for vevent in parsed_cal.vevent_list: title = vevent.summary.value date_start = vevent.dtstart.value @@ -71,6 +74,9 @@ class IcalImport(BrowserView): event_id = self.plone_utils.normalizeString(base_id % base_parts) if not hasattr(self.context, event_id): self.context.invokeFactory('tabellio.agenda.event', event_id, title=title) + created += 1 + else: + updated += 1 event = getattr(self.context, event_id) event.title = title event.start = date_start @@ -105,5 +111,13 @@ class IcalImport(BrowserView): self.portal_workflow.doActionFor(getattr(self.context, event_id), 'publish') except WorkflowException: pass + seen_ids.append(event.id) - return 'OK' + deleted = 0 + for event_id in self.context.objectIds(): + if event_id in seen_ids: + continue + self.context.manage_delObjects(event_id) + deleted += 1 + + return 'OK (created: %s, updated: %s, deleted: %s)' % (created, updated, deleted)