use more data to create event id (#1033)

This commit is contained in:
Frédéric Péters 2011-11-30 21:22:13 +01:00
parent 1208b37176
commit 6d9733430a
1 changed files with 26 additions and 9 deletions

View File

@ -47,11 +47,28 @@ class IcalImport(BrowserView):
date_end = datetime.datetime.fromordinal(date_end.toordinal())
except:
date_end = None
event_id = self.plone_utils.normalizeString(
'%04d-%02d-%02d-%s' % (date_start.year,
date_start.month,
date_start.day,
title))
location = None
try:
location = vevent.location.value
except:
pass
base_id = '%(year)04d%(month)02d%(day)02d'
base_parts = {'year': date_start.year,
'month': date_start.month,
'day': date_start.day}
if date_start.hour != 0 and date_start.minute != 0:
base_id = base_id + '-%(hour)02d%(minute)02d'
base_parts.update({'hour': date_start.hour,
'minute': date_start.minute})
if location:
base_id = base_id + '-%(location)s'
base_parts.update({'location': location})
if title:
base_id = base_id + '-%(title)s'
base_parts.update({'title': title})
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)
event = getattr(self.context, event_id)
@ -75,12 +92,12 @@ class IcalImport(BrowserView):
event.text = RichTextValue(raw=description,
mimeType='text/html', outputMimeType='text/x-html-safe')
try:
event.place = vevent.location.value
except:
pass
event.place = location
notify(ObjectModifiedEvent(event))
try:
self.portal_workflow.doActionFor(getattr(self.context, event_id), 'publish')
except WorkflowException:
pass
return 'OK'