From 13954f4e9534139d899108902bf99bdce918ce47 Mon Sep 17 00:00:00 2001 From: Ben Beauregard Date: Wed, 18 Dec 2024 22:30:17 -0500 Subject: [PATCH] feat(users): only show current students Show current students (and their guardians) by default, with a button to show all students or guardians. Also adds a count of the number of users being displayed. Signed-off-by: Ben Beauregard --- appdata/.gitignore | 5 ++-- signinapp/event.py | 4 +-- signinapp/team.py | 35 +++++++++++++++++------ signinapp/templates/user_list.html.jinja2 | 14 +++++++++ signinapp/util.py | 9 ++++++ 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/appdata/.gitignore b/appdata/.gitignore index 6176789..7288846 100644 --- a/appdata/.gitignore +++ b/appdata/.gitignore @@ -1,2 +1,3 @@ -cssignin.yaml -db/ \ No newline at end of file +cssignin.yaml +db/ +kanboard/ \ No newline at end of file diff --git a/signinapp/event.py b/signinapp/event.py index 3bfd0d9..32b7911 100644 --- a/signinapp/event.py +++ b/signinapp/event.py @@ -200,9 +200,9 @@ def export_stamps( @login_required def export(): if current_user.role.admin: - name = request.values.get("name", None) + name = request.values.get("name", current_user.email) else: - name = current_user.name + name = current_user.email user = User.from_email(name) start = request.args.get("start", None) end = request.args.get("end", None) diff --git a/signinapp/team.py b/signinapp/team.py index be8e20e..f056b27 100644 --- a/signinapp/team.py +++ b/signinapp/team.py @@ -6,8 +6,8 @@ from sqlalchemy import or_ from sqlalchemy.future import select -from .model import Role, ShirtSizes, Subteam, User, db -from .util import mentor_required +from .model import Role, ShirtSizes, Student, Subteam, User, db +from .util import get_current_graduation_years, mentor_required team = Blueprint("team", __name__) @@ -43,25 +43,42 @@ def subteam(): @team.route("/users/students") @mentor_required def list_students(): - users = db.session.scalars( - select(User) - .where(or_(User.role.has(name="student"), User.role.has(name="lead"))) - .order_by(User.name) - ) + include_all = request.args.get("include_all", False) == "true" + select_stmt = select(User).where(or_(User.role.has(name="student"), User.role.has(name="lead"))) + if not include_all: + select_stmt = select_stmt.join(Student).where( + Student.graduation_year.in_(get_current_graduation_years()) + ) + users = db.session.scalars(select_stmt.order_by(User.name)).all() return render_template("user_list.html.jinja2", role="Student", users=users) @team.route("/users/guardians") @mentor_required def list_guardians(): - users = db.session.scalars(select(User).where(User.role.has(guardian=True)).order_by(User.name)) + include_all = request.args.get("include_all", False) == "true" + users = db.session.scalars( + select(User).where(User.role.has(guardian=True)).order_by(User.name) + ).all() + if not include_all: + users = [ + guardian + for guardian in users + if any( + student + for student in guardian.guardian_user_data.students + if student.graduation_year in get_current_graduation_years() + ) + ] return render_template("user_list.html.jinja2", role="Guardian", users=users) @team.route("/users/mentors") @mentor_required def list_mentors(): - users = db.session.scalars(select(User).where(User.role.has(mentor=True)).order_by(User.name)) + users = db.session.scalars( + select(User).where(User.role.has(mentor=True)).order_by(User.name) + ).all() return render_template("user_list.html.jinja2", role="Mentor", users=users) diff --git a/signinapp/templates/user_list.html.jinja2 b/signinapp/templates/user_list.html.jinja2 index c69d732..1bc0487 100644 --- a/signinapp/templates/user_list.html.jinja2 +++ b/signinapp/templates/user_list.html.jinja2 @@ -7,6 +7,20 @@

{{ role }} List

+
+ {{ users|length }} {{ role }}s + {% if role == "Student" or role == "Guardian" %} + {% if request.args.get('include_all',"false") == 'true' -%} + Show Active + {% else %} + Show All + {% endif %} + {% endif %} +
{% if role == "Student" %} list[int]: + today = date.today() + this_grad_year = today.year + # If it's past June then graduation is a year from now + if today.month > 6: + this_grad_year += 1 + return [this_grad_year + 3, this_grad_year + 2, this_grad_year + 1, this_grad_year]