changes of db config add .env file and rename of ex_formate.html to file_formate.html
This commit is contained in:
31
.env
Normal file
31
.env
Normal file
@@ -0,0 +1,31 @@
|
||||
# -----------------------------
|
||||
# Flask App Configuration
|
||||
# -----------------------------
|
||||
FLASK_ENV=development
|
||||
FLASK_DEBUG=True
|
||||
FLASK_HOST=127.0.0.1
|
||||
FLASK_PORT=5001
|
||||
|
||||
# -----------------------------
|
||||
# Security
|
||||
# -----------------------------
|
||||
SECRET_KEY=change-this-to-strong-secret-key
|
||||
|
||||
# -----------------------------
|
||||
# Database Configuration
|
||||
# -----------------------------
|
||||
DB_DIALECT=mysql
|
||||
DB_DRIVER=pymysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_NAME=comparisondb
|
||||
DB_USER=root
|
||||
DB_PASSWORD=root
|
||||
|
||||
# DATABASE_URL=mysql+pymysql://root:root@localhost/comparisondb
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -3,11 +3,12 @@ app/__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
*.__pycache__
|
||||
|
||||
# Ingnor upload files
|
||||
app/static/uploads/
|
||||
|
||||
# Ignore files
|
||||
# Ignore env files
|
||||
venv
|
||||
|
||||
# Ignore Log files ss
|
||||
@@ -17,4 +18,3 @@ logs/
|
||||
instance/
|
||||
|
||||
|
||||
*.__pycache__
|
||||
@@ -1,3 +1,34 @@
|
||||
# from flask import Flask
|
||||
# from app.config import Config
|
||||
# from app.services.db_service import db
|
||||
|
||||
# def create_app():
|
||||
# app = Flask(__name__)
|
||||
# app.config.from_object(Config)
|
||||
|
||||
# db.init_app(app)
|
||||
|
||||
# from app.routes.auth import auth_bp
|
||||
# from app.routes.user import user_bp
|
||||
# from app.routes.dashboard import dashboard_bp
|
||||
# from app.routes.subcontractor_routes import subcontractor_bp
|
||||
# from app.routes.file_import import file_import_bp
|
||||
# from app.routes.file_report import file_report_bp
|
||||
# from app.routes.generate_comparison_report import generate_report_bp
|
||||
# from app.routes.file_format import file_format
|
||||
|
||||
# app.register_blueprint(auth_bp)
|
||||
# app.register_blueprint(user_bp)
|
||||
# app.register_blueprint(dashboard_bp)
|
||||
# app.register_blueprint(subcontractor_bp)
|
||||
# app.register_blueprint(file_import_bp)
|
||||
# app.register_blueprint(file_report_bp)
|
||||
# app.register_blueprint(generate_report_bp)
|
||||
# app.register_blueprint(file_format)
|
||||
|
||||
# return app
|
||||
|
||||
|
||||
from flask import Flask
|
||||
from app.config import Config
|
||||
from app.services.db_service import db
|
||||
@@ -6,8 +37,19 @@ def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
# Initialize extensions
|
||||
db.init_app(app)
|
||||
|
||||
# Register blueprints
|
||||
register_blueprints(app)
|
||||
|
||||
# Register error handlers
|
||||
register_error_handlers(app)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def register_blueprints(app):
|
||||
from app.routes.auth import auth_bp
|
||||
from app.routes.user import user_bp
|
||||
from app.routes.dashboard import dashboard_bp
|
||||
@@ -15,7 +57,7 @@ def create_app():
|
||||
from app.routes.file_import import file_import_bp
|
||||
from app.routes.file_report import file_report_bp
|
||||
from app.routes.generate_comparison_report import generate_report_bp
|
||||
from app.routes.file_format import file_format
|
||||
from app.routes.file_format import file_format_bp
|
||||
|
||||
app.register_blueprint(auth_bp)
|
||||
app.register_blueprint(user_bp)
|
||||
@@ -24,6 +66,14 @@ def create_app():
|
||||
app.register_blueprint(file_import_bp)
|
||||
app.register_blueprint(file_report_bp)
|
||||
app.register_blueprint(generate_report_bp)
|
||||
app.register_blueprint(file_format)
|
||||
app.register_blueprint(file_format_bp )
|
||||
|
||||
return app
|
||||
|
||||
def register_error_handlers(app):
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return "Page Not Found", 404
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_error(e):
|
||||
return "Internal Server Error", 500
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
import os
|
||||
# project base url
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
class Config:
|
||||
# secret key
|
||||
SECRET_KEY = os.getenv("SECRET_KEY", "dev-secret-key")
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:root@localhost/comparisondb"
|
||||
# Database varibles
|
||||
DB_DIALECT = os.getenv("DB_DIALECT")
|
||||
DB_DRIVER = os.getenv("DB_DRIVER")
|
||||
DB_USER = os.getenv("DB_USER")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
DB_NAME = os.getenv("DB_NAME")
|
||||
# database connection url
|
||||
SQLALCHEMY_DATABASE_URI = (
|
||||
f"{DB_DIALECT}+{DB_DRIVER}://"
|
||||
f"{DB_USER}:{DB_PASSWORD}@"
|
||||
f"{DB_HOST}:{DB_PORT}/"
|
||||
f"{DB_NAME}"
|
||||
)
|
||||
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
SECRET_KEY = "secret123"
|
||||
|
||||
UPLOAD_FOLDER = "app/static/uploads/"
|
||||
# uploads folder path
|
||||
UPLOAD_FOLDER = os.path.join(BASE_DIR, "static", "uploads")
|
||||
# file extension
|
||||
ALLOWED_EXTENSIONS = {"xlsx", "xls", "csv"}
|
||||
|
||||
@@ -2,15 +2,15 @@ from flask import Blueprint, render_template, send_from_directory, abort, curren
|
||||
from app.utils.helpers import login_required
|
||||
import os
|
||||
|
||||
file_format = Blueprint("file_format", __name__)
|
||||
file_format_bp = Blueprint("file_format", __name__)
|
||||
|
||||
@file_format.route("/file_format")
|
||||
@file_format_bp .route("/file_format")
|
||||
@login_required
|
||||
def download_format():
|
||||
return render_template("ex_format.html", title="Download File Formats")
|
||||
return render_template("file_format.html", title="Download File Formats")
|
||||
|
||||
|
||||
@file_format.route("/file_format/download/<filename>")
|
||||
@file_format_bp .route("/file_format/download/<filename>")
|
||||
@login_required
|
||||
def download_excel_format(filename):
|
||||
|
||||
|
||||
14
run.py
14
run.py
@@ -1,9 +1,17 @@
|
||||
from app import create_app, db
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
from app import create_app
|
||||
from app.services.db_service import db
|
||||
import os
|
||||
|
||||
app = create_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host='0.0.0.0' ,debug=True, port=5001)
|
||||
app.run(
|
||||
host=os.getenv("FLASK_HOST"),
|
||||
port=int(os.getenv("FLASK_PORT")),
|
||||
debug=os.getenv("FLASK_DEBUG") == "True"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user