2019-08-28 03:46:04 +02:00
|
|
|
import os
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
from flask import Blueprint, abort
|
|
|
|
from flask import current_app as app
|
|
|
|
from flask import render_template, send_from_directory, url_for
|
|
|
|
from flask_login import login_required
|
|
|
|
|
|
|
|
from models import Location, Order
|
2019-09-05 03:33:29 +02:00
|
|
|
|
2019-08-28 03:46:04 +02:00
|
|
|
# import views
|
|
|
|
from views.order import get_orders
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
general_bp = Blueprint("general_bp", __name__)
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/")
|
2019-08-28 03:46:04 +02:00
|
|
|
def home():
|
|
|
|
prev_day = datetime.now() - timedelta(days=1)
|
|
|
|
recently_closed = get_orders(
|
2019-09-05 03:33:29 +02:00
|
|
|
((Order.stoptime > prev_day) & (Order.stoptime < datetime.now()))
|
|
|
|
)
|
|
|
|
return render_template(
|
|
|
|
"home.html", orders=get_orders(), recently_closed=recently_closed
|
|
|
|
)
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/map", defaults={"id": None})
|
|
|
|
@general_bp.route("/map/<int:id>")
|
2019-08-28 03:46:04 +02:00
|
|
|
def map(id):
|
2019-09-05 03:33:29 +02:00
|
|
|
locs = Location.query.order_by("name")
|
|
|
|
return render_template("maps.html", locations=locs)
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/location")
|
2019-08-28 03:46:04 +02:00
|
|
|
def locations():
|
2019-09-05 03:33:29 +02:00
|
|
|
locs = Location.query.order_by("name")
|
|
|
|
return render_template("locations.html", locations=locs)
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/location/<int:id>")
|
2019-08-28 03:46:04 +02:00
|
|
|
def location(id):
|
|
|
|
loc = Location.query.filter(Location.id == id).first()
|
|
|
|
if loc is None:
|
|
|
|
abort(404)
|
2019-09-05 03:33:29 +02:00
|
|
|
return render_template("location.html", location=loc, title=loc.name)
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/about/")
|
2019-08-28 03:46:04 +02:00
|
|
|
def about():
|
2019-09-05 03:33:29 +02:00
|
|
|
return render_template("about.html")
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/profile/")
|
2019-08-28 03:46:04 +02:00
|
|
|
@login_required
|
|
|
|
def profile():
|
2019-09-05 03:33:29 +02:00
|
|
|
return render_template("profile.html")
|
2019-08-28 03:46:04 +02:00
|
|
|
|
|
|
|
|
2019-09-05 03:33:29 +02:00
|
|
|
@general_bp.route("/favicon.ico")
|
2019-08-28 03:46:04 +02:00
|
|
|
def favicon():
|
|
|
|
if len(get_orders((Order.stoptime > datetime.now()))) == 0:
|
2019-09-05 03:33:29 +02:00
|
|
|
return send_from_directory(
|
|
|
|
os.path.join(app.root_path, "static"),
|
|
|
|
"favicon.ico",
|
|
|
|
mimetype="image/x-icon",
|
|
|
|
)
|
2019-08-28 03:46:04 +02:00
|
|
|
else:
|
2019-09-05 03:33:29 +02:00
|
|
|
return send_from_directory(
|
|
|
|
os.path.join(app.root_path, "static"),
|
|
|
|
"favicon_orange.ico",
|
|
|
|
mimetype="image/x-icon",
|
|
|
|
)
|