haldis/app/views/__init__.py

86 lines
2.3 KiB
Python
Raw Normal View History

2015-03-31 20:15:22 +02:00
from datetime import datetime, timedelta
2019-02-13 20:25:44 +01:00
from flask import url_for, render_template, abort, send_from_directory
2017-01-06 12:05:31 +01:00
from flask_login import login_required
2019-02-13 20:25:44 +01:00
import os
2016-09-10 15:49:52 +02:00
from app import app
from models import Order, Location
2015-03-31 20:15:22 +02:00
# import views
from views.order import get_orders
2016-09-10 15:49:52 +02:00
from views import stats
2015-03-31 20:15:22 +02:00
@app.route('/')
def home():
prev_day = datetime.now() - timedelta(days=1)
2016-09-10 15:49:52 +02:00
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-31 20:15:22 +02:00
@app.route('/map', defaults= {'id': None})
2019-02-14 16:43:07 +01:00
@app.route('/map/<int:id>')
def map(id):
locs = Location.query.order_by('name')
return render_template('maps.html', locations= locs)
2016-08-01 23:40:04 +02:00
@app.route('/location')
def locations():
locs = Location.query.order_by('name')
return render_template('locations.html', locations=locs)
@app.route('/location/<int:id>')
def location(id):
2016-09-10 15:49:52 +02:00
loc = Location.query.filter(Location.id == id).first()
2016-08-01 23:40:04 +02:00
if loc is None:
abort(404)
return render_template('location.html', location=loc)
2016-09-10 15:49:52 +02:00
2015-03-31 20:15:22 +02:00
@app.route('/about/')
def about():
2016-09-10 15:49:52 +02:00
return render_template('about.html')
2015-03-31 20:15:22 +02:00
2015-06-05 11:39:34 +02:00
@app.route('/profile/')
@login_required
def profile():
return render_template('profile.html')
2015-03-31 20:15:22 +02:00
2019-02-13 20:25:44 +01:00
@app.route('/favicon.ico')
def favicon():
2019-02-13 21:41:07 +01:00
if len(get_orders((Order.stoptime > datetime.now()))) == 0:
return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/x-icon')
else:
return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon_orange.ico', mimetype='image/x-icon')
2019-02-13 20:25:44 +01:00
2015-03-31 20:15:22 +02:00
if app.debug: # add route information
@app.route('/routes')
@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.parse.unquote(
"{:50s} {:20s} {}".format(rule.endpoint, methods, url))
output.append(line)
string = ''
for line in sorted(output):
string += line + "<br/>"
return string