From 6a94de909b027dc1259b3fc8b4d1cd16d1d2c467 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Tue, 13 Apr 2010 16:33:20 +0530 Subject: [REF+IMP] document bzr revid: hmo@tinyerp.com-20100413110320-9x1fy7l432sinxvd --- addons/caldav/caldav_node.py | 141 +++++++++++++++++++++++++++++++----------- addons/caldav/caldav_view.xml | 3 +- addons/caldav/calendar.py | 22 ++++++- 3 files changed, 126 insertions(+), 40 deletions(-) (limited to 'addons/caldav') diff --git a/addons/caldav/caldav_node.py b/addons/caldav/caldav_node.py index fd17b52f478..6ecfcd30027 100644 --- a/addons/caldav/caldav_node.py +++ b/addons/caldav/caldav_node.py @@ -25,31 +25,122 @@ import pooler import tools import time import base64 +from document import nodes +import StringIO +class node_database(nodes.node_database): + def _child_get(self, cr, name=False, parent_id=False, domain=None): + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + if not domain: + domain = [] + domain2 = domain + [('calendar_collection','=', False)] + res = super(node_database, self)._child_get(cr, name=name, parent_id=parent_id, domain=domain2) + where = [('parent_id','=',parent_id)] + domain2 = domain + [('calendar_collection','=', True)] + if name: + where.append(('name','=',name)) + if domain2: + where += domain2 -class node_calendar(object): - def __init__(self, path, context, calendar): - self.path = path - self.context = context - self.calendar_id = calendar.id + where2 = where + [('type', '=', 'directory')] + ids = dirobj.search(cr, uid, where2, context=ctx) + for dirr in dirobj.browse(cr,uid,ids,context=ctx): + res.append(node_calendar_collection(dirr.name,self,self.context,dirr)) + return res + +class node_calendar_collection(nodes.node_dir): + def get_dav_props(self, cr): + res = {} + return res + + def get_dav_eprop(self,cr,ns,prop): + return None + + def _child_get(self, cr, name=False, parent_id=False, domain=None): + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + where = [('collection_id','=',self.dir_id)] + if name: + where.append(('name','=',name)) + if not domain: + domain = [] + + fil_obj = dirobj.pool.get('basic.calendar') + ids = fil_obj.search(cr,uid,where,context=ctx) + res = [] + if ids: + for fil in fil_obj.browse(cr,uid,ids,context=ctx): + res.append(node_calendar(fil.name,self,self.context,fil)) + return res + + + def get_etag(self, cr): + """ Get a tag, unique per object + modification. + + see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """ + return self._get_ttag(cr) + ':' + self._get_wtag(cr) + + def _get_wtag(self, cr): + """ Return the modification time as a unique, compact string """ + if self.write_date: + wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S')) + else: wtime = time.time() + return str(wtime) + + def _get_ttag(self, cr): + return 'calendar collection-%d' % self.dir_id + +class node_calendar(nodes.node_class): + our_type = 'file' + def __init__(self,path, parent, context, calendar): + super(node_calendar,self).__init__(path, parent,context) + self.calendar_id = calendar.id self.mimetype = 'ics' self.create_date = calendar.create_date self.write_date = calendar.write_date or calendar.create_date self.content_length = 0 - self.displayname = calendar.name + self.displayname = calendar.name + + def open(self, cr, mode=False): + uid = self.context.uid + if self.type in ('collection','database'): + return False + fobj = self.context._dirobj.pool.get('basic.calendar').browse(cr, uid, self.calendar_id, context=self.context.context) + s = StringIO.StringIO(self.get_data(cr, fobj)) + s.name = self + return s + def get_dav_props(self, cr): + res = {} + return res - def get_data(self, cr, uid): - calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar') - return calendar_obj.export_cal(cr, uid, [self.calendar_id]) + def get_dav_eprop(self,cr,ns,prop): + return None - def get_data_len(self, cr): + + def get_data(self, cr, fil_obj = None): + uid = self.context.uid + calendar_obj = self.context._dirobj.pool.get('basic.calendar') + return calendar_obj.export_cal(cr, uid, [self.calendar_id]) + + def get_data_len(self, cr, fil_obj = None): return self.content_length - def set_data(self, cr, uid, data): - calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar') + 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) + def _get_ttag(self,cr): + return 'calendar-%d' % self.calendar_id + + + def get_etag(self, cr): """ Get a tag, unique per object + modification. @@ -61,27 +152,5 @@ class node_calendar(object): if self.write_date: wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S')) else: wtime = time.time() - return str(wtime) - - def _get_ttag(self, cr): - return 'calendar-%d' % self.calendar_id - - -class Calendar(osv.osv): - _inherit = 'basic.calendar' - - def get_calendar_object(self, cr, uid, uri, context=None): - if not uri: - return None - if len(uri) > 1: - return None - name, file_type = tuple(uri[0].split('.')) - res = self.name_search(cr, uid, name) - if not res: - return None - calendar_id, calendar_name = res[0] - calendar = self.browse(cr, uid, calendar_id) - return node_calendar(uri, context, calendar) -Calendar() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4 \ No newline at end of file + return str(wtime) +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4 diff --git a/addons/caldav/caldav_view.xml b/addons/caldav/caldav_view.xml index 152baf6c876..c982d695fac 100644 --- a/addons/caldav/caldav_view.xml +++ b/addons/caldav/caldav_view.xml @@ -17,8 +17,7 @@ Calendar Collections : Tree document.directory - tree - child_ids + tree diff --git a/addons/caldav/calendar.py b/addons/caldav/calendar.py index bcf7eb58d76..6ccd5989d5c 100644 --- a/addons/caldav/calendar.py +++ b/addons/caldav/calendar.py @@ -31,7 +31,7 @@ import pytz import re import tools import time - +import caldav_node try: import vobject @@ -418,7 +418,12 @@ class calendar_collection(osv.osv): } _default = { 'calendar_collection' : False, - } + } + def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext): + """ try to locate the node in uri, + Return a tuple (node_dir, remaining_path) + """ + return (caldav_node.node_database(context=ncontext), uri) calendar_collection() @@ -449,6 +454,19 @@ class Calendar(CalDAV, osv.osv): 'write_date': fields.datetime('Modifided Date'), } + def get_calendar_object(self, cr, uid, uri, context=None): + if not uri: + return None + if len(uri) > 1: + return None + name, file_type = tuple(uri[0].split('.')) + res = self.name_search(cr, uid, name) + if not res: + return None + calendar_id, calendar_name = res[0] + calendar = self.browse(cr, uid, calendar_id) + return node_calendar(uri, context, calendar) + def export_cal(self, cr, uid, ids, vobj='vevent', context={}): """ Export Calendar @param self: The object pointer -- cgit v1.2.3