1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
23 from tools.translate import _
28 from document import nodes
31 class node_database(nodes.node_database):
32 def _child_get(self, cr, name=False, parent_id=False, domain=None):
33 dirobj = self.context._dirobj
34 uid = self.context.uid
35 ctx = self.context.context.copy()
39 domain2 = domain + [('calendar_collection','=', False)]
40 res = super(node_database, self)._child_get(cr, name=name, parent_id=parent_id, domain=domain2)
41 where = [('parent_id','=',parent_id)]
42 domain2 = domain + [('calendar_collection','=', True)]
44 where.append(('name','=',name))
48 where2 = where + [('type', '=', 'directory')]
49 ids = dirobj.search(cr, uid, where2, context=ctx)
50 for dirr in dirobj.browse(cr,uid,ids,context=ctx):
51 res.append(node_calendar_collection(dirr.name,self,self.context,dirr))
54 class node_calendar_collection(nodes.node_dir):
55 def get_dav_props(self, cr):
59 def get_dav_eprop(self,cr,ns,prop):
62 def _child_get(self, cr, name=False, parent_id=False, domain=None):
63 dirobj = self.context._dirobj
64 uid = self.context.uid
65 ctx = self.context.context.copy()
67 where = [('collection_id','=',self.dir_id)]
69 where.append(('name','=',name))
73 fil_obj = dirobj.pool.get('basic.calendar')
74 ids = fil_obj.search(cr,uid,where,context=ctx)
77 for fil in fil_obj.browse(cr,uid,ids,context=ctx):
78 res.append(node_calendar(fil.name,self,self.context,fil))
82 def get_etag(self, cr):
83 """ Get a tag, unique per object + modification.
85 see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
86 return self._get_ttag(cr) + ':' + self._get_wtag(cr)
88 def _get_wtag(self, cr):
89 """ Return the modification time as a unique, compact string """
91 wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S'))
92 else: wtime = time.time()
95 def _get_ttag(self, cr):
96 return 'calendar collection-%d' % self.dir_id
98 class node_calendar(nodes.node_class):
100 def __init__(self,path, parent, context, calendar):
101 super(node_calendar,self).__init__(path, parent,context)
102 self.calendar_id = calendar.id
103 self.mimetype = 'ics'
104 self.create_date = calendar.create_date
105 self.write_date = calendar.write_date or calendar.create_date
106 self.content_length = 0
107 self.displayname = calendar.name
109 def open(self, cr, mode=False):
110 uid = self.context.uid
111 if self.type in ('collection','database'):
113 fobj = self.context._dirobj.pool.get('basic.calendar').browse(cr, uid, self.calendar_id, context=self.context.context)
114 s = StringIO.StringIO(self.get_data(cr, fobj))
118 def get_dav_props(self, cr):
122 def get_dav_eprop(self,cr,ns,prop):
126 def get_data(self, cr, fil_obj = None):
127 uid = self.context.uid
128 calendar_obj = self.context._dirobj.pool.get('basic.calendar')
129 return calendar_obj.export_cal(cr, uid, [self.calendar_id])
131 def get_data_len(self, cr, fil_obj = None):
132 return self.content_length
134 def set_data(self, cr, data, fil_obj = None):
135 uid = self.context.uid
136 calendar_obj = self.context._dirobj.pool.get('basic.calendar')
137 return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
139 def _get_ttag(self,cr):
140 return 'calendar-%d' % self.calendar_id
144 def get_etag(self, cr):
145 """ Get a tag, unique per object + modification.
147 see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
148 return self._get_ttag(cr) + ':' + self._get_wtag(cr)
150 def _get_wtag(self, cr):
151 """ Return the modification time as a unique, compact string """
153 wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S'))
154 else: wtime = time.time()
156 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4