Pass extension pages to all extensions' "project settings" pages.
This commit is contained in:
parent
f953f1e51b
commit
2c78697e80
@ -5,9 +5,11 @@ unique usernames from emails. Calls out to the pillar_server.modules.blender_id
|
|||||||
module for Blender ID communication.
|
module for Blender ID communication.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
|
import typing
|
||||||
|
|
||||||
|
import bson
|
||||||
from bson import tz_util
|
from bson import tz_util
|
||||||
from flask import g
|
from flask import g
|
||||||
from flask import request
|
from flask import request
|
||||||
@ -226,7 +228,7 @@ def _delete_expired_tokens():
|
|||||||
# log.debug('Deleted %i expired authentication tokens', result.deleted_count)
|
# log.debug('Deleted %i expired authentication tokens', result.deleted_count)
|
||||||
|
|
||||||
|
|
||||||
def current_user_id():
|
def current_user_id() -> typing.Optional[bson.ObjectId]:
|
||||||
"""None-safe fetching of user ID. Can return None itself, though."""
|
"""None-safe fetching of user ID. Can return None itself, though."""
|
||||||
|
|
||||||
current_user = g.get('current_user') or {}
|
current_user = g.get('current_user') or {}
|
||||||
|
@ -108,10 +108,12 @@ class PillarExtension(object, metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def project_settings(self, project: pillarsdk.Project) -> flask.Response:
|
def project_settings(self, project: pillarsdk.Project, **template_args: dict) -> flask.Response:
|
||||||
"""Renders the project settings page for this extension.
|
"""Renders the project settings page for this extension.
|
||||||
|
|
||||||
Set YourExtension.has_project_settings = True and Pillar will call this function.
|
Set YourExtension.has_project_settings = True and Pillar will call this function.
|
||||||
|
|
||||||
|
:param project: the project for which to render the settings.
|
||||||
|
:param template_args: additional template arguments.
|
||||||
:returns: a Flask HTTP response
|
:returns: a Flask HTTP response
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import itertools
|
import itertools
|
||||||
|
import typing
|
||||||
|
|
||||||
from pillarsdk import Node
|
from pillarsdk import Node
|
||||||
from pillarsdk import Project
|
from pillarsdk import Project
|
||||||
@ -21,6 +22,8 @@ from pillar import current_app
|
|||||||
from pillar.web import system_util
|
from pillar.web import system_util
|
||||||
from pillar.web import utils
|
from pillar.web import utils
|
||||||
from pillar.web.utils.jstree import jstree_get_children
|
from pillar.web.utils.jstree import jstree_get_children
|
||||||
|
import pillar.extension
|
||||||
|
|
||||||
from .forms import ProjectForm
|
from .forms import ProjectForm
|
||||||
from .forms import NodeTypeForm
|
from .forms import NodeTypeForm
|
||||||
|
|
||||||
@ -469,10 +472,6 @@ def edit(project: Project):
|
|||||||
status=project.status,
|
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():
|
if form.validate_on_submit():
|
||||||
project = Project.find(project._id, api=api)
|
project = Project.find(project._id, api=api)
|
||||||
project.name = form.name.data
|
project.name = form.name.data
|
||||||
@ -511,10 +510,17 @@ def edit(project: Project):
|
|||||||
form=form,
|
form=form,
|
||||||
hidden_fields=hidden_fields,
|
hidden_fields=hidden_fields,
|
||||||
project=project,
|
project=project,
|
||||||
ext_pages=ext_pages,
|
ext_pages=find_extension_pages(),
|
||||||
api=api)
|
api=api)
|
||||||
|
|
||||||
|
|
||||||
|
def find_extension_pages() -> typing.List[pillar.extension.PillarExtension]:
|
||||||
|
"""Returns a list of Pillar extensions that have project settings pages."""
|
||||||
|
|
||||||
|
return [ext for ext in current_app.pillar_extensions.values()
|
||||||
|
if ext.has_project_settings]
|
||||||
|
|
||||||
|
|
||||||
@blueprint.route('/<project_url>/edit/node-type')
|
@blueprint.route('/<project_url>/edit/node-type')
|
||||||
@login_required
|
@login_required
|
||||||
@project_view()
|
@project_view()
|
||||||
@ -522,6 +528,7 @@ def edit_node_types(project: Project):
|
|||||||
api = system_util.pillar_api()
|
api = system_util.pillar_api()
|
||||||
return render_template('projects/edit_node_types.html',
|
return render_template('projects/edit_node_types.html',
|
||||||
api=api,
|
api=api,
|
||||||
|
ext_pages=find_extension_pages(),
|
||||||
project=project)
|
project=project)
|
||||||
|
|
||||||
|
|
||||||
@ -600,6 +607,7 @@ def sharing(project: Project):
|
|||||||
return render_template('projects/sharing.html',
|
return render_template('projects/sharing.html',
|
||||||
api=api,
|
api=api,
|
||||||
project=project,
|
project=project,
|
||||||
|
ext_pages=find_extension_pages(),
|
||||||
users=users['_items'])
|
users=users['_items'])
|
||||||
|
|
||||||
|
|
||||||
@ -795,4 +803,5 @@ def edit_extension(project: Project, extension_name):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise wz_exceptions.NotFound()
|
raise wz_exceptions.NotFound()
|
||||||
|
|
||||||
return ext.project_settings(project)
|
return ext.project_settings(project,
|
||||||
|
ext_pages=find_extension_pages())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user