Merge pull request #185 from ZeusWPI/fix/pylint

Fix pylint on everything
This commit is contained in:
Maxime 2022-04-19 23:59:47 +02:00 committed by GitHub
commit 0ace54a8fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 23 deletions

View file

@ -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.

View file

@ -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 = [

View file

@ -24,6 +24,7 @@ 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(
@ -79,7 +80,8 @@ def register_plugins(app: Flask) -> 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]:
@ -91,7 +93,7 @@ def add_handlers(app: Flask) -> None:
def add_routes(application: Flask) -> None: def add_routes(application: Flask) -> None:
"Add all routes to Haldis" """Add all routes to Haldis"""
# import views # TODO convert to blueprint # import views # TODO convert to blueprint
# import views.stats # TODO convert to blueprint # import views.stats # TODO convert to blueprint
@ -113,7 +115,8 @@ def add_routes(application: Flask) -> None:
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")
def countdown( def countdown(
@ -150,6 +153,8 @@ def add_template_filters(app: Flask) -> None:
app.template_filter("all")(all) app.template_filter("all")(all)
def create_app():
"""Initializer for the Flask app object"""
app = Flask(__name__) app = Flask(__name__)
# Load the config file # Load the config file
@ -160,7 +165,10 @@ add_handlers(app)
add_routes(app) add_routes(app)
add_template_filters(app) add_template_filters(app)
return app_manager
# For usage when you directly call the script with python # For usage when you directly call the script with python
if __name__ == "__main__": if __name__ == "__main__":
app_manager.run() app_mgr = create_app()
app_mgr.run()

View file

@ -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(

View file

@ -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"

View file

@ -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")
@ -76,7 +77,7 @@ class AnonOrderItemForm(OrderItemForm):
self.user_name.data = session.get("anon_name", None) self.user_name.data = session.get("anon_name", None)
def validate(self) -> bool: def validate(self) -> bool:
"Check if the provided anon_name is not already taken" """Check if the provided anon_name is not already taken"""
rv = OrderForm.validate(self) rv = OrderForm.validate(self)
if not rv: if not rv:
return False return False

View file

@ -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

View file

@ -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)