diff --git a/openerp/__init__.py b/openerp/__init__.py index a06c85d0c21..995822c9cb0 100644 --- a/openerp/__init__.py +++ b/openerp/__init__.py @@ -19,17 +19,27 @@ # ############################################################################## -""" OpenERP core library.. - -""" - -import sys +""" OpenERP core library.""" +#---------------------------------------------------------- +# Running mode flags (gevent, prefork) +#---------------------------------------------------------- # Is the server running with gevent. +import sys evented = False if sys.modules.get("gevent") is not None: evented = True +# Is the server running in pefork mode (e.g. behind Gunicorn). +# If this is True, the processes have to communicate some events, +# e.g. database update or cache invalidation. Each process has also +# its own copy of the data structure and we don't need to care about +# locks between threads. +multi_process = False + +#---------------------------------------------------------- +# libc UTC hack +#---------------------------------------------------------- # Make sure the OpenERP server runs in UTC. This is especially necessary # under Windows as under Linux it seems the real import of time is # sufficiently deferred so that setting the TZ environment variable @@ -40,9 +50,22 @@ import time # ... *then* import time. del os del time +#---------------------------------------------------------- +# Shortcuts +#---------------------------------------------------------- # The hard-coded super-user id (a.k.a. administrator, or root user). SUPERUSER_ID = 1 +def registry(database_name): + """ + Return the model registry for the given database. If the registry does not + exist yet, it is created on the fly. + """ + return modules.registry.RegistryManager.get(database_name) + +#---------------------------------------------------------- +# Imports +#---------------------------------------------------------- import addons import cli import conf @@ -58,23 +81,6 @@ import service import sql_db import tools import workflow -# backward compatilbility -# TODO: This is for the web addons, can be removed later. -wsgi = service -wsgi.register_wsgi_handler = wsgi.wsgi_server.register_wsgi_handler -# Is the server running in multi-process mode (e.g. behind Gunicorn). -# If this is True, the processes have to communicate some events, -# e.g. database update or cache invalidation. Each process has also -# its own copy of the data structure and we don't need to care about -# locks between threads. -multi_process = False - -def registry(database_name): - """ - Return the model registry for the given database. If the registry does not - exist yet, it is created on the fly. - """ - return modules.registry.RegistryManager.get(database_name) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/__init__.py b/openerp/addons/__init__.py index 9554e9bd850..e040e19defd 100644 --- a/openerp/addons/__init__.py +++ b/openerp/addons/__init__.py @@ -34,7 +34,4 @@ Importing them from here is deprecated. """ -# get_module_path is used only by base_module_quality -from openerp.modules import get_module_resource, get_module_path - # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/base/__init__.py b/openerp/addons/base/__init__.py index a5bc4c59484..26b39de74ad 100644 --- a/openerp/addons/base/__init__.py +++ b/openerp/addons/base/__init__.py @@ -25,6 +25,7 @@ import module import res import report import test +import tests # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/base/__openerp__.py b/openerp/addons/base/__openerp__.py index 808dd18d3e5..3c3c290f986 100644 --- a/openerp/addons/base/__openerp__.py +++ b/openerp/addons/base/__openerp__.py @@ -92,8 +92,6 @@ The kernel of OpenERP, needed for all installation. ], 'test': [ 'test/base_test.yml', - 'test/test_context.xml', - 'test/bug_lp541545.xml', 'test/test_osv_expression.yml', 'test/test_ir_rule.yml', # <-- These tests modify/add/delete ir_rules. ], diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index c1e9bbe50d8..e7fa064e33a 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -910,6 +910,29 @@ class ir_actions_server(osv.osv): if action.link_new_record and action.link_field_id: self.pool[action.model_id.model].write(cr, uid, [context.get('active_id')], {action.link_field_id.name: res_id}) + def _get_eval_context(self, cr, uid, action, context=None): + """ Prepare the context used when evaluating python code, like the + condition or code server actions. + + :param action: the current server action + :type action: browse record + :returns: dict -- evaluation context given to (safe_)eval """ + user = self.pool.get('res.users').browse(cr, uid, uid, context=context) + obj_pool = self.pool[action.model_id.model] + obj = None + if context.get('active_model') == action.model_id.model and context.get('active_id'): + obj = obj_pool.browse(cr, uid, context['active_id'], context=context) + return { + 'self': obj_pool, + 'object': obj, + 'obj': obj, + 'pool': self.pool, + 'time': time, + 'cr': cr, + 'uid': uid, + 'user': user, + } + def run(self, cr, uid, ids, context=None): """ Runs the server action. For each server action, the condition is checked. Note that a void (``False``) condition is considered as always @@ -932,25 +955,9 @@ class ir_actions_server(osv.osv): if context is None: context = {} res = False - user = self.pool.get('res.users').browse(cr, uid, uid) active_ids = context.get('active_ids', [context.get('active_id')]) for action in self.browse(cr, uid, ids, context): - obj_pool = self.pool[action.model_id.model] - obj = None - if context.get('active_model') == action.model_id.model and context.get('active_id'): - obj = obj_pool.browse(cr, uid, context['active_id'], context=context) - - # evaluation context for python strings to evaluate - eval_context = { - 'self': obj_pool, - 'object': obj, - 'obj': obj, - 'pool': self.pool, - 'time': time, - 'cr': cr, - 'uid': uid, - 'user': user, - } + eval_context = self._get_eval_context(cr, uid, action, context=context) condition = action.condition if condition is False: # Void (aka False) conditions are considered as True diff --git a/openerp/addons/base/ir/ir_fields.py b/openerp/addons/base/ir/ir_fields.py index f238bf78719..217ea319d8e 100644 --- a/openerp/addons/base/ir/ir_fields.py +++ b/openerp/addons/base/ir/ir_fields.py @@ -13,6 +13,7 @@ from openerp.osv import orm from openerp.tools.translate import _ from openerp.tools.misc import DEFAULT_SERVER_DATE_FORMAT,\ DEFAULT_SERVER_DATETIME_FORMAT +from openerp.tools import html_sanitize REFERENCING_FIELDS = set([None, 'id', '.id']) def only_ref_fields(record): @@ -188,7 +189,7 @@ class ir_fields_converter(orm.Model): def _str_id(self, cr, uid, model, column, value, context=None): return value, [] - _str_to_reference = _str_to_char = _str_to_text = _str_to_binary = _str_id + _str_to_reference = _str_to_char = _str_to_text = _str_to_binary = _str_to_html = _str_id def _str_to_date(self, cr, uid, model, column, value, context=None): try: diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index 8ea46bcfa4d..011ba2dc792 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -337,7 +337,7 @@ class view(osv.osv): if isinstance(spec, SKIPPED_ELEMENT_TYPES): continue if spec.tag == 'data': - specs += [ c for c in specs_tree ] + specs += [c for c in spec] continue node = self.locate_node(source, spec) if node is not None: diff --git a/openerp/addons/base/res/res_partner_view.xml b/openerp/addons/base/res/res_partner_view.xml index 822c6a36fd2..a0e32ab83bd 100644 --- a/openerp/addons/base/res/res_partner_view.xml +++ b/openerp/addons/base/res/res_partner_view.xml @@ -129,7 +129,7 @@
-
+