From 6a94de909b027dc1259b3fc8b4d1cd16d1d2c467 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Tue, 13 Apr 2010 16:33:20 +0530 Subject: [PATCH] [REF+IMP] document bzr revid: hmo@tinyerp.com-20100413110320-9x1fy7l432sinxvd --- addons/caldav/caldav_node.py | 139 +++++++++---- addons/caldav/caldav_view.xml | 3 +- addons/caldav/calendar.py | 22 +- addons/document/document_directory.py | 48 +---- addons/document/document_view.xml | 3 +- addons/document/nodes.py | 192 +++++++++--------- .../document_ftp/ftpserver/abstracted_fs.py | 35 +--- addons/document_ics/document_demo.xml | 4 +- addons/document_ics/document_ics.py | 34 +--- addons/document_ics/document_view.xml | 28 +-- 10 files changed, 253 insertions(+), 255 deletions(-) diff --git a/addons/caldav/caldav_node.py b/addons/caldav/caldav_node.py index fd17b52f478..6ecfcd30027 100644 --- a/addons/caldav/caldav_node.py +++ b/addons/caldav/caldav_node.py @@ -25,31 +25,60 @@ import pooler import tools import time import base64 +from document import nodes +import StringIO +class node_database(nodes.node_database): + def _child_get(self, cr, name=False, parent_id=False, domain=None): + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + if not domain: + domain = [] + domain2 = domain + [('calendar_collection','=', False)] + res = super(node_database, self)._child_get(cr, name=name, parent_id=parent_id, domain=domain2) + where = [('parent_id','=',parent_id)] + domain2 = domain + [('calendar_collection','=', True)] + if name: + where.append(('name','=',name)) + if domain2: + where += domain2 -class node_calendar(object): - def __init__(self, path, context, calendar): - self.path = path - self.context = context - self.calendar_id = calendar.id - self.mimetype = 'ics' - self.create_date = calendar.create_date - self.write_date = calendar.write_date or calendar.create_date - self.content_length = 0 - self.displayname = calendar.name + where2 = where + [('type', '=', 'directory')] + ids = dirobj.search(cr, uid, where2, context=ctx) + for dirr in dirobj.browse(cr,uid,ids,context=ctx): + res.append(node_calendar_collection(dirr.name,self,self.context,dirr)) + return res +class node_calendar_collection(nodes.node_dir): + def get_dav_props(self, cr): + res = {} + return res - def get_data(self, cr, uid): - calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar') - return calendar_obj.export_cal(cr, uid, [self.calendar_id]) + def get_dav_eprop(self,cr,ns,prop): + return None - def get_data_len(self, cr): - return self.content_length - - def set_data(self, cr, uid, data): - calendar_obj = pooler.get_pool(cr.dbname).get('basic.calendar') - return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id) + def _child_get(self, cr, name=False, parent_id=False, domain=None): + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + where = [('collection_id','=',self.dir_id)] + if name: + where.append(('name','=',name)) + if not domain: + domain = [] + + fil_obj = dirobj.pool.get('basic.calendar') + ids = fil_obj.search(cr,uid,where,context=ctx) + res = [] + if ids: + for fil in fil_obj.browse(cr,uid,ids,context=ctx): + res.append(node_calendar(fil.name,self,self.context,fil)) + return res + def get_etag(self, cr): """ Get a tag, unique per object + modification. @@ -64,24 +93,64 @@ class node_calendar(object): return str(wtime) def _get_ttag(self, cr): + return 'calendar collection-%d' % self.dir_id + +class node_calendar(nodes.node_class): + our_type = 'file' + def __init__(self,path, parent, context, calendar): + super(node_calendar,self).__init__(path, parent,context) + self.calendar_id = calendar.id + self.mimetype = 'ics' + self.create_date = calendar.create_date + self.write_date = calendar.write_date or calendar.create_date + self.content_length = 0 + self.displayname = calendar.name + + def open(self, cr, mode=False): + uid = self.context.uid + if self.type in ('collection','database'): + return False + fobj = self.context._dirobj.pool.get('basic.calendar').browse(cr, uid, self.calendar_id, context=self.context.context) + s = StringIO.StringIO(self.get_data(cr, fobj)) + s.name = self + return s + + def get_dav_props(self, cr): + res = {} + return res + + def get_dav_eprop(self,cr,ns,prop): + return None + + + def get_data(self, cr, fil_obj = None): + uid = self.context.uid + calendar_obj = self.context._dirobj.pool.get('basic.calendar') + return calendar_obj.export_cal(cr, uid, [self.calendar_id]) + + def get_data_len(self, cr, fil_obj = None): + return self.content_length + + def set_data(self, cr, data, fil_obj = None): + uid = self.context.uid + calendar_obj = self.context._dirobj.pool.get('basic.calendar') + return calendar_obj.import_cal(cr, uid, base64.encodestring(data), self.calendar_id) + + def _get_ttag(self,cr): return 'calendar-%d' % self.calendar_id + -class Calendar(osv.osv): - _inherit = 'basic.calendar' + def get_etag(self, cr): + """ Get a tag, unique per object + modification. - def get_calendar_object(self, cr, uid, uri, context=None): - if not uri: - return None - if len(uri) > 1: - return None - name, file_type = tuple(uri[0].split('.')) - res = self.name_search(cr, uid, name) - if not res: - return None - calendar_id, calendar_name = res[0] - calendar = self.browse(cr, uid, calendar_id) - return node_calendar(uri, context, calendar) -Calendar() + see. http://tools.ietf.org/html/rfc2616#section-13.3.3 """ + return self._get_ttag(cr) + ':' + self._get_wtag(cr) -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4 \ No newline at end of file + def _get_wtag(self, cr): + """ Return the modification time as a unique, compact string """ + if self.write_date: + wtime = time.mktime(time.strptime(self.write_date, '%Y-%m-%d %H:%M:%S')) + else: wtime = time.time() + return str(wtime) +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4 diff --git a/addons/caldav/caldav_view.xml b/addons/caldav/caldav_view.xml index 152baf6c876..c982d695fac 100644 --- a/addons/caldav/caldav_view.xml +++ b/addons/caldav/caldav_view.xml @@ -17,8 +17,7 @@ Calendar Collections : Tree document.directory - tree - child_ids + tree diff --git a/addons/caldav/calendar.py b/addons/caldav/calendar.py index bcf7eb58d76..6ccd5989d5c 100644 --- a/addons/caldav/calendar.py +++ b/addons/caldav/calendar.py @@ -31,7 +31,7 @@ import pytz import re import tools import time - +import caldav_node try: import vobject @@ -418,7 +418,12 @@ class calendar_collection(osv.osv): } _default = { 'calendar_collection' : False, - } + } + def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext): + """ try to locate the node in uri, + Return a tuple (node_dir, remaining_path) + """ + return (caldav_node.node_database(context=ncontext), uri) calendar_collection() @@ -449,6 +454,19 @@ class Calendar(CalDAV, osv.osv): 'write_date': fields.datetime('Modifided Date'), } + def get_calendar_object(self, cr, uid, uri, context=None): + if not uri: + return None + if len(uri) > 1: + return None + name, file_type = tuple(uri[0].split('.')) + res = self.name_search(cr, uid, name) + if not res: + return None + calendar_id, calendar_name = res[0] + calendar = self.browse(cr, uid, calendar_id) + return node_calendar(uri, context, calendar) + def export_cal(self, cr, uid, ids, vobj='vevent', context={}): """ Export Calendar @param self: The object pointer diff --git a/addons/document/document_directory.py b/addons/document/document_directory.py index 270f2d9353f..b64ee8df9e2 100644 --- a/addons/document/document_directory.py +++ b/addons/document/document_directory.py @@ -93,8 +93,7 @@ class document_directory(osv.osv): 'user_id': lambda self,cr,uid,ctx: uid, 'domain': lambda self,cr,uid,ctx: '[]', 'type': lambda *args: 'directory', - 'ressource_id': lambda *a: 0, - 'parent_id': _get_root_directory, + 'ressource_id': lambda *a: 0, 'storage_id': _get_def_storage, } _sql_constraints = [ @@ -198,52 +197,11 @@ class document_directory(osv.osv): raise - def _locate_child(self, cr,uid, root_id, uri,nparent, ncontext): + def _locate_child(self, cr, uid, root_id, uri,nparent, ncontext): """ try to locate the node in uri, Return a tuple (node_dir, remaining_path) """ - did = root_id - duri = uri - path = [] - context = ncontext.context - while len(duri): - nid = self.search(cr,uid,[('parent_id','=',did),('name','=',duri[0]),('type','=','directory')], context=context) - if not nid: - break - if len(nid)>1: - print "Duplicate dir? p= %d, n=\"%s\"" %(did,duri[0]) - path.append(duri[0]) - duri = duri[1:] - did = nid[0] - root_node = did and self.browse(cr,uid,did, context) or False - return (nodes.node_dir(path, nparent,ncontext, root_node), duri) - - - nid = self.search(cr,uid,[('parent_id','=',did),('name','=',duri[0]),('type','=','ressource')], context=context) - if nid: - if len(nid)>1: - print "Duplicate dir? p= %d, n=\"%s\"" %(did,duri[0]) - path.append(duri[0]) - duri = duri[1:] - did = nid[0] - return nodes.node_res_dir(path, nparent,ncontext,self.browse(cr,uid,did, context)) - - # Here, we must find the appropriate non-dir child.. - # Chech for files: - fil_obj = self.pool.get('ir.attachment') - nid = fil_obj.search(cr,uid,[('parent_id','=',did),('name','=',duri[0])],context=context) - if nid: - if len(duri)>1: - # cannot treat child as a dir - return None - if len(nid)>1: - print "Duplicate file?",did,duri[0] - path.append(duri[0]) - return nodes.node_file(path,nparent,ncontext,fil_obj.browse(cr,uid,nid[0],context)) - - print "nothing found:",did, duri - #still, nothing found - return None + return (nodes.node_database(context=ncontext), uri) def old_code(): if not uri: diff --git a/addons/document/document_view.xml b/addons/document/document_view.xml index 252b9b36a26..3cc3d139b13 100644 --- a/addons/document/document_view.xml +++ b/addons/document/document_view.xml @@ -118,8 +118,7 @@ document.directory document.directory - tree - child_ids + tree diff --git a/addons/document/nodes.py b/addons/document/nodes.py index a8553426d3f..4957078c442 100644 --- a/addons/document/nodes.py +++ b/addons/document/nodes.py @@ -20,7 +20,7 @@ ############################################################################## import base64 - +import StringIO from osv import osv, fields from osv.orm import except_orm import urlparse @@ -69,14 +69,6 @@ class node_context(object): return ndir -class node_database(): - """ A node representing the database directory - Useless? - """ - def __init__(self,ncontext): - self.nctx = ncontext - - class node_class(object): @@ -163,7 +155,76 @@ class node_class(object): def get_dav_eprop(self,cr,ns,prop): return None -class node_dir(node_class): +class node_database(node_class): + """ A node representing the database directory + + """ + our_type = 'database' + def __init__(self, path=[], parent=False, context=None): + super(node_database,self).__init__(path, parent, context) + + def children(self,cr): + res = self._child_get(cr) + self._file_get(cr) + return res + + def child(self, cr, name): + res = self._child_get(cr,name) + if res: + return res[0] + res = self._file_get(cr,name) + if res: + return res[0] + return None + + def _child_get(self, cr, name=False, parent_id=False, domain=None): + dirobj = self.context._dirobj + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + where = [('parent_id','=',parent_id)] + if name: + where.append(('name','=',name)) + if not domain: + domain = [] + + where2 = where + domain + [('type', '=', 'directory')] + ids = dirobj.search(cr, uid, where2, context=ctx) + res = [] + for dirr in dirobj.browse(cr,uid,ids,context=ctx): + res.append(node_dir(dirr.name,self,self.context,dirr)) + + where2 = where + domain + [('type', '=', 'ressource'), ('ressource_parent_type_id','=',False)] + ids = dirobj.search(cr, uid, where2, context=ctx) + for dirr in dirobj.browse(cr,uid,ids,context=ctx): + res.append(node_res_dir(dirr.name,self,self.context,dirr)) + + fil_obj = dirobj.pool.get('ir.attachment') + ids = fil_obj.search(cr,uid,where,context=ctx) + if ids: + for fil in fil_obj.browse(cr,uid,ids,context=ctx): + res.append(node_file(fil.name,self,self.context,fil)) + return res + + def _file_get(self,cr, nodename=False, directory_id=False): + res = [] + cntobj = self.context._dirobj.pool.get('document.directory.content') + uid = self.context.uid + ctx = self.context.context.copy() + ctx.update(self.dctx) + where = [('directory_id','=',directory_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) + if res3: + res.extend(res3) + + return res + + def _get_ttag(self,cr): + return 'db-%s' % cr.dbname + + +class node_dir(node_database): our_type = 'collection' def __init__(self,path, parent, context, dirr, dctx=None): super(node_dir,self).__init__(path, parent,context) @@ -192,93 +253,20 @@ class node_dir(node_class): print e pass - def children(self,cr): - res = self._child_get(cr) + self._file_get(cr) - return res - + def get_data(self,cr): return '' - def child(self,cr, name): - res = self._child_get(cr,name) - if res: - return res[0] - res = self._file_get(cr,name) - if res: - return res[0] - return None + def _file_get(self,cr, nodename=False): - res = [] - cntobj = self.context._dirobj.pool.get('document.directory.content') - uid = self.context.uid - 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) - if res3: - res.extend(res3) + return super(node_dir,self)._file_get(cr, nodename, self.dir_id) - return res - - def get_dav_props(self, cr): - res = {} - cntobj = self.context._dirobj.pool.get('document.directory.content') - uid = self.context.uid - 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): - if content.extension == '.ics': # FIXME: call the content class! - res['http://groupdav.org/'] = ('resourcetype',) - break - return res - - def get_dav_eprop(self,cr,ns,prop): - if ns != 'http://groupdav.org/' or prop != 'resourcetype': - print "Who asked for %s:%s?" % (ns,prop) - return None - res = {} - cntobj = self.context._dirobj.pool.get('document.directory.content') - uid = self.context.uid - 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): - if content.extension == '.ics': # FIXME: call the content class! - return ('vevent-collection','http://groupdav.org/') - return None - - def _child_get(self,cr,name = None): - dirobj = self.context._dirobj - uid = self.context.uid - ctx = self.context.context.copy() - ctx.update(self.dctx) - where = [('parent_id','=',self.dir_id) ] - if name: - where.append(('name','=',name)) - - ids = dirobj.search(cr, uid, where + [('ressource_parent_type_id','=',False)],context=ctx) - res = [] - if ids: - for dirr in dirobj.browse(cr,uid,ids,context=ctx): - if dirr.type == 'directory': - res.append(node_dir(dirr.name,self,self.context,dirr)) - elif dirr.type == 'ressource': - res.append(node_res_dir(dirr.name,self,self.context,dirr)) - - fil_obj=dirobj.pool.get('ir.attachment') - #where2 = where # + [('res_model', '=', None)] - ids = fil_obj.search(cr,uid,where,context=ctx) - if ids: - for fil in fil_obj.browse(cr,uid,ids,context=ctx): - res.append(node_file(fil.name,self,self.context,fil)) - return res + + def _child_get(self, cr, name = None): + return super(node_dir,self)._child_get(cr, name, self.dir_id) + def create_child(self,cr,path,data): """ API function to create a child file object and node @@ -601,7 +589,19 @@ class node_file(node_class): if fil.parent_id: self.storage_id = fil.parent_id.storage_id.id else: - self.storage_id = None + self.storage_id = None + + def open(self, cr, mode=False): + uid = self.context.uid + if self.type in ('collection','database'): + return False + fobj = self.context._dirobj.pool.get('ir.attachment').browse(cr, uid, self.file_id, context=self.context.context) + if fobj.store_method and fobj.store_method== 'fs' : + s = StringIO.StringIO(self.get_data(cr, fobj)) + else: + s = StringIO.StringIO(base64.decodestring(fobj.db_datas or '')) + s.name = self + return s def fix_ppath(self, cr, fbro): """Sometimes we may init this w/o path, parent. @@ -687,6 +687,16 @@ class node_content(node_class): if dctx: self.dctx.update(dctx) self.act_id = act_id + + def open(self, cr, mode=False): + uid = self.context.uid + if self.type in ('collection','database'): + return False + pool = self.context._dirobj.pool + res = getattr(pool.get('document.directory.content'), 'process_read')(cr, uid, self) + res = StringIO.StringIO(res) + res.name = self + return res def fill_fields(self,cr,dctx = None): """ Try to read the object and fill missing fields, like mimetype, diff --git a/addons/document_ftp/ftpserver/abstracted_fs.py b/addons/document_ftp/ftpserver/abstracted_fs.py index 0ffa8eb80f2..54b2cb9830f 100644 --- a/addons/document_ftp/ftpserver/abstracted_fs.py +++ b/addons/document_ftp/ftpserver/abstracted_fs.py @@ -309,31 +309,18 @@ class abstracted_fs: def open(self, node, mode): if not node: raise OSError(1, 'Operation not permited.') - # Reading operation - if node.type == 'file': - cr = pooler.get_db(node.context.dbname).cursor() - uid = node.context.uid - if not self.isfile(node): - raise OSError(1, 'Operation not permited.') - fobj = node.context._dirobj.pool.get('ir.attachment').browse(cr, uid, node.file_id, context=node.context.context) - if fobj.store_method and fobj.store_method== 'fs' : - s = StringIO.StringIO(node.get_data(cr, fobj)) - else: - s = StringIO.StringIO(base64.decodestring(fobj.db_datas or '')) - s.name = node - cr.close() - return s - 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) - res = StringIO.StringIO(res) - res.name = node - cr.close() - return res - else: + # Reading operation + cr = pooler.get_db(node.context.dbname).cursor() + res = False + #try: + if node.type not in ('collection','database'): + res = node.open(cr, mode) + #except: + # pass + cr.close() + if not res: raise OSError(1, 'Operation not permited.') + return res # ok, but need test more diff --git a/addons/document_ics/document_demo.xml b/addons/document_ics/document_demo.xml index a4c892340de..06c72022fe7 100644 --- a/addons/document_ics/document_demo.xml +++ b/addons/document_ics/document_demo.xml @@ -7,14 +7,14 @@ shcal - + Calendars Calendars meetings - + .ics diff --git a/addons/document_ics/document_ics.py b/addons/document_ics/document_ics.py index 9056b3250b4..00f8927eb18 100644 --- a/addons/document_ics/document_ics.py +++ b/addons/document_ics/document_ics.py @@ -332,8 +332,8 @@ class document_directory_content(osv.osv): return s document_directory_content() -class crm_case(osv.osv): - _inherit = 'crm.case' +class crm_meeting(osv.osv): + _inherit = 'crm.meeting' _columns = { 'code': fields.char('Calendar Code', size=64), 'date_deadline': fields.datetime('Deadline', help="Deadline Date is automatically\ @@ -341,7 +341,7 @@ class crm_case(osv.osv): } _defaults = { - 'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.case'), + 'code': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'crm.meeting'), } def copy(self, cr, uid, id, default=None, context=None): @@ -356,32 +356,10 @@ class crm_case(osv.osv): 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) + default.update({'code': self.pool.get('ir.sequence').get(cr, uid, 'crm.meeting'), 'id': False}) + return super(crm_meeting, self).copy(cr, uid, id, default, context) - def on_change_duration(self, cr, uid, id, date, duration): - """ Change Duration - @param self: The object pointer - @param cr: the current row, from the database cursor, - @param uid: the current user’s ID for security checks, - @param id: crm case's ID, - @param date: Pass the Date, - @param duration: Pass the 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() +crm_meeting() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/document_ics/document_view.xml b/addons/document_ics/document_view.xml index ac99f3723db..0cbfb6f81e2 100644 --- a/addons/document_ics/document_view.xml +++ b/addons/document_ics/document_view.xml @@ -39,36 +39,16 @@ - - crm.case.code.form - crm.case + + crm.meeting.code.form + crm.meeting form - + - - - - - crm.case.inherit.form1 - crm.case - form - - - - - - - - -