From 2c5ed210110d5a9cc28e61855d5fa5fc592e05a8 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Sat, 11 Jun 2022 18:08:24 +0100 Subject: [PATCH] Fixed the weird database issue --- ref-test/app/__init__.py | 51 --------------------------- ref-test/app/data.py | 2 +- ref-test/app/install.py | 5 ++- ref-test/app/modules.py | 10 ++++++ ref-test/app/modules/__init__.py | 0 ref-test/app/modules/bootstrap.py | 2 -- ref-test/app/modules/csrf.py | 2 -- ref-test/app/modules/db.py | 2 -- ref-test/app/modules/login_manager.py | 2 -- ref-test/app/modules/mail.py | 2 -- ref-test/app/tools/data.py | 2 +- ref-test/app/tools/logs.py | 2 +- ref-test/main.py | 51 +++++++++++++++++++++++++-- 13 files changed, 64 insertions(+), 69 deletions(-) create mode 100644 ref-test/app/modules.py delete mode 100644 ref-test/app/modules/__init__.py delete mode 100644 ref-test/app/modules/bootstrap.py delete mode 100644 ref-test/app/modules/csrf.py delete mode 100644 ref-test/app/modules/db.py delete mode 100644 ref-test/app/modules/login_manager.py delete mode 100644 ref-test/app/modules/mail.py diff --git a/ref-test/app/__init__.py b/ref-test/app/__init__.py index a8ae420..e69de29 100644 --- a/ref-test/app/__init__.py +++ b/ref-test/app/__init__.py @@ -1,51 +0,0 @@ -from .modules.bootstrap import bootstrap -from .modules.csrf import csrf -from .modules.db import db -from .modules.login_manager import login_manager -from .modules.mail import mail -from .config import DevelopmentConfig as Config - -from flask import Flask -from flask_wtf.csrf import CSRFError -from flask.json import jsonify -from werkzeug.middleware.proxy_fix import ProxyFix - -from datetime import datetime - -from .admin.views import admin -from .api.views import api -from .views import views -from .quiz.views import quiz - -def create_app(): - app = Flask(__name__) - app.config.from_object(Config()) - app.wsgi_app = ProxyFix(app.wsgi_app, x_proto= 1, x_host= 1) - - bootstrap.init_app(app) - csrf.init_app(app) - db.init_app(app) - login_manager.init_app(app) - mail.init_app(app) - - login_manager.login_view = 'admin._login' - @login_manager.user_loader - def _load_user(user_id): - pass - - @app.errorhandler(404) - def _404_handler(error): - return jsonify({'error':'404 — Not Found'}), 404 - @app.errorhandler(CSRFError) - def _csrf_handler(): - return jsonify({'error':'Could not validate a secure connection.'}), 403 - @app.context_processor - def _now(): - return {'now': datetime.utcnow()} - - app.register_blueprint(admin, url_prefix='/admin') - app.register_blueprint(api, url_prefix='/api') - app.register_blueprint(views) - app.register_blueprint(quiz) - - return app diff --git a/ref-test/app/data.py b/ref-test/app/data.py index b6b4ce1..ba972f9 100644 --- a/ref-test/app/data.py +++ b/ref-test/app/data.py @@ -1,4 +1,4 @@ -from . import Config +from main import Config from os import path from pathlib import Path diff --git a/ref-test/app/install.py b/ref-test/app/install.py index 2ea9759..b54ccec 100644 --- a/ref-test/app/install.py +++ b/ref-test/app/install.py @@ -1,7 +1,6 @@ -from main import app -from . import Config +from main import app, Config from .data import data -from .modules.db import db +from .modules import db from .tools.data import save from .tools.logs import write diff --git a/ref-test/app/modules.py b/ref-test/app/modules.py new file mode 100644 index 0000000..873c3d1 --- /dev/null +++ b/ref-test/app/modules.py @@ -0,0 +1,10 @@ +from flask_bootstrap import Bootstrap +bootstrap = Bootstrap() +from flask_wtf.csrf import CSRFProtect +csrf = CSRFProtect() +from flask_sqlalchemy import SQLAlchemy +db = SQLAlchemy() +from flask_login import LoginManager +login_manager = LoginManager() +from flask_mail import Mail +mail = Mail() \ No newline at end of file diff --git a/ref-test/app/modules/__init__.py b/ref-test/app/modules/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/ref-test/app/modules/bootstrap.py b/ref-test/app/modules/bootstrap.py deleted file mode 100644 index 32a6a6a..0000000 --- a/ref-test/app/modules/bootstrap.py +++ /dev/null @@ -1,2 +0,0 @@ -from flask_bootstrap import Bootstrap -bootstrap = Bootstrap() \ No newline at end of file diff --git a/ref-test/app/modules/csrf.py b/ref-test/app/modules/csrf.py deleted file mode 100644 index edda995..0000000 --- a/ref-test/app/modules/csrf.py +++ /dev/null @@ -1,2 +0,0 @@ -from flask_wtf.csrf import CSRFProtect -csrf = CSRFProtect() \ No newline at end of file diff --git a/ref-test/app/modules/db.py b/ref-test/app/modules/db.py deleted file mode 100644 index 589c64f..0000000 --- a/ref-test/app/modules/db.py +++ /dev/null @@ -1,2 +0,0 @@ -from flask_sqlalchemy import SQLAlchemy -db = SQLAlchemy() \ No newline at end of file diff --git a/ref-test/app/modules/login_manager.py b/ref-test/app/modules/login_manager.py deleted file mode 100644 index 4a9813d..0000000 --- a/ref-test/app/modules/login_manager.py +++ /dev/null @@ -1,2 +0,0 @@ -from flask_login import LoginManager -login_manager = LoginManager() \ No newline at end of file diff --git a/ref-test/app/modules/mail.py b/ref-test/app/modules/mail.py deleted file mode 100644 index 6636ec6..0000000 --- a/ref-test/app/modules/mail.py +++ /dev/null @@ -1,2 +0,0 @@ -from flask_mail import Mail -mail = Mail() \ No newline at end of file diff --git a/ref-test/app/tools/data.py b/ref-test/app/tools/data.py index cd03555..a99cdce 100644 --- a/ref-test/app/tools/data.py +++ b/ref-test/app/tools/data.py @@ -1,4 +1,4 @@ -from .. import Config +from main import Config from ..data import data as data_dir import json diff --git a/ref-test/app/tools/logs.py b/ref-test/app/tools/logs.py index e4e24c1..b095cf5 100644 --- a/ref-test/app/tools/logs.py +++ b/ref-test/app/tools/logs.py @@ -1,4 +1,4 @@ -from .. import Config +from main import Config from ..data import data from datetime import datetime diff --git a/ref-test/main.py b/ref-test/main.py index 3042cee..0f84d66 100644 --- a/ref-test/main.py +++ b/ref-test/main.py @@ -1,6 +1,53 @@ -#!/bin/env python -from app import create_app +from app.modules import bootstrap, csrf, db, login_manager, mail +from app.config import DevelopmentConfig as Config + +from flask import Flask +from flask_wtf.csrf import CSRFError +from flask.json import jsonify +from werkzeug.middleware.proxy_fix import ProxyFix + +from datetime import datetime + +from app.admin.views import admin +from app.api.views import api +from app.views import views +from app.quiz.views import quiz + +def create_app(): + app = Flask(__name__) + app.config.from_object(Config()) + app.wsgi_app = ProxyFix(app.wsgi_app, x_proto= 1, x_host= 1) + + bootstrap.init_app(app) + csrf.init_app(app) + db.init_app(app) + login_manager.init_app(app) + mail.init_app(app) + + login_manager.login_view = 'admin._login' + @login_manager.user_loader + def _load_user(user_id): + pass + + @app.errorhandler(404) + def _404_handler(error): + return jsonify({'error':'404 — Not Found'}), 404 + @app.errorhandler(CSRFError) + def _csrf_handler(): + return jsonify({'error':'Could not validate a secure connection.'}), 403 + @app.context_processor + def _now(): + return {'now': datetime.utcnow()} + + app.register_blueprint(admin, url_prefix='/admin') + app.register_blueprint(api, url_prefix='/api') + app.register_blueprint(views) + app.register_blueprint(quiz) + + return app + app = create_app() + if __name__ == '__main__': from app.install import install_scripts install_scripts()