haldis/app/views/__init__.py

52 lines
1.4 KiB
Python
Raw Normal View History

2015-03-28 00:02:12 +01:00
__author__ = 'feliciaan'
from flask import url_for, render_template, abort, redirect, request
2015-03-27 18:25:09 +01:00
from flask.ext.login import current_user, login_required
2015-03-28 21:25:55 +01:00
from datetime import datetime, timedelta
2015-03-26 21:49:14 +01:00
from app import app, db
2015-03-28 00:02:12 +01:00
from models import Order, OrderItem
2015-03-26 21:49:14 +01:00
2015-03-28 00:02:12 +01:00
# import views
2015-03-28 21:25:55 +01:00
from views.order import get_orders
2015-03-26 21:49:14 +01:00
@app.route('/')
def home():
2015-03-28 21:25:55 +01:00
prev_day = datetime.now() - timedelta(days=1)
recently_closed = get_orders(((Order.stoptime > prev_day) & (Order.stoptime < datetime.now())))
return render_template('home.html', orders=get_orders(), recently_closed=recently_closed)
2015-03-26 21:49:14 +01:00
@app.route('/about/')
def about():
return render_template('about.html')
@app.route('/stats/')
def stats():
return render_template('stats.html')
if app.debug: # add route information
@app.route('/routes')
2015-03-27 18:25:09 +01:00
@login_required
def list_routes():
2015-03-26 21:49:14 +01:00
import urllib
output = []
for rule in app.url_map.iter_rules():
options = {}
for arg in rule.arguments:
options[arg] = "[{0}]".format(arg)
2015-03-28 00:02:12 +01:00
print(rule.endpoint)
2015-03-26 21:49:14 +01:00
methods = ','.join(rule.methods)
url = url_for(rule.endpoint, **options)
2015-03-28 00:02:12 +01:00
line = urllib.parse.unquote(
2015-03-26 21:49:14 +01:00
"{:50s} {:20s} {}".format(rule.endpoint, methods, url))
output.append(line)
string = ''
for line in sorted(output):
string += line + "<br/>"
return string