Doc API, caldav: move the get_wtag code into document module.

It is the same case, that we want node.write_date to be used in the wtag
all over.

bzr revid: p_christ@hol.gr-20100729133937-4sgseg4keexeamd4
This commit is contained in:
P. Christeas
2010-07-29 16:39:37 +03:00
parent 6987e89efe
commit 99087be2b5
2 changed files with 19 additions and 68 deletions
+2 -49
View File
@@ -28,18 +28,6 @@ import base64
from document import nodes
import StringIO
def _str2time(cre):
""" Convert a string with time representation (from db) into time (float)
"""
if not cre:
return time.time()
frac = 0.0
if isinstance(cre, basestring) and '.' in cre:
fdot = cre.find('.')
frac = float(cre[fdot:])
cre = cre[:fdot]
return time.mktime(time.strptime(cre,'%Y-%m-%d %H:%M:%S')) + frac
class node_database(nodes.node_database):
def _child_get(self, cr, name=False, parent_id=False, domain=None):
dirobj = self.context._dirobj
@@ -107,18 +95,8 @@ class node_calendar_collection(nodes.node_dir):
# Todo?
return False
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 """
return str(_str2time(self.write_date))
def _get_ttag(self, cr):
return 'calendar collection-%d' % self.dir_id
return 'calen-dir-%d' % self.dir_id
def _get_dav_getctag(self, cr):
result = self.get_etag(cr)
@@ -266,28 +244,16 @@ class 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)
def get_data_len(self, cr, fil_obj = None):
return self.content_length
def _get_ttag(self,cr):
return 'calendar-%d' % (self.calendar_id,)
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 """
return str(_str2time(self.write_date))
def rmcol(self, cr):
return False
@@ -434,20 +400,7 @@ class res_node_calendar(nodes.node_class):
return res
def _get_caldav_schedule_outbox_URL(self, cr):
return self._get_caldav_schedule_inbox_URL(cr)
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 """
return str(_str2time(self.write_date))
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4
+17 -19
View File
@@ -44,6 +44,20 @@ from StringIO import StringIO
# root: if we are at the first directory of a ressource
#
def _str2time(cre):
""" Convert a string with time representation (from db) into time (float)
Note: a place to fix if datetime is used in db.
"""
if not cre:
return time.time()
frac = 0.0
if isinstance(cre, basestring) and '.' in cre:
fdot = cre.find('.')
frac = float(cre[fdot:])
cre = cre[:fdot]
return time.mktime(time.strptime(cre,'%Y-%m-%d %H:%M:%S')) + frac
def get_node_context(cr, uid, context):
return node_context(cr, uid, context)
@@ -255,19 +269,16 @@ class node_class(object):
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):
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)
return str(_str2time(self.write_date))
def _get_ttag(self,cr):
""" Get a unique tag for this type/id of object.
Must be overriden, so that each node is uniquely identified.
"""
print "node_class.get_ttag()",self
raise RuntimeError("get_etag stub()")
raise NotImplementedError("get_etag stub()")
def get_dav_props(self, cr):
""" If this class has special behaviour for GroupDAV etc, export
@@ -596,19 +607,6 @@ class node_dir(node_database):
fnode.set_data(cr, data, fil)
return fnode
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 'dir-%d' % self.dir_id