haldis/app/admin.py

37 lines
999 B
Python
Raw Normal View History

2015-03-26 22:17:50 +01:00
from flask.ext.admin import Admin
2015-03-26 21:49:14 +01:00
from flask.ext.admin.contrib.sqla import ModelView
from flask.ext import login
from app import app, db
2015-03-26 23:17:51 +01:00
from models import User, Location, Food, Order, OrderItem
2015-03-26 22:17:50 +01:00
2015-03-26 21:49:14 +01:00
class ModelBaseView(ModelView):
def is_accessible(self):
if login.current_user.is_anonymous():
return False
return login.current_user.is_admin()
class UserAdminModel(ModelBaseView):
column_searchable_list = ('username',)
inline_models = None
2015-03-26 23:17:51 +01:00
class LocationAdminModel(ModelBaseView):
column_searchable_list = ('name', 'address', 'website')
inline_models = None
form_columns = ('name', 'address', 'website')
2015-03-26 21:49:14 +01:00
admin = Admin(app, name='FoodBot', url='/admin', template_mode='bootstrap3')
2015-03-26 21:49:14 +01:00
admin.add_view(UserAdminModel(User, db.session))
2015-03-26 23:17:51 +01:00
admin.add_view(LocationAdminModel(Location, db.session))
admin.add_view(ModelBaseView(Food, db.session))
admin.add_view(ModelBaseView(Order, db.session))
admin.add_view(ModelBaseView(OrderItem, db.session))