Skip to content

Commit

Permalink
Merge pull request #7 from NikhilRaikar17/FTR-1-refactor-old-code
Browse files Browse the repository at this point in the history
Refactored old_code and bought it to sync with python 3.10
  • Loading branch information
NikhilRaikar17 authored Aug 4, 2024
2 parents 655dfdb + c828b26 commit 4e09783
Show file tree
Hide file tree
Showing 27 changed files with 761 additions and 1,390 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/flask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Flask App Test

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8.x'
cache: 'pip'

- name: Install dependencies
working-directory: e_invoice
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Flask app
working-directory: e_invoice
run: |
nohup python manage.py > server.log 2>&1 &
echo $! > flask_server.pid
- name: Test /login route
run: |
sleep 10 # Wait for the server to start
curl -s --head http://127.0.0.1:5000/login | head -n 10
- name: Stop Flask app
run: |
kill $(cat flask_server.pid)
continue-on-error: true
2 changes: 1 addition & 1 deletion e_invoice/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*.pyc
.idea
/.vscode
__pycache__
__pycache__
61 changes: 61 additions & 0 deletions e_invoice/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
exclude: |
(?x)^(
.*\.xml$| # Exclude all XML files
venv/.*| # Exclude everything in the venv directory
.*\.pyc$| # Exclude all Python compiled files
\.idea/.*| # Exclude everything in the .idea directory
\.vscode/.*| # Exclude everything in the .vscode directory
__pycache__/.* # Exclude everything in the __pycache__ directory
application/static/.* # Exclude everything in the application/static directory
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: double-quote-string-fixer
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/asottile/reorder-python-imports
rev: v3.13.0
hooks:
- id: reorder-python-imports
exclude: ^(pre_commit/resources/|testing/resources/python3_hooks_repo/)
args: [--py39-plus, --add-import, 'from __future__ import annotations']

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/hhatto/autopep8
rev: v2.3.1
hooks:
- id: autopep8

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
hooks:
- id: mypy
additional_dependencies: [types-all]
exclude: ^testing/resources/
2 changes: 1 addition & 1 deletion e_invoice/Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: gunicorn manage:gunicorn_app --log-file -
web: gunicorn manage:gunicorn_app --log-file -
6 changes: 4 additions & 2 deletions e_invoice/application/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()
login_manager = LoginManager()


def create_app():
app = Flask(__name__)
app.config.from_object("config.DevelopmentConfig")
app.config.from_object('config.DevelopmentConfig')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
login_manager.init_app(app)
Expand Down
25 changes: 18 additions & 7 deletions e_invoice/application/models/db_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

from application import db


class Users(db.Model):
__tablename__ = "users"
__tablename__ = 'users'
# primary keys are required by SQLAlchemy
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), unique=True)
Expand Down Expand Up @@ -46,14 +48,23 @@ class Invoice(db.Model):
# primary keys are required by SQLAlchemy
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100))
customer_id = db.Column(db.Integer, db.ForeignKey(
"customers.id"), nullable=False)
customer_id = db.Column(
db.Integer, db.ForeignKey(
'customers.id',
), nullable=False,
)


class InvoiceMaps(db.Model):
__tablename__ = 'invoicemaps'
id = db.Column(db.Integer, primary_key=True)
customer_id = db.Column(db.Integer, db.ForeignKey(
"customers.id"), nullable=False)
product_id = db.Column(db.Integer, db.ForeignKey(
"products.id"), nullable=False)
customer_id = db.Column(
db.Integer, db.ForeignKey(
'customers.id',
), nullable=False,
)
product_id = db.Column(
db.Integer, db.ForeignKey(
'products.id',
), nullable=False,
)
Loading

0 comments on commit 4e09783

Please sign in to comment.