lol admin interface

This commit is contained in:
Feliciaan De Palmenaer 2015-03-26 23:17:51 +01:00
parent 4e2780d9be
commit e58ed018bd
5 changed files with 23 additions and 4 deletions

View file

@ -4,7 +4,7 @@ from flask.ext import login
from app import app, db from app import app, db
from models import User from models import User, Location, Food, Order, OrderItem
@ -20,8 +20,18 @@ class ModelBaseView(ModelView):
class UserAdminModel(ModelBaseView): class UserAdminModel(ModelBaseView):
column_searchable_list = ('username',) column_searchable_list = ('username',)
inline_models = None inline_models = None
form_columns = ('username', 'admin')
class LocationAdminModel(ModelBaseView):
column_searchable_list = ('name', 'address', 'website')
inline_models = None
form_columns = ('name', 'address', 'website')
admin = Admin(app, name='FoodBot', url='/foodbot/admin', template_mode='bootstrap3') admin = Admin(app, name='FoodBot', url='/foodbot/admin', template_mode='bootstrap3')
admin.add_view(UserAdminModel(User, db.session)) admin.add_view(UserAdminModel(User, db.session))
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))

View file

@ -1,3 +1,8 @@
# TEMPORARY ## SHOULD BE DELETED AFTER KELDER.ZEUS HAS THEIR CERTIFICATE
import os
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
from views import * from views import *
from app import app, db from app import app, db

View file

@ -6,7 +6,8 @@ class User(db.Model):
username = db.Column(db.String(80), unique=True) username = db.Column(db.String(80), unique=True)
admin = db.Column(db.Boolean) admin = db.Column(db.Boolean)
bias = db.Column(db.Integer) bias = db.Column(db.Integer)
orders = db.relationship('Order', backref='courrier', lazy='dynamic') runs = db.relationship('Order', backref='courrier', lazy='dynamic')
orders = db.relationship('OrderItem', backref='user', lazy='dynamic')
def configure(self, username, admin, bias): def configure(self, username, admin, bias):
self.username = username self.username = username
@ -56,6 +57,8 @@ class Food(db.Model):
location_id = db.Column(db.Integer, db.ForeignKey('location.id')) location_id = db.Column(db.Integer, db.ForeignKey('location.id'))
name = db.Column(db.String(120)) name = db.Column(db.String(120))
price = db.Column(db.Integer) price = db.Column(db.Integer)
orders = db.relationship('OrderItem', backref='food', lazy='dynamic')
def configure(self, location, name, price): def configure(self, location, name, price):
self.location = location self.location = location
@ -84,6 +87,7 @@ class Order(db.Model):
def __repr__(self): def __repr__(self):
return 'Order' return 'Order'
class OrderItem(db.Model): class OrderItem(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

View file

@ -8,7 +8,6 @@ MarkupSafe==0.23
SQLAlchemy==0.9.8 SQLAlchemy==0.9.8
WTForms==2.0 WTForms==2.0
Werkzeug==0.9.6 Werkzeug==0.9.6
flup==1.0.2
itsdangerous==0.24 itsdangerous==0.24
requests==2.4.0 requests==2.4.0
Flask-OAuthlib==0.8.0 Flask-OAuthlib==0.8.0

View file

@ -15,6 +15,7 @@
<li><a href="{{ url_for('home') }}">Home</a></li> <li><a href="{{ url_for('home') }}">Home</a></li>
<li><a href="{{ url_for('stats') }}">Stats</a></li> <li><a href="{{ url_for('stats') }}">Stats</a></li>
<li><a href="{{ url_for('about') }}">About</a></li> <li><a href="{{ url_for('about') }}">About</a></li>
<li><a href="{{ url_for('login') }}">Login</a></li>
</ul> </ul>
</nav> </nav>
</div> </div>