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

Fixed filtering for GroupView's form

This commit is contained in:
Mo 2021-08-18 20:06:18 +02:00
parent 18fac6c683
commit ab1eded4b7
2 changed files with 8 additions and 7 deletions

View file

@ -5,7 +5,7 @@ from flask_admin.helpers import get_form_data
from flask_admin.menu import MenuLink
from flask_admin.model.template import EndpointLinkRowAction
from flask_security import admin_change_password, current_user, hash_password
from sqlalchemy import func, or_
from sqlalchemy import func, or_, and_
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
from wtforms.fields.html5 import DateField
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
@ -371,7 +371,12 @@ class GroupView(SecureAdminModelView):
else:
def query_factory():
return partStudentQueryFactory().filter(or_(PartStudent.group == None, PartStudent.group == group))
return partStudentQueryFactory().filter(
or_(
and_(PartStudent.group == None, PartStudent.part.has(Part.program == group.program)),
PartStudent.group == group,
)
)
class CustomForm(Form):
part_students = QuerySelectMultipleField(

View file

@ -95,18 +95,14 @@ class Group(db.Model):
def check(part_students, program=None):
commonProgram = part_students[0].part.program
if program and program != commonProgram:
raise DataBaseException("Group's program and students' program mismatch!")
commonSemester = part_students[0].part.semester
for partStudent in part_students[1:]:
if partStudent.part.program != commonProgram:
raise DataBaseException(f"Part Students {part_students} are not in the same program!")
if partStudent.part.semester != commonSemester:
raise DataBaseException(f"Part Students {part_students} are not in the same semester!")
def customInit(part_students):
Group.check(part_students)