mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
33 lines
895 B
Python
33 lines
895 B
Python
from flask_admin import AdminIndexView
|
|
from flask_security import current_user
|
|
from flask import flash
|
|
from flask_admin.contrib.sqla import ModelView
|
|
|
|
from advlabdb.utils import userActiveSemester
|
|
|
|
|
|
def adminViewIsAccessible():
|
|
return current_user.has_role("admin")
|
|
|
|
def handleAdminView():
|
|
flash("User active semester: " + userActiveSemester(flashWarning=True).label)
|
|
|
|
class SecureAdminIndexView(AdminIndexView):
|
|
def is_accessible(self):
|
|
return adminViewIsAccessible()
|
|
|
|
def _handle_view(self, *args, **kwargs):
|
|
handleAdminView()
|
|
return super()._handle_view(*args, **kwargs)
|
|
|
|
|
|
class SecureModelView(ModelView):
|
|
can_export = True
|
|
can_set_page_size = True
|
|
|
|
def is_accessible(self):
|
|
return adminViewIsAccessible()
|
|
|
|
def _handle_view(self, *args, **kwargs):
|
|
handleAdminView()
|
|
return super()._handle_view(*args, **kwargs)
|