From 12fcd1be2f1a891b7fe099ad0044e68c45280907 Mon Sep 17 00:00:00 2001 From: "uco (OpenERP)" Date: Fri, 19 Nov 2010 19:18:01 +0530 Subject: [IMP] : Added context=None on methods used for _constraints and replaced context={} with context=None. bzr revid: uco@tinyerp.com-20101119134801-974ev29j4tu46pq2 --- addons/document/document.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index e3d810668b4..0ccd0ec51ec 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -38,7 +38,9 @@ class document_file(osv.osv): def _get_filestore(self, cr): return os.path.join(DMS_ROOT_PATH, cr.dbname) - def _data_get(self, cr, uid, ids, name, arg, context): + def _data_get(self, cr, uid, ids, name, arg, context=None): + if not context: + context = {} fbrl = self.browse(cr, uid, ids, context=context) nctx = nodes.get_node_context(cr, uid, context={}) # nctx will /not/ inherit the caller's context. Most of @@ -59,9 +61,11 @@ class document_file(osv.osv): # # This code can be improved # - def _data_set(self, cr, uid, id, name, value, arg, context): + def _data_set(self, cr, uid, id, name, value, arg, context=None): if not value: return True + if not context: + context = {} fbro = self.browse(cr, uid, id, context=context) nctx = nodes.get_node_context(cr, uid, context={}) fnode = nodes.node_file(None, None, nctx, fbro) @@ -136,10 +140,12 @@ class document_file(osv.osv): def copy(self, cr, uid, id, default=None, context=None): if not default: default = {} + if not context: + context = {} if 'name' not in default: name = self.read(cr, uid, [id])[0]['name'] default.update({'name': name + " (copy)"}) - return super(document_file, self).copy(cr, uid, id, default, context) + return super(document_file, self).copy(cr, uid, id, default, context=context) def write(self, cr, uid, ids, vals, context=None): result = False @@ -222,11 +228,13 @@ class document_file(osv.osv): cr.commit() # ? return result - def __get_partner_id(self, cr, uid, res_model, res_id, context): + def __get_partner_id(self, cr, uid, res_model, res_id, context=None): """ A helper to retrieve the associated partner from any res_model+id It is a hack that will try to discover if the mentioned record is clearly associated with a partner record. """ + if not context: + context = {} obj_model = self.pool.get(res_model) if obj_model._name == 'res.partner': return res_id @@ -241,12 +249,14 @@ class document_file(osv.osv): def unlink(self, cr, uid, ids, context=None): stor = self.pool.get('document.storage') unres = [] + if not context: + context = {} # We have to do the unlink in 2 stages: prepare a list of actual # files to be unlinked, update the db (safer to do first, can be # rolled back) and then unlink the files. The list wouldn't exist # after we discard the objects ids = self.search(cr, uid, [('id','in',ids)]) - for f in self.browse(cr, uid, ids, context): + for f in self.browse(cr, uid, ids, context=context): # TODO: update the node cache par = f.parent_id storage_id = None -- cgit v1.2.3 From 6dd290e8245f4ea91ce87b0f3b5f29bafeaf12e9 Mon Sep 17 00:00:00 2001 From: "uco (OpenERP)" Date: Tue, 23 Nov 2010 12:35:05 +0530 Subject: [REF]: Replace the condition 'if not context' with 'if context is None'. bzr revid: uco@tinyerp.com-20101123070505-9i2lrqhgxzaii3zn --- addons/document/document.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 0ccd0ec51ec..7e575f38a37 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -39,7 +39,7 @@ class document_file(osv.osv): return os.path.join(DMS_ROOT_PATH, cr.dbname) def _data_get(self, cr, uid, ids, name, arg, context=None): - if not context: + if context is None: context = {} fbrl = self.browse(cr, uid, ids, context=context) nctx = nodes.get_node_context(cr, uid, context={}) @@ -64,8 +64,6 @@ class document_file(osv.osv): def _data_set(self, cr, uid, id, name, value, arg, context=None): if not value: return True - if not context: - context = {} fbro = self.browse(cr, uid, id, context=context) nctx = nodes.get_node_context(cr, uid, context={}) fnode = nodes.node_file(None, None, nctx, fbro) @@ -140,8 +138,6 @@ class document_file(osv.osv): def copy(self, cr, uid, id, default=None, context=None): if not default: default = {} - if not context: - context = {} if 'name' not in default: name = self.read(cr, uid, [id])[0]['name'] default.update({'name': name + " (copy)"}) @@ -233,8 +229,6 @@ class document_file(osv.osv): It is a hack that will try to discover if the mentioned record is clearly associated with a partner record. """ - if not context: - context = {} obj_model = self.pool.get(res_model) if obj_model._name == 'res.partner': return res_id @@ -249,8 +243,6 @@ class document_file(osv.osv): def unlink(self, cr, uid, ids, context=None): stor = self.pool.get('document.storage') unres = [] - if not context: - context = {} # We have to do the unlink in 2 stages: prepare a list of actual # files to be unlinked, update the db (safer to do first, can be # rolled back) and then unlink the files. The list wouldn't exist -- cgit v1.2.3