flush unfound events (#1032)
This commit is contained in:
parent
2aba26916e
commit
748738f6c7
|
@ -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)
|
||||
|
|
Reference in New Issue