From c276f12eb7a7162f75a5125c52867a861cbb4ccd Mon Sep 17 00:00:00 2001 From: ld507 <ld507@ic.ac.uk> Date: Wed, 12 Oct 2022 17:40:19 +0100 Subject: [PATCH] Fix: moving full names to be displayed to a new, separate dictionary, so that values in objects that correspond to dictionary columns are not overwrite --- .../pages/staff/shortlisted-projects.html | 2 +- .../pages/student/shortlisted-projects.html | 2 +- app/views/staff.py | 14 ++++++++++++-- app/views/student.py | 9 +++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/templates/pages/staff/shortlisted-projects.html b/app/templates/pages/staff/shortlisted-projects.html index f93f8ce..5351e61 100644 --- a/app/templates/pages/staff/shortlisted-projects.html +++ b/app/templates/pages/staff/shortlisted-projects.html @@ -15,7 +15,7 @@ <i class="fa-solid fa-bars"></i>  </span> <span> - {{ shortlisting.project.title }} - {{ shortlisting.student }} + {{ shortlisting.project.title }} - {{ full_names[shortlisting.id] }} </span> </li> {% endfor %} diff --git a/app/templates/pages/student/shortlisted-projects.html b/app/templates/pages/student/shortlisted-projects.html index dd11c6d..d0e9024 100644 --- a/app/templates/pages/student/shortlisted-projects.html +++ b/app/templates/pages/student/shortlisted-projects.html @@ -15,7 +15,7 @@ <i class="fa-solid fa-bars"></i>  </span> <span> - {{ project.title }}{{ project.proposer }} + {{ project.title }} - {{ full_names[project.id] }} </span> </li> {% endfor %} diff --git a/app/views/staff.py b/app/views/staff.py index 547164b..6f4815e 100644 --- a/app/views/staff.py +++ b/app/views/staff.py @@ -124,13 +124,23 @@ def projects_ranking(): .order_by(Shortlisting.staff_ranking) .all() ) + + full_names = {} + for shortlisting in projects: person = Person.query.filter( Person.username == shortlisting.student ).first() or Person(username=shortlisting.student, firstname="", lastname="") - shortlisting.student = person.full_name if person.full_name else person.username - return render_template("pages/staff/shortlisted-projects.html", projects=projects) + full_names[shortlisting.id] = ( + person.full_name if person.full_name else person.username + ) + + return render_template( + "pages/staff/shortlisted-projects.html", + projects=projects, + full_names=full_names, + ) @bp.route("/projects/rankings", methods=["PUT"]) diff --git a/app/views/student.py b/app/views/student.py index d44f73c..25ee47e 100644 --- a/app/views/student.py +++ b/app/views/student.py @@ -42,6 +42,9 @@ def projects_ranking(): .order_by(Shortlisting.ranking) .all() ) + + full_names = {} + for shortlisting in shortlisted_projects: username = ( shortlisting.proposer @@ -53,12 +56,14 @@ def projects_ranking(): username=username, firstname="", lastname="" ) - shortlisting.proposer = " - " + ( + full_names[shortlisting.id] = ( person.full_name if person.full_name else person.username ) return render_template( - "pages/student/shortlisted-projects.html", projects=shortlisted_projects + "pages/student/shortlisted-projects.html", + projects=shortlisted_projects, + full_names=full_names, ) -- GitLab