1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Handle endpoints

This commit is contained in:
Mo 2022-06-28 16:57:55 +02:00
parent d214652ea9
commit b1a01743e2
5 changed files with 71 additions and 52 deletions

View file

@ -46,17 +46,15 @@ adminSpace = Admin(
app,
name="Admin@AdvLabDB",
url="/admin",
endpoint="adminSpace",
template_mode="bootstrap3",
index_view=customClasses.SecureAdminIndexView(name="Home", url="/admin", endpoint="adminSpace"),
index_view=customClasses.SecureAdminIndexView(name="Home", url="/admin", endpoint="admin"),
)
assistantSpace = Admin(
app,
name="Assistant@AdvLabDB",
url="/assistant",
endpoint="assistantSpace",
template_mode="bootstrap3",
index_view=customClasses.SecureAssistantIndexView(name="Home", url="/assistant", endpoint="assistantSpace"),
index_view=customClasses.SecureAssistantIndexView(name="Home", url="/assistant", endpoint="assistant"),
)
from . import models

View file

@ -414,7 +414,7 @@ class StudentView(SecureAdminModelView):
column_extra_row_actions = [
EndpointLinkRowAction(
icon_class="fa fa-history",
endpoint="experimentmark.index_view",
endpoint="admin_experiment_mark.index_view",
id_arg="flt1_0",
title="Experiments history",
)
@ -499,17 +499,17 @@ class PartStudentView(SecureAdminModelView):
column_extra_row_actions = [
StudentEndpointLinkRowAction(
icon_class="fa fa-user",
endpoint="student.details_view",
endpoint="admin_student.details_view",
title="Student",
),
GroupEndpointLinkRowAction(
icon_class="fa fa-users",
endpoint="group.details_view",
endpoint="admin_group.details_view",
title="Group",
),
PartEndpointLinkRowAction(
icon_class="fa fa-puzzle-piece",
endpoint="part.details_view",
endpoint="admin_part.details_view",
title="Part",
),
]
@ -565,6 +565,8 @@ class GroupView(SecureAdminModelView):
return CustomForm
can_view_details = True
column_display_all_relations = True
column_exclude_list = [
@ -719,7 +721,7 @@ class SemesterExperimentView(SecureAdminModelView):
column_extra_row_actions = [
ExperimentEndpointLinkRowAction(
icon_class="fa fa-flask",
endpoint="experiment.details_view",
endpoint="admin_experiment.details_view",
title="Experiment",
),
]
@ -823,7 +825,7 @@ class AssistantView(SecureAdminModelView):
column_extra_row_actions = [
UserEndpointLinkRowAction(
icon_class="fa fa-user",
endpoint="user.details_view",
endpoint="admin_user.details_view",
title="User",
),
]
@ -851,7 +853,7 @@ class AdminView(SecureAdminModelView):
column_extra_row_actions = [
UserEndpointLinkRowAction(
icon_class="fa fa-user",
endpoint="user.details_view",
endpoint="admin_user.details_view",
title="User",
),
]
@ -965,6 +967,8 @@ class GroupExperimentView(SecureAdminModelView):
note = group_experiment_note_field()
can_view_details = True
column_display_all_relations = True
column_filters = (
@ -978,12 +982,12 @@ class GroupExperimentView(SecureAdminModelView):
column_extra_row_actions = [
GroupEndpointLinkRowAction(
icon_class="fa fa-users",
endpoint="group.details_view",
endpoint="admin_group.details_view",
title="Group",
),
SemesterExperimentEndpointLinkRowAction(
icon_class="fa fa-flask",
endpoint="semesterexperiment.details_view",
endpoint="admin_semester_experiment.details_view",
title="SemesterExperiment",
),
]
@ -1080,12 +1084,12 @@ class AppointmentView(SecureAdminModelView):
column_extra_row_actions = [
GroupExperimentEndpointLinkRowAction(
icon_class="fa fa-flask",
endpoint="groupexperiment.details_view",
endpoint="admin_group_experiment.details_view",
title="GroupExperiment",
),
AssistantEndpointLinkRowAction(
icon_class="fa fa-user-secret",
endpoint="assistant.details_view",
endpoint="admin_assistant.details_view",
title="Assistant",
),
]
@ -1233,17 +1237,17 @@ class ExperimentMarkView(SecureAdminModelView):
column_extra_row_actions = [
PartStudentEndpointLinkRowAction(
icon_class="fa fa-user",
endpoint="partstudent.details_view",
endpoint="admin_part_student.details_view",
title="PartStudent",
),
GroupExperimentEndpointLinkRowAction(
icon_class="fa fa-flask",
endpoint="groupexperiment.details_view",
endpoint="admin_group_experiment.details_view",
title="GroupExperiment",
),
AssistantEndpointLinkRowAction(
icon_class="fa fa-user-secret",
endpoint="assistant.details_view",
endpoint="admin_assistant.details_view",
title="Assistant",
),
]
@ -1508,20 +1512,20 @@ class DocsView(SecureAdminBaseView):
return self.render("docs/docs.html", role="admin")
adminSpace.add_view(StudentView(Student, db.session, url="student"))
adminSpace.add_view(PartStudentView(PartStudent, db.session, url="part_student"))
adminSpace.add_view(GroupView(Group, db.session, url="group"))
adminSpace.add_view(GroupExperimentView(GroupExperiment, db.session, url="group_experiment"))
adminSpace.add_view(AppointmentView(Appointment, db.session, url="appointment"))
adminSpace.add_view(ExperimentMarkView(ExperimentMark, db.session, url="experiment_mark"))
adminSpace.add_view(ExperimentView(Experiment, db.session, url="experiment"))
adminSpace.add_view(SemesterExperimentView(SemesterExperiment, db.session, url="semester_experiment"))
adminSpace.add_view(SemesterView(Semester, db.session, url="semester"))
adminSpace.add_view(PartView(Part, db.session, url="part"))
adminSpace.add_view(AssistantView(Assistant, db.session, url="assistant"))
adminSpace.add_view(AdminView(Admin, db.session, url="admin"))
adminSpace.add_view(UserView(User, db.session, url="user"))
adminSpace.add_view(ProgramView(Program, db.session, url="program"))
adminSpace.add_view(StudentView(Student, url="student"))
adminSpace.add_view(PartStudentView(PartStudent, url="part_student"))
adminSpace.add_view(GroupView(Group, url="group"))
adminSpace.add_view(GroupExperimentView(GroupExperiment, url="group_experiment"))
adminSpace.add_view(AppointmentView(Appointment, url="appointment"))
adminSpace.add_view(ExperimentMarkView(ExperimentMark, url="experiment_mark"))
adminSpace.add_view(ExperimentView(Experiment, url="experiment"))
adminSpace.add_view(SemesterExperimentView(SemesterExperiment, url="semester_experiment"))
adminSpace.add_view(SemesterView(Semester, url="semester"))
adminSpace.add_view(PartView(Part, url="part"))
adminSpace.add_view(AssistantView(Assistant, url="assistant"))
adminSpace.add_view(AdminView(Admin, url="admin"))
adminSpace.add_view(UserView(User, url="user"))
adminSpace.add_view(ProgramView(Program, url="program"))
adminSpace.add_view(ImportView(name="Import", url="import"))
adminSpace.add_view(ActionsView(name="Actions", url="actions"))
adminSpace.add_view(AnalysisView(name="Analysis", url="analysis"))

View file

@ -60,7 +60,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
column_extra_row_actions = [
EndpointLinkRowAction(
icon_class="fa fa-pencil",
endpoint="assistant_groupexperiment.form_view",
endpoint="assistant_group_experiment.form_view",
title="Edit",
)
]
@ -225,12 +225,8 @@ class AssistantDocsView(SecureAssistantBaseView):
return self.render("docs/docs.html", role="assistant")
assistantSpace.add_view(
AssistantGroupExperimentView(
GroupExperiment, db.session, endpoint="assistant_groupexperiment", url="group_experiment"
)
)
assistantSpace.add_view(AssistantUserView(User, db.session, endpoint="assistant_user", url="user"))
assistantSpace.add_view(AssistantDocsView(name="Docs", endpoint="assistant_docs", url="docs"))
assistantSpace.add_view(AssistantGroupExperimentView(GroupExperiment, url="group_experiment"))
assistantSpace.add_view(AssistantUserView(User, url="user"))
assistantSpace.add_view(AssistantDocsView(name="Docs", url="docs"))
initActiveSemesterMenuLinks(assistantSpace)

View file

@ -28,6 +28,14 @@ def assistantViewIsAccessible():
return current_user.has_role("assistant")
def get_url(kwargs):
url = kwargs["url"]
if "/" in url:
raise ModelViewException("url can not contain a slash!")
return url
class CustomIndexView(AdminIndexView):
def inaccessible_callback(self, name, **kwargs):
# Redirect to login page if user doesn't have access
@ -205,6 +213,10 @@ class SecureAdminModelView(CustomModelView):
edit_template = "admin_edit.html"
details_template = "admin_details.html"
def __init__(self, model, **kwargs):
url = get_url(kwargs)
super().__init__(model, db.session, endpoint="admin_" + url, **kwargs)
def is_accessible(self):
return adminViewIsAccessible()
@ -232,6 +244,10 @@ class SecureAssistantModelView(CustomModelView):
can_create = False
can_delete = False
def __init__(self, model, **kwargs):
url = get_url(kwargs)
super().__init__(model, db.session, endpoint="assistant_" + url, **kwargs)
def is_accessible(self):
return assistantViewIsAccessible()
@ -305,11 +321,19 @@ class SecureAssistantModelView(CustomModelView):
class SecureAdminBaseView(BaseView):
def __init__(self, **kwargs):
url = get_url(kwargs)
super().__init__(endpoint="admin_" + url, **kwargs)
def is_accessible(self):
return adminViewIsAccessible()
class SecureAssistantBaseView(BaseView):
def __init__(self, **kwargs):
url = get_url(kwargs)
super().__init__(endpoint="assistant_" + url, **kwargs)
def is_accessible(self):
return assistantViewIsAccessible()

View file

@ -16,22 +16,19 @@ def util_processor():
@app.route("/")
def index():
if current_user.has_role("admin"):
url = url_for("index") + "admin"
if current_user.login_count == 1:
url += "/docs"
return redirect(url)
endpoint_base = "admin"
elif current_user.has_role("assistant"):
url = url_for("index") + "assistant"
if current_user.login_count == 1:
url += "/docs"
return redirect(url)
endpoint_base = "assistant"
else:
return redirect(url_for("security.login"))
if current_user.login_count == 1:
url = url_for(endpoint_base + ".docs_view")
else:
url = url_for(endpoint_base + ".index")
return redirect(url)
@app.route("/set_semester")
@auth_required()