From 98527c72f4c5d2004634693a63b58cb775f8e262 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 4 Oct 2017 21:51:07 +0200 Subject: [PATCH] Support for extra_template_args in node view This allows for wrapping the view function in another function which will provide additional args. Originally implemented in order to allow Dillo post view to provide the Project object to the view_embed template. --- pillar/web/nodes/routes.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pillar/web/nodes/routes.py b/pillar/web/nodes/routes.py index a9b29d5a..bf282a32 100644 --- a/pillar/web/nodes/routes.py +++ b/pillar/web/nodes/routes.py @@ -108,7 +108,7 @@ def jstree(node_id): @blueprint.route("//view") -def view(node_id): +def view(node_id, extra_template_args: dict=None): api = system_util.pillar_api() # Get node, we'll embed linked objects later. @@ -201,9 +201,6 @@ def view(node_id): if node.file and node.file_variations: node.file.length = max(var.length for var in node.file_variations) - if request.args.get('embed_project') == '1': - node.project = Project.find(node.project, api=api) - if request.args.get('format') == 'json': node = node.to_dict() node['url_edit'] = url_for('nodes.edit', node_id=node['_id']) @@ -225,6 +222,8 @@ def view(node_id): write_access = 'PUT' in (node.allowed_methods or set()) + if extra_template_args is None: + extra_template_args = {} try: return render_template(template_path, node_id=node._id, @@ -233,7 +232,8 @@ def view(node_id): children=children, config=current_app.config, write_access=write_access, - api=api) + api=api, + **extra_template_args) except TemplateNotFound: log.error('Template %s does not exist for node type %s', template_path, node_type_name) return render_template('nodes/error_type_not_found.html', @@ -243,7 +243,8 @@ def view(node_id): children=children, config=current_app.config, write_access=write_access, - api=api) + api=api, + **extra_template_args) def _view_handler_asset(node, template_path, template_action, link_allowed):