From 5dd49fa5ddcc530c5cb0fabed02c570473dd2a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 11 Oct 2016 16:33:44 +0200 Subject: [PATCH] Pillar Extensions can now add links to the sidebar. --- pillar/__init__.py | 16 +++++++++++++++- pillar/extension.py | 8 ++++++++ pillar/web/projects/routes.py | 8 +++++++- src/templates/projects/view.jade | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pillar/__init__.py b/pillar/__init__.py index 98b03f59..fc832e4c 100644 --- a/pillar/__init__.py +++ b/pillar/__init__.py @@ -1,5 +1,6 @@ """Pillar server.""" +import collections import copy import logging import logging.config @@ -36,7 +37,8 @@ class PillarServer(Eve): kwargs.setdefault('validator', custom_field_validation.ValidateCustomFields) super(PillarServer, self).__init__(settings=empty_settings, **kwargs) - self.pillar_extensions = {} # mapping from extension name to extension object. + # mapping from extension name to extension object. + self.pillar_extensions = collections.OrderedDict() self.pillar_extensions_template_paths = [] # list of paths self.app_root = os.path.abspath(app_root) @@ -517,3 +519,15 @@ class PillarServer(Eve): """ return self.data.driver.db + + def extension_sidebar_links(self, project): + """Returns the sidebar links for the given projects. + + :returns: HTML as a string for the sidebar. + """ + + if not project: + return '' + + return jinja2.Markup(''.join(ext.sidebar_links(project) + for ext in self.pillar_extensions.values())) diff --git a/pillar/extension.py b/pillar/extension.py index ff22b3af..34f7bfed 100644 --- a/pillar/extension.py +++ b/pillar/extension.py @@ -86,3 +86,11 @@ class PillarExtension(object): def setup_app(self, app): """Called during app startup, after all extensions have loaded.""" + + def sidebar_links(self, project): + """Returns the sidebar link(s) for the given projects. + + :returns: HTML as a string for the sidebar. + """ + + return '' diff --git a/pillar/web/projects/routes.py b/pillar/web/projects/routes.py index 0fee5a77..8475b41a 100644 --- a/pillar/web/projects/routes.py +++ b/pillar/web/projects/routes.py @@ -301,6 +301,8 @@ def render_project(project, api, extra_context=None, template_name=None): embed_string = '' template_name = "projects/view{0}.html".format(embed_string) + extension_sidebar_links = current_app.extension_sidebar_links(project) + return render_template(template_name, api=api, project=project, @@ -308,6 +310,7 @@ def render_project(project, api, extra_context=None, template_name=None): show_node=False, show_project=True, og_picture=project.picture_header, + extension_sidebar_links=extension_sidebar_links, **extra_context) @@ -355,13 +358,16 @@ def view_node(project_url, node_id): # Append _theatre to load the proper template theatre = '_theatre' if theatre_mode else '' + extension_sidebar_links = current_app.extension_sidebar_links(project) + return render_template('projects/view{}.html'.format(theatre), api=api, project=project, node=node, show_node=True, show_project=False, - og_picture=og_picture) + og_picture=og_picture, + extension_sidebar_links=extension_sidebar_links) def find_project_or_404(project_url, embedded=None, api=None): diff --git a/src/templates/projects/view.jade b/src/templates/projects/view.jade index ce0a75a7..3740921b 100644 --- a/src/templates/projects/view.jade +++ b/src/templates/projects/view.jade @@ -82,6 +82,7 @@ link(href="{{ url_for('static_pillar', filename='assets/css/project-main.css', v a(href="{{url_for('projects.search', project_url=project.url, _external=True)}}") i.pi-search | {% endif %} + | {{ extension_sidebar_links }} .project_nav-toggle-btn( title="Expand Navigation [T]",