CalDAV: various improvements, manage to save ics now.
bzr revid: p_christ@hol.gr-20100729133938-fd64qv7ybnv8386d
This commit is contained in:
parent
f536feba96
commit
e5adb8e76c
|
@ -1500,6 +1500,7 @@ true, it will allow you to hide the event alarm information without removing it.
|
|||
@param context: A standard dictionary for contextual values
|
||||
@return: List of Dictionary of form [{‘name_of_the_field’: value, ...}, ...]
|
||||
"""
|
||||
# FIXME This whole id mangling has to go!
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ from tools.translate import _
|
|||
import pooler
|
||||
import tools
|
||||
import time
|
||||
import base64
|
||||
from document import nodes
|
||||
import StringIO
|
||||
|
||||
|
@ -235,18 +234,22 @@ class node_calendar(nodes.node_class):
|
|||
res = fil_obj.get_calendar_objects(cr, uid, [self.calendar_id], self, domain=where, context=ctx)
|
||||
return res
|
||||
|
||||
def create_child(self,cr,path,data):
|
||||
def create_child(self, cr, path, data):
|
||||
""" API function to create a child file object and node
|
||||
Return the node_* created
|
||||
"""
|
||||
return self.set_data(cr, data)
|
||||
# we ignore the path, it will be re-generated automatically
|
||||
res = self.set_data(cr, data)
|
||||
|
||||
# TODO: use the res to create at least one node
|
||||
return None
|
||||
|
||||
|
||||
def set_data(self, cr, data, fil_obj = None):
|
||||
uid = self.context.uid
|
||||
*-*
|
||||
calendar_obj = self.context._dirobj.pool.get('basic.calendar')
|
||||
return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
|
||||
res = calendar_obj.import_cal(cr, uid, data, self.calendar_id)
|
||||
return res
|
||||
|
||||
def get_data_len(self, cr, fil_obj = None):
|
||||
return self.content_length
|
||||
|
@ -315,7 +318,8 @@ class res_node_calendar(nodes.node_class):
|
|||
def set_data(self, cr, data, fil_obj = None):
|
||||
uid = self.context.uid
|
||||
calendar_obj = self.context._dirobj.pool.get('basic.calendar')
|
||||
return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
|
||||
res = calendar_obj.import_cal(cr, uid, data, self.calendar_id)
|
||||
return res
|
||||
|
||||
def _get_ttag(self,cr):
|
||||
res = False
|
||||
|
|
|
@ -24,7 +24,6 @@ from dateutil import parser
|
|||
from dateutil.rrule import *
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
import base64
|
||||
import math
|
||||
import pooler
|
||||
import pytz
|
||||
|
@ -52,6 +51,8 @@ def uid2openobjectid(cr, uidval, oomodel, rdate):
|
|||
@param rdate: Get Recurrent Date
|
||||
"""
|
||||
__rege = re.compile(r'OpenObject-([\w|\.]+)_([0-9]+)@(\w+)$')
|
||||
if not uidval:
|
||||
return (False, None)
|
||||
wematch = __rege.match(uidval.encode('utf8'))
|
||||
if not wematch:
|
||||
return (False, None)
|
||||
|
@ -381,7 +382,7 @@ class CalDAV(object):
|
|||
raise osv.except_osv(('Error !'), (str(e)))
|
||||
return ids
|
||||
|
||||
def export_cal(self, cr, uid, datas, vobj=None, context={}):
|
||||
def export_cal(self, cr, uid, datas, vobj=None, context=None):
|
||||
""" Export Calendar
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
|
@ -396,7 +397,7 @@ class CalDAV(object):
|
|||
self.create_ics(cr, uid, datas, vobj, ical, context=context)
|
||||
return ical
|
||||
except Exception, e:
|
||||
raise osv.except_osv(('Error !'), (str(e)))
|
||||
raise # osv.except_osv(('Error !'), (str(e)))
|
||||
|
||||
def import_cal(self, cr, uid, content, data_id=None, context=None):
|
||||
""" Import Calendar
|
||||
|
@ -407,7 +408,7 @@ class CalDAV(object):
|
|||
@param context: A standard dictionary for contextual values
|
||||
"""
|
||||
|
||||
ical_data = base64.decodestring(content)
|
||||
ical_data = content
|
||||
self.__attribute__ = get_attribute_mapping(cr, uid, self._calname, context)
|
||||
parsedCal = vobject.readOne(ical_data)
|
||||
res = []
|
||||
|
@ -479,11 +480,10 @@ class Calendar(CalDAV, osv.osv):
|
|||
|
||||
def export_cal(self, cr, uid, ids, vobj='vevent', context=None):
|
||||
""" Export Calendar
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of calendar’s IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
@param vobj: the type of object to export
|
||||
|
||||
@return the ical data.
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
|
@ -521,7 +521,7 @@ class Calendar(CalDAV, osv.osv):
|
|||
if not context:
|
||||
context = {}
|
||||
vals = []
|
||||
ical_data = base64.decodestring(content)
|
||||
ical_data = content
|
||||
parsedCal = vobject.readOne(ical_data)
|
||||
if not data_id:
|
||||
data_id = self.search(cr, uid, [])[0]
|
||||
|
@ -541,14 +541,19 @@ class Calendar(CalDAV, osv.osv):
|
|||
val = self.parse_ics(cr, uid, child, cal_children=cal_children, context=context)
|
||||
vals.append(val)
|
||||
objs.append(cal_children[child.name.lower()])
|
||||
|
||||
res = []
|
||||
for obj_name in list(set(objs)):
|
||||
obj = self.pool.get(obj_name)
|
||||
if hasattr(obj, 'check_import'):
|
||||
obj.check_import(cr, uid, vals, context=context)
|
||||
r = obj.check_import(cr, uid, vals, context=context)
|
||||
checked = True
|
||||
res.extend(r)
|
||||
|
||||
if not checked:
|
||||
self.check_import(cr, uid, vals, context=context)
|
||||
return {}
|
||||
r = self.check_import(cr, uid, vals, context=context)
|
||||
res.extend(r)
|
||||
return res
|
||||
Calendar()
|
||||
|
||||
|
||||
|
@ -632,6 +637,10 @@ class basic_calendar_fields(osv.osv):
|
|||
'fn': lambda *a: 'field',
|
||||
}
|
||||
|
||||
_sql_constraints = [
|
||||
( 'name_type_uniq', 'UNIQUE(name, type_id)', 'Can not map a field more than once'),
|
||||
]
|
||||
|
||||
def check_line(self, cr, uid, vals, name, context=None):
|
||||
""" check calendar's line
|
||||
@param self: The object pointer
|
||||
|
@ -667,12 +676,6 @@ class basic_calendar_fields(osv.osv):
|
|||
name = name[0]
|
||||
if name in ('valarm', 'attendee'):
|
||||
self.check_line(cr, uid, vals, name, context=context)
|
||||
cr.execute("Select count(id) from basic_calendar_fields \
|
||||
where name=%s and type_id=%s" % (vals.get('name'), vals.get('type_id')))
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
if res[0] > 0:
|
||||
raise osv.except_osv(_('Warning !'), _('Can not map the field more than once'))
|
||||
return super(basic_calendar_fields, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
|
@ -691,13 +694,6 @@ class basic_calendar_fields(osv.osv):
|
|||
name = field.name.name
|
||||
if name in ('valarm', 'attendee'):
|
||||
self.check_line(cr, uid, vals, name, context=context)
|
||||
qry = "Select count(id) from basic_calendar_fields \
|
||||
where name=%s and type_id=%s" % (field.name.id, field.type_id.id)
|
||||
cr.execute(qry)
|
||||
res = cr.fetchone()
|
||||
if res:
|
||||
if res[0] > 1:
|
||||
raise osv.except_osv(_('Warning !'), _('Can not map same field more than once'))
|
||||
return super(basic_calendar_fields, self).write(cr, uid, ids, vals, context)
|
||||
|
||||
basic_calendar_fields()
|
||||
|
|
Loading…
Reference in New Issue