From dd45fa67a55c1d1bdb0d1d8925ff35927ff5e09a Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Mon, 14 Dec 2009 16:37:43 +0530 Subject: [PATCH] [IMP]:caldav: Improvement in crm+caldav for attendee import, made mapping function generic to be used in all class in caldav bzr revid: rpa@tinyerp.com-20091214110743-84c0g8271hbuqab4 --- addons/caldav/__terp__.py | 22 ++++++++------- addons/caldav/calendar.py | 57 +++++++++++++++++++++++++++++--------- addons/crm/crm_calendar.py | 26 ++++++----------- 3 files changed, 65 insertions(+), 40 deletions(-) diff --git a/addons/caldav/__terp__.py b/addons/caldav/__terp__.py index c700cd75d2d..6846ed5801b 100644 --- a/addons/caldav/__terp__.py +++ b/addons/caldav/__terp__.py @@ -21,11 +21,11 @@ { - "name" : "CalDAV", - "version" : "1.0", + "name" : "CalDAV", + "version" : "1.0", "depends" : [ - "base", - ], + "base", + ], 'description': """ To develop a full featured caldav system that support: - access through webdav (based on xrg code) @@ -34,14 +34,16 @@ - invitations to others people (exactly like sunbird) - availabilities of users/calendars - full day events""", - "author" : "Tiny", - "init_xml" : [], - + "author" : "Tiny", + 'category': 'Generic Modules/Others', + 'website': 'http://www.openerp.com', + "init_xml" : [], + "demo_xml" : [], "update_xml" : [ 'security/ir.model.access.csv' - ], - "installable" : True, - "active" : False, + ], + "installable" : True, + "active" : False, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/caldav/calendar.py b/addons/caldav/calendar.py index 5163784759f..71e44cdf5ed 100644 --- a/addons/caldav/calendar.py +++ b/addons/caldav/calendar.py @@ -30,12 +30,39 @@ from dateutil import parser from datetime import datetime from time import strftime from pytz import timezone +import re # O-1 Optional and can come only once # O-n Optional and can come more than once # R-1 Required and can come only once # R-n Required and can come more than once +def map_data(cr, uid, obj): + vals = {} + for map_dict in obj.__attribute__: + map_val = obj.ical_get(map_dict, 'value') + field = obj.ical_get(map_dict, 'field') + field_type = obj.ical_get(map_dict, 'type') + if field and map_val: + if field_type == 'selection': + mapping =obj.__attribute__[map_dict].get('mapping', False) + if mapping: + map_val = mapping[map_val] + if field_type == 'many2many': + ids = [] + model = obj.__attribute__[map_dict].get('object', False) + modobj = obj.pool.get(model) + for map_vall in map_val: + id = modobj.create(cr, uid, map_vall) + ids.append(id) + vals[field] = [(6, 0, ids)] + continue + if field_type == 'many2one': + # TODO: Map field value to many2one object + continue # For now + vals[field] = map_val + return vals + class CalDAV(object): __attribute__= { } @@ -66,14 +93,19 @@ class CalDAV(object): def import_ical(self, cr, uid, ical_data): parsedCal = vobject.readOne(ical_data) + att_data = [] for child in parsedCal.getChildren(): for cal_data in child.getChildren(): if cal_data.name.lower() == 'attendee': attendee = self.pool.get('caldav.attendee') - attendee.import_ical(cr, uid, cal_data) + att_data.append(attendee.import_ical(cr, uid, cal_data)) + self.ical_set(cal_data.name.lower(), att_data , 'value') + continue if cal_data.name.lower() in self.__attribute__: self.ical_set(cal_data.name.lower(), cal_data.value, 'value') - return True + vals = map_data(cr, uid, self) + return vals + class Calendar(CalDAV, osv.osv_memory): _name = 'caldav.calendar' @@ -94,6 +126,7 @@ class Calendar(CalDAV, osv.osv_memory): def import_ical(self, cr, uid, ical_data): # Write openobject data from ical_data + ical = vobject.readOne(ical_data) for child in ical.getChildren(): child_name = child.name.lower() @@ -205,7 +238,7 @@ class Event(CalDAV, osv.osv_memory): if not startdate: startdate = datetime.now() else: - startdate = todate(startdate) + startdate = todate(''.join((re.compile('\d')).findall(startdate)) + 'Z') rset1 = rrulestr(rrulestring, dtstart=startdate, forceset=True) for date in exdate: datetime_obj = datetime.strptime(date, "%Y-%m-%d %H:%M:%S") @@ -310,14 +343,12 @@ class Attendee(CalDAV, osv.osv_memory): } def import_ical(self, cr, uid, ical_data): - if ical_data.value: - self.__attribute__['sent-by'] = ical_data.value - for key, val in ical_data.params.items(): - if self.__attribute__.has_key(key.lower()): - if type(val) == type([]): - self.__attribute__[key] = val[0] - else: - self.__attribute__[key] = val - return + for para in ical_data.params: + if para.lower() == 'cn': + self.ical_set(para.lower(), ical_data.params[para][0]+':'+ ical_data.value, 'value') + else: + self.ical_set(para.lower(), ical_data.params[para][0], 'value') + vals = map_data(cr, uid, self) + return vals -Attendee() +Attendee() \ No newline at end of file diff --git a/addons/crm/crm_calendar.py b/addons/crm/crm_calendar.py index baeff6a41ce..25267ac8011 100644 --- a/addons/crm/crm_calendar.py +++ b/addons/crm/crm_calendar.py @@ -54,7 +54,7 @@ class crm_caldav_attendee(osv.osv): __attribute__ = { 'cutype' : {'field':'cutype', 'type':'text'}, # Use: 0-1 Specify the type of calendar user specified by the property like "INDIVIDUAL"/"GROUP"/"RESOURCE"/"ROOM"/"UNKNOWN". 'member' : {'field':'member', 'type':'text'}, # Use: 0-1 Specify the group or list membership of the calendar user specified by the property. - 'role' : {'field':'role', 'type':'text'}, # Use: 0-1 Specify the participation role for the calendar user specified by the property like "CHAIR"/"REQ-PARTICIPANT"/"OPT-PARTICIPANT"/"NON-PARTICIPANT" + 'role' : {'field':'role', 'type':'selection'}, # Use: 0-1 Specify the participation role for the calendar user specified by the property like "CHAIR"/"REQ-PARTICIPANT"/"OPT-PARTICIPANT"/"NON-PARTICIPANT" 'partstat' : {'field':'partstat', 'type':'text'}, # Use: 0-1 Specify the participation status for the calendar user specified by the property. like use for VEVENT :- "NEEDS-ACTION"/"ACCEPTED"/"DECLINED"/"TENTATIVE"/"DELEGATED", use for VTODO :-"NEEDS-ACTION"/"ACCEPTED"/"DECLINED"/"TENTATIVE"/"DELEGATED"/"COMPLETED"/"IN-PROCESS" and use for VJOURNAL :- "NEEDS-ACTION"/"ACCEPTED"/"DECLINED". 'rsvp' : {'field':'rsvp', 'type':'boolean'}, # Use: 0-1 Specify whether there is an expectation of a favor of a reply from the calendar user specified by the property value like TRUE / FALSE. 'delegated-to' : {'field':'delegated_to', 'type':'char'}, # Use: 0-1 Specify the calendar users to whom the calendar user specified by the property has delegated participation. @@ -147,7 +147,7 @@ class crm_case(osv.osv): 'url' : {'field':'caldav_url', 'type':'text'}, 'recurid' : None, # 'attach' : {'field':'attachment_ids', 'sub-field':'datas', 'type':'list'}, - 'attendee' : {'field':'attendees', 'type':'text'}, + 'attendee' : {'field':'attendees', 'type':'many2many', 'object' : 'crm.caldav.attendee'}, # 'categories' : {'field':'categ_id', 'sub-field':'name'}, # 'categories' : {'field':None , 'sub-field':'name', 'type':'text'}, # keep none for now 'comment' : None, @@ -302,21 +302,12 @@ class crm_case(osv.osv): file_content = base64.decodestring(data['form']['file_path']) event_obj = self.pool.get('caldav.event') event_obj.__attribute__.update(self.__attribute__) - event_obj.import_ical(cr, uid, file_content) - vals = {} - for map_dict in event_obj.__attribute__: - map_val = event_obj.ical_get(map_dict, 'value') - field = event_obj.ical_get(map_dict, 'field') - field_type = event_obj.ical_get(map_dict, 'type') - if field and map_val: - if field_type == 'selection': - mapping =event_obj.__attribute__[map_dict].get('mapping', False) - if mapping: - map_val = mapping[map_val] - if field_type == 'many2one': - # TODO: Map field value to many2one object - continue # For now - vals[field] = map_val + + attendee_obj = self.pool.get('caldav.attendee') + crm_attendee = self.pool.get('crm.caldav.attendee') + attendee_obj.__attribute__.update(crm_attendee.__attribute__) + + vals = event_obj.import_ical(cr, uid, file_content) # TODO: Select proper section section_id = self.pool.get('crm.case.section').search(cr, uid, [])[0] vals.update({'section_id' : section_id}) @@ -395,6 +386,7 @@ class crm_case(osv.osv): self.write(cr, uid, [int(str(id).split('-')[0])], {'rrule' : record['rrule'] +"\n" + str(date_new)}) else: return super(crm_case, self).unlink(cr, uid, ids) + crm_case()