diff --git a/app/app.py b/app/app.py index 11bac36..c4e09cd 100644 --- a/app/app.py +++ b/app/app.py @@ -1,8 +1,10 @@ from flask import Flask +from flask.ext.bootstrap import Bootstrap from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__) app.config.from_object('config.Configuration') +Bootstrap(app) db = SQLAlchemy(app) diff --git a/app/create_database.py b/app/create_database.py index 82caa5b..44c7b21 100644 --- a/app/create_database.py +++ b/app/create_database.py @@ -9,7 +9,8 @@ feli.configure("feliciaan", True, 0) db.session.add(feli) destro = User() -destro.configure('destro', True, 0) +destro.configure('wout', True, 0) +db.session.add(destro) # To future developers, add yourself here diff --git a/app/foodbot.py b/app/foodbot.py index 0165261..92df91e 100644 --- a/app/foodbot.py +++ b/app/foodbot.py @@ -10,7 +10,9 @@ from app import app, db from admin import admin from login import login_manager from models import * +from forms import * +from utils import * from views import * if __name__ == '__main__': - app.run(debug=True) + app.run() diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..8aa1a20 --- /dev/null +++ b/app/forms.py @@ -0,0 +1,31 @@ +from datetime import datetime, timedelta +from flask_wtf import Form +from wtforms import SelectField, DateTimeField, validators, SubmitField, HiddenField +from models import User, Location +from utils import euro + +__author__ = 'feliciaan' + + +class OrderForm(Form): + courrier_id = SelectField('Courrier', coerce=int) + location_id = SelectField('Location', coerce=int, validators=[validators.required()]) + starttime = DateTimeField('Starttime', default=datetime.now) + stoptime = DateTimeField('Stoptime') + submit_button = SubmitField('Submit') + + def populate(self): + self.courrier_id.choices = [(0, None)] + \ + [(u.id, u.username) for u in User.query.order_by('username')] + self.location_id.choices = [(l.id, l.name) + for l in Location.query.order_by('name')] + if self.stoptime.data is None: + self.stoptime.data = datetime.now() + timedelta(hours=1) + + +class OrderItemForm(Form): + food_id = SelectField('Item', coerce=int) + submit_button = SubmitField('Submit') + + def populate(self, location): + self.food_id.choices = [(i.id, (i.name + ": " + euro(i.price))) for i in location.food] \ No newline at end of file diff --git a/app/models.py b/app/models.py index 2fc7274..86ca9e5 100644 --- a/app/models.py +++ b/app/models.py @@ -43,6 +43,8 @@ class Location(db.Model): address = db.Column(db.String(254)) website = db.Column(db.String(120)) food = db.relationship('Food', backref='location', lazy='dynamic') + orders = db.relationship('Order', backref='location', lazy='dynamic') + def configure(self, name, address, website): self.name = name @@ -85,7 +87,7 @@ class Order(db.Model): self.stoptime = stoptime def __repr__(self): - return 'Order' + return 'Order %s' % (self.location.name) class OrderItem(db.Model): diff --git a/app/requirements.txt b/app/requirements.txt index 44bb7c4..b101d8f 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -3,6 +3,7 @@ Flask-Admin==1.0.9 Flask-Login==0.2.11 Flask-SQLAlchemy==2.0 Flask-WTF==0.10.3 +Flask-Bootstrap==3.3.2.1 Jinja2==2.7.2 MarkupSafe==0.23 SQLAlchemy==0.9.8 diff --git a/app/templates/about.html b/app/templates/about.html index a36d7c4..b2732d5 100644 --- a/app/templates/about.html +++ b/app/templates/about.html @@ -1,6 +1,7 @@ -{% extends "layout.html" %} - -{% block content %} +{% extends "layout.html" -%} +{% set active_page = "about" -%} + +{% block container %}
This is an About page for FoodBot. Don't I look good? Oh stop, you're making me blush.
{% endblock %} \ No newline at end of file diff --git a/app/templates/errors/401.html b/app/templates/errors/401.html new file mode 100644 index 0000000..59d7815 --- /dev/null +++ b/app/templates/errors/401.html @@ -0,0 +1,9 @@ +{% extends "layout.html" -%} + +{% block container %} + +{% endblock %} \ No newline at end of file diff --git a/app/templates/errors/404.html b/app/templates/errors/404.html new file mode 100644 index 0000000..534a1e1 --- /dev/null +++ b/app/templates/errors/404.html @@ -0,0 +1,9 @@ +{% extends "layout.html" -%} + +{% block container %} + +{% endblock %} \ No newline at end of file diff --git a/app/templates/home.html b/app/templates/home.html index 91b872c..f2bd54d 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -1,5 +1,6 @@ -{% extends "layout.html" %} -{% block content %} +{% extends "layout.html" -%} +{% set active_page = "home" -%} +{% block container %}Forgot your password? Click here to reset it.
-TOP 4
{% endblock %} \ No newline at end of file diff --git a/app/utils.py b/app/utils.py new file mode 100644 index 0000000..60150bf --- /dev/null +++ b/app/utils.py @@ -0,0 +1,17 @@ +from flask import render_template + +from app import app +__author__ = 'feliciaan' + +@app.template_filter('euro') +def euro(value): + result = '€' + str(value/100) + return result + +@app.errorhandler(404) +def handle404(e): + return render_template('errors/404.html'), 404 + +@app.errorhandler(401) +def handle401(e): + return render_template('errors/401.html'), 401 \ No newline at end of file diff --git a/app/views.py b/app/views/__init__.py similarity index 56% rename from app/views.py rename to app/views/__init__.py index d9401f0..f68989f 100644 --- a/app/views.py +++ b/app/views/__init__.py @@ -1,11 +1,20 @@ -from flask import url_for, render_template +__author__ = 'feliciaan' -from app import app +from flask import url_for, render_template, abort, redirect, request +from flask.ext.login import current_user, login_required +from datetime import datetime +from app import app, db +from models import Order, OrderItem +# import views +import views.order @app.route('/') def home(): + if not current_user.is_anonymous(): + orders = Order.query.filter((Order.stoptime > datetime.now()) | (Order.stoptime == None)).all() + return render_template('home_loggedin.html', orders=orders) return render_template('home.html') @@ -15,23 +24,25 @@ def about(): @app.route('/stats/') +@login_required def stats(): return render_template('stats.html') if app.debug: # add route information @app.route('/routes') - def list_routes(self): + @login_required + def list_routes(): import urllib output = [] for rule in app.url_map.iter_rules(): options = {} for arg in rule.arguments: options[arg] = "[{0}]".format(arg) - + print(rule.endpoint) methods = ','.join(rule.methods) url = url_for(rule.endpoint, **options) - line = urllib.unquote( + line = urllib.parse.unquote( "{:50s} {:20s} {}".format(rule.endpoint, methods, url)) output.append(line) diff --git a/app/views/order.py b/app/views/order.py new file mode 100644 index 0000000..e3f094c --- /dev/null +++ b/app/views/order.py @@ -0,0 +1,61 @@ +__author__ = 'feliciaan' +from flask import url_for, render_template, abort, redirect +from flask.ext.login import current_user, login_required +from datetime import datetime + +from app import app, db +from models import Order, OrderItem +from forms import OrderItemForm, OrderForm + + +@app.route('/order/