mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Fixed adding students to a group
This commit is contained in:
parent
1787a84d30
commit
58d1ec73b5
1 changed files with 27 additions and 8 deletions
|
@ -3,7 +3,7 @@ from flask_admin.contrib.sqla.filters import BaseSQLAFilter
|
|||
from flask_admin.menu import MenuLink
|
||||
from flask_admin.model.template import EndpointLinkRowAction
|
||||
from flask_security import current_user, hash_password, admin_change_password
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import func, or_
|
||||
from wtforms import Form, BooleanField, SelectField, TextField, RadioField
|
||||
from wtforms.validators import DataRequired, Email, Optional, URL
|
||||
from flask_admin.contrib.sqla.fields import QuerySelectMultipleField, QuerySelectField
|
||||
|
@ -297,17 +297,28 @@ class PartStudentView(SecureModelView):
|
|||
return super().update_model(form, model)
|
||||
|
||||
|
||||
def partStudentsQueryFactory():
|
||||
def partStudentQueryFactory():
|
||||
return PartStudent.query.filter(PartStudent.part_id.in_([part.id for part in userActiveSemester().parts]))
|
||||
|
||||
|
||||
class GroupView(SecureModelView):
|
||||
class CreateForm(Form):
|
||||
def formFactory(create, group):
|
||||
if create:
|
||||
|
||||
def query_factory():
|
||||
return partStudentQueryFactory().filter(PartStudent.group == None)
|
||||
|
||||
else:
|
||||
|
||||
def query_factory():
|
||||
return partStudentQueryFactory().filter(or_(PartStudent.group == None, PartStudent.group == group))
|
||||
|
||||
class CustomForm(Form):
|
||||
part_students = QuerySelectMultipleField(
|
||||
"Part Students", query_factory=partStudentsQueryFactory, validators=[DataRequired()]
|
||||
"Part Students", query_factory=query_factory, validators=[DataRequired()]
|
||||
)
|
||||
|
||||
form = CreateForm
|
||||
return CustomForm
|
||||
|
||||
column_list = ["number", "semester", "program", "part_students", "group_experiments"]
|
||||
column_filters = ["number", "semester", "program"]
|
||||
|
@ -338,6 +349,14 @@ class GroupView(SecureModelView):
|
|||
else:
|
||||
return super().update_model(form, model)
|
||||
|
||||
def create_form(self, obj=None):
|
||||
form = GroupView.formFactory(create=True, group=None)
|
||||
return form(get_form_data(), obj=obj)
|
||||
|
||||
def edit_form(self, obj=None):
|
||||
form = GroupView.formFactory(create=False, group=obj)
|
||||
return form(get_form_data(), obj=obj)
|
||||
|
||||
|
||||
class ExperimentView(SecureModelView):
|
||||
can_view_details = True
|
||||
|
@ -623,7 +642,7 @@ class ExperimentMarkView(SecureModelView):
|
|||
class CreateForm(Form):
|
||||
part_student = QuerySelectField(
|
||||
"Part Student",
|
||||
query_factory=partStudentsQueryFactory,
|
||||
query_factory=partStudentQueryFactory,
|
||||
validators=[DataRequired()],
|
||||
allow_blank=True,
|
||||
blank_text="-",
|
||||
|
|
Loading…
Reference in a new issue