-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin.py
41 lines (27 loc) · 1.09 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import redirect, url_for
from flask.ext.admin import Admin, AdminIndexView, expose
from flask.ext.admin.contrib.sqla import ModelView
from flask.ext.user import current_user
import db
# Create customized index view class that handles login & registration
class MyAdminIndexView(AdminIndexView):
@expose('/')
def index(self):
if not current_user.is_authenticated():
return redirect(url_for('user.login'))
return super(MyAdminIndexView, self).index()
class UserView(ModelView):
def __init__(self, session, **kwargs):
super(UserView, self).__init__(db.User, session, **kwargs)
def is_accessible(self):
return current_user.is_authenticated()
class BumpView(ModelView):
def __init__(self, session, **kwargs):
super(BumpView, self).__init__(db.Bump, session, **kwargs)
def is_accessible(self):
return current_user.is_authenticated()
def setup(app):
admin = Admin(app, index_view=MyAdminIndexView())
admin.add_view(UserView(db.db.session))
admin.add_view(BumpView(db.db.session))
return admin