From ec82639c5c0d666e812cfc57930826e0902cdc03 Mon Sep 17 00:00:00 2001 From: Jan-Pieter Baert Date: Tue, 10 Sep 2019 01:06:11 +0200 Subject: [PATCH] Fix pylint for models files --- app/models/__init__.py | 2 ++ app/models/anonymous_user.py | 4 ++++ app/models/database.py | 1 + app/models/location.py | 8 +++++--- app/models/order.py | 20 ++++++++++++-------- app/models/orderitem.py | 7 +++++++ app/models/product.py | 14 ++++++++------ app/models/user.py | 4 ++++ 8 files changed, 43 insertions(+), 17 deletions(-) diff --git a/app/models/__init__.py b/app/models/__init__.py index 60576f2..4fcaf0a 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -1,3 +1,5 @@ +"The base file for everything related to the models" +# pylint: disable=C0301 # This file will expose what we want from the models module # This will probably be everything. But putting the imports here makes it possible to import all models in one line like this: # diff --git a/app/models/anonymous_user.py b/app/models/anonymous_user.py index 76f99f7..2ae10f2 100644 --- a/app/models/anonymous_user.py +++ b/app/models/anonymous_user.py @@ -1,3 +1,7 @@ +"AnonymouseUser for people who are not logged in the normal way" +# pylint: disable=R0201,C0111 + + class AnonymouseUser: id = None diff --git a/app/models/database.py b/app/models/database.py index f0b13d6..5f6799b 100644 --- a/app/models/database.py +++ b/app/models/database.py @@ -1,3 +1,4 @@ +# pylint: disable=C0111 from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() diff --git a/app/models/location.py b/app/models/location.py index 539e21d..15ad76c 100644 --- a/app/models/location.py +++ b/app/models/location.py @@ -1,9 +1,11 @@ +"Script for everything Location related in the database" import typing from models import db class Location(db.Model): + "Class used for configuring the Location model in the database" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) address = db.Column(db.String(254)) @@ -12,9 +14,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: + "Configure the Location" self.name = name self.address = address self.website = website diff --git a/app/models/order.py b/app/models/order.py index 44718fd..1be6106 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -1,3 +1,4 @@ +"Script for everything Order related in the database" import typing from datetime import datetime @@ -7,6 +8,7 @@ from .user import User class Order(db.Model): + "Class used for configuring the Order model in the database" id = db.Column(db.Integer, primary_key=True) courrier_id = db.Column(db.Integer, nullable=True) location_id = db.Column(db.Integer, db.ForeignKey("location.id")) @@ -15,31 +17,31 @@ 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: + "Configure the Order" + # pylint: disable=W0201 self.courrier = courrier self.location = location self.starttime = starttime self.stoptime = stoptime def __repr__(self) -> str: + # pylint: disable=R1705 if self.location: return "Order %d @ %s" % (self.id, self.location.name or "None") else: return "Order %d" % (self.id) def group_by_user(self) -> typing.Dict[str, typing.Any]: + "Group items of an Order by user" group: typing.Dict[str, typing.Any] = dict() 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.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] @@ -48,6 +50,7 @@ class Order(db.Model): return group def group_by_product(self) -> typing.Dict[str, typing.Any]: + "Group items of an Order by product" group: typing.Dict[str, typing.Any] = dict() for item in self.items: product = group.get(item.product.name, dict()) @@ -59,6 +62,7 @@ class Order(db.Model): return group def can_close(self, user_id: int) -> bool: + "Check if a user can close the Order" if self.stoptime and self.stoptime < datetime.now(): return False user = None diff --git a/app/models/orderitem.py b/app/models/orderitem.py index d699a90..8460a98 100644 --- a/app/models/orderitem.py +++ b/app/models/orderitem.py @@ -1,3 +1,4 @@ +"Script for everything OrderItem related in the database" from datetime import datetime from .database import db @@ -7,6 +8,7 @@ from .user import User class OrderItem(db.Model): + "Class used for configuring the OrderItem model in the database" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) order_id = db.Column(db.Integer, db.ForeignKey("order.id"), nullable=False) @@ -20,11 +22,14 @@ class OrderItem(db.Model): name = db.Column(db.String(120)) def configure(self, user: User, order: Order, product: Product) -> None: + "Configure the OrderItem" + # pylint: disable=W0201 self.user = user self.order = order self.product = product def get_name(self) -> str: + "Get the name of the user which 'owns' the item" if self.user_id is not None and self.user_id > 0: return self.user.username return self.name @@ -39,7 +44,9 @@ class OrderItem(db.Model): product_name or "None", ) + # pylint: disable=W0613 def can_delete(self, order_id: int, user_id: int, name: str) -> bool: + "Check if a user can delete an item" if int(self.order_id) != int(order_id): return False if self.order.stoptime and self.order.stoptime < datetime.now(): diff --git a/app/models/product.py b/app/models/product.py index 7e8e1a7..d02c469 100644 --- a/app/models/product.py +++ b/app/models/product.py @@ -1,23 +1,25 @@ +"Script for everything Product related in the database" from models import db from .location import Location class Product(db.Model): + "Class used for configuring the Product model in the database" id = db.Column(db.Integer, primary_key=True) 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: + "Configure the Product" + # pylint: disable=W0201 self.location = location self.name = name self.price = price def __repr__(self) -> str: - return "%s (€%d)from %s" % ( - self.name, - self.price / 100, - self.location or "None", - ) + return "%s (€%d)from %s" % (self.name, self.price / 100, + self.location or "None",) diff --git a/app/models/user.py b/app/models/user.py index 4ed2fe8..463075e 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -1,7 +1,9 @@ +"Script for everything User related in the database" from models import db class User(db.Model): + "Class used for configuring the User model in the database" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) admin = db.Column(db.Boolean) @@ -15,10 +17,12 @@ class User(db.Model): orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic") def configure(self, username: str, admin: bool, bias: int) -> None: + "Configure the User" self.username = username self.admin = admin self.bias = bias + # pylint: disable=C0111, R0201 def is_authenticated(self) -> bool: return True