summaryrefslogtreecommitdiff
path: root/addons/caldav/caldav_node.py
diff options
context:
space:
mode:
authorHarry (Open ERP) <hmo@tinyerp.com>2010-04-13 16:33:20 +0530
committerHarry (Open ERP) <hmo@tinyerp.com>2010-04-13 16:33:20 +0530
commit6a94de909b027dc1259b3fc8b4d1cd16d1d2c467 (patch)
treed20f1cf24c56199078e5125b28a7372bf8fb536e /addons/caldav/caldav_node.py
parent522724913410a7aa2cf881f1394a36cbd9a8107e (diff)
[REF+IMP] document
bzr revid: hmo@tinyerp.com-20100413110320-9x1fy7l432sinxvd
Diffstat (limited to 'addons/caldav/caldav_node.py')
-rw-r--r--addons/caldav/caldav_node.py141
1 files changed, 105 insertions, 36 deletions
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