diff --git a/pillar/extension.py b/pillar/extension.py index 928948b2..cc9a574f 100644 --- a/pillar/extension.py +++ b/pillar/extension.py @@ -17,10 +17,14 @@ can then be registered to the application at app creation time: import abc +import flask import pillarsdk class PillarExtension(object, metaclass=abc.ABCMeta): + # Set to True when your extension implements the project_settings() method. + has_project_settings = False + @property @abc.abstractmethod def name(self): @@ -103,3 +107,11 @@ class PillarExtension(object, metaclass=abc.ABCMeta): """ return '' + + def project_settings(self, project: pillarsdk.Project) -> flask.Response: + """Renders the project settings page for this extension. + + Set YourExtension.has_project_settings = True and Pillar will call this function. + + :returns: a Flask HTTP response + """ diff --git a/pillar/web/projects/routes.py b/pillar/web/projects/routes.py index 28a6a705..0af5e5d9 100644 --- a/pillar/web/projects/routes.py +++ b/pillar/web/projects/routes.py @@ -468,6 +468,10 @@ def edit(project: Project): status=project.status, ) + # Collect extension pages. + ext_pages = [ext for ext in current_app.pillar_extensions.values() + if ext.has_project_settings] + if form.validate_on_submit(): project = Project.find(project._id, api=api) project.name = form.name.data @@ -506,6 +510,7 @@ def edit(project: Project): form=form, hidden_fields=hidden_fields, project=project, + ext_pages=ext_pages, api=api) @@ -778,3 +783,15 @@ def delete(): project.delete(api=api) return jsonify(dict(staus='success', data=dict( message='Project deleted {}'.format(project['_id'])))) + + +@blueprint.route('//edit/', methods=['GET', 'POST']) +@login_required +@project_view() +def edit_extension(project: Project, extension_name): + try: + ext = current_app.pillar_extensions[extension_name] + except KeyError: + raise wz_exceptions.NotFound() + + return ext.project_settings(project) diff --git a/src/templates/projects/edit.jade b/src/templates/projects/edit.jade index ae5e6f8b..b1832282 100644 --- a/src/templates/projects/edit.jade +++ b/src/templates/projects/edit.jade @@ -65,7 +65,12 @@ a(href="{{ url_for('projects.edit_node_types', project_url=project.url) }}") i.pi-puzzle | Node Types - + | {% for ext in ext_pages %} + li(class="{% if title == ext.name %}active{% endif %}") + a(href="{{ url_for('projects.edit_extension', project_url=project.url, extension_name=ext.name) }}") + i(class="pi-{{ext.icon}}") + | {{ext.name | title}} + | {% endfor %} .project_split(title="Toggle Navigation [T]") #project_context-container