Added an order detail view, and open orders on the homepage
This commit is contained in:
parent
55a5c9b927
commit
6e660399a2
12 changed files with 78 additions and 36 deletions
7
app/filters.py
Normal file
7
app/filters.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from app import app
|
||||||
|
__author__ = 'feliciaan'
|
||||||
|
|
||||||
|
@app.template_filter('euro')
|
||||||
|
def euro(value):
|
||||||
|
result = '€' + str(value/100)
|
||||||
|
return result
|
|
@ -10,6 +10,7 @@ from app import app, db
|
||||||
from admin import admin
|
from admin import admin
|
||||||
from login import login_manager
|
from login import login_manager
|
||||||
from models import *
|
from models import *
|
||||||
|
from filters import *
|
||||||
from views import *
|
from views import *
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -43,6 +43,8 @@ class Location(db.Model):
|
||||||
address = db.Column(db.String(254))
|
address = db.Column(db.String(254))
|
||||||
website = db.Column(db.String(120))
|
website = db.Column(db.String(120))
|
||||||
food = db.relationship('Food', backref='location', lazy='dynamic')
|
food = db.relationship('Food', backref='location', lazy='dynamic')
|
||||||
|
orders = db.relationship('Order', backref='location', lazy='dynamic')
|
||||||
|
|
||||||
|
|
||||||
def configure(self, name, address, website):
|
def configure(self, name, address, website):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -85,7 +87,7 @@ class Order(db.Model):
|
||||||
self.stoptime = stoptime
|
self.stoptime = stoptime
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'Order'
|
return 'Order %s' % (self.location.name)
|
||||||
|
|
||||||
|
|
||||||
class OrderItem(db.Model):
|
class OrderItem(db.Model):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" -%}
|
||||||
|
{% set active_page = "about" -%}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>About</h1>
|
<h1>About</h1>
|
||||||
<p>This is an About page for FoodBot. Don't I look good? Oh stop, you're making me blush.</p>
|
<p>This is an About page for FoodBot. Don't I look good? Oh stop, you're making me blush.</p>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" -%}
|
||||||
|
{% set active_page = "home" -%}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h2>Welcome to FoodBot</h2>
|
<h2>Welcome to FoodBot</h2>
|
||||||
|
|
14
app/templates/home_loggedin.html
Normal file
14
app/templates/home_loggedin.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends "home.html" %}
|
||||||
|
{% block content %}
|
||||||
|
{{ super() }}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
<h3>Open orders:</h3>
|
||||||
|
<ul>
|
||||||
|
{% for order in orders %}
|
||||||
|
<li><a href="{{ url_for('order', id=order.id) }}">{{ order.location.name }}-{{ order.stoptime }}</a></li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1,3 +1,12 @@
|
||||||
|
{% set navbar = [
|
||||||
|
('home', 'Home'),
|
||||||
|
('about', 'About'),
|
||||||
|
('stats', 'Stats'),
|
||||||
|
] -%}
|
||||||
|
{% if current_user.is_admin() -%}
|
||||||
|
{% set navbar = navbar + [('admin.index', 'Admin')] -%}
|
||||||
|
{% endif -%}
|
||||||
|
{% set active_page = active_page|default('index') -%}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head lang="en">
|
<head lang="en">
|
||||||
|
@ -24,9 +33,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="navbar-collapse collapse">
|
<div id="navbar" class="navbar-collapse collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li><a href="{{ url_for('home') }}">Home</a></li>
|
{% for id, text in navbar -%}
|
||||||
<li><a href="{{ url_for('about') }}">About</a></li>
|
<li class="{{ 'active' if id == active_page else '' }}">
|
||||||
<li><a href="{{ url_for('stats') }}">Stats</a></li>
|
<a href="{{ url_for(id) }}">{{ text|e }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor -%}
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
{% if current_user.is_anonymous() %}
|
{% if current_user.is_anonymous() %}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
{% extends "layout.html" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<section class="container">
|
|
||||||
<div class="login">
|
|
||||||
<h1>Login with Zeus-Account</h1>
|
|
||||||
<form method="post" action="{{ url_for('home') }}">
|
|
||||||
<p><input type="text" name="login" value="" placeholder="Zeus e-mail "></p>
|
|
||||||
<p><input type="password" name="password" value="" placeholder="Password"></p>
|
|
||||||
<p class="remember_me">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" name="remember_me" id="remember_me">
|
|
||||||
Remember me on this computer
|
|
||||||
</label>
|
|
||||||
</p>
|
|
||||||
<p class="submit"><input type="submit" name="commit" value="Login"></p>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="login-help">
|
|
||||||
<p>Forgot your password? <a href="{{ url_for('home') }}">Click here to reset it</a>.</p>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{% endblock %}
|
|
16
app/templates/order.html
Normal file
16
app/templates/order.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12"><!-- Shitty html-->
|
||||||
|
<h3>Order {{ order.id }}</h3>
|
||||||
|
Courrier: {{ order.courrier.username }}<br/>
|
||||||
|
Location: <a href="{{ order.location.website }}">{{ order.location.name }}</a><br/>
|
||||||
|
Starttime: {{ order.starttime }}<br/>
|
||||||
|
Stoptime: {{ order.stoptime }}<br/>
|
||||||
|
<h3>Orders</h3>
|
||||||
|
{% for item in order.orders %}
|
||||||
|
{{ item.user.username }} - {{ item.food.name }} - {{ item.food.price|euro }}<br/>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" -%}
|
||||||
|
{% set active_page = "stats" -%}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Stats bruh</h1>
|
<h1>Stats bruh</h1>
|
||||||
<p>TOP 4</p>
|
<p>TOP 4</p>
|
||||||
|
|
17
app/views.py
17
app/views.py
|
@ -1,11 +1,17 @@
|
||||||
from flask import url_for, render_template
|
from flask import url_for, render_template, abort
|
||||||
|
from flask.ext.login import current_user
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
|
from models import Order
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
|
if not current_user.is_anonymous():
|
||||||
|
orders = Order.query.filter(Order.stoptime > datetime.now()).all()
|
||||||
|
return render_template('home_loggedin.html', orders=orders)
|
||||||
return render_template('home.html')
|
return render_template('home.html')
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,9 +25,16 @@ def stats():
|
||||||
return render_template('stats.html')
|
return render_template('stats.html')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/order/<int:id>')
|
||||||
|
def order(id):
|
||||||
|
order = Order.query.filter(Order.id == id).first()
|
||||||
|
if order is not None:
|
||||||
|
return render_template('order.html', order=order)
|
||||||
|
return abort(404)
|
||||||
|
|
||||||
if app.debug: # add route information
|
if app.debug: # add route information
|
||||||
@app.route('/routes')
|
@app.route('/routes')
|
||||||
def list_routes(self):
|
def list_routes():
|
||||||
import urllib
|
import urllib
|
||||||
output = []
|
output = []
|
||||||
for rule in app.url_map.iter_rules():
|
for rule in app.url_map.iter_rules():
|
||||||
|
|
|
@ -60,7 +60,7 @@ def get_zeus_oauth_token():
|
||||||
|
|
||||||
def login_and_redirect_user(user):
|
def login_and_redirect_user(user):
|
||||||
login_user(user)
|
login_user(user)
|
||||||
return redirect(url_for("admin.index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
def create_user(username):
|
def create_user(username):
|
||||||
|
|
Loading…
Reference in a new issue