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))
81 def get_owner(self, cr):
85 def get_etag(self, cr):
86 """ Get a tag, unique per object + modification.
88 see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
89 return self._get_ttag(cr) + ':' + self._get_wtag(cr)
91 def _get_wtag(self, cr):
92 """ Return the modification time as a unique, compact string """
94 wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S'))
95 else: wtime = time.time()
98 def _get_ttag(self, cr):
99 return 'calendar collection-%d' % self.dir_id
101 def get_ctag(self, cr):
102 return self.get_etag(cr)
105 class node_calendar(nodes.node_class):
107 def __init__(self,path, parent, context, calendar):
108 super(node_calendar,self).__init__(path, parent,context)
109 self.calendar_id = calendar.id
110 self.mimetype = 'ics'
111 self.create_date = calendar.create_date
112 self.write_date = calendar.write_date or calendar.create_date
113 self.content_length = 0
114 self.displayname = calendar.name
116 def open(self, cr, mode=False):
117 uid = self.context.uid
118 if self.type in ('collection','database'):
120 fobj = self.context._dirobj.pool.get('basic.calendar').browse(cr, uid, self.calendar_id, context=self.context.context)
121 s = StringIO.StringIO(self.get_data(cr, fobj))
125 def get_dav_props(self, cr):
129 def get_dav_eprop(self,cr,ns,prop):
133 def get_data(self, cr, fil_obj = None):
134 uid = self.context.uid
135 calendar_obj = self.context._dirobj.pool.get('basic.calendar')
136 return calendar_obj.export_cal(cr, uid, [self.calendar_id])
138 def get_data_len(self, cr, fil_obj = None):
139 return self.content_length
141 def set_data(self, cr, data, fil_obj = None):
142 uid = self.context.uid
143 calendar_obj = self.context._dirobj.pool.get('basic.calendar')
144 return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
146 def _get_ttag(self,cr):
147 return 'calendar-%d' % self.calendar_id
151 def get_etag(self, cr):
152 """ Get a tag, unique per object + modification.
154 see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
155 return self._get_ttag(cr) + ':' + self._get_wtag(cr)
157 def _get_wtag(self, cr):
158 """ Return the modification time as a unique, compact string """
160 wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S'))
161 else: wtime = time.time()
163 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4