Coverage for shopyo_admin.py : 55%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from flask import redirect
2from flask import request
3from flask import url_for
4from flask_admin import AdminIndexView
5from flask_admin import expose
6from flask_admin.contrib import sqla as flask_admin_sqla
7from flask_login import current_user
10class DefaultModelView(flask_admin_sqla.ModelView):
11 def __init__(self, *args, **kwargs):
12 super().__init__(*args, **kwargs)
14 def is_accessible(self):
15 return current_user.is_authenticated and current_user.is_admin
17 def inaccessible_callback(self, name, **kwargs):
18 # redirect to login page if user doesn't have access
19 return redirect(url_for("auth.login", next=request.url))
22class MyAdminIndexView(AdminIndexView):
23 def is_accessible(self):
24 return current_user.is_authenticated and current_user.is_admin
26 def inaccessible_callback(self, name, **kwargs):
27 # redirect to login page if user doesn't have access
28 return redirect(url_for("auth.login", next=request.url))
30 @expose("/")
31 def index(self):
32 if not current_user.is_authenticated and current_user.is_admin:
33 return redirect(url_for("auth.login"))
34 return super().index()
36 @expose("/dashboard")
37 def indexs(self):
38 if not current_user.is_authenticated and current_user.is_admin:
39 return redirect(url_for("auth.login"))
40 return super().index()