mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Add custom filters
This commit is contained in:
parent
205d90f88a
commit
978dfd340f
3 changed files with 51 additions and 5 deletions
File diff suppressed because one or more lines are too long
|
@ -44,6 +44,7 @@ from advlabdb.models import (
|
|||
SemesterExperiment,
|
||||
Student,
|
||||
User,
|
||||
Admin,
|
||||
)
|
||||
from advlabdb.utils import (
|
||||
flashRandomPassword,
|
||||
|
@ -494,7 +495,6 @@ class GroupView(SecureAdminModelView):
|
|||
]
|
||||
column_filters = [
|
||||
"number",
|
||||
"semester",
|
||||
"program",
|
||||
]
|
||||
|
||||
|
@ -682,10 +682,44 @@ class AssistantView(SecureAdminModelView):
|
|||
}
|
||||
|
||||
|
||||
# TODO: Add AdminView
|
||||
|
||||
|
||||
assistantBlankText = "Auto assign if experiment has only one assistant"
|
||||
|
||||
|
||||
class GroupExperimentView(SecureAdminModelView):
|
||||
@expose("/")
|
||||
def index_view(self):
|
||||
# To update filter options
|
||||
self._refresh_filters_cache()
|
||||
return super().index_view()
|
||||
|
||||
class ExperimentFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
activeExperiments = Experiment.query.filter(Experiment.active == True).all()
|
||||
return (
|
||||
(
|
||||
f"{activeExperiment.number},{activeExperiment.program.id}",
|
||||
f"{activeExperiment.number} {activeExperiment.program.repr()}",
|
||||
)
|
||||
for activeExperiment in activeExperiments
|
||||
)
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
values = value.split(",")
|
||||
experimentNumber = int(values[0])
|
||||
programId = int(values[1])
|
||||
|
||||
return query.filter(
|
||||
self.column.semester_experiment.has(
|
||||
SemesterExperiment.experiment.has(Experiment.program_id == programId)
|
||||
),
|
||||
self.column.semester_experiment.has(
|
||||
SemesterExperiment.experiment.has(Experiment.number == experimentNumber)
|
||||
),
|
||||
)
|
||||
|
||||
class CreateForm(Form):
|
||||
group = QuerySelectField(
|
||||
"Group",
|
||||
|
@ -738,7 +772,7 @@ class GroupExperimentView(SecureAdminModelView):
|
|||
]
|
||||
column_filters = [
|
||||
"group",
|
||||
"semester_experiment.experiment",
|
||||
ExperimentFilter(GroupExperiment, "Experiment"),
|
||||
"appointments",
|
||||
]
|
||||
|
||||
|
@ -857,6 +891,17 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
assistants = Assistant.query.filter(Assistant.user.has(User.active == True)).all()
|
||||
return ((assistant.id, assistant.repr()) for assistant in assistants)
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
return query.filter(self.column == int(value))
|
||||
|
||||
class AdminFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
admins = Admin.query.filter(Admin.user.has(User.active == True)).all()
|
||||
return ((admin.id, admin.repr()) for admin in admins)
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
return query.filter(self.column == int(value))
|
||||
|
||||
class CreateForm(Form):
|
||||
part_student = QuerySelectField(
|
||||
"Part Student",
|
||||
|
@ -897,13 +942,14 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
|
||||
column_filters = [
|
||||
StudentFilter(PartStudent.id, "Student / ID"),
|
||||
AssistantFilter(ExperimentMark.assistant_id, "Assistant"),
|
||||
AdminFilter(ExperimentMark.admin_id, "Admin"),
|
||||
"part_student.part.program",
|
||||
"part_student.part",
|
||||
"part_student.student",
|
||||
"group_experiment.group",
|
||||
"group_experiment.semester_experiment.semester",
|
||||
"group_experiment.semester_experiment.experiment",
|
||||
AssistantFilter(Assistant.id, "Assistant"),
|
||||
"oral_mark",
|
||||
"protocol_mark",
|
||||
"final_experiment_mark",
|
||||
|
|
|
@ -562,7 +562,7 @@ class Role(db.Model, FsRoleMixin):
|
|||
|
||||
class Program(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
label = db.Column(db.String(25), nullable=False)
|
||||
label = db.Column(db.String(25), nullable=False, unique=True)
|
||||
|
||||
parts = db.relationship("Part", backref="program", lazy=True)
|
||||
experiments = db.relationship("Experiment", backref="program", lazy=True)
|
||||
|
|
Loading…
Reference in a new issue