1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +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, app,
name="Admin@AdvLabDB", name="Admin@AdvLabDB",
url="/admin", url="/admin",
endpoint="adminSpace",
template_mode="bootstrap3", 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( assistantSpace = Admin(
app, app,
name="Assistant@AdvLabDB", name="Assistant@AdvLabDB",
url="/assistant", url="/assistant",
endpoint="assistantSpace",
template_mode="bootstrap3", 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 from . import models

View file

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

View file

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

View file

@ -28,6 +28,14 @@ def assistantViewIsAccessible():
return current_user.has_role("assistant") 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): class CustomIndexView(AdminIndexView):
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
@ -205,6 +213,10 @@ class SecureAdminModelView(CustomModelView):
edit_template = "admin_edit.html" edit_template = "admin_edit.html"
details_template = "admin_details.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): def is_accessible(self):
return adminViewIsAccessible() return adminViewIsAccessible()
@ -232,6 +244,10 @@ class SecureAssistantModelView(CustomModelView):
can_create = False can_create = False
can_delete = 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): def is_accessible(self):
return assistantViewIsAccessible() return assistantViewIsAccessible()
@ -305,11 +321,19 @@ class SecureAssistantModelView(CustomModelView):
class SecureAdminBaseView(BaseView): class SecureAdminBaseView(BaseView):
def __init__(self, **kwargs):
url = get_url(kwargs)
super().__init__(endpoint="admin_" + url, **kwargs)
def is_accessible(self): def is_accessible(self):
return adminViewIsAccessible() return adminViewIsAccessible()
class SecureAssistantBaseView(BaseView): class SecureAssistantBaseView(BaseView):
def __init__(self, **kwargs):
url = get_url(kwargs)
super().__init__(endpoint="assistant_" + url, **kwargs)
def is_accessible(self): def is_accessible(self):
return assistantViewIsAccessible() return assistantViewIsAccessible()

View file

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