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 _
30 class node_calendar(object):
31 def __init__(self, path, context, calendar):
33 self.context = context
34 self.calendar_id = calendar.id
36 self.create_date = calendar.create_date
37 self.write_date = calendar.write_date or calendar.create_date
38 self.content_length = 0
39 self.displayname = calendar.name
42 def get_data(self, cr, uid):
43 calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar')
44 return calendar_obj.export_cal(cr, uid, [self.calendar_id])
46 def get_data_len(self, cr):
47 return self.content_length
49 def set_data(self, cr, uid, data):
50 calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar')
51 return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
53 def get_etag(self, cr):
54 """ Get a tag, unique per object + modification.
56 see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
57 return self._get_ttag(cr) + ':' + self._get_wtag(cr)
59 def _get_wtag(self, cr):
60 """ Return the modification time as a unique, compact string """
62 wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S'))
63 else: wtime = time.time()
66 def _get_ttag(self, cr):
67 return 'calendar-%d' % self.calendar_id
70 class Calendar(osv.osv):
71 _inherit = 'basic.calendar'
73 def get_calendar_object(self, cr, uid, uri, context=None):
78 name, file_type = tuple(uri[0].split('.'))
79 res = self.name_search(cr, uid, name)
82 calendar_id, calendar_name = res[0]
83 calendar = self.browse(cr, uid, calendar_id)
84 return node_calendar(uri, context, calendar)
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4