From 7dd6305f47e9c86ac4577b4b3861a846c2295bbd Mon Sep 17 00:00:00 2001 From: Ben Beauregard Date: Wed, 18 Dec 2024 22:34:01 -0500 Subject: [PATCH] feat(students): adds basic student export Adds a basic export functionality which exports a students name and email along with their guardian's names and emails. Signed-off-by: Ben Beauregard --- signinapp/team.py | 38 ++- signinapp/templates/base.html.jinja2 | 443 ++++++++++++++------------- 2 files changed, 260 insertions(+), 221 deletions(-) diff --git a/signinapp/team.py b/signinapp/team.py index f056b27..be70309 100644 --- a/signinapp/team.py +++ b/signinapp/team.py @@ -1,5 +1,7 @@ from collections import defaultdict +from datetime import datetime +import flask_excel as excel from flask import Blueprint, Flask, request from flask.templating import render_template from flask_login import login_required @@ -7,7 +9,7 @@ from sqlalchemy.future import select from .model import Role, ShirtSizes, Student, Subteam, User, db -from .util import get_current_graduation_years, mentor_required +from .util import admin_required, get_current_graduation_years, mentor_required team = Blueprint("team", __name__) @@ -82,5 +84,39 @@ def list_mentors(): return render_template("user_list.html.jinja2", role="Mentor", users=users) +@team.route("/users/students/export") +@admin_required +def students_export(): + result = [ + [ + "Student Name", + "Email", + "First Parent Name", + "First Parent Email", + "Second Parent Name", + "Second Parent Email", + ] + ] + [ + [ + student.user.full_name, + student.user.email, + student.guardians[0].user.name if student.guardians else "", + student.guardians[0].user.email if student.guardians else "", + student.guardians[1].user.name if len(student.guardians) > 1 else "", + student.guardians[1].user.email if len(student.guardians) > 1 else "", + ] + for student in db.session.scalars( + select(Student) + .where(Student.graduation_year.in_(get_current_graduation_years())) + .order_by(Student.user_id) + ) + ] + return excel.make_response_from_array( + result, + "csv", + file_name=f"students-parents-{datetime.now().strftime('%Y-%m-%d')}.csv", + ) + + def init_app(app: Flask): app.register_blueprint(team) diff --git a/signinapp/templates/base.html.jinja2 b/signinapp/templates/base.html.jinja2 index 11a2108..9f6f831 100644 --- a/signinapp/templates/base.html.jinja2 +++ b/signinapp/templates/base.html.jinja2 @@ -1,220 +1,223 @@ - - - {% from 'bootstrap5/utils.html' import render_icon, render_messages %} - {%- macro show_badge(b) -%} - {%- if b.emoji -%} - {{ b.emoji }} - {%- elif b.icon -%} - {{ render_icon(b.icon, color=b.color) }} - {%- endif -%} - {{ b.name }} - {%- endmacro -%} - - {% block head %} - - - - - - {% block styles %} - - {% assets "custom_css" %} - - {% endassets %} - {% endblock styles %} - - {% block title %} - Chop Shop Sign In - {% endblock title %} - - {{ config['TITLE'] }} - - {% endblock head %} - - - - - - {% block content %} - {% endblock content %} - {% block scripts %} - - {{ bootstrap.load_js() }} - {% endblock scripts %} - - + + + {% from 'bootstrap5/utils.html' import render_icon, render_messages %} + {%- macro show_badge(b) -%} + {%- if b.emoji -%} + {{ b.emoji }} + {%- elif b.icon -%} + {{ render_icon(b.icon, color=b.color) }} + {%- endif -%} + {{ b.name }} + {%- endmacro -%} + + {% block head %} + + + + + + {% block styles %} + + {% assets "custom_css" %} + + {% endassets %} + {% endblock styles %} + + {% block title %} + Chop Shop Sign In + {% endblock title %} + - {{ config['TITLE'] }} + + {% endblock head %} + + + + + + {% block content %} + {% endblock content %} + {% block scripts %} + + {{ bootstrap.load_js() }} + {% endblock scripts %} + +