1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
31 from osv import osv, fields
32 from osv.orm import except_orm
46 'last-modified':'normal' ,
48 'attendee':'multiple',
50 'categories': 'normal',
51 'description':'normal'
54 class document_directory_ics_fields(osv.osv):
55 _name = 'document.directory.ics.fields'
57 'field_id': fields.many2one('ir.model.fields', 'Open ERP Field', required=True),
58 'name': fields.selection(map(lambda x: (x,x), ICS_TAGS.keys()),'ICS Value', required=True),
59 'content_id': fields.many2one('document.directory.content', 'Content', required=True, ondelete='cascade')
61 document_directory_ics_fields()
63 class document_directory_content(osv.osv):
64 _inherit = 'document.directory.content'
66 'ics_object_id': fields.many2one('ir.model', 'Object'),
67 'ics_domain': fields.char('Domain', size=64),
68 'ics_field_ids': fields.one2many('document.directory.ics.fields', 'content_id', 'Fields Mapping')
71 'ics_domain': lambda *args: '[]'
73 def process_read_ics(self, cr, uid, node, context={}):
76 obj_class = self.pool.get(node.content.ics_object_id.model)
77 # Can be improved to use context and active_id !
78 domain = eval(node.content.ics_domain)
79 ids = obj_class.search(cr, uid, domain, context)
80 cal = vobject.iCalendar()
81 for obj in obj_class.browse(cr, uid, ids, context):
82 event = cal.add('vevent')
83 for field in node.content.ics_field_ids:
84 if ICS_TAGS[field.name]=='normal':
85 value = getattr(obj, field.field_id.name) or ''
86 event.add(field.name).value = value
87 elif ICS_TAGS[field.name]=='date':
88 dt = getattr(obj, field.field_id.name) or time.strftime('%Y-%m-%d %H:%M:%S')
90 if field.name=='dtend':
94 value = datetime.datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
95 event.add(field.name).value = value
96 s= StringIO.StringIO(cal.serialize())
99 document_directory_content()