1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Fixed markChoices and queryFilter

This commit is contained in:
Mo 2021-07-13 03:37:00 +02:00
parent 64165218ca
commit 3024d2661e

View file

@ -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):