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 _
29 class node_calendar(object):
30 def __init__(self, path, context, calendar):
32 self.context = context
33 self.calendar_id = calendar.id
35 self.create_date = calendar.create_date
36 self.write_date = calendar.write_date or calendar.create_date
37 self.content_length = 0
38 self.displayname = calendar.name
41 def get_data(self, cr, uid):
42 calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar')
43 return calendar_obj.export_cal(cr, uid, [self.calendar_id])
45 def get_data_len(self, cr):
46 return self.content_length
48 def set_data(self, cr, uid, data):
49 calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar')
50 return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id)
52 def get_etag(self,cr):
53 """ Get a tag, unique per object + modification.
55 see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """
56 return self._get_ttag(cr) + ':' + self._get_wtag(cr)
58 def _get_wtag(self,cr):
59 """ Return the modification time as a unique, compact string """
61 wtime = time.mktime(time.strptime(self.write_date,'%Y-%m-%d %H:%M:%S'))
62 else: wtime = time.time()
65 def _get_ttag(self,cr):
66 return 'calendar-%d' % self.calendar_id
68 class Calendar(osv.osv):
69 _inherit = 'basic.calendar'
71 def get_calendar_object(self, cr, uid, uri, context=None):
76 name, file_type = tuple(uri[0].split('.'))
77 res = self.name_search(cr, uid, name)
80 calendar_id, calendar_name = res[0]
81 calendar = self.browse(cr, uid, calendar_id)
82 return node_calendar(uri, context, calendar)