Added an order detail view, and open orders on the homepage

This commit is contained in:
Feliciaan De Palmenaer 2015-03-27 18:07:06 +01:00
parent 55a5c9b927
commit 6e660399a2
12 changed files with 78 additions and 36 deletions

7
app/filters.py Normal file
View file

@ -0,0 +1,7 @@
from app import app
__author__ = 'feliciaan'
@app.template_filter('euro')
def euro(value):
result = '' + str(value/100)
return result

View file

@ -10,6 +10,7 @@ from app import app, db
from admin import admin
from login import login_manager
from models import *
from filters import *
from views import *
if __name__ == '__main__':

View file

@ -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):

View file

@ -1,4 +1,5 @@
{% extends "layout.html" %}
{% extends "layout.html" -%}
{% set active_page = "about" -%}
{% block content %}
<h1>About</h1>

View file

@ -1,4 +1,5 @@
{% extends "layout.html" %}
{% extends "layout.html" -%}
{% set active_page = "home" -%}
{% block content %}
<div class="jumbotron">
<h2>Welcome to FoodBot</h2>

View 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 %}

View file

@ -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>
<html>
<head lang="en">
@ -24,9 +33,11 @@
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="{{ url_for('home') }}">Home</a></li>
<li><a href="{{ url_for('about') }}">About</a></li>
<li><a href="{{ url_for('stats') }}">Stats</a></li>
{% for id, text in navbar -%}
<li class="{{ 'active' if id == active_page else '' }}">
<a href="{{ url_for(id) }}">{{ text|e }}</a>
</li>
{% endfor -%}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if current_user.is_anonymous() %}

View file

@ -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
View 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 %}

View file

@ -1,5 +1,5 @@
{% extends "layout.html" %}
{% extends "layout.html" -%}
{% set active_page = "stats" -%}
{% block content %}
<h1>Stats bruh</h1>
<p>TOP 4</p>

View file

@ -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 models import Order
@app.route('/')
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')
@ -19,9 +25,16 @@ def stats():
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
@app.route('/routes')
def list_routes(self):
def list_routes():
import urllib
output = []
for rule in app.url_map.iter_rules():

View file

@ -60,7 +60,7 @@ def get_zeus_oauth_token():
def login_and_redirect_user(user):
login_user(user)
return redirect(url_for("admin.index"))
return redirect(url_for("index"))
def create_user(username):