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 models import Location, Product
menuitems = [
"Spicy Chicken",

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
from models import Location, Product
from app import db
from models import Location, Product
bickies = {
"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
import add_oceans_garden, add_admins, add_simpizza, add_primadonna, add_fitchen
entry_sets = {
"Admins": add_admins.add,

View file

@ -1,8 +1,15 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
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
# access to the values within the .ini file in use.
config = context.config
@ -11,11 +18,6 @@ config = context.config
# This line sets up loggers basically.
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(
"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"
down_revision = None
from alembic import op
import sqlalchemy as sa
from alembic import op
def upgrade():

View file

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

View file

@ -15,8 +15,13 @@ class Order(db.Model):
public = db.Column(db.Boolean, default=True)
items = db.relationship("OrderItem", backref="order", lazy="dynamic")
def configure(self, courrier: User, location: Location,
starttime: db.DateTime, stoptime: db.DateTime) -> None:
def configure(
self,
courrier: User,
location: Location,
starttime: db.DateTime,
stoptime: db.DateTime,
) -> None:
self.courrier = courrier
self.location = location
self.starttime = starttime
@ -33,8 +38,9 @@ class Order(db.Model):
for item in self.items:
user = group.get(item.get_name(), dict())
user["total"] = user.get("total", 0) + item.product.price
user["to_pay"] = (user.get("to_pay", 0) + item.product.price if
not item.paid else 0)
user["to_pay"] = (
user.get("to_pay", 0) + item.product.price if not item.paid else 0
)
user["paid"] = user.get("paid", True) and item.paid
user["products"] = user.get("products", []) + [item.product]
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"))
name = db.Column(db.String(120), nullable=False)
price = db.Column(db.Integer, nullable=False)
orderItems = db.relationship("OrderItem",
backref="product", lazy="dynamic")
orderItems = db.relationship("OrderItem", backref="product", lazy="dynamic")
def configure(self, location: Location, name: str, price: int) -> None:
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 models import Location, Order
# import views
from views.order import get_orders

View file

@ -1,21 +1,13 @@
from werkzeug.wrappers import Response
import random
from datetime import datetime
import typing
# from flask import current_app as app
from flask import (
Blueprint,
abort,
flash,
redirect,
render_template,
request,
session,
url_for,
wrappers,
)
from datetime import datetime
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 werkzeug.wrappers import Response
from forms import AnonOrderItemForm, OrderForm, OrderItemForm
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")
abort(401)
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)
if order.stoptime and order.stoptime < datetime.now():
form = None
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])
return render_template("order.html", order=order, form=form,
total_price=total_price, debts=debts)
return render_template(
"order.html", order=order, form=form, total_price=total_price, debts=debts
)
@order_bp.route("/<id>/items")
@ -85,8 +77,7 @@ def items_showcase(id: int, form: OrderForm = None) -> str:
@login_required
def order_edit(id: int) -> typing.Union[str, Response]:
order = Order.query.filter(Order.id == id).first()
if current_user.id is not order.courrier_id and \
not current_user.is_admin():
if current_user.id is not order.courrier_id and not current_user.is_admin():
abort(401)
if order is None:
abort(404)
@ -111,8 +102,7 @@ def order_item_create(id: int) -> typing.Any:
if current_user.is_anonymous() and not current_order.public:
flash("Please login to see this order.", "info")
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)
if form.validate_on_submit():
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:
item.paid = True
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()), "success")
return redirect(url_for("order_bp.order", id=order_id))
abort(404)
@order_bp.route("/<order_id>/<user_name>/user_paid")
@login_required
def items_user_paid(order_id: int,
user_name: str) -> typing.Optional[Response]:
def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]:
user = User.query.filter(User.username == user_name).first()
items: typing.List[OrderItem] = []
if user:
@ -164,8 +152,7 @@ def items_user_paid(order_id: int,
for item in items:
item.paid = True
db.session.commit()
flash("Paid %d items for %s" %
(len(items), item.get_name()), "success")
flash("Paid %d items for %s" % (len(items), item.get_name()), "success")
return redirect(url_for("order_bp.order", id=order_id))
abort(404)
@ -253,6 +240,5 @@ def get_orders(expression=None) -> typing.List[Order]:
if not current_user.is_anonymous():
orders = Order.query.filter(expression).all()
else:
orders = Order.query.filter(
(expression & (Order.public == True))).all()
orders = Order.query.filter((expression & (Order.public == True))).all()
return orders