mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Deduplicate index_view
This commit is contained in:
parent
2de977e1c1
commit
99703439a3
2 changed files with 36 additions and 44 deletions
|
@ -80,12 +80,6 @@ def semesterFilterOptions():
|
|||
|
||||
|
||||
class UserView(SecureAdminModelView):
|
||||
@expose("/")
|
||||
def index_view(self):
|
||||
# To update filter options
|
||||
self._refresh_filters_cache()
|
||||
return super().index_view()
|
||||
|
||||
class SemesterFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
return semesterFilterOptions()
|
||||
|
@ -162,10 +156,13 @@ class UserView(SecureAdminModelView):
|
|||
"last_name",
|
||||
"email",
|
||||
]
|
||||
|
||||
column_filters = (
|
||||
SemesterFilter(User, "Active Semester"),
|
||||
"active",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_editable_list = [
|
||||
"active",
|
||||
]
|
||||
|
@ -445,12 +442,6 @@ def partFilterOptions():
|
|||
|
||||
|
||||
class PartStudentView(SecureAdminModelView):
|
||||
@expose("/")
|
||||
def index_view(self):
|
||||
# To update filter options
|
||||
self._refresh_filters_cache()
|
||||
return super().index_view()
|
||||
|
||||
class PartFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
return partFilterOptions()
|
||||
|
@ -515,6 +506,7 @@ class PartStudentView(SecureAdminModelView):
|
|||
"group.number",
|
||||
"experiment_marks",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_extra_row_actions = [
|
||||
StudentEndpointLinkRowAction(
|
||||
|
@ -545,18 +537,16 @@ def partStudentQueryFactory():
|
|||
return PartStudent.query.filter(PartStudent.part.has(Part.semester == userActiveSemester()))
|
||||
|
||||
|
||||
class GroupView(SecureAdminModelView):
|
||||
@expose("/")
|
||||
def index_view(self):
|
||||
# To update filter options
|
||||
self._refresh_filters_cache()
|
||||
return super().index_view()
|
||||
|
||||
class ProgramFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
def programFilterOptions():
|
||||
programs = Program.query
|
||||
return tuple((program.id, program.repr()) for program in programs)
|
||||
|
||||
|
||||
class GroupView(SecureAdminModelView):
|
||||
class ProgramFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
return programFilterOptions()
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
return query.filter(self.column.program_id == int(value))
|
||||
|
||||
|
@ -595,10 +585,12 @@ class GroupView(SecureAdminModelView):
|
|||
"group_experiments",
|
||||
]
|
||||
column_details_list = column_list
|
||||
|
||||
column_filters = (
|
||||
ProgramFilter(Group, "Program"),
|
||||
"number",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
def queryFilter(self):
|
||||
return Group.semester == userActiveSemester()
|
||||
|
@ -618,8 +610,7 @@ class GroupView(SecureAdminModelView):
|
|||
class ExperimentView(SecureAdminModelView):
|
||||
class ProgramFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
programs = Program.query
|
||||
return tuple((program.id, program.repr()) for program in programs)
|
||||
return programFilterOptions()
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
return query.filter(self.column.program_id == int(value))
|
||||
|
@ -630,6 +621,8 @@ class ExperimentView(SecureAdminModelView):
|
|||
ProgramFilter(Experiment, "Program"),
|
||||
"active",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_list = [
|
||||
"number",
|
||||
"program",
|
||||
|
@ -679,8 +672,7 @@ def assistantQueryFactory():
|
|||
class SemesterExperimentView(SecureAdminModelView):
|
||||
class ProgramFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
programs = Program.query
|
||||
return tuple((program.id, program.repr()) for program in programs)
|
||||
return programFilterOptions()
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
return query.filter(self.column.experiment.has(Experiment.program_id == int(value)))
|
||||
|
@ -743,7 +735,10 @@ class SemesterExperimentView(SecureAdminModelView):
|
|||
"final_weighting",
|
||||
"group_experiments",
|
||||
]
|
||||
|
||||
column_filters = (ProgramFilter(SemesterExperiment, "Program"),)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_searchable_list = [
|
||||
"experiment.number",
|
||||
"experiment.title",
|
||||
|
@ -889,12 +884,6 @@ def experimentFilterOptions():
|
|||
|
||||
|
||||
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):
|
||||
return experimentFilterOptions()
|
||||
|
@ -971,12 +960,14 @@ class GroupExperimentView(SecureAdminModelView):
|
|||
"experiment_marks",
|
||||
]
|
||||
column_details_list = column_list
|
||||
|
||||
column_filters = (
|
||||
ExperimentFilter(GroupExperiment, "Experiment"),
|
||||
"group.number",
|
||||
"appointments",
|
||||
"experiment_marks",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_extra_row_actions = [
|
||||
GroupEndpointLinkRowAction(
|
||||
|
@ -1029,12 +1020,6 @@ def assistantFilterOptions():
|
|||
|
||||
|
||||
class AppointmentView(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):
|
||||
return experimentFilterOptions()
|
||||
|
@ -1096,6 +1081,8 @@ class AppointmentView(SecureAdminModelView):
|
|||
"date",
|
||||
"special",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_editable_list = [
|
||||
"date",
|
||||
"special",
|
||||
|
@ -1147,12 +1134,6 @@ class AppointmentView(SecureAdminModelView):
|
|||
|
||||
|
||||
class ExperimentMarkView(SecureAdminModelView):
|
||||
@expose("/")
|
||||
def index_view(self):
|
||||
# To update filter options
|
||||
self._refresh_filters_cache()
|
||||
return super().index_view()
|
||||
|
||||
class StudentFilter(FilterEqual):
|
||||
def validate(self, value):
|
||||
if Student.query.get(value):
|
||||
|
@ -1202,8 +1183,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
|
||||
class ProgramFilter(FilterEqual):
|
||||
def get_options(self, view):
|
||||
programs = Program.query
|
||||
return tuple((program.id, program.repr()) for program in programs)
|
||||
return programFilterOptions()
|
||||
|
||||
def apply(self, query, value, alias=None):
|
||||
return query.filter(self.column.part_student.has(PartStudent.part.has(Part.program_id == int(value))))
|
||||
|
@ -1287,6 +1267,8 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
"protocol_mark",
|
||||
"final_experiment_mark",
|
||||
)
|
||||
refreshFiltersCache = True
|
||||
|
||||
column_default_sort = [("oral_mark", False), ("protocol_mark", False)]
|
||||
|
||||
column_extra_row_actions = [
|
||||
|
|
|
@ -93,6 +93,16 @@ class CustomModelView(ModelView):
|
|||
|
||||
can_view_details = False
|
||||
|
||||
refreshFiltersCache = False
|
||||
|
||||
@expose("/")
|
||||
def index_view(self):
|
||||
if self.refreshFiltersCache:
|
||||
# Update filter options
|
||||
self._refresh_filters_cache()
|
||||
|
||||
return super().index_view()
|
||||
|
||||
def inaccessible_callback(self, name, **kwargs):
|
||||
# Redirect to login page if user doesn't have access
|
||||
return redirect(url_for("security.login", next=request.url))
|
||||
|
|
Loading…
Reference in a new issue