Fix pylint for views and templates

This commit is contained in:
Jan-Pieter Baert 2019-09-10 02:50:22 +02:00
parent ec82639c5c
commit c4f9222558
No known key found for this signature in database
GPG key ID: B19186932178234A
11 changed files with 106 additions and 71 deletions

View file

@ -11,7 +11,7 @@ def post_order_to_webhook(order_item) -> None:
message = "" message = ""
if order_item.courrier is not None: if order_item.courrier is not None:
message = "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format( message = "<!channel|@channel> {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format(
url_for("order_bp.order", id=order_item.id, _external=True), url_for("order_bp.order_from_id", order_id=order_item.id, _external=True),
order_item.location.name, order_item.location.name,
remaining_minutes(order_item.stoptime), remaining_minutes(order_item.stoptime),
order_item.courrier.username.title(), order_item.courrier.username.title(),
@ -20,7 +20,7 @@ def post_order_to_webhook(order_item) -> None:
message = "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format( message = "<!channel|@channel> New order for {}. Deadline in {} minutes. <{}|Open here.>".format(
order_item.location.name, order_item.location.name,
remaining_minutes(order_item.stoptime), remaining_minutes(order_item.stoptime),
url_for("order_bp.order", id=order_item.id, _external=True), url_for("order_bp.order_from_id", order_id=order_item.id, _external=True),
) )
webhookthread = WebhookSenderThread(message, app.config["SLACK_WEBHOOK"]) webhookthread = WebhookSenderThread(message, app.config["SLACK_WEBHOOK"])
webhookthread.start() webhookthread.start()

View file

@ -5,7 +5,7 @@
('general_bp.home', 'Home'), ('general_bp.home', 'Home'),
('order_bp.orders', 'Orders'), ('order_bp.orders', 'Orders'),
('general_bp.locations', 'Locations'), ('general_bp.locations', 'Locations'),
('general_bp.map', 'Map'), ('general_bp.map_view', 'Map'),
('general_bp.about', 'About'), ('general_bp.about', 'About'),
('stats_blueprint.stats', 'Stats'), ('stats_blueprint.stats', 'Stats'),
] -%} ] -%}

View file

@ -14,7 +14,7 @@
<tbody> <tbody>
{% for loc in locations -%} {% for loc in locations -%}
<tr> <tr>
<td><a href="{{ url_for('general_bp.location', id=loc.id) }}">{{ loc.name }}</a></td> <td><a href="{{ url_for('general_bp.location', location_id=loc.id) }}">{{ loc.name }}</a></td>
<td>{{ loc.address }}<td> <td>{{ loc.address }}<td>
<td><a href="{{ loc.website}}"><span class="glyphicon glyphicon-link"></span></a></td> <td><a href="{{ loc.website}}"><span class="glyphicon glyphicon-link"></span></a></td>
<td> <td>

View file

@ -28,7 +28,7 @@
loc = { loc = {
"address": "{{loc.address}}", "address": "{{loc.address}}",
"name": "{{loc.name}}", "name": "{{loc.name}}",
"url": "{{ url_for('general_bp.location', id=loc.id) }}" "url": "{{ url_for('general_bp.location', location_id=loc.id) }}"
}; };
locations.push(loc); locations.push(loc);

View file

