From 26ffd32aece6eb19c75ffbdf7520a622f2506ff2 Mon Sep 17 00:00:00 2001 From: Casey Becking Date: Mon, 18 Nov 2024 07:06:33 -0800 Subject: [PATCH] pylint updates --- api/account/controllers.py | 22 +++++++++++++ api/base/models.py | 19 +++++++++-- api/categories/models.py | 2 +- api/categories_group/models.py | 2 +- api/categories_type/controllers.py | 2 +- api/categories_type/models.py | 4 +-- api/institution/models.py | 2 +- api/institution_account/models.py | 6 ++-- api/transaction/controllers.py | 7 ++-- api/transaction/models.py | 53 +++++++++++++++++++++++++++--- api/user/controllers.py | 1 - api/user/models.py | 7 ++-- app/__init__.py | 8 ++--- app/account/controllers.py | 8 ++--- app/cli.py | 12 +++---- app/dashboard/controllers.py | 2 +- app/database.py | 2 +- app/institution/controllers.py | 2 +- main.py | 2 +- .pylintrc => pylintrc | 11 +++++-- 20 files changed, 129 insertions(+), 45 deletions(-) rename .pylintrc => pylintrc (98%) diff --git a/api/account/controllers.py b/api/account/controllers.py index fb78f61..5667021 100644 --- a/api/account/controllers.py +++ b/api/account/controllers.py @@ -20,8 +20,30 @@ @g.api.route('/account/signup') class Signup(Resource): + """ + Signup Resource for creating a new user account. + + This resource handles the POST request to create a new user account. It expects + a JSON payload with the user's email, username, password, first name, and last name. + It checks if the email or username already exists in the database and returns an error + message if they do. Otherwise, it creates a new user with the provided details. + + Methods: + post: Handle POST requests to create a new user account. + """ @g.api.expect(account_model) def post(self): + """ + Handle POST requests to create a new user account. + + This method extracts the user details from the request JSON payload, checks if the + email or username already exists in the database, and returns an error message if they do. + If the email and username are unique, it creates a new user with the provided details + and hashes the password using the scrypt method. + + Returns: + Response: JSON response with a success or error message. + """ data = request.json email = data.get('email') username = data.get('username') diff --git a/api/base/models.py b/api/base/models.py index 32fee7e..e5752fb 100644 --- a/api/base/models.py +++ b/api/base/models.py @@ -1,7 +1,16 @@ -from app import db import uuid +from app import db class Base(db.Model): + """ + Base represents the base table in the database. + + Attributes: + id (str): The ID of the base. + created_at (datetime): The date and time the base was created. + updated_at (datetime): The date and time the base was last updated. + """ + __abstract__ = True id = db.Column('id', db.Text, default=lambda: str(uuid.uuid4()), primary_key=True) @@ -9,9 +18,15 @@ class Base(db.Model): updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp()) def save(self): + """ + Save the Base instance to the database. + """ db.session.add(self) db.session.commit() def delete(self): + """ + Delete the Base instance from the database. + """ db.session.delete(self) - db.session.commit() \ No newline at end of file + db.session.commit() diff --git a/api/categories/models.py b/api/categories/models.py index cb5bf17..ee53743 100644 --- a/api/categories/models.py +++ b/api/categories/models.py @@ -42,7 +42,7 @@ def __repr__(self): Returns: str: String representation of the category. """ - return '' % self.name + return f'' def to_dict(self): """ diff --git a/api/categories_group/models.py b/api/categories_group/models.py index 2a3363e..69908b1 100644 --- a/api/categories_group/models.py +++ b/api/categories_group/models.py @@ -11,7 +11,7 @@ def __init__(self, user_id, name): self.name = name def __repr__(self): - return '' % self.name + return f'' def to_dict(self): return { diff --git a/api/categories_type/controllers.py b/api/categories_type/controllers.py index f48b370..905b860 100644 --- a/api/categories_type/controllers.py +++ b/api/categories_type/controllers.py @@ -26,4 +26,4 @@ def post(self): def get(self): categories_type = CategoriesTypeModel.query.all() _categories_type = [category_type.to_dict() for category_type in categories_type] - return make_response(jsonify({'categories_type': _categories_type}), 200) \ No newline at end of file + return make_response(jsonify({'categories_type': _categories_type}), 200) diff --git a/api/categories_type/models.py b/api/categories_type/models.py index 0206f35..ed9d140 100644 --- a/api/categories_type/models.py +++ b/api/categories_type/models.py @@ -12,8 +12,8 @@ def __init__(self, user_id, name): self.name = name def __repr__(self): - return '' % self.name - + return f'' + def to_dict(self): return { 'id': self.id, diff --git a/api/institution/models.py b/api/institution/models.py index b58bc80..8a1c812 100644 --- a/api/institution/models.py +++ b/api/institution/models.py @@ -16,7 +16,7 @@ def __init__(self, user_id, name, location, description): self.description = description def __repr__(self): - return '' % self.name + return f'' def to_dict(self): return { diff --git a/api/institution_account/models.py b/api/institution_account/models.py index 63efffb..249c6df 100644 --- a/api/institution_account/models.py +++ b/api/institution_account/models.py @@ -20,8 +20,8 @@ def __init__(self, institution_id, user_id, name, number, status, balance): self.balance = balance def __repr__(self): - return '' % self.name - + return f'' + def to_dict(self): return { 'id': self.id, @@ -43,5 +43,3 @@ def save(self): def delete(self): db.session.delete(self) db.session.commit() - - diff --git a/api/transaction/controllers.py b/api/transaction/controllers.py index 66e91fe..72eebee 100644 --- a/api/transaction/controllers.py +++ b/api/transaction/controllers.py @@ -7,7 +7,8 @@ 'categories_id': fields.String(required=True, description='Categories ID'), 'account_id': fields.String(required=True, description='Account ID'), 'amount': fields.Float(required=True, description='Amount'), - 'transaction_type': fields.String(required=True, description='Transaction Type') + 'transaction_type': fields.String(required=True, description='Transaction Type'), + 'external_id': fields.String(description='External ID') }) @g.api.route('/transaction') @@ -20,13 +21,15 @@ def post(self): account_id = data.get('account_id') amount = data.get('amount') transaction_type = data.get('transaction_type') + external_id = data.get('external_id') new_transaction = TransactionModel( user_id=user_id, categories_id=categories_id, account_id=account_id, amount=amount, - transaction_type=transaction_type + transaction_type=transaction_type, + external_id=external_id ) new_transaction.save() diff --git a/api/transaction/models.py b/api/transaction/models.py index e82058a..d528dc4 100644 --- a/api/transaction/models.py +++ b/api/transaction/models.py @@ -1,26 +1,62 @@ from app import db from api.base.models import Base - class TransactionModel(Base): + """ + TransactionModel represents the transaction table in the database. + + Attributes: + user_id (str): The ID of the user associated with the transaction. + categories_id (str): The ID of the category associated with the transaction. + account_id (str): The ID of the account associated with the transaction. + amount (float): The amount of the transaction. + type (str): The type of the transaction. + external_id (str): The external ID of the transaction. + """ + __tablename__ = 'transaction' user_id = db.Column('user_id', db.Text, db.ForeignKey('user.id'), nullable=False) categories_id = db.Column('categories_id', db.Text, db.ForeignKey('categories.id'), nullable=False) account_id = db.Column('account_id', db.Text, db.ForeignKey('account.id'), nullable=False) amount = db.Column(db.Float, nullable=False) transaction_type = db.Column(db.String(255), nullable=False) + external_id = db.Column(db.String(255), nullable=False) + + def __init__(self, user_id, categories_id, account_id, amount, transaction_type, external_id): + """ + Initialize a TransactionModel instance. - def __init__(self, user_id, categories_id, account_id, amount, transaction_type): + Args: + user_id (str): The ID of the user associated with the transaction. + categories_id (str): The ID of the category associated with the transaction. + account_id (str): The ID of the account associated with the transaction. + amount (float): The amount of the transaction. + transaction_type (str): The transaction_type of the transaction. + external_id (str): The external ID of the transaction. + """ self.user_id = user_id self.categories_id = categories_id self.account_id = account_id self.amount = amount self.transaction_type = transaction_type + self.external_id = external_id def __repr__(self): - return '' % self.id - + """ + Return a string representation of the TransactionModel instance. + + Returns: + str: String representation of the transaction. + """ + return f'' + def to_dict(self): + """ + Convert the TransactionModel instance to a dictionary. + + Returns: + dict: Dictionary representation of the transaction. + """ return { 'id': self.id, 'user_id': self.user_id, @@ -28,14 +64,21 @@ def to_dict(self): 'account_id': self.account_id, 'amount': self.amount, 'transaction_type': self.transaction_type, + 'external_id': self.external_id, 'created_at': self.created_at, 'updated_at': self.updated_at } def save(self): + """ + Save the TransactionModel instance to the database. + """ db.session.add(self) db.session.commit() def delete(self): + """ + Delete the TransactionModel instance from the database. + """ db.session.delete(self) - db.session.commit() \ No newline at end of file + db.session.commit() diff --git a/api/user/controllers.py b/api/user/controllers.py index fb684ff..9191eda 100644 --- a/api/user/controllers.py +++ b/api/user/controllers.py @@ -44,4 +44,3 @@ def get(self): users = _user_model.query.all() users = [user.to_dict() for user in users] return make_response(jsonify({'users': users}), 200) - diff --git a/api/user/models.py b/api/user/models.py index 43474b5..0861ac4 100644 --- a/api/user/models.py +++ b/api/user/models.py @@ -1,7 +1,7 @@ +import secrets from flask_login import UserMixin from app import db from api.base.models import Base -import secrets class User(Base, UserMixin): __tablename__ = 'user' @@ -21,7 +21,7 @@ def __init__(self, email, username, password, first_name, last_name): self.api_key = None # Initialize without an API key def __repr__(self): - return '' % self.username + return f'' def to_dict(self): return { @@ -38,6 +38,3 @@ def generate_api_key(self): """Generate a new unique API key and save it to the database.""" self.api_key = secrets.token_hex(32) # Generate a 64-character API key db.session.commit() # Save the new key to the database - - - \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py index c7e700c..26c8c15 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,3 +1,5 @@ +# CSV +import csv # Flask from flask import Flask from flask import g @@ -8,8 +10,7 @@ # Baseline from app.config import Config from app.database import db -# CSV -import csv + def create_app(): app = Flask(__name__) @@ -58,10 +59,9 @@ def create_app(): #CLI from app.cli import insert_categories - @app.cli.command('insert-categories') + @app.cli.command('insert-categories') def insert_cat(): insert_categories() - db.create_all() diff --git a/app/account/controllers.py b/app/account/controllers.py index 7ac03e2..3479f09 100644 --- a/app/account/controllers.py +++ b/app/account/controllers.py @@ -1,10 +1,10 @@ -from flask import Blueprint, render_template, request, redirect, url_for +from flask import Blueprint, render_template, redirect, url_for from flask_login import logout_user, login_required account_blueprint = Blueprint('account', __name__) -@account_blueprint.route('/account/signup') -def signup(): +@account_blueprint.route('/account/signup') +def signup(): return render_template('account/signup.html') @account_blueprint.route('/account/login') @@ -15,4 +15,4 @@ def login(): @login_required def logout(): logout_user() - return redirect(url_for('account.login')) \ No newline at end of file + return redirect(url_for('account.login')) diff --git a/app/cli.py b/app/cli.py index fc74fb6..4156558 100644 --- a/app/cli.py +++ b/app/cli.py @@ -1,8 +1,8 @@ +# CSV +import csv # APP from app import db from app.config import Config -# CSV -import csv # MODELS from api.categories_type.models import CategoriesTypeModel as CategoriesType from api.categories_group.models import CategoriesGroupModel as CategoriesGroup @@ -12,7 +12,7 @@ def insert_categories(): user_id = Config.DEFAULT_USER_ID categories_type = [] categories_group = [] - with open("data/categories_data.csv", "r") as f_in: + with open("data/categories_data.csv", "r", encoding=str) as f_in: reader = csv.reader(f_in, quotechar="'") next(reader) # skip header ## categories_type @@ -35,8 +35,8 @@ def insert_categories(): cat = CategoriesGroup(name=category_group, user_id=user_id) db.session.add(cat) db.session.commit() - - with open("data/categories_data.csv", "r") as f_in: + + with open("data/categories_data.csv", "r", encoding=str) as f_in: reader = csv.reader(f_in, quotechar="'") next(reader) # skip header ## categories_type @@ -50,4 +50,4 @@ def insert_categories(): if _categories is None: cat = Categories(name=category, categories_group_id=_category_group_id, categories_type_id=_category_type_id, user_id=user_id) db.session.add(cat) - db.session.commit() \ No newline at end of file + db.session.commit() diff --git a/app/dashboard/controllers.py b/app/dashboard/controllers.py index 2c4917f..d9fcaa0 100644 --- a/app/dashboard/controllers.py +++ b/app/dashboard/controllers.py @@ -6,4 +6,4 @@ @dashboards.route('/') @login_required def index(): - return render_template('dashboards/index.html') \ No newline at end of file + return render_template('dashboards/index.html') diff --git a/app/database.py b/app/database.py index 2e1eeb6..f0b13d6 100644 --- a/app/database.py +++ b/app/database.py @@ -1,3 +1,3 @@ from flask_sqlalchemy import SQLAlchemy -db = SQLAlchemy() \ No newline at end of file +db = SQLAlchemy() diff --git a/app/institution/controllers.py b/app/institution/controllers.py index 804931b..1a7542a 100644 --- a/app/institution/controllers.py +++ b/app/institution/controllers.py @@ -8,7 +8,7 @@ @login_required def institution(): api_url = url_for('institution', _external=True) - response = requests.get(api_url) + response = requests.get(api_url, timeout=15) institutions = response.json().get('institutions', []) user_id = session.get('_user_id') diff --git a/main.py b/main.py index 523d51a..a3fdaf3 100644 --- a/main.py +++ b/main.py @@ -3,4 +3,4 @@ app = create_app() if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(debug=True) diff --git a/.pylintrc b/pylintrc similarity index 98% rename from .pylintrc rename to pylintrc index 4cd7a2a..b499dd3 100644 --- a/.pylintrc +++ b/pylintrc @@ -73,7 +73,7 @@ ignored-modules= # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use, and will cap the count on Windows to # avoid hangs. -jobs=1 +jobs=0 # Control the amount of potential inferred values when inferring a single # object. This can help the performance when dealing with large functions or @@ -440,7 +440,14 @@ disable=raw-checker-failed, use-implicit-booleaness-not-comparison-to-string, use-implicit-booleaness-not-comparison-to-zero, missing-module-docstring, - line-too-long + line-too-long, + missing-class-docstring, + missing-function-docstring, + import-outside-toplevel, + too-many-positional-arguments, + too-many-arguments, + unused-import, + too-many-locals # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option