Skip to content

Commit

Permalink
Improve performance and layout of past projects inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
ds283 committed Mar 21, 2024
1 parent 0fa4736 commit de8f786
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions app/ajax/faculty/past_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
# Contributors: David Seery <D.Seery@sussex.ac.uk>
#

from flask import render_template_string, jsonify, url_for, get_template_attribute
from flask import jsonify, get_template_attribute, current_app, render_template
from jinja2 import Template, Environment

# language=jinja2
_project_menu = """
_menu = """
<div class="dropdown">
<button class="btn btn-secondary btn-sm full-width-button dropdown-toggle" type="button" data-bs-toggle="dropdown">
Actions
Expand All @@ -35,13 +36,9 @@

# language=jinja2
_name = """
{% from "faculty/macros.html" import project_metadata %}
<a class="text-decoration-none" href="{{ url_for('faculty.live_project', pid=p.id, text='offered projects view', url=url_for('faculty.past_projects')) }}">
{{ p.name }}
</a>
<div>
{{ project_metadata(p) }}
</div>
"""


Expand All @@ -64,29 +61,62 @@

# language=jinja2
_metadata = """
{% from "faculty/macros.html" import project_selection_data, project_rank_data %}
<div>
{{ project_selection_data(p) }}
</div>
<div style="margin-top: 6px;">
{{ project_rank_data(p, url_for('faculty.past_projects'), text='past projects view', live=false) }}
<div class="mt-1">
{{ project_metadata(p) }}
</div>
"""


def _build_name_templ() -> Template:
env: Environment = current_app.jinja_env
return env.from_string(_name)


def _build_pclass_templ() -> Template:
env: Environment = current_app.jinja_env
return env.from_string(_pclass)


def _build_affiliation_templ() -> Template:
env: Environment = current_app.jinja_env
return env.from_string(_affiliation)


def _build_metadata_templ() -> Template:
env: Environment = current_app.jinja_env
return env.from_string(_metadata)


def _build_menu_templ() -> Template:
env: Environment = current_app.jinja_env
return env.from_string(_menu)


def pastproject_data(projects):
simple_label = get_template_attribute("labels.html", "simple_label")
truncate = get_template_attribute("macros.html", "truncate")

project_metadata = get_template_attribute("faculty/macros.html", "project_metadata")
project_selection_data = get_template_attribute("faculty/macros.html", "project_selection_data")

name_templ: Template = _build_name_templ()
pclass_templ: Template = _build_pclass_templ()
affiliation_templ: Template = _build_affiliation_templ()
metadata_templ: Template = _build_metadata_templ()
menu_templ: Template = _build_menu_templ()

data = [
{
"year": "{c}".format(c=p.config.year),
"name": render_template_string(_name, p=p),
"pclass": render_template_string(_pclass, config=p.config),
"group": render_template_string(_affiliation, project=p, simple_label=simple_label, truncate=truncate),
"metadata": render_template_string(_metadata, p=p),
"students": "Not yet implemented",
"menu": render_template_string(_project_menu, project=p),
"name": render_template(name_templ, p=p),
"pclass": render_template(pclass_templ, config=p.config),
"group": render_template(affiliation_templ, project=p, simple_label=simple_label, truncate=truncate),
"metadata": render_template(metadata_templ, p=p, project_selection_data=project_selection_data, project_metadata=project_metadata),
"students": '<i class="fas fa-ban"></i> Not yet implemented',
"menu": render_template(menu_templ, project=p),
}
for p in projects
]
Expand Down

0 comments on commit de8f786

Please sign in to comment.