Fixed the weird database issue

This commit is contained in:
Vivek Santayana 2022-06-11 18:08:24 +01:00
parent 59281db9cb
commit 2c5ed21011
13 changed files with 64 additions and 69 deletions

View File

@ -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

View File

@ -1,4 +1,4 @@
from . import Config from main import Config
from os import path from os import path
from pathlib import Path from pathlib import Path

View File

@ -1,7 +1,6 @@
from main import app from main import app, Config
from . import Config
from .data import data from .data import data
from .modules.db import db from .modules import db
from .tools.data import save from .tools.data import save
from .tools.logs import write from .tools.logs import write

10
ref-test/app/modules.py Normal file
View File

@ -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()

View File

@ -1,2 +0,0 @@
from flask_bootstrap import Bootstrap
bootstrap = Bootstrap()

View File

@ -1,2 +0,0 @@
from flask_wtf.csrf import CSRFProtect
csrf = CSRFProtect()

View File

@ -1,2 +0,0 @@
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()

View File

@ -1,2 +0,0 @@
from flask_login import LoginManager
login_manager = LoginManager()

View File

@ -1,2 +0,0 @@
from flask_mail import Mail
mail = Mail()

View File

@ -1,4 +1,4 @@
from .. import Config from main import Config
from ..data import data as data_dir from ..data import data as data_dir
import json import json

View File

@ -1,4 +1,4 @@
from .. import Config from main import Config
from ..data import data from ..data import data
from datetime import datetime from datetime import datetime

View File

@ -1,6 +1,53 @@
#!/bin/env python from app.modules import bootstrap, csrf, db, login_manager, mail
from app import create_app 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() app = create_app()
if __name__ == '__main__': if __name__ == '__main__':
from app.install import install_scripts from app.install import install_scripts
install_scripts() install_scripts()