diff --git a/src/application.py b/src/application.py index 0be4744..38c866d 100644 --- a/src/application.py +++ b/src/application.py @@ -22,19 +22,24 @@ import flask from src.models import db from views.errors import error_pages from views.scoreboard import scoreboard +from config import config -# General Configurations -app = flask.Flask(__name__) -basedir = os.path.abspath(os.path.dirname(__file__)) -# Database Configuration -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'database.sqlite') -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True -db.init_app(app) +def create_app(config_name): + app = flask.Flask(__name__) + app.config.from_object(config[config_name]) + + config[config_name].init_app(app) + db.init_app(app) + + app.register_blueprint(scoreboard) + app.register_blueprint(error_pages) + + return app + + +app = create_app('default') if __name__ == "__main__": - app.register_blueprint(scoreboard) - app.register_blueprint(error_pages) app.run("0.0.0.0") diff --git a/src/config.lock.py b/src/config.lock.py new file mode 100644 index 0000000..1b4b487 --- /dev/null +++ b/src/config.lock.py @@ -0,0 +1,46 @@ +""" + Author: Denis Nutiu + This file is part of scoreboard-benchmark. + + scoreboard-benchmark is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + scoreboard-benchmark is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with scoreboard-benchmark . If not, see . +""" +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + +class Config: + SQLALCHEMY_TRACK_MODIFICATIONS = False + SQLALCHEMY_COMMIT_ON_TEARDOWN = True + + @staticmethod + def init_app(app): + pass + + +class DevelopmentConfig(Config): + SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'database.sqlite') + + +class ProductionConfig(Config): + pass + + +class TestingConfig(Config): + pass + +config = { + 'development': DevelopmentConfig, + 'production' : ProductionConfig, + 'testing' : TestingConfig, + 'default' : DevelopmentConfig +} \ No newline at end of file