diff --git a/addons/document/directory_content.py b/addons/document/directory_content.py index a43b5730627..b82da1bce8a 100644 --- a/addons/document/directory_content.py +++ b/addons/document/directory_content.py @@ -67,7 +67,7 @@ class document_directory_content(osv.osv): 'include_name': lambda *args: 1, } - def _file_get(self,cr,node, nodename, content, context=None): + def _file_get(self, cr, node, nodename, content, context=None): """ return the nodes of a parent having a content The return value MUST be false or a list of node_class objects. """ diff --git a/addons/document/ftpserver/abstracted_fs.py b/addons/document/ftpserver/abstracted_fs.py index 0073b26b9f2..46ddba18128 100644 --- a/addons/document/ftpserver/abstracted_fs.py +++ b/addons/document/ftpserver/abstracted_fs.py @@ -307,8 +307,8 @@ class abstracted_fs: def open(self, node, mode): if not node: raise OSError(1, 'Operation not permited.') - # Reading operation - if node.type=='file': + # Reading operation + if node.type == 'file': cr = pooler.get_db(node.context.dbname).cursor() uid = node.context.uid if not self.isfile(node): @@ -321,13 +321,15 @@ class abstracted_fs: s.name = node cr.close() return s - elif node.type=='content': + elif node.type == 'content': uid = node.context.uid cr = pooler.get_db(node.context.dbname).cursor() pool = pooler.get_pool(node.context.dbname) res = getattr(pool.get('document.directory.content'), 'process_read')(cr, uid, node) - cr.close() - return res + cr.close() + s = StringIO.StringIO(res) + s.name = node + return s else: raise OSError(1, 'Operation not permited.') diff --git a/addons/document/ftpserver/ftpserver.py b/addons/document/ftpserver/ftpserver.py index 13c44287303..e265987ae32 100644 --- a/addons/document/ftpserver/ftpserver.py +++ b/addons/document/ftpserver/ftpserver.py @@ -2165,7 +2165,7 @@ class FTPHandler(asynchat.async_chat): datacr = self.fs.get_cr(line) file = self.fs.ftp2fs(line, datacr) line = self.fs.ftpnorm(line) - fd = self.run_as_current_user(self.fs.open, file, 'rb') + fd = self.run_as_current_user(self.fs.open, file, 'rb') except OSError, err: self.fs.close_cr(datacr) why = _strerror(err) diff --git a/addons/document/nodes.py b/addons/document/nodes.py index e6a614bf6aa..6216d4c3428 100644 --- a/addons/document/nodes.py +++ b/addons/document/nodes.py @@ -168,7 +168,9 @@ class node_dir(node_class): #todo: more info from dirr self.mimetype = 'application/x-directory' # 'httpd/unix-directory' - self.create_date = dirr.create_date + self.create_date = dirr.create_date + self.domain = dirr.domain + self.res_model = dirr.ressource_type_id and dirr.ressource_type_id.model or False # TODO: the write date should be MAX(file.write).. self.write_date = dirr.write_date or dirr.create_date self.content_length = 0 @@ -205,9 +207,9 @@ class node_dir(node_class): ctx = self.context.context.copy() ctx.update(self.dctx) where = [('directory_id','=',self.dir_id) ] - ids = cntobj.search(cr,uid,where,context=ctx) - for content in cntobj.browse(cr,uid,ids,context=ctx): - res3 = cntobj._file_get(cr,self,nodename,content) + ids = cntobj.search(cr, uid, where, context=ctx) + for content in cntobj.browse(cr, uid, ids, context=ctx): + res3 = cntobj._file_get(cr, self, nodename, content) if res3: res.extend(res3) @@ -312,7 +314,7 @@ class node_res_dir(node_class): # TODO: the write date should be MAX(file.write).. self.write_date = dirr.write_date or dirr.create_date self.content_length = 0 - self.res_model = dirr.ressource_type_id.model + self.res_model = dirr.ressource_type_id and dirr.ressource_type_id.model or False self.resm_id = dirr.ressource_id self.namefield = dirr.resource_field or 'name' self.displayname = dirr.name diff --git a/addons/document_ics/document.py b/addons/document_ics/document.py deleted file mode 100644 index bf32009f404..00000000000 --- a/addons/document_ics/document.py +++ /dev/null @@ -1,191 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from osv import osv, fields -from osv.orm import except_orm -import os -import StringIO -import base64 -import datetime -import time -import random -import tools - -ICS_TAGS = { - 'summary':'normal', - 'uid':'normal' , - 'dtstart':'date' , - 'dtend':'date' , - 'created':'date' , - 'dtstamp':'date' , - 'last-modified':'normal' , - 'url':'normal' , - 'attendee':'multiple', - 'location':'normal', - 'categories': 'normal', - 'description':'normal', - - # TODO: handle the 'duration' property -} - -class document_directory_ics_fields(osv.osv): - _name = 'document.directory.ics.fields' - _columns = { - 'field_id': fields.many2one('ir.model.fields', 'Open ERP Field', required=True), - 'name': fields.selection(map(lambda x: (x, x), ICS_TAGS.keys()), 'ICS Value', required=True), - 'content_id': fields.many2one('document.directory.content', 'Content', required=True, ondelete='cascade') - } -document_directory_ics_fields() - -class document_directory_content(osv.osv): - _inherit = 'document.directory.content' - _columns = { - 'ics_object_id': fields.many2one('ir.model', 'Object'), - 'ics_domain': fields.char('Domain', size=64), - 'ics_field_ids': fields.one2many('document.directory.ics.fields', 'content_id', 'Fields Mapping') - } - _defaults = { - 'ics_domain': lambda *args: '[]' - } - def process_write_ics(self, cr, uid, node, data, context={}): - import vobject - parsedCal = vobject.readOne(data) - fields = {} - fobj = self.pool.get('document.directory.content') - content = fobj.browse(cr, uid, node.content.id, context) - - idomain = {} - for d in eval(content.ics_domain): - idomain[d[0]]=d[2] - for n in content.ics_field_ids: - fields[n.name] = n.field_id.name - if 'uid' not in fields: - return True - for child in parsedCal.getChildren(): - result = {} - uuid = None - for event in child.getChildren(): - if event.name.lower()=='uid': - uuid = event.value - if event.name.lower() in fields: - if ICS_TAGS[event.name.lower()]=='normal': - result[fields[event.name.lower()]] = event.value.encode('utf8') - elif ICS_TAGS[event.name.lower()]=='date': - result[fields[event.name.lower()]] = event.value.strftime('%Y-%m-%d %H:%M:%S') - if not uuid: - continue - - fobj = self.pool.get(content.ics_object_id.model) - id = fobj.search(cr, uid, [(fields['uid'], '=', uuid.encode('utf8'))], context=context) - if id: - fobj.write(cr, uid, id, result, context=context) - else: - r = idomain.copy() - r.update(result) - fobj.create(cr, uid, r, context=context) - - return True - - def process_read_ics(self, cr, uid, node, context={}): - def ics_datetime(idate, short=False): - if short: - return datetime.date.fromtimestamp(time.mktime(time.strptime(idate, '%Y-%m-%d'))) - else: - return datetime.datetime.strptime(idate, '%Y-%m-%d %H:%M:%S') - - import vobject - obj_class = self.pool.get(node.content.ics_object_id.model) - # Can be improved to use context and active_id ! - domain = eval(node.content.ics_domain) - ids = obj_class.search(cr, uid, domain, context) - cal = vobject.iCalendar() - for obj in obj_class.browse(cr, uid, ids, context): - event = cal.add('vevent') - # Fix dtstamp et last-modified with create and write date on the object line - perm = obj_class.perm_read(cr, uid, [obj.id], context) - event.add('created').value = ics_datetime(time.strftime('%Y-%m-%d %H:%M:%S')) - event.add('dtstamp').value = ics_datetime(perm[0]['create_date'][:19]) - if perm[0]['write_date']: - event.add('last-modified').value = ics_datetime(perm[0]['write_date'][:19]) - for field in node.content.ics_field_ids: - value = getattr(obj, field.field_id.name) - value = value and tools.ustr(value) - if (not value) and field.name=='uid': - value = 'OpenERP-%s_%s@%s' % (node.content.ics_object_id.model, str(obj.id), cr.dbname,) - obj_class.write(cr, uid, [obj.id], {field.field_id.name: value}) - if ICS_TAGS[field.name]=='normal': - if type(value)==type(obj): - value=value.name - value = value or '' - event.add(field.name).value = value or '' - elif ICS_TAGS[field.name]=='date' and value: - if field.name == 'dtstart': - date_start = start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(value , "%Y-%m-%d %H:%M:%S"))) - if field.name == 'dtend' and isinstance(value, float): - value = (start_date + datetime.timedelta(hours=value)).strftime('%Y-%m-%d %H:%M:%S') - if len(value)==10: - value = ics_datetime(value, True) - else: - value = ics_datetime(value) - event.add(field.name).value = value - s= StringIO.StringIO(cal.serialize()) - s.name = node - cr.commit() - return s -document_directory_content() - -class crm_case(osv.osv): - _inherit = 'crm.case' - _columns = { - 'code': fields.char('Calendar Code', size=64), - 'date_deadline': fields.datetime('Deadline', help="Deadline Date is automatically computed from Start Date + Duration"), - } - - _defaults = { - 'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.case'), - } - - def copy(self, cr, uid, id, default=None, context=None): - """ - code field must be unique in ICS file - """ - if not default: default = {} - if not context: context = {} - default.update({'code': self.pool.get('ir.sequence').get(cr, uid, 'crm.case'), 'id': False}) - return super(crm_case, self).copy(cr, uid, id, default, context) - - def on_change_duration(self, cr, uid, id, date, duration): - if not date: - return {} - start_date = datetime.datetime.fromtimestamp(time.mktime(time.strptime(date, "%Y-%m-%d %H:%M:%S"))) - if duration >= 0 : - end = start_date + datetime.timedelta(hours=duration) - if duration < 0: - raise osv.except_osv(_('Warning !'), - _('You can not set negative Duration.')) - - res = {'value' : {'date_deadline' : end.strftime('%Y-%m-%d %H:%M:%S')}} - return res - -crm_case() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/document_ics/document_ics.py b/addons/document_ics/document_ics.py index caccf25e3ce..1fb8518050b 100644 --- a/addons/document_ics/document_ics.py +++ b/addons/document_ics/document_ics.py @@ -87,15 +87,16 @@ class document_directory_content(osv.osv): } def _file_get(self, cr, node, nodename, content, context=None): if not content.obj_iterate: - return super(document_directory_content, self)._file_get(cr,node,nodename,content) + return super(document_directory_content, self)._file_get(cr, node, nodename, content) else: - # print "iterate over ", content.object_id.model + if not content.object_id: + return False mod = self.pool.get(content.object_id.model) uid = node.context.uid fname_fld = content.fname_field or 'id' - where = [] + where = [] if node.domain: - where.append(node.domain) + where += eval(node.domain) if nodename: # Reverse-parse the nodename to deduce the clause: prefix = (content.prefix or '') @@ -107,7 +108,7 @@ class document_directory_content(osv.osv): tval = nodename[len(prefix):0 - len(suffix)] where.append((fname_fld,'=',tval)) # print "ics iterate clause:", where - resids = mod.search(cr,uid,where,context=context) + resids = mod.search(cr, uid, where, context=context) if not resids: return False @@ -244,13 +245,15 @@ class document_directory_content(osv.osv): return datetime.datetime.strptime(idate, '%Y-%m-%d %H:%M:%S') if node.extension != '.ics': - return super(document_directory_content).process_read(cr, uid, node, context) + return super(document_directory_content).process_read(cr, uid, node, context) import vobject ctx = (context or {}) ctx.update(node.context.context.copy()) ctx.update(node.dctx) content = self.browse(cr, uid, node.cnt_id, ctx) + if not content.object_id: + return super(document_directory_content).process_read(cr, uid, node, context) obj_class = self.pool.get(content.object_id.model) if content.ics_domain: @@ -261,7 +264,7 @@ class document_directory_content(osv.osv): domain.append(('id','=',node.act_id)) # print "process read clause:",domain ids = obj_class.search(cr, uid, domain, context=ctx) - cal = vobject.iCalendar() + cal = vobject.iCalendar() for obj in obj_class.browse(cr, uid, ids): event = cal.add('vevent') # Fix dtstamp et last-modified with create and write date on the object line