From 6d9733430aa1155b12f976ccdcaf25a7e39dea57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 30 Nov 2011 21:22:13 +0100 Subject: [PATCH] use more data to create event id (#1033) --- tabellio/icalimport/icalimport.py | 35 +++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/tabellio/icalimport/icalimport.py b/tabellio/icalimport/icalimport.py index 50296b6..11b4cba 100644 --- a/tabellio/icalimport/icalimport.py +++ b/tabellio/icalimport/icalimport.py @@ -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'