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