2021-04-24 10:05:58 +00:00
|
|
|
from flask_admin import AdminIndexView
|
2021-04-18 23:33:46 +00:00
|
|
|
from flask_security import current_user
|
2021-05-17 14:55:04 +00:00
|
|
|
from flask import flash
|
|
|
|
from flask_admin.contrib.sqla import ModelView
|
|
|
|
|
|
|
|
from advlabdb.utils import userActiveSemester
|
|
|
|
|
2021-04-18 23:33:46 +00:00
|
|
|
|
2021-05-17 14:55:04 +00:00
|
|
|
def adminViewIsAccessible():
|
|
|
|
return current_user.has_role("admin")
|
|
|
|
|
2021-04-18 23:33:46 +00:00
|
|
|
|
2021-04-24 10:05:58 +00:00
|
|
|
class SecureAdminIndexView(AdminIndexView):
|
2021-04-18 23:33:46 +00:00
|
|
|
def is_accessible(self):
|
2021-05-17 14:55:04 +00:00
|
|
|
return adminViewIsAccessible()
|
|
|
|
|
2021-04-18 23:33:46 +00:00
|
|
|
|
2021-04-24 10:05:58 +00:00
|
|
|
class SecureModelView(ModelView):
|
|
|
|
can_export = True
|
2021-04-24 12:01:14 +00:00
|
|
|
can_set_page_size = True
|
2021-04-24 10:05:58 +00:00
|
|
|
|
2021-05-17 19:34:49 +00:00
|
|
|
list_template = "admin_list.html"
|
|
|
|
create_template = "admin_create.html"
|
|
|
|
edit_template = "admin_edit.html"
|
|
|
|
|
2021-04-18 23:33:46 +00:00
|
|
|
def is_accessible(self):
|
2021-05-17 14:55:04 +00:00
|
|
|
return adminViewIsAccessible()
|