diff --git a/app.py b/app.py index 51e7d4f..0ccdfc4 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,6 @@ # Validate configuration before starting the app from functions.validate_config import validate_config -from config import item_attributes +from config import item_attributes, sql_conf config_status = validate_config(item_attributes) if config_status != "Ok": @@ -23,7 +23,7 @@ from routes.confirm_save import confirm_save_bp app = Flask(__name__) app.secret_key = 'your_secret_key' # Required for flashing messages and session -app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://assetadmin:1234@localhost/asset_test_db' +app.config['SQLALCHEMY_DATABASE_URI'] = f'mysql://{sql_conf.SQL_USER}:{sql_conf.SQL_PASSWORD}@{sql_conf.SQL_HOST}/{sql_conf.SQL_DB}' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) diff --git a/config.py b/config.py index 949d5aa..30eb21a 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,13 @@ from definitions.attribute import Attribute +# MySQL information +class sql_conf: + SQL_USER = "assetadmin" + SQL_PASSWORD = "1234" + SQL_HOST = "localhost" + SQL_DB = "asset_test_db" + SQL_TABLE = "asset_test" + item_attributes = { "assettag": Attribute( display_name="Asset Tag", diff --git a/definitions/models.py b/definitions/models.py index 0272c88..a64ba83 100644 --- a/definitions/models.py +++ b/definitions/models.py @@ -1,6 +1,7 @@ from flask_sqlalchemy import SQLAlchemy from config import item_attributes # Import the configuration from sqlalchemy import Enum, Integer, String, Date, Column +from config import sql_conf db = SQLAlchemy() @@ -10,7 +11,7 @@ def create_asset_model(): Dynamically creates the Asset model based on the configuration in item_attributes. """ attrs = { - '__tablename__': 'asset_test', # Table name + '__tablename__': sql_conf.SQL_TABLE, # Table name '__init__': lambda self, **kwargs: self.__dict__.update(kwargs), # Constructor '__repr__': lambda self: f"" # Representation }