Add context processor to put allow accessing workspace in template

This commit is contained in:
Patrick Smith 2018-08-21 14:52:06 -04:00
parent f8c3ac824a
commit 34d652f33a
3 changed files with 13 additions and 12 deletions

View File

@ -5,6 +5,13 @@ from atst.domain.workspaces import Members, Projects, Workspaces
bp = Blueprint("workspaces", __name__) bp = Blueprint("workspaces", __name__)
@bp.context_processor
def workspace():
workspace = None
if "workspace_id" in http_request.view_args:
workspace = Workspaces.get(http_request.view_args["workspace_id"])
return { "workspace": workspace }
@bp.route("/workspaces") @bp.route("/workspaces")
def workspaces(): def workspaces():
@ -14,21 +21,15 @@ def workspaces():
@bp.route("/workspaces/<workspace_id>/projects") @bp.route("/workspaces/<workspace_id>/projects")
def workspace_projects(workspace_id): def workspace_projects(workspace_id):
projects = Projects.get_many(workspace_id) projects = Projects.get_many(workspace_id)
return render_template( return render_template("workspace_projects.html", projects=projects)
"workspace_projects.html", workspace_id=workspace_id, projects=projects
)
@bp.route("/workspaces/<workspace_id>/members") @bp.route("/workspaces/<workspace_id>/members")
def workspace_members(workspace_id): def workspace_members(workspace_id):
members = Members.get_many(workspace_id) members = Members.get_many(workspace_id)
return render_template( return render_template("workspace_members.html", members=members)
"workspace_members.html", workspace_id=workspace_id, members=members
)
@bp.route("/workspaces/<workspace_id>/reports") @bp.route("/workspaces/<workspace_id>/reports")
def workspace_reports(workspace_id): def workspace_reports(workspace_id):
return render_template( return render_template("workspace_reports.html")
"workspace_reports.html", workspace_id=workspace_id
)

View File

@ -6,9 +6,9 @@
{{ Icon('shield', classes='topbar__link-icon') }} {{ Icon('shield', classes='topbar__link-icon') }}
</a> </a>
<div class="topbar__context topbar__context--{{context}}"> <div class="topbar__context {% if workspace %}topbar__context--workspace{% endif %}">
<a href="/" class="topbar__link"> <a href="/" class="topbar__link">
<span class="topbar__link-label">{{ "Workspace 123456" if context == 'workspace' else "JEDI" }}</span> <span class="topbar__link-label">{{ ("Workspace " + workspace.name) if workspace else "JEDI" }}</span>
{{ Icon('caret_down', classes='topbar__link-icon icon--tiny') }} {{ Icon('caret_down', classes='topbar__link-icon icon--tiny') }}
</a> </a>

View File

@ -4,7 +4,7 @@
{% block workspace_content %} {% block workspace_content %}
{{ Alert("Funding Information & Reports for Workspace " + workspace_id, {{ Alert("Funding Information & Reports for Workspace " + workspace.name,
message="<p>On this screen you'll find detailed reporting information on this workspace. This message needs to be written better and be dismissable.</p>", message="<p>On this screen you'll find detailed reporting information on this workspace. This message needs to be written better and be dismissable.</p>",
actions=[ actions=[
{"label": "Learn More", "href": "/", "icon": "info"}, {"label": "Learn More", "href": "/", "icon": "info"},