Allow extensions to have a project settings page.
This commit is contained in:
@@ -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
|
||||
"""
|
||||
|
@@ -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('/<project_url>/edit/<extension_name>', 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)
|
||||
|
Reference in New Issue
Block a user