From 3024d2661e4319bb2c8021fb2f3095f48f1e29ae Mon Sep 17 00:00:00 2001 From: Mo8it Date: Tue, 13 Jul 2021 03:37:00 +0200 Subject: [PATCH] Fixed markChoices and queryFilter --- advlabdb/modelViews.py | 66 +++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index 744fb46..ff926f8 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -186,7 +186,7 @@ class PartView(SecureModelView): form_columns = ["label", "semester"] def queryFilter(self): - return Part.id.in_([part.id for part in userActiveSemester().parts]) + return Part.semester == userActiveSemester() class StudentView(SecureModelView): @@ -223,24 +223,39 @@ def groupQueryFactory(): return Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts])) +markChoices = [(-1, "-")] + list(zip(range(16)[::-1], range(16)[::-1])) + + class PartStudentView(SecureModelView): class CreateForm(Form): def studentQueryFactory(): return Student.query student = QuerySelectField( - "Student", query_factory=studentQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-" + "Student", + query_factory=studentQueryFactory, + validators=[DataRequired()], + allow_blank=True, + blank_text="-", ) part = QuerySelectField( - "Part", query_factory=partQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-" + "Part", + query_factory=partQueryFactory, + validators=[DataRequired()], + allow_blank=True, + blank_text="-", + ) + group = QuerySelectField( + "Group", + query_factory=groupQueryFactory, + allow_blank=True, + blank_text="-", ) - group = QuerySelectField("Group", query_factory=groupQueryFactory, allow_blank=True, blank_text="-") class EditForm(CreateForm): student = None part = None - marks = range(16)[::-1] - final_part_mark = SelectField("Final Part Mark", choices=[(-1, "-")] + list(zip(marks, marks)), coerce=int) + final_part_mark = SelectField("Final Part Mark", choices=markChoices, coerce=int) form = EditForm @@ -272,13 +287,18 @@ class PartStudentView(SecureModelView): return super().update_model(form, model) +def partStudentsQueryFactory(): + return PartStudent.query.filter(PartStudent.part_id.in_([part.id for part in userActiveSemester().parts])) + + class GroupView(SecureModelView): class CreateForm(Form): - def partStudentsQueryFactory(): - return PartStudent.query.filter(PartStudent.part_id.in_([part.id for part in userActiveSemester().parts])) - part = QuerySelectField( - "Part", query_factory=partQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-" + "Part", + query_factory=partQueryFactory, + validators=[DataRequired()], + allow_blank=True, + blank_text="-", ) part_students = QuerySelectMultipleField("Part Students", query_factory=partStudentsQueryFactory) @@ -380,7 +400,11 @@ class GroupExperimentView(SecureModelView): return SemesterExperiment.query.filter(SemesterExperiment.semester == userActiveSemester()) group = QuerySelectField( - "Group", query_factory=groupQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-" + "Group", + query_factory=groupQueryFactory, + validators=[DataRequired()], + allow_blank=True, + blank_text="-", ) semester_experiment = QuerySelectField( "Semester Experiment", @@ -416,7 +440,10 @@ class GroupExperimentView(SecureModelView): def queryFilter(self): return GroupExperiment.group_id.in_( - [g.id for g in Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts]))] + [ + group.id + for group in Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts])) + ] ) def create_model(self, form): @@ -465,7 +492,11 @@ def groupExperimentQueryFactory(): class AppointmentView(SecureModelView): class CreateForm(Form): group_experiment = QuerySelectField( - "Group Experiment", query_factory=groupExperimentQueryFactory, validators=[DataRequired()] + "Group Experiment", + query_factory=groupExperimentQueryFactory, + validators=[DataRequired()], + allow_blank=True, + blank_text="-", ) date = DateField("Date", validators=[DataRequired()]) special = BooleanField("Special", default=False) @@ -565,13 +596,8 @@ class ExperimentMarkView(SecureModelView): ] def queryFilter(self=None): - return GroupExperiment.semester_experiment_id.in_( - [ - semesterExperiment.id - for semesterExperiment in SemesterExperiment.query.filter( - SemesterExperiment.semester == userActiveSemester() - ) - ] + return ExperimentMark.group_experiment_id.in_( + groupExperiment.id for groupExperiment in groupExperimentQueryFactory() ) def checkForm(form):