admin_utils.py 649 B

12345678910111213141516171819202122
  1. from flask_admin import AdminIndexView
  2. from flask_admin.contrib.sqla import ModelView
  3. from flask_login import current_user
  4. class ProtectedAdminIndexView(AdminIndexView):
  5. def is_accessible(self):
  6. return current_user.is_authenticated() and current_user.has_admin_privs
  7. class ProtectedModelView(ModelView):
  8. page_size = 50
  9. def __init__(self, *args, **kwargs):
  10. from project import db
  11. self.form_optional_types = (db.Boolean, db.String)
  12. super(ProtectedModelView, self).__init__(*args, **kwargs)
  13. def is_accessible(self):
  14. return current_user.is_authenticated() and current_user.has_admin_privs