Run black and isort on all code

This commit is contained in:
Jan-Pieter Baert 2019-09-08 02:02:16 +02:00
parent 15794b06b7
commit c64e4bd998
No known key found for this signature in database
GPG key ID: B19186932178234A
13 changed files with 51 additions and 57 deletions

View file

@ -1,6 +1,5 @@
from models import Location, Product
from app import db from app import db
from models import Location, Product
menuitems = [ menuitems = [
"Spicy Chicken", "Spicy Chicken",

View file

@ -1,7 +1,7 @@
from models import Location, Product
from app import db
from itertools import product from itertools import product
from app import db
from models import Location, Product
zetmelen = ["Nasi", "Bami"] zetmelen = ["Nasi", "Bami"]
vlezen = ["Rundsvlees", "Varkensvlees", "Kippenstukkjes"] vlezen = ["Rundsvlees", "Varkensvlees", "Kippenstukkjes"]

View file

@ -1,5 +1,5 @@
from models import Location, Product
from app import db from app import db
from models import Location, Product
def add(): def add():

View file

@ -1,6 +1,5 @@
from models import Location, Product
from app import db from app import db
from models import Location, Product
pizzas = [ pizzas = [
"Bolognese de luxe", "Bolognese de luxe",

View file

@ -1,5 +1,5 @@
from models import Location, Product
from app import db from app import db
from models import Location, Product
bickies = { bickies = {
"Bicky Burger Original": 330, "Bicky Burger Original": 330,

View file

@ -1,6 +1,9 @@
import add_admins
import add_fitchen
import add_oceans_garden
import add_primadonna
import add_simpizza
from app import db from app import db
import add_oceans_garden, add_admins, add_simpizza, add_primadonna, add_fitchen
entry_sets = { entry_sets = {
"Admins": add_admins.add, "Admins": add_admins.add,

View file

@ -1,8 +1,15 @@
from __future__ import with_statement from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig from logging.config import fileConfig
from alembic import context
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
from sqlalchemy import engine_from_config, pool
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides
# access to the values within the .ini file in use. # access to the values within the .ini file in use.
config = context.config config = context.config
@ -11,11 +18,6 @@ config = context.config
# This line sets up loggers basically. # This line sets up loggers basically.
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option( config.set_main_option(
"sqlalchemy.url", current_app.config.get("SQLALCHEMY_DATABASE_URI") "sqlalchemy.url", current_app.config.get("SQLALCHEMY_DATABASE_URI")

View file

@ -10,8 +10,8 @@ Create Date: 2019-04-02 18:00:12.618368
revision = "150252c1cdb1" revision = "150252c1cdb1"
down_revision = None down_revision = None
from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op
def upgrade(): def upgrade():

View file

@ -12,8 +12,9 @@ class Location(db.Model):
products = db.relationship("Product", backref="location", lazy="dynamic") products = db.relationship("Product", backref="location", lazy="dynamic")
orders = db.relationship("Order", backref="location", lazy="dynamic") orders = db.relationship("Order", backref="location", lazy="dynamic")
def configure(self, name: str, address: str, def configure(
telephone: typing.Optional[str], website: str) -> None: self, name: str, address: str, telephone: typing.Optional[str], website: str
) -> None:
self.name = name self.name = name
self.address = address self.address = address
self.website = website self.website = website

View file

@ -15,8 +15,13 @@ class Order(db.Model):
public = db.Column(db.Boolean, default=True) public = db.Column(db.Boolean, default=True)
items = db.relationship("OrderItem", backref="order", lazy="dynamic") items = db.relationship("OrderItem", backref="order", lazy="dynamic")
def configure(self, courrier: User, location: Location, def configure(
starttime: db.DateTime, stoptime: db.DateTime) -> None: self,
courrier: User,
location: Location,
starttime: db.DateTime,
stoptime: db.DateTime,
) -> None:
self.courrier = courrier self.courrier = courrier
self.location = location self.location = location
self.starttime = starttime self.starttime = starttime
@ -33,8 +38,9 @@ class Order(db.Model):
for item in self.items: for item in self.items:
user = group.get(item.get_name(), dict()) user = group.get(item.get_name(), dict())
user["total"] = user.get("total", 0) + item.product.price user["total"] = user.get("total", 0) + item.product.price
user["to_pay"] = (user.get("to_pay", 0) + item.product.price if user["to_pay"] = (
not item.paid else 0) user.get("to_pay", 0) + item.product.price if not item.paid else 0
)
user["paid"] = user.get("paid", True) and item.paid user["paid"] = user.get("paid", True) and item.paid
user["products"] = user.get("products", []) + [item.product] user["products"] = user.get("products", []) + [item.product]
group[item.get_name()] = user group[item.get_name()] = user

View file

@ -8,8 +8,7 @@ class Product(db.Model):
location_id = db.Column(db.Integer, db.ForeignKey("location.id")) location_id = db.Column(db.Integer, db.ForeignKey("location.id"))
name = db.Column(db.String(120), nullable=False) name = db.Column(db.String(120), nullable=False)
price = db.Column(db.Integer, nullable=False) price = db.Column(db.Integer, nullable=False)
orderItems = db.relationship("OrderItem", orderItems = db.relationship("OrderItem", backref="product", lazy="dynamic")
backref="product", lazy="dynamic")
def configure(self, location: Location, name: str, price: int) -> None: def configure(self, location: Location, name: str, price: int) -> None:
self.location = location self.location = location

View file

@ -7,7 +7,6 @@ from flask import render_template, send_from_directory, url_for
from flask_login import login_required from flask_login import login_required
from models import Location, Order from models import Location, Order
# import views # import views
from views.order import get_orders from views.order import get_orders

View file

@ -1,21 +1,13 @@
from werkzeug.wrappers import Response
import random import random
from datetime import datetime
import typing import typing
# from flask import current_app as app from datetime import datetime
from flask import (
Blueprint,
abort,
flash,
redirect,
render_template,
request,
session,
url_for,
wrappers,
)
import werkzeug import werkzeug
# from flask import current_app as app
from flask import (Blueprint, abort, flash, redirect, render_template, request,
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
@ -59,15 +51,15 @@ def order(id: int, form: OrderForm = None) -> str:
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() \ form = AnonOrderItemForm() if current_user.is_anonymous() else OrderItemForm()
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("order.html", order=order, form=form, return render_template(
total_price=total_price, debts=debts) "order.html", order=order, form=form, total_price=total_price, debts=debts
)
@order_bp.route("/<id>/items") @order_bp.route("/<id>/items")
@ -85,8 +77,7 @@ def items_showcase(id: int, form: OrderForm = None) -> str:
@login_required @login_required
def order_edit(id: int) -> typing.Union[str, Response]: def order_edit(id: int) -> typing.Union[str, Response]:
order = Order.query.filter(Order.id == id).first() order = Order.query.filter(Order.id == id).first()
if current_user.id is not order.courrier_id and \ if current_user.id is not order.courrier_id and not current_user.is_admin():
not current_user.is_admin():
abort(401) abort(401)
if order is None: if order is None:
abort(404) abort(404)
@ -111,8 +102,7 @@ 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() \ form = AnonOrderItemForm() if current_user.is_anonymous() else OrderItemForm()
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()
@ -137,16 +127,14 @@ def item_paid(order_id: int, item_id: int) -> typing.Optional[Response]:
if item.order.courrier_id == id or current_user.admin: if item.order.courrier_id == 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()), flash("Paid %s by %s" % (item.product.name, item.get_name()), "success")
"success")
return redirect(url_for("order_bp.order", id=order_id)) return redirect(url_for("order_bp.order", id=order_id))
abort(404) abort(404)
@order_bp.route("/<order_id>/<user_name>/user_paid") @order_bp.route("/<order_id>/<user_name>/user_paid")
@login_required @login_required
def items_user_paid(order_id: int, def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]:
user_name: str) -> typing.Optional[Response]:
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:
@ -164,8 +152,7 @@ def items_user_paid(order_id: int,
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" % flash("Paid %d items for %s" % (len(items), item.get_name()), "success")
(len(items), item.get_name()), "success")
return redirect(url_for("order_bp.order", id=order_id)) return redirect(url_for("order_bp.order", id=order_id))
abort(404) abort(404)
@ -253,6 +240,5 @@ def get_orders(expression=None) -> typing.List[Order]:
if not current_user.is_anonymous(): if not current_user.is_anonymous():
orders = Order.query.filter(expression).all() orders = Order.query.filter(expression).all()
else: else:
orders = Order.query.filter( orders = Order.query.filter((expression & (Order.public == True))).all()
(expression & (Order.public == True))).all()
return orders return orders