Doc Webdav, caldav: get the create/write dates w. perm_read(). convert.
create_date, write_date may not be specified as object fields, so we cannot always call them. Use the perm_read() instead (which works for all objects). However, the datetime returned may have fractional secs, in which case a better conversion function shall be used. bzr revid: p_christ@hol.gr-20100729133937-fslzb5xba2pq5grj
This commit is contained in:
parent
08ad3c0993
commit
6987e89efe
|
@ -28,6 +28,18 @@ 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
|
||||
|
@ -103,10 +115,7 @@ class node_calendar_collection(nodes.node_dir):
|
|||
|
||||
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):
|
||||
return 'calendar collection-%d' % self.dir_id
|
||||
|
@ -277,10 +286,7 @@ class node_calendar(nodes.node_class):
|
|||
|
||||
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 rmcol(self, cr):
|
||||
return False
|
||||
|
@ -311,8 +317,9 @@ class res_node_calendar(nodes.node_class):
|
|||
self.calendar_id = hasattr(parent, 'calendar_id') and parent.calendar_id or False
|
||||
if res_obj:
|
||||
if not self.calendar_id: self.calendar_id = res_obj.id
|
||||
self.create_date = res_obj.create_date
|
||||
self.write_date = res_obj.write_date or res_obj.create_date
|
||||
pr = res_obj.perm_read()[0]
|
||||
self.create_date = pr.get('create_date')
|
||||
self.write_date = pr.get('write_date') or pr.get('create_date')
|
||||
self.displayname = res_obj.name
|
||||
|
||||
self.content_length = 0
|
||||
|
@ -441,9 +448,6 @@ class res_node_calendar(nodes.node_class):
|
|||
|
||||
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))
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4
|
||||
|
|
|
@ -59,6 +59,19 @@ class DAV_NotFound2(DAV_NotFound):
|
|||
args = (path, )
|
||||
DAV_NotFound.__init__(self, *args)
|
||||
|
||||
|
||||
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 openerp_dav_handler(dav_interface):
|
||||
"""
|
||||
This class models a OpenERP interface for the DAV server
|
||||
|
@ -420,18 +433,14 @@ class openerp_dav_handler(dav_interface):
|
|||
@memoize(CACHE_SIZE)
|
||||
def get_lastmodified(self, uri):
|
||||
""" return the last modified date of the object """
|
||||
today = time.time()
|
||||
cr, uid, pool, dbname, uri2 = self.get_cr(uri)
|
||||
if not dbname:
|
||||
return today
|
||||
return time.time()
|
||||
try:
|
||||
node = self.uri2object(cr, uid, pool, uri2)
|
||||
if not node:
|
||||
raise DAV_NotFound2(uri2)
|
||||
if node.write_date:
|
||||
return time.mktime(time.strptime(node.write_date,'%Y-%m-%d %H:%M:%S'))
|
||||
else:
|
||||
return today
|
||||
return _str2time(node.write_date)
|
||||
finally:
|
||||
if cr: cr.close()
|
||||
|
||||
|
@ -456,11 +465,8 @@ class openerp_dav_handler(dav_interface):
|
|||
node = self.uri2object(cr, uid, pool, uri2)
|
||||
if not node:
|
||||
raise DAV_NotFound2(uri2)
|
||||
if node.create_date:
|
||||
result = time.mktime(time.strptime(node.create_date,'%Y-%m-%d %H:%M:%S'))
|
||||
else:
|
||||
result = time.time()
|
||||
return result
|
||||
|
||||
return _str2time(node.create_date)
|
||||
finally:
|
||||
if cr: cr.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue