update download student endpoint for coordinator view - generate list by mode of students
This commit is contained in:
parent
3914d19138
commit
7a90c84178
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user