mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Fixed filtering for GroupView's form
This commit is contained in:
parent
18fac6c683
commit
ab1eded4b7
2 changed files with 8 additions and 7 deletions
|
@ -5,7 +5,7 @@ from flask_admin.helpers import get_form_data
|
||||||
from flask_admin.menu import MenuLink
|
from flask_admin.menu import MenuLink
|
||||||
from flask_admin.model.template import EndpointLinkRowAction
|
from flask_admin.model.template import EndpointLinkRowAction
|
||||||
from flask_security import admin_change_password, current_user, hash_password
|
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 import BooleanField, Form, RadioField, SelectField, TextField
|
||||||
from wtforms.fields.html5 import DateField
|
from wtforms.fields.html5 import DateField
|
||||||
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
|
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
|
||||||
|
@ -371,7 +371,12 @@ class GroupView(SecureAdminModelView):
|
||||||
else:
|
else:
|
||||||
|
|
||||||
def query_factory():
|
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):
|
class CustomForm(Form):
|
||||||
part_students = QuerySelectMultipleField(
|
part_students = QuerySelectMultipleField(
|
||||||
|
|
|
@ -95,18 +95,14 @@ class Group(db.Model):
|
||||||
|
|
||||||
def check(part_students, program=None):
|
def check(part_students, program=None):
|
||||||
commonProgram = part_students[0].part.program
|
commonProgram = part_students[0].part.program
|
||||||
|
|
||||||
if program and program != commonProgram:
|
if program and program != commonProgram:
|
||||||
raise DataBaseException("Group's program and students' program mismatch!")
|
raise DataBaseException("Group's program and students' program mismatch!")
|
||||||
|
|
||||||
commonSemester = part_students[0].part.semester
|
|
||||||
|
|
||||||
for partStudent in part_students[1:]:
|
for partStudent in part_students[1:]:
|
||||||
if partStudent.part.program != commonProgram:
|
if partStudent.part.program != commonProgram:
|
||||||
raise DataBaseException(f"Part Students {part_students} are not in the same program!")
|
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):
|
def customInit(part_students):
|
||||||
Group.check(part_students)
|
Group.check(part_students)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue