.ics to Plone ATEvent, any reliable solution ?
bertdelongue
bertdelongue at hotmail.com
Wed Sep 5 09:23:31 UTC 2007
Wow, we can't say this post generates enthusistic answers!
I just provide my adapter's code hereunder with comments on what's wrong,
just in case someone somewhere can (and wants to) help:
Cheers,
Bert
class InternalEventAdapter(Adapter):
"""
a BDL try to adapt the ics import capabitlities to AT events (and not CMF
events as it does by default)
it works for start and end date !!!!! Indeed, Internal Events is a copy of
ATevents
"""
portal_type = 'Internal Events'
def __init__(self, obj):
self._obj = obj
self.portal = self._portal()
self.encoding = self._encoding()
self.portal_url = self._portal_url()
def after_update(self):
"We must reindex catalog with new values"
self._obj.reindexObject()
# Private helpers
def _portal(self):
# get the portal
u_tool = self._obj.portal_url
return u_tool.getPortalObject()
def _encoding(self):
# returns the sites encoding
return self.portal.portal_properties.site_properties.default_charset
or 'utf-8'
def _portal_url(self):
# get the
return self.portal.absolute_url()
# get/set helpers
def _set(self, attr, val):
# set string with default encoding from unicode
val = val.encode(self.encoding)
setattr(self._obj, attr, val)
def _get(self, attr):
# get unicode string from default encoding
val = getattr(self._obj, attr)
val = val.replace('\r\n', '\n') # Behave on windows!
return val.decode(self.encoding)
# def test(self):
# "For trying out stuff"
# return self._obj.Creator()
##
def get_summary(self):
"Title/summary of the event"
return self._obj.title_or_id().decode(self.encoding)
def set_summary(self, summary):
"Title/summary of the event"
return self._set('title', summary)
def get_description(self):
"Long description of the event"
return self._get('Description')
def set_description(self, description):
"Long description of the event"
return self._set('Description', description)
# the description of the ics doesn't appear in the description field of
the event :-(
def get_dtstart(self):
"Start time of event"
return self._get('startDate')
def set_dtstart(self, dtstart):
"Start time of event"
self._obj.startDate = dt2DT(dtstart)
"""
dt2DT returns something like '2007/09/07 06:00:00 Universal' , where I want
to have '2007/09/07 08:00:00 GMT+2 ' ; the reason I don't want date in
Universal Time is because I is misinterpreted inside plone (displays some
times 6:00, sometimes 8:00 depending on the view!!)
"""
def get_dtend(self):
"End time of event"
return self._get('endDate')
def set_dtend(self, dtend):
"End time of event"
self._obj.endDate = dt2DT(DT2dt(dt2DT(dtend)))
# icalendar defines a timestamp, Zope too. So they should be saved
# seperately for meaningfull roundtrip importing/exporting
DTSTAMP_ATTR_NAME = 'icalendar_dtstamp'
def get_dtstamp(self):
"Creation time of the event"
if hasattr(self._obj, self.DTSTAMP_ATTR_NAME):
return DT2dt(getattr(self._obj, self.DTSTAMP_ATTR_NAME))
# if no ical timestamp is imported, use the Zope one
return DT2dt(DateTime(self._obj.created()))
def set_dtstamp(self, dtstamp):
"Creation time of the event"
setattr(self._obj, self.DTSTAMP_ATTR_NAME, dt2DT(dtstamp))
def get_organizer(self):
"Organizer/owner of the event"
contact_name = self._get('contact_name')
contact_email = self._get('contact_email')
if contact_email: # email is organizer id!!!
return (contact_name, contact_email)
else: # get organizer from creator of event
membership = self.portal.portal_membership
# argh this sucks, email of creator isn't cataloged
# so we look in portal memberdata for it.
try: # member may have been deleted
organizer_id = self._obj.getOwner().getId()
member = membership.getMemberById(organizer_id)
if not member is None:
email = member.email
fullname = member.fullname
if not fullname:
fullname = organizer_id
if email:
return (fullname.decode(self.encoding),
email.decode(self.encoding))
else:
return ()
except:
return ()
def set_organizer(self, organizer):
"Organizer/owner of the event"
fullname, email = organizer
self._set('contact_name', fullname)
self._set('contact_email', email)
def get_location(self):
"Location where the event takes place"
return self._get('location')
def set_location(self, location):
"Location where the event takes place"
self._set('location', location)
# it is asumed that events imported from an external icalender, will
have
# this attribute set.
UID_ATTR_NAME = 'icalendar_uid'
def get_uid(self):
"Globally unique id of the event. If none exist we create one."
if hasattr(self._obj, self.UID_ATTR_NAME):
return self._get(self.UID_ATTR_NAME)
else:
dtstamp =
DateTime(self._obj.created()).strftime('%Y%m%dT%H%M%SZ')
netloc = urlparse.urlparse(self.portal_url)[1].split(':')[0]
path = '/'.join(self._obj.getPhysicalPath())
return '%s-%s@%s' % (dtstamp, path, netloc)
def set_uid(self, uid):
"Globally unique id of the event."
self._set(self.UID_ATTR_NAME, uid)
ATTENDEE_ATTR_NAME = 'icalendar_attendees'
# Attendees do't exist in a Plone event, but it makes for better
import/export
# of iCalendar VEvents if they are there.
def get_attendees(self):
"Attendees at the event [(name,email,)]"
attendees = getattr(self._obj, self.ATTENDEE_ATTR_NAME, [])
result = []
for attendee in attendees:
name, email = attendee
result.append((name.decode(self.encoding),
email.decode(self.encoding)))
return result
def set_attendees(self, attendees):
"Attendees at the event [(name,email,)]"
encoded = []
for attendee in attendees:
name, email = attendee
encoded.append((name.encode(self.encoding),
email.encode(self.encoding)))
setattr(self._obj, self.ATTENDEE_ATTR_NAME, encoded)
def get_categories(self):
"The categories/Subjects of the event"
return [sub.decode(self.encoding) for sub in self._obj.Subject()]
def set_categories(self, categories):
"The categories/Subjects of the event"
self._obj.subject = [cat.encode(self.encoding) for cat in
categories]
#categories from ics file are NOT imported :-( why??
def get_url(self):
"Link to the event"
url = self._get('event_url')
return url or unicode(self._obj.absolute_url())
def set_url(self, url):
"Link to the event"
self._set('event_url', url)
def get_contact(self):
"Contact/phone"
return self._get('contact_phone')
def set_contact(self, contact):
"Contact/phone"
return self._set('contact_phone', contact)
######################################################
bertdelongue wrote:
>
> Hi all,
>
> I am trying to find my way in the jungle of plone events management and I
> am facing to a major gap in the plenty of possibibilities kindly offered
> by the Plone Developper's community.
>
> Is there any SIMPLE and RELIABLE solution to import events encoded in a
> stadard .ics file (ical standard) to Plone ATevent ??
>
> The product which is closest to my wishes is mxm_ical, BUT i have
> following issues :
>
> - it's importing CMF events and not ATevents (it's outdated in my
> opinion), so a lot of informations are lost by importing, because both
> types don't use the same field names;
> - I experience problems with time zones (it displays in my local time or
> in UTC depending on the 'view' on the Event object), I think it's due to
> the fact mxm_ical doesn't convert the UTC time contained in the ical file
> to a standard '2007/07/06 18:00:00 GMT+2' time format.
>
> I tried to develop my own adapter (which manages the 'translation' from
> ical file to any Plone Content type in mxm_ical_tools), but I am pretty
> new in python and plone, so I suffer a lot.
>
> Help, help, hep!!! Thanks a lot!
>
> p.s.: my instal= Plone 2.5.3 CMF 1.6.4 Zope 2.9.7 Python 2.4.4
>
--
View this message in context: http://www.nabble.com/.ics-to-Plone-ATEvent%2C-any-reliable-solution---tf4371478s20094.html#a12494613
Sent from the Product Developers mailing list archive at Nabble.com.
More information about the Product-Developers
mailing list