@ -11,16 +11,16 @@
<h3 id="order-title">Order {{ order.id }} <h3 id="order-title">Order {{ order.id }}
<div class="pull-right"> <div class="pull-right">
{% if order.can_close(current_user.id) -%} {% if order.can_close(current_user.id) -%}
<form action="{{ url_for('order_bp.close_order', id=order.id) }}" method="post" style="display:inline"> <form action="{{ url_for('order_bp.close_order', order_id=order.id) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-danger" value="Close"></input> <input type="submit" class="btn btn-danger" value="Close"></input>
</form> </form>
{% endif %}{% if courier_or_admin %} {% endif %}{% if courier_or_admin %}
<a class="btn btn-warning" href="{{ url_for('order_bp.order_edit', id=order.id) }}">Edit</a> <a class="btn btn-warning" href="{{ url_for('order_bp.order_edit', order_id=order.id) }}">Edit</a>
{%- endif %} {%- endif %}
</div></h3> </div></h3>
courier: {{ order.courrier.username }} courier: {{ order.courrier.username }}
{% if order.courrier == None and not current_user.is_anonymous() %} {% if order.courrier == None and not current_user.is_anonymous() %}
<form action="{{ url_for('order_bp.volunteer', id=order.id) }}" method="post" style="display:inline"> <form action="{{ url_for('order_bp.volunteer', order_id=order.id) }}" method="post" style="display:inline">
<input type="submit" class="btn btn-primary btn-sm" value="Volunteer"></input> <input type="submit" class="btn btn-primary btn-sm" value="Volunteer"></input>
</form> </form>
{% endif %} {% endif %}
@ -38,7 +38,7 @@
{% if form -%} {% if form -%}
<div class="col-md-push-1 col-md-10 darker" id="form"> <div class="col-md-push-1 col-md-10 darker" id="form">
<h4>Order:</h4> <h4>Order:</h4>
<form method="post" action="{{ url_for('order_bp.order_item_create', id=order.id) }}"> <form method="post" action="{{ url_for('order_bp.order_item_create', order_id=order.id) }}">
<span class="pull-right"> <span class="pull-right">
<a class="btn btn-primary" onclick="chooseRandom()">Choose for me</a> <a class="btn btn-primary" onclick="chooseRandom()">Choose for me</a>
</span> </span>
@ -99,7 +99,7 @@
</div> </div>
<div class="col-md-push-2 col-md-4 darker box" id="items-ordered"> <div class="col-md-push-2 col-md-4 darker box" id="items-ordered">
<h3>Ordered products: {{ order.items.count() }}</h3> <h3>Ordered products: {{ order.items.count() }}</h3>
<a class="divLink" href="{{ url_for('order_bp.items_showcase', id=order.id) }}"></a> <a class="divLink" href="{{ url_for('order_bp.items_showcase', order_id=order.id) }}"></a>
{% for key, value in order.group_by_product().items() -%} {% for key, value in order.group_by_product().items() -%}
<div class="product"> <div class="product">
{{ key }}: {{ value["count"] }} {{ key }}: {{ value["count"] }}

View file

@ -11,7 +11,7 @@
<h3>Edit order:</h3> <h3>Edit order:</h3>
<div class="row darker"> <div class="row darker">
<div class="col-sm-12"> <div class="col-sm-12">
<form method="post" action="{{ url_for('.order_edit', id=order_id) }}"> <form method="post" action="{{ url_for('.order_edit', order_id=order_id) }}">
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}"> <div class="form-group select2 {{ 'has-errors' if form.courrier_id.errors else ''}}">
{{ form.courrier_id.label(class='control-label') }}<br> {{ form.courrier_id.label(class='control-label') }}<br>

View file

@ -9,7 +9,7 @@
<b>Orders:</b> {{ order.items.count() }}</p> <b>Orders:</b> {{ order.items.count() }}</p>
</div> </div>
<div class="col-md-4 col-lg-3"> <div class="col-md-4 col-lg-3">
<a class="btn btn-primary btn-block align-bottom" href="{{ url_for('order_bp.order', id=order.id) }}">Expand</a> <a class="btn btn-primary btn-block align-bottom" href="{{ url_for('order_bp.order', order_id=order.id) }}">Expand</a>
</div> </div>
</div> </div>
{%- endmacro %} {%- endmacro %}

View file

@ -1,3 +1,4 @@
"View used for debugging Haldis"
from flask import Blueprint from flask import Blueprint
from flask import current_app as app from flask import current_app as app
from flask import url_for from flask import url_for
@ -9,6 +10,7 @@ debug_bp = Blueprint("debug_bp", __name__)
@debug_bp.route("/routes") @debug_bp.route("/routes")
@login_required @login_required
def list_routes() -> str: def list_routes() -> str:
"List all routes of the application"
import urllib import urllib
output = [] output = []

View file

@ -1,3 +1,4 @@
"Script to generate the general views of Haldis"
import os import os
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -15,6 +16,7 @@ general_bp = Blueprint("general_bp", __name__)
@general_bp.route("/") @general_bp.route("/")
def home() -> str: def home() -> str:
"Generate the home view"
prev_day = datetime.now() - timedelta(days=1) prev_day = datetime.now() - timedelta(days=1)
recently_closed = get_orders( recently_closed = get_orders(
((Order.stoptime > prev_day) & (Order.stoptime < datetime.now())) ((Order.stoptime > prev_day) & (Order.stoptime < datetime.now()))
@ -24,22 +26,24 @@ def home() -> str:
) )
@general_bp.route("/map", defaults={"id": None}) @general_bp.route("/map")
@general_bp.route("/map/<int:id>") def map_view() -> str:
def map(id) -> str: "Generate the map view"
locs = Location.query.order_by("name") locs = Location.query.order_by("name")
return render_template("maps.html", locations=locs) return render_template("maps.html", locations=locs)
@general_bp.route("/location") @general_bp.route("/location")
def locations() -> str: def locations() -> str:
"Generate the location view"
locs = Location.query.order_by("name") locs = Location.query.order_by("name")
return render_template("locations.html", locations=locs) return render_template("locations.html", locations=locs)
@general_bp.route("/location/<int:id>") @general_bp.route("/location/<int:location_id>")
def location(id) -> str: def location(location_id) -> str:
loc = Location.query.filter(Location.id == id).first() "Generate the location view given an id"
loc = Location.query.filter(Location.id == location_id).first()
if loc is None: if loc is None:
abort(404) abort(404)
return render_template("location.html", location=loc, title=loc.name) return render_template("location.html", location=loc, title=loc.name)
@ -47,18 +51,22 @@ def location(id) -> str:
@general_bp.route("/about/") @general_bp.route("/about/")
def about() -> str: def about() -> str:
"Generate the about view"
return render_template("about.html") return render_template("about.html")
@general_bp.route("/profile/") @general_bp.route("/profile/")
@login_required @login_required
def profile() -> str: def profile() -> str:
"Generate the profile view"
return render_template("profile.html") return render_template("profile.html")
@general_bp.route("/favicon.ico") @general_bp.route("/favicon.ico")
def favicon() -> str: def favicon() -> str:
if len(get_orders((Order.stoptime > datetime.now()))) == 0: "Generate the favicon"
# pylint: disable=R1705
if not get_orders((Order.stoptime > datetime.now())):
return send_from_directory( return send_from_directory(
os.path.join(str(app.root_path), "static"), os.path.join(str(app.root_path), "static"),
"favicon.ico", "favicon.ico",

View file

@ -1,13 +1,13 @@
"Script to generate the order related views of Haldis"
import random import random
import typing import typing
from datetime import datetime from datetime import datetime
import werkzeug from werkzeug.wrappers import Response
# from flask import current_app as app # from flask import current_app as app
from flask import (Blueprint, abort, flash, redirect, render_template, request, from flask import (Blueprint, abort, flash, redirect, render_template, request,
session, url_for, wrappers) session, url_for, wrappers)
from flask_login import current_user, login_required from flask_login import current_user, login_required
from werkzeug.wrappers import Response
from forms import AnonOrderItemForm, OrderForm, OrderItemForm from forms import AnonOrderItemForm, OrderForm, OrderItemForm
from models import Order, OrderItem, User, db from models import Order, OrderItem, User, db
@ -18,6 +18,7 @@ order_bp = Blueprint("order_bp", "order")
@order_bp.route("/") @order_bp.route("/")
def orders(form: OrderForm = None) -> str: def orders(form: OrderForm = None) -> str:
"Generate general order view"
if form is None and not current_user.is_anonymous(): if form is None and not current_user.is_anonymous():
form = OrderForm() form = OrderForm()
location_id = request.args.get("location_id") location_id = request.args.get("location_id")
@ -30,6 +31,7 @@ def orders(form: OrderForm = None) -> str:
@order_bp.route("/create", methods=["POST"]) @order_bp.route("/create", methods=["POST"])
@login_required @login_required
def order_create() -> typing.Union[str, Response]: def order_create() -> typing.Union[str, Response]:
"Generate order create view"
orderForm = OrderForm() orderForm = OrderForm()
orderForm.populate() orderForm.populate()
if orderForm.validate_on_submit(): if orderForm.validate_on_submit():
@ -38,33 +40,35 @@ def order_create() -> typing.Union[str, Response]:
db.session.add(order) db.session.add(order)
db.session.commit() db.session.commit()
post_order_to_webhook(order) post_order_to_webhook(order)
return redirect(url_for("order_bp.order", id=order.id)) return redirect(url_for("order_bp.order_from_id", order_id=order.id))
return orders(form=orderForm) return orders(form=orderForm)
@order_bp.route("/<id>") @order_bp.route("/<order_id>")
def order(id: int, form: OrderForm = None) -> str: def order_from_id(order_id: int, form: OrderForm = None) -> str:
order = Order.query.filter(Order.id == id).first() "Generate order view from id"
order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) abort(404)
if current_user.is_anonymous() and not order.public: if current_user.is_anonymous() and not order.public:
flash("Please login to see this order.", "info") flash("Please login to see this order.", "info")
abort(401) abort(401)
if form is None: if form is None:
form = AnonOrderItemForm() if current_user.is_anonymous() else OrderItemForm() form = AnonOrderItemForm() if current_user.is_anonymous() \
else OrderItemForm()
form.populate(order.location) form.populate(order.location)
if order.stoptime and order.stoptime < datetime.now(): if order.stoptime and order.stoptime < datetime.now():
form = None form = None
total_price = sum([o.product.price for o in order.items]) total_price = sum([o.product.price for o in order.items])
debts = sum([o.product.price for o in order.items if not o.paid]) debts = sum([o.product.price for o in order.items if not o.paid])
return render_template( return render_template("order.html", order=order, form=form,
"order.html", order=order, form=form, total_price=total_price, debts=debts total_price=total_price, debts=debts)
)
@order_bp.route("/<id>/items") @order_bp.route("/<order_id>/items")
def items_showcase(id: int, form: OrderForm = None) -> str: def items_showcase(order_id: int) -> str:
order = Order.query.filter(Order.id == id).first() "Generate order items view from id"
order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) abort(404)
if current_user.is_anonymous() and not order.public: if current_user.is_anonymous() and not order.public:
@ -73,11 +77,13 @@ def items_showcase(id: int, form: OrderForm = None) -> str:
return render_template("order_items.html", order=order) return render_template("order_items.html", order=order)
@order_bp.route("/<id>/edit", methods=["GET", "POST"]) @order_bp.route("/<order_id>/edit", methods=["GET", "POST"])
@login_required @login_required
def order_edit(id: int) -> typing.Union[str, Response]: def order_edit(order_id: int) -> typing.Union[str, Response]:
order = Order.query.filter(Order.id == id).first() "Generate order edit view from id"
if current_user.id is not order.courrier_id and not current_user.is_admin(): order = Order.query.filter(Order.id == order_id).first()
if current_user.id is not order.courrier_id and \
not current_user.is_admin():
abort(401) abort(401)
if order is None: if order is None:
abort(404) abort(404)
@ -86,15 +92,17 @@ def order_edit(id: int) -> typing.Union[str, Response]:
if orderForm.validate_on_submit(): if orderForm.validate_on_submit():
orderForm.populate_obj(order) orderForm.populate_obj(order)
db.session.commit() db.session.commit()
return redirect(url_for("order_bp.order", id=order.id)) return redirect(url_for("order_bp.order_from_id", order_id=order.id))
return render_template("order_edit.html", form=orderForm, order_id=id) return render_template("order_edit.html", form=orderForm,
order_id=order_id)
@order_bp.route("/<id>/create", methods=["POST"]) @order_bp.route("/<order_id>/create", methods=["POST"])
def order_item_create(id: int) -> typing.Any: def order_item_create(order_id: int) -> typing.Any:
# type is 'typing.Union[str, Response]', but this errors due to # type is 'typing.Union[str, Response]', but this errors due to
# https://github.com/python/mypy/issues/7187 # https://github.com/python/mypy/issues/7187
current_order = Order.query.filter(Order.id == id).first() "Add item to order from id"
current_order = Order.query.filter(Order.id == order_id).first()
if current_order is None: if current_order is None:
abort(404) abort(404)
if current_order.stoptime and current_order.stoptime < datetime.now(): if current_order.stoptime and current_order.stoptime < datetime.now():
@ -102,12 +110,13 @@ def order_item_create(id: int) -> typing.Any:
if current_user.is_anonymous() and not current_order.public: if current_user.is_anonymous() and not current_order.public:
flash("Please login to see this order.", "info") flash("Please login to see this order.", "info")
abort(401) abort(401)
form = AnonOrderItemForm() if current_user.is_anonymous() else OrderItemForm() form = AnonOrderItemForm() if current_user.is_anonymous() \
else OrderItemForm()
form.populate(current_order.location) form.populate(current_order.location)
if form.validate_on_submit(): if form.validate_on_submit():
item = OrderItem() item = OrderItem()
form.populate_obj(item) form.populate_obj(item)
item.order_id = id item.order_id = order_id
if not current_user.is_anonymous(): if not current_user.is_anonymous():
item.user_id = current_user.id item.user_id = current_user.id
else: else:
@ -115,26 +124,31 @@ def order_item_create(id: int) -> typing.Any:
db.session.add(item) db.session.add(item)
db.session.commit() db.session.commit()
flash("Ordered %s" % (item.product.name), "success") flash("Ordered %s" % (item.product.name), "success")
return redirect(url_for("order_bp.order", id=id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
return order(id, form=form) return order_from_id(order_id, form=form)
@order_bp.route("/<order_id>/<item_id>/paid", methods=["POST"]) @order_bp.route("/<order_id>/<item_id>/paid", methods=["POST"])
@login_required @login_required
# pylint: disable=R1710
def item_paid(order_id: int, item_id: int) -> typing.Optional[Response]: def item_paid(order_id: int, item_id: int) -> typing.Optional[Response]:
"Indicate payment status for an item in an order"
item = OrderItem.query.filter(OrderItem.id == item_id).first() item = OrderItem.query.filter(OrderItem.id == item_id).first()
id = current_user.id user_id = current_user.id
if item.order.courrier_id == id or current_user.admin: if item.order.courrier_id == user_id or current_user.admin:
item.paid = True item.paid = True
db.session.commit() db.session.commit()
flash("Paid %s by %s" % (item.product.name, item.get_name()), "success") flash("Paid %s by %s" % (item.product.name, item.get_name()),
return redirect(url_for("order_bp.order", id=order_id)) "success")
return redirect(url_for("order_bp.order_from_id", order_id=order_id))
abort(404) abort(404)
@order_bp.route("/<order_id>/<user_name>/user_paid", methods=["POST"]) @order_bp.route("/<order_id>/<user_name>/user_paid", methods=["POST"])
@login_required @login_required
def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]: # pylint: disable=R1710
def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]: # pylint:disable=C0301
"Indicate payment status for a user in an order"
user = User.query.filter(User.username == user_name).first() user = User.query.filter(User.username == user_name).first()
items: typing.List[OrderItem] = [] items: typing.List[OrderItem] = []
if user: if user:
@ -152,33 +166,37 @@ def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]:
for item in items: for item in items:
item.paid = True item.paid = True
db.session.commit() db.session.commit()
flash("Paid %d items for %s" % (len(items), item.get_name()), "success") flash("Paid %d items for %s" %
return redirect(url_for("order_bp.order", id=order_id)) (len(items), item.get_name()), "success")
return redirect(url_for("order_bp.order_from_id", order_id=order_id))
abort(404) abort(404)
@order_bp.route("/<order_id>/<item_id>/delete", methods=["POST"]) @order_bp.route("/<order_id>/<item_id>/delete", methods=["POST"])
# pylint: disable=R1710
def delete_item(order_id: int, item_id: int) -> typing.Any: def delete_item(order_id: int, item_id: int) -> typing.Any:
# type is 'typing.Optional[Response]', but this errors due to # type is 'typing.Optional[Response]', but this errors due to
# https://github.com/python/mypy/issues/7187 # https://github.com/python/mypy/issues/7187
"Delete an item from an order"
item = OrderItem.query.filter(OrderItem.id == item_id).first() item = OrderItem.query.filter(OrderItem.id == item_id).first()
id = None user_id = None
if not current_user.is_anonymous(): if not current_user.is_anonymous():
print("%s tries to delete orders" % (current_user.username)) print("%s tries to delete orders" % (current_user.username))
id = current_user.id user_id = current_user.id
if item.can_delete(order_id, id, session.get("anon_name", "")): if item.can_delete(order_id, user_id, session.get("anon_name", "")):
product_name = item.product.name product_name = item.product.name
db.session.delete(item) db.session.delete(item)
db.session.commit() db.session.commit()
flash("Deleted %s" % (product_name), "success") flash("Deleted %s" % (product_name), "success")
return redirect(url_for("order_bp.order", id=order_id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
abort(404) abort(404)
@order_bp.route("/<id>/volunteer", methods=["POST"]) @order_bp.route("/<order_id>/volunteer", methods=["POST"])
@login_required @login_required
def volunteer(id: int) -> Response: def volunteer(order_id: int) -> Response:
order = Order.query.filter(Order.id == id).first() "Add a volunteer to an order"
order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) abort(404)
if order.courrier_id is None or order.courrier_id == 0: if order.courrier_id is None or order.courrier_id == 0:
@ -187,18 +205,18 @@ def volunteer(id: int) -> Response:
flash("Thank you for volunteering!") flash("Thank you for volunteering!")
else: else:
flash("Volunteering not possible!") flash("Volunteering not possible!")
return redirect(url_for("order_bp.order", id=id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
@order_bp.route("/<id>/close", methods=["POST"]) @order_bp.route("/<order_id>/close", methods=["POST"])
@login_required @login_required
def close_order(id: int) -> typing.Optional[Response]: def close_order(order_id: int) -> typing.Optional[Response]:
order = Order.query.filter(Order.id == id).first() "Close an order"
order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) abort(404)
if (current_user.id == order.courrier_id or current_user.is_admin()) and ( if (current_user.id == order.courrier_id or current_user.is_admin()) and (
order.stoptime is None or (order.stoptime > datetime.now()) order.stoptime is None or (order.stoptime > datetime.now())):
):
order.stoptime = datetime.now() order.stoptime = datetime.now()
if order.courrier_id == 0 or order.courrier_id is None: if order.courrier_id == 0 or order.courrier_id is None:
courrier = select_user(order.items) courrier = select_user(order.items)
@ -206,7 +224,7 @@ def close_order(id: int) -> typing.Optional[Response]:
if courrier is not None: if courrier is not None:
order.courrier_id = courrier.id order.courrier_id = courrier.id
db.session.commit() db.session.commit()
return redirect(url_for("order_bp.order", id=id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
# The line below is to make sure mypy doesn't say # The line below is to make sure mypy doesn't say
# "Missing return statement" # "Missing return statement"
# https://github.com/python/mypy/issues/4223 # https://github.com/python/mypy/issues/4223
@ -214,11 +232,12 @@ def close_order(id: int) -> typing.Optional[Response]:
def select_user(items) -> typing.Optional[User]: def select_user(items) -> typing.Optional[User]:
"Select a random user from those who are signed up for the order"
user = None user = None
# remove non users # remove non users
items = [i for i in items if i.user_id] items = [i for i in items if i.user_id]
if len(items) <= 0: if not items:
return None return None
while user is None: while user is None:
@ -232,13 +251,17 @@ def select_user(items) -> typing.Optional[User]:
def get_orders(expression=None) -> typing.List[Order]: def get_orders(expression=None) -> typing.List[Order]:
orders: typing.List[OrderForm] = [] "Give the list of all currently open and public Orders"
order_list: typing.List[OrderForm] = []
if expression is None: if expression is None:
expression = (datetime.now() > Order.starttime) & ( expression = (datetime.now() > Order.starttime) & (
Order.stoptime > datetime.now() Order.stoptime > datetime.now()
# pylint: disable=C0121
) | (Order.stoptime == None) ) | (Order.stoptime == None)
if not current_user.is_anonymous(): if not current_user.is_anonymous():
orders = Order.query.filter(expression).all() order_list = Order.query.filter(expression).all()
else: else:
orders = Order.query.filter((expression & (Order.public == True))).all() order_list = Order.query.filter(
return orders # pylint: disable=C0121
(expression & (Order.public == True))).all()
return order_list

View file

@ -1,3 +1,4 @@
"Script to generate the stats related views of Haldis"
from flask import Blueprint from flask import Blueprint
from flask import current_app as app from flask import current_app as app
from flask import render_template from flask import render_template
@ -9,6 +10,7 @@ stats_blueprint = Blueprint("stats_blueprint", __name__)
@stats_blueprint.route("/") @stats_blueprint.route("/")
def stats() -> str: def stats() -> str:
"Generate Haldis data in a pretty format"
data = { data = {
"amount": { "amount": {
"orders": FatOrder.amount(), "orders": FatOrder.amount(),