summaryrefslogtreecommitdiff
path: root/addons/web/controllers/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/controllers/main.py')
-rw-r--r--addons/web/controllers/main.py71
1 files changed, 16 insertions, 55 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index b34c33d4a23..5050ad16e49 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -32,6 +32,7 @@ except ImportError:
import openerp
import openerp.modules.registry
from openerp.addons.base.ir.ir_qweb import AssetsBundle, QWebTemplateNotFound
+from openerp.tools import topological_sort
from openerp.tools.translate import _
from openerp import http
@@ -141,50 +142,6 @@ def ensure_db(redirect='/web/database/selector'):
request.session.db = db
-def module_topological_sort(modules):
- """ Return a list of module names sorted so that their dependencies of the
- modules are listed before the module itself
-
- modules is a dict of {module_name: dependencies}
-
- :param modules: modules to sort
- :type modules: dict
- :returns: list(str)
- """
-
- dependencies = set(itertools.chain.from_iterable(modules.itervalues()))
- # incoming edge: dependency on other module (if a depends on b, a has an
- # incoming edge from b, aka there's an edge from b to a)
- # outgoing edge: other module depending on this one
-
- # [Tarjan 1976], http://en.wikipedia.org/wiki/Topological_sorting#Algorithms
- #L ← Empty list that will contain the sorted nodes
- L = []
- #S ← Set of all nodes with no outgoing edges (modules on which no other
- # module depends)
- S = set(module for module in modules if module not in dependencies)
-
- visited = set()
- #function visit(node n)
- def visit(n):
- #if n has not been visited yet then
- if n not in visited:
- #mark n as visited
- visited.add(n)
- #change: n not web module, can not be resolved, ignore
- if n not in modules: return
- #for each node m with an edge from m to n do (dependencies of n)
- for m in modules[n]:
- #visit(m)
- visit(m)
- #add n to L
- L.append(n)
- #for each node n in S do
- for n in S:
- #visit(n)
- visit(n)
- return L
-
def module_installed():
# Candidates module the current heuristic is the /static dir
loadable = http.addons_manifest.keys()
@@ -202,7 +159,7 @@ def module_installed():
dependencies = [i['name'] for i in deps_read]
modules[module['name']] = dependencies
- sorted_modules = module_topological_sort(modules)
+ sorted_modules = topological_sort(modules)
return sorted_modules
def module_installed_bypass_session(dbname):
@@ -224,7 +181,7 @@ def module_installed_bypass_session(dbname):
modules[module['name']] = dependencies
except Exception,e:
pass
- sorted_modules = module_topological_sort(modules)
+ sorted_modules = topological_sort(modules)
return sorted_modules
def module_boot(db=None):
@@ -710,7 +667,8 @@ class Proxy(http.Controller):
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
- return Client(request.httprequest.app, BaseResponse).get(path).data
+ base_url = request.httprequest.base_url
+ return Client(request.httprequest.app, BaseResponse).get(path, base_url=base_url).data
class Database(http.Controller):
@@ -775,7 +733,7 @@ class Database(http.Controller):
password, db = operator.itemgetter(
'drop_pwd', 'drop_db')(
dict(map(operator.itemgetter('name', 'value'), fields)))
-
+
try:
if request.session.proxy("db").drop(password, db):
return True
@@ -1289,7 +1247,7 @@ class Binary(http.Controller):
class Action(http.Controller):
@http.route('/web/action/load', type='json', auth="user")
- def load(self, action_id, do_not_eval=False):
+ def load(self, action_id, do_not_eval=False, additional_context=None):
Actions = request.session.model('ir.actions.actions')
value = False
try:
@@ -1304,11 +1262,12 @@ class Action(http.Controller):
base_action = Actions.read([action_id], ['type'], request.context)
if base_action:
- ctx = {}
+ ctx = request.context
action_type = base_action[0]['type']
if action_type == 'ir.actions.report.xml':
ctx.update({'bin_size': True})
- ctx.update(request.context)
+ if additional_context:
+ ctx.update(additional_context)
action = request.session.model(action_type).read([action_id], False, ctx)
if action:
value = clean_action(action[0])
@@ -1489,16 +1448,18 @@ class ExportFormat(object):
raise NotImplementedError()
def base(self, data, token):
+ params = simplejson.loads(data)
model, fields, ids, domain, import_compat = \
operator.itemgetter('model', 'fields', 'ids', 'domain',
'import_compat')(
- simplejson.loads(data))
+ params)
Model = request.session.model(model)
- ids = ids or Model.search(domain, 0, False, False, request.context)
+ context = dict(request.context or {}, **params.get('context', {}))
+ ids = ids or Model.search(domain, 0, False, False, context)
field_names = map(operator.itemgetter('name'), fields)
- import_data = Model.export_data(ids, field_names, self.raw_data, context=request.context).get('datas',[])
+ import_data = Model.export_data(ids, field_names, self.raw_data, context=context).get('datas',[])
if import_compat:
columns_headers = field_names
@@ -1686,7 +1647,7 @@ class Apps(http.Controller):
sakey = Session().save_session_action(action)
debug = '?debug' if req.debug else ''
return werkzeug.utils.redirect('/web{0}#sa={1}'.format(debug, sakey))
-
+
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: