[IMP] caldav
bzr revid: hmo@tinyerp.com-20100413140404-bku8u3agsv79evyx
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
import calendar
|
||||
import caldav_fs
|
||||
import caldav_server
|
||||
import wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -19,7 +19,51 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from document_webdav import dav_fs
|
||||
from document_webdav.cache import memoize
|
||||
class openerp_dav_handler(dav_fs.openerp_dav_handler):
|
||||
PROPS = {'DAV:': dav_fs.openerp_dav_handler.PROPS['DAV:'] +
|
||||
('owner',),
|
||||
'http://calendarserver.org/ns/': ('getctag')}
|
||||
|
||||
M_NS = { "DAV:" : dav_fs.openerp_dav_handler.M_NS['DAV:'],
|
||||
"http://calendarserver.org/ns/" : '_get_dav'}
|
||||
|
||||
@memoize(dav_fs.CACHE_SIZE)
|
||||
def _get_dav_getctag(self,uri):
|
||||
print """ return the CTag of an object """
|
||||
self.parent.log_message('get ctag: %s' % uri)
|
||||
if uri[-1]=='/':uri=uri[:-1]
|
||||
result = 0
|
||||
cr, uid, pool, dbname, uri2 = self.get_cr(uri)
|
||||
if not dbname:
|
||||
cr.close()
|
||||
return '0'
|
||||
node = self.uri2object(cr, uid, pool, uri2)
|
||||
if not node:
|
||||
cr.close()
|
||||
raise DAV_NotFound(uri2)
|
||||
result = node.get_ctag(cr)
|
||||
cr.close()
|
||||
return str(result)
|
||||
|
||||
@memoize(dav_fs.CACHE_SIZE)
|
||||
def _get_dav_owner(self,uri):
|
||||
print """ return the Owner of an object """
|
||||
self.parent.log_message('get ctag: %s' % uri)
|
||||
if uri[-1]=='/':uri=uri[:-1]
|
||||
result = 0
|
||||
cr, uid, pool, dbname, uri2 = self.get_cr(uri)
|
||||
if not dbname:
|
||||
cr.close()
|
||||
return '0'
|
||||
node = self.uri2object(cr, uid, pool, uri2)
|
||||
if not node:
|
||||
cr.close()
|
||||
raise DAV_NotFound(uri2)
|
||||
result = node.get_owner(cr)
|
||||
cr.close()
|
||||
return str(result)
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -78,6 +78,9 @@ class node_calendar_collection(nodes.node_dir):
|
||||
res.append(node_calendar(fil.name,self,self.context,fil))
|
||||
return res
|
||||
|
||||
def get_owner(self, cr):
|
||||
return False
|
||||
|
||||
|
||||
def get_etag(self, cr):
|
||||
""" Get a tag, unique per object + modification.
|
||||
@@ -94,6 +97,10 @@ class node_calendar_collection(nodes.node_dir):
|
||||
|
||||
def _get_ttag(self, cr):
|
||||
return 'calendar collection-%d' % self.dir_id
|
||||
|
||||
def get_ctag(self, cr):
|
||||
return self.get_etag(cr)
|
||||
|
||||
|
||||
class node_calendar(nodes.node_class):
|
||||
our_type = 'file'
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from service import http_server
|
||||
from document_webdav import webdav_server
|
||||
import tools
|
||||
from caldav_fs import openerp_dav_handler
|
||||
from tools.config import config
|
||||
|
||||
class DAVHandler(webdav_server.DAVHandler):
|
||||
def setup(self):
|
||||
davpath = '/'+config.get_misc('webdav','vdir','webdav')
|
||||
self.baseuri = "http://%s:%d/"% (self.server.server_name,self.server.server_port)
|
||||
self.IFACE_CLASS = openerp_dav_handler(self, self.verbose)
|
||||
|
||||
|
||||
|
||||
handler = webdav_server.handler
|
||||
if handler:
|
||||
handler = DAVHandler
|
||||
handler.debug = config.get_misc('webdav','debug',True)
|
||||
handler._config = webdav_server.conf
|
||||
|
||||
if http_server.httpd and handler:
|
||||
for vdir in http_server.httpd.server.vdirs:
|
||||
print vdir.handler , webdav_server.DAVHandler
|
||||
if vdir.handler == webdav_server.DAVHandler:
|
||||
vdir.handler = handler
|
||||
if http_server.httpsd and handler:
|
||||
for vdir in http_server.httpsd.server.vdirs:
|
||||
if vdir.handler == webdav_server.DAVHandler:
|
||||
vdir.handler = handler
|
||||
@@ -289,6 +289,19 @@ class node_dir(node_database):
|
||||
fnode = node_file(path,self,self.context,fil)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user