From 7a90c841787d6ab9c4f1136366d1cce5a2e86260 Mon Sep 17 00:00:00 2001 From: dominik24c Date: Tue, 14 Jun 2022 09:42:48 +0200 Subject: [PATCH] update download student endpoint for coordinator view - generate list by mode of students --- backend/app/coordinator/routes/students.py | 11 ++++++++--- backend/app/coordinator/schemas.py | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/app/coordinator/routes/students.py b/backend/app/coordinator/routes/students.py index 7546445..ed0154c 100644 --- a/backend/app/coordinator/routes/students.py +++ b/backend/app/coordinator/routes/students.py @@ -10,7 +10,7 @@ from flask_sqlalchemy import get_debug_queries from ...students.models import Student, Group from ...project_supervisor.models import ProjectSupervisor from ..schemas import StudentSchema, StudentEditSchema, StudentsPaginationSchema, \ - StudentCreateSchema, MessageSchema, FileSchema, StudentQuerySchema + StudentCreateSchema, MessageSchema, FileSchema, StudentQuerySchema, StudentListFileDownloaderSchema from ...dependencies import db from ..utils import parse_csv, generate_csv from ..exceptions import InvalidNameOrTypeHeaderException @@ -126,11 +126,16 @@ def upload_students(file: dict) -> dict: @bp.route("/download/", methods=["POST"]) -def download_students() -> Response: - students = db.session.query(Student).join(Group).join(ProjectSupervisor).all() +@bp.input(StudentListFileDownloaderSchema, location='query') +def download_students(query: dict) -> Response: + mode = query.get('mode') or True + students = db.session.query(Student).join(Group).\ + join(ProjectSupervisor).filter(Student.mode == mode).all() + if len(students) == 0: abort(404, "Not found students, which are assigned to group!") csv_file = generate_csv(students) response = Response(csv_file, mimetype='text/csv') response.headers.set("Content-Disposition", "attachment", filename="students_list.csv") + print(get_debug_queries()) return response diff --git a/backend/app/coordinator/schemas.py b/backend/app/coordinator/schemas.py index c507625..94235df 100644 --- a/backend/app/coordinator/schemas.py +++ b/backend/app/coordinator/schemas.py @@ -36,6 +36,10 @@ class StudentsPaginationSchema(ma.Schema): max_pages = fields.Integer() +class StudentListFileDownloaderSchema(ma.Schema): + mode = fields.Integer() + + class StudentCreateSchema(ma.Schema): first_name = fields.Str(validate=validate.Length(min=1, max=255), required=True) last_name = fields.Str(validate=validate.Length(min=1, max=255), required=True)