Skip to content

Commit 2b74101

Browse files
committed
FIX admin panel
1 parent 44a96f8 commit 2b74101

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
+9-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from flask_admin import Admin
2-
32
from projeto.ext.admin.views import EstacaoView, SensorView, UserView
43
from projeto.ext.api.models import Estacao, Sensor
5-
from projeto.ext.auth import UserAuth
4+
from projeto.ext.auth.models import UserAuth
65
from projeto.ext.db import db
76

8-
admin = Admin(name='FlaskAPI', template_mode='bootstrap3')
7+
admin = Admin(name="Dashboard", template_mode="bootstrap3")
98

9+
views = [
10+
UserView(UserAuth, db.session),
11+
EstacaoView(Estacao, db.session),
12+
SensorView(Sensor, db.session),
13+
]
14+
admin.add_views(*views)
1015

11-
def init_app(app):
12-
admin.add_view(EstacaoView(Estacao, db.session))
13-
admin.add_view(SensorView(Sensor, db.session))
14-
admin.add_view(UserView(UserAuth, db.session))
1516

17+
def init_app(app):
1618
admin.init_app(app)

prototipo/projeto/ext/admin/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
class AdminView(ModelView):
77
@login_required
88
def is_accessible(self):
9+
print(current_user.is_authenticated)
10+
print(current_user.is_admin)
911
if current_user.is_authenticated and current_user.is_admin:
1012
return True
1113
return False
@@ -16,6 +18,7 @@ def inaccessible_callback(self, name, **kwargs):
1618

1719

1820
class UserView(AdminView):
21+
column_list = ("id", "email", "is_admin")
1922
column_sortable_list = ()
2023

2124

0 commit comments

Comments
 (0)