Pillar Extensions can now add links to the sidebar.
This commit is contained in:
parent
6429c3df21
commit
5dd49fa5dd
@ -1,5 +1,6 @@
|
|||||||
"""Pillar server."""
|
"""Pillar server."""
|
||||||
|
|
||||||
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
@ -36,7 +37,8 @@ class PillarServer(Eve):
|
|||||||
kwargs.setdefault('validator', custom_field_validation.ValidateCustomFields)
|
kwargs.setdefault('validator', custom_field_validation.ValidateCustomFields)
|
||||||
super(PillarServer, self).__init__(settings=empty_settings, **kwargs)
|
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.pillar_extensions_template_paths = [] # list of paths
|
||||||
|
|
||||||
self.app_root = os.path.abspath(app_root)
|
self.app_root = os.path.abspath(app_root)
|
||||||
@ -517,3 +519,15 @@ class PillarServer(Eve):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return self.data.driver.db
|
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()))
|
||||||
|
@ -86,3 +86,11 @@ class PillarExtension(object):
|
|||||||
|
|
||||||
def setup_app(self, app):
|
def setup_app(self, app):
|
||||||
"""Called during app startup, after all extensions have loaded."""
|
"""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 ''
|
||||||
|
@ -301,6 +301,8 @@ def render_project(project, api, extra_context=None, template_name=None):
|
|||||||
embed_string = ''
|
embed_string = ''
|
||||||
template_name = "projects/view{0}.html".format(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,
|
return render_template(template_name,
|
||||||
api=api,
|
api=api,
|
||||||
project=project,
|
project=project,
|
||||||
@ -308,6 +310,7 @@ def render_project(project, api, extra_context=None, template_name=None):
|
|||||||
show_node=False,
|
show_node=False,
|
||||||
show_project=True,
|
show_project=True,
|
||||||
og_picture=project.picture_header,
|
og_picture=project.picture_header,
|
||||||
|
extension_sidebar_links=extension_sidebar_links,
|
||||||
**extra_context)
|
**extra_context)
|
||||||
|
|
||||||
|
|
||||||
@ -355,13 +358,16 @@ def view_node(project_url, node_id):
|
|||||||
# Append _theatre to load the proper template
|
# Append _theatre to load the proper template
|
||||||
theatre = '_theatre' if theatre_mode else ''
|
theatre = '_theatre' if theatre_mode else ''
|
||||||
|
|
||||||
|
extension_sidebar_links = current_app.extension_sidebar_links(project)
|
||||||
|
|
||||||
return render_template('projects/view{}.html'.format(theatre),
|
return render_template('projects/view{}.html'.format(theatre),
|
||||||
api=api,
|
api=api,
|
||||||
project=project,
|
project=project,
|
||||||
node=node,
|
node=node,
|
||||||
show_node=True,
|
show_node=True,
|
||||||
show_project=False,
|
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):
|
def find_project_or_404(project_url, embedded=None, api=None):
|
||||||
|
@ -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)}}")
|
a(href="{{url_for('projects.search', project_url=project.url, _external=True)}}")
|
||||||
i.pi-search
|
i.pi-search
|
||||||
| {% endif %}
|
| {% endif %}
|
||||||
|
| {{ extension_sidebar_links }}
|
||||||
|
|
||||||
.project_nav-toggle-btn(
|
.project_nav-toggle-btn(
|
||||||
title="Expand Navigation [T]",
|
title="Expand Navigation [T]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user