Fix pylint on everything
Except hlds related files because that's a mess
This commit is contained in:
parent
461664f629
commit
e93460743a
8 changed files with 60 additions and 41 deletions
|
@ -5,7 +5,7 @@
|
||||||
# run arbitrary code.
|
# run arbitrary code.
|
||||||
extension-pkg-whitelist=
|
extension-pkg-whitelist=
|
||||||
|
|
||||||
fail-under=9
|
fail-under=9.58
|
||||||
|
|
||||||
# Add files or directories to the blacklist. They should be base names, not
|
# Add files or directories to the blacklist. They should be base names, not
|
||||||
# paths.
|
# paths.
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
"Module for everything related to Admin users"
|
||||||
import flask_login as login
|
import flask_login as login
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_admin import Admin
|
from flask_admin import Admin
|
||||||
|
@ -7,12 +8,15 @@ from models import Order, OrderItem, OrderItemChoice, User
|
||||||
|
|
||||||
|
|
||||||
class ModelBaseView(ModelView):
|
class ModelBaseView(ModelView):
|
||||||
|
"Class for the base view of the model"
|
||||||
# pylint: disable=too-few-public-methods, no-self-use
|
# pylint: disable=too-few-public-methods, no-self-use
|
||||||
def is_accessible(self) -> bool:
|
def is_accessible(self) -> bool:
|
||||||
|
"Function to check if the logged in user is an admin"
|
||||||
return login.current_user.is_admin()
|
return login.current_user.is_admin()
|
||||||
|
|
||||||
|
|
||||||
class UserAdminModel(ModelBaseView):
|
class UserAdminModel(ModelBaseView):
|
||||||
|
"Class for the model of a UserAdmin"
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
column_searchable_list = ("username",)
|
column_searchable_list = ("username",)
|
||||||
column_editable_list = ("username",)
|
column_editable_list = ("username",)
|
||||||
|
@ -21,6 +25,7 @@ class UserAdminModel(ModelBaseView):
|
||||||
|
|
||||||
|
|
||||||
class OrderAdminModel(ModelBaseView):
|
class OrderAdminModel(ModelBaseView):
|
||||||
|
"Class for the model of a OrderAdmin"
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
column_default_sort = ("starttime", True)
|
column_default_sort = ("starttime", True)
|
||||||
column_list = ["starttime", "stoptime", "location_name", "location_id", "courier"]
|
column_list = ["starttime", "stoptime", "location_name", "location_id", "courier"]
|
||||||
|
@ -34,6 +39,7 @@ class OrderAdminModel(ModelBaseView):
|
||||||
|
|
||||||
|
|
||||||
class OrderItemAdminModel(ModelBaseView):
|
class OrderItemAdminModel(ModelBaseView):
|
||||||
|
"Class for the model of a OrderItemAdmin"
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
column_default_sort = ("order_id", True)
|
column_default_sort = ("order_id", True)
|
||||||
column_list = [
|
column_list = [
|
||||||
|
|
61
app/app.py
61
app/app.py
|
@ -23,69 +23,70 @@ from utils import euro_string, price_range_string
|
||||||
from zeus import init_oauth
|
from zeus import init_oauth
|
||||||
|
|
||||||
|
|
||||||
def register_plugins(app: Flask) -> Manager:
|
def register_plugins(_app: Flask) -> Manager:
|
||||||
|
"Register the plugins to the app"
|
||||||
# pylint: disable=W0612
|
# pylint: disable=W0612
|
||||||
if not app.debug:
|
if not _app.debug:
|
||||||
timedFileHandler = TimedRotatingFileHandler(
|
timedFileHandler = TimedRotatingFileHandler(
|
||||||
app.config["LOGFILE"], when="midnight", backupCount=100
|
_app.config["LOGFILE"], when="midnight", backupCount=100
|
||||||
)
|
)
|
||||||
timedFileHandler.setLevel(logging.DEBUG)
|
timedFileHandler.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
loglogger = logging.getLogger("werkzeug")
|
loglogger = logging.getLogger("werkzeug")
|
||||||
loglogger.setLevel(logging.DEBUG)
|
loglogger.setLevel(logging.DEBUG)
|
||||||
loglogger.addHandler(timedFileHandler)
|
loglogger.addHandler(timedFileHandler)
|
||||||
app.logger.addHandler(timedFileHandler)
|
_app.logger.addHandler(timedFileHandler)
|
||||||
|
|
||||||
# Initialize SQLAlchemy
|
# Initialize SQLAlchemy
|
||||||
db.init_app(app)
|
db.init_app(_app)
|
||||||
|
|
||||||
# Initialize Flask-Migrate
|
# Initialize Flask-Migrate
|
||||||
migrate = Migrate(app, db)
|
migrate = Migrate(_app, db)
|
||||||
app_manager = Manager(app)
|
_app_manager = Manager(_app)
|
||||||
app_manager.add_command("db", MigrateCommand)
|
_app_manager.add_command("db", MigrateCommand)
|
||||||
app_manager.add_command("runserver", Server(port=8000))
|
_app_manager.add_command("runserver", Server(port=8000))
|
||||||
init_admin(app, db)
|
init_admin(_app, db)
|
||||||
|
|
||||||
# Init login manager
|
# Init login manager
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(_app)
|
||||||
login_manager.anonymous_user = AnonymouseUser
|
login_manager.anonymous_user = AnonymouseUser
|
||||||
init_login(app)
|
init_login(_app)
|
||||||
|
|
||||||
# Add oauth
|
# Add oauth
|
||||||
zeus = init_oauth(app)
|
zeus = init_oauth(_app)
|
||||||
app.zeus = zeus
|
_app.zeus = zeus
|
||||||
|
|
||||||
# Load the bootstrap local cdn
|
# Load the bootstrap local cdn
|
||||||
Bootstrap(app)
|
Bootstrap(_app)
|
||||||
app.config["BOOTSTRAP_SERVE_LOCAL"] = True
|
_app.config["BOOTSTRAP_SERVE_LOCAL"] = True
|
||||||
|
|
||||||
# use our own bootstrap theme
|
# use our own bootstrap theme
|
||||||
app.extensions["bootstrap"]["cdns"]["bootstrap"] = StaticCDN()
|
_app.extensions["bootstrap"]["cdns"]["bootstrap"] = StaticCDN()
|
||||||
|
|
||||||
# Load the flask debug toolbar
|
# Load the flask debug toolbar
|
||||||
toolbar = DebugToolbarExtension(app)
|
toolbar = DebugToolbarExtension(_app)
|
||||||
|
|
||||||
# Make cookies more secure
|
# Make cookies more secure
|
||||||
app.config.update(
|
_app.config.update(
|
||||||
SESSION_COOKIE_HTTPONLY=True,
|
SESSION_COOKIE_HTTPONLY=True,
|
||||||
SESSION_COOKIE_SAMESITE="Lax",
|
SESSION_COOKIE_SAMESITE="Lax",
|
||||||
)
|
)
|
||||||
|
|
||||||
if not app.debug:
|
if not _app.debug:
|
||||||
app.config.update(SESSION_COOKIE_SECURE=True)
|
_app.config.update(SESSION_COOKIE_SECURE=True)
|
||||||
|
|
||||||
return app_manager
|
return _app_manager
|
||||||
|
|
||||||
|
|
||||||
def add_handlers(app: Flask) -> None:
|
def add_handlers(_app: Flask) -> None:
|
||||||
"Add handlers for 4xx error codes"
|
"Add handlers for 4xx error codes"
|
||||||
# pylint: disable=W0612,W0613
|
# pylint: disable=W0612,W0613
|
||||||
@app.errorhandler(404)
|
@_app.errorhandler(404)
|
||||||
def handle404(e) -> typing.Tuple[str, int]:
|
def handle404(e) -> typing.Tuple[str, int]:
|
||||||
return render_template("errors/404.html"), 404
|
return render_template("errors/404.html"), 404
|
||||||
|
|
||||||
@app.errorhandler(401)
|
@_app.errorhandler(401)
|
||||||
def handle401(e) -> typing.Tuple[str, int]:
|
def handle401(e) -> typing.Tuple[str, int]:
|
||||||
return render_template("errors/401.html"), 401
|
return render_template("errors/401.html"), 401
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ def add_routes(application: Flask) -> None:
|
||||||
application.register_blueprint(debug_bp, url_prefix="/debug")
|
application.register_blueprint(debug_bp, url_prefix="/debug")
|
||||||
|
|
||||||
|
|
||||||
def add_template_filters(app: Flask) -> None:
|
def add_template_filters(_app: Flask) -> None:
|
||||||
"Add functions which can be used in the templates"
|
"Add functions which can be used in the templates"
|
||||||
# pylint: disable=W0612
|
# pylint: disable=W0612
|
||||||
@app.template_filter("countdown")
|
@app.template_filter("countdown")
|
||||||
|
@ -144,10 +145,10 @@ def add_template_filters(app: Flask) -> None:
|
||||||
def current_year(_value: typing.Any) -> str:
|
def current_year(_value: typing.Any) -> str:
|
||||||
return str(datetime.now().year)
|
return str(datetime.now().year)
|
||||||
|
|
||||||
app.template_filter("euro")(euro_string)
|
_app.template_filter("euro")(euro_string)
|
||||||
app.template_filter("price_range")(price_range_string)
|
_app.template_filter("price_range")(price_range_string)
|
||||||
app.template_filter("any")(any)
|
_app.template_filter("any")(any)
|
||||||
app.template_filter("all")(all)
|
_app.template_filter("all")(all)
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
|
@ -41,7 +41,7 @@ def recreate_from_scratch() -> None:
|
||||||
|
|
||||||
def add_to_current() -> None:
|
def add_to_current() -> None:
|
||||||
"""Add things to the current database"""
|
"""Add things to the current database"""
|
||||||
available = [entry_set for entry_set in entry_sets]
|
available = list(entry_sets)
|
||||||
|
|
||||||
def add_numbers() -> str:
|
def add_numbers() -> str:
|
||||||
return " ".join(
|
return " ".join(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
"Module used for everything related to the fat versions of models"
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from hlds.definitions import location_definitions
|
from hlds.definitions import location_definitions
|
||||||
|
@ -7,16 +8,24 @@ from sqlalchemy.sql import desc, func
|
||||||
|
|
||||||
|
|
||||||
class FatModel:
|
class FatModel:
|
||||||
|
"General class for the fat version of models"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all(cls):
|
def all(cls):
|
||||||
|
"Function to query all"
|
||||||
|
# pylint: disable=E1101
|
||||||
return cls.query.all()
|
return cls.query.all()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def amount(cls):
|
def amount(cls):
|
||||||
|
"Function to query the amount"
|
||||||
|
# pylint: disable=E1101
|
||||||
return cls.query.count()
|
return cls.query.count()
|
||||||
|
|
||||||
|
|
||||||
class FatLocation(Location, FatModel):
|
class FatLocation(Location, FatModel):
|
||||||
|
"Fat version of the Location model"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all(cls):
|
def all(cls):
|
||||||
return location_definitions
|
return location_definitions
|
||||||
|
@ -27,6 +36,7 @@ class FatLocation(Location, FatModel):
|
||||||
|
|
||||||
|
|
||||||
class FatOrder(Order, FatModel):
|
class FatOrder(Order, FatModel):
|
||||||
|
"Fat version of the Order model"
|
||||||
|
|
||||||
# It's hard to add the unique user constraint,
|
# It's hard to add the unique user constraint,
|
||||||
# as DISTINCT seems to apply after a GROUP BY and aggregate
|
# as DISTINCT seems to apply after a GROUP BY and aggregate
|
||||||
|
@ -34,16 +44,15 @@ class FatOrder(Order, FatModel):
|
||||||
# even if they get reduced by the disctinct afterwards.
|
# even if they get reduced by the disctinct afterwards.
|
||||||
@classmethod
|
@classmethod
|
||||||
def items_per_order(cls):
|
def items_per_order(cls):
|
||||||
return (
|
"Function to get the total of all items per order"
|
||||||
Order.query.join(OrderItem)
|
return (Order.query.join(OrderItem).group_by(Order.id).with_entities(
|
||||||
.group_by(Order.id)
|
Order.id,
|
||||||
.with_entities(Order.id, func.count(OrderItem.user_id).label("total"))
|
func.count(OrderItem.user_id).label("total")))
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class FatUser(User, FatModel):
|
class FatUser(User, FatModel):
|
||||||
pass
|
"Fat version of the User model"
|
||||||
|
|
||||||
|
|
||||||
class FatOrderItem(OrderItem, FatModel):
|
class FatOrderItem(OrderItem, FatModel):
|
||||||
pass
|
"Fat version of the OrderItem model"
|
||||||
|
|
|
@ -50,6 +50,7 @@ class OrderItemForm(Form):
|
||||||
submit_button = SubmitField("Submit")
|
submit_button = SubmitField("Submit")
|
||||||
|
|
||||||
def populate(self, location: Location) -> None:
|
def populate(self, location: Location) -> None:
|
||||||
|
"Populate the order item form"
|
||||||
self.dish_id.choices = [(dish.id, dish.name) for dish in location.dishes]
|
self.dish_id.choices = [(dish.id, dish.name) for dish in location.dishes]
|
||||||
if not self.is_submitted() and self.comment.data is None:
|
if not self.is_submitted() and self.comment.data is None:
|
||||||
self.comment.data = request.args.get("comment")
|
self.comment.data = request.args.get("comment")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
"Module used for parsing the HLDS files"
|
||||||
|
|
||||||
from hlds.parser import parse_files
|
from hlds.parser import parse_files
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ def euro_string(value: int) -> str:
|
||||||
euro, cents = divmod(value, 100)
|
euro, cents = divmod(value, 100)
|
||||||
if cents:
|
if cents:
|
||||||
return f"€ {euro}.{cents:02}"
|
return f"€ {euro}.{cents:02}"
|
||||||
else:
|
return f"€ {euro}"
|
||||||
return f"€ {euro}"
|
|
||||||
|
|
||||||
|
|
||||||
def price_range_string(price_range, include_upper=False):
|
def price_range_string(price_range, include_upper=False):
|
||||||
|
"Convert a price range to a string formatted euro"
|
||||||
if price_range[0] == price_range[1]:
|
if price_range[0] == price_range[1]:
|
||||||
return euro_string(price_range[0])
|
return euro_string(price_range[0])
|
||||||
return ("{}—{}" if include_upper else "from {}").format(
|
return ("{}—{}" if include_upper else "from {}").format(
|
||||||
|
@ -33,4 +33,5 @@ def first(iterable: Iterable, default=None):
|
||||||
|
|
||||||
|
|
||||||
def ignore_none(iterable: Iterable):
|
def ignore_none(iterable: Iterable):
|
||||||
|
"Filter to ignore None objects"
|
||||||
return filter(lambda x: x is not None, iterable)
|
return filter(lambda x: x is not None, iterable)
|
||||||
|
|
Loading…
Reference in a new issue