move blueprints in dedicated folder

This commit is contained in:
Patrick Jentsch 2024-09-30 13:30:13 +02:00
parent 5fc3015bf1
commit eeb5a280b3
75 changed files with 44 additions and 58 deletions

View File

@ -92,45 +92,45 @@ def create_app(config: Config = Config) -> Flask:
# endregion Extensions # endregion Extensions
# region Blueprints # region Blueprints
from .admin import bp as admin_blueprint from .blueprints.admin import bp as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin') app.register_blueprint(admin_blueprint, url_prefix='/admin')
from .api import bp as api_blueprint from .blueprints.api import bp as api_blueprint
app.register_blueprint(api_blueprint, url_prefix='/api') app.register_blueprint(api_blueprint, url_prefix='/api')
from .auth import bp as auth_blueprint from .blueprints.auth import bp as auth_blueprint
app.register_blueprint(auth_blueprint) app.register_blueprint(auth_blueprint)
from .contributions import bp as contributions_blueprint from .blueprints.contributions import bp as contributions_blueprint
app.register_blueprint(contributions_blueprint, url_prefix='/contributions') app.register_blueprint(contributions_blueprint, url_prefix='/contributions')
from .corpora import bp as corpora_blueprint from .blueprints.corpora import bp as corpora_blueprint
app.register_blueprint(corpora_blueprint, cli_group='corpus', url_prefix='/corpora') app.register_blueprint(corpora_blueprint, cli_group='corpus', url_prefix='/corpora')
from .errors import bp as errors_bp from .blueprints.errors import bp as errors_bp
app.register_blueprint(errors_bp) app.register_blueprint(errors_bp)
from .jobs import bp as jobs_blueprint from .blueprints.jobs import bp as jobs_blueprint
app.register_blueprint(jobs_blueprint, url_prefix='/jobs') app.register_blueprint(jobs_blueprint, url_prefix='/jobs')
from .main import bp as main_blueprint from .blueprints.main import bp as main_blueprint
app.register_blueprint(main_blueprint, cli_group=None) app.register_blueprint(main_blueprint, cli_group=None)
from .services import bp as services_blueprint from .blueprints.services import bp as services_blueprint
app.register_blueprint(services_blueprint, url_prefix='/services') app.register_blueprint(services_blueprint, url_prefix='/services')
from .settings import bp as settings_blueprint from .blueprints.settings import bp as settings_blueprint
app.register_blueprint(settings_blueprint, url_prefix='/settings') app.register_blueprint(settings_blueprint, url_prefix='/settings')
from .users import bp as users_blueprint from .blueprints.users import bp as users_blueprint
app.register_blueprint(users_blueprint, cli_group='user', url_prefix='/users') app.register_blueprint(users_blueprint, cli_group='user', url_prefix='/users')
from .workshops import bp as workshops_blueprint from .blueprints.workshops import bp as workshops_blueprint
app.register_blueprint(workshops_blueprint, url_prefix='/workshops') app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
# endregion Blueprints # endregion Blueprints
# region SocketIO Namespaces # region SocketIO Namespaces
from .corpora.cqi_over_sio import CQiOverSocketIO from .blueprints.corpora.cqi_over_sio import CQiOverSocketIO
socketio.on_namespace(CQiOverSocketIO('/cqi_over_sio')) socketio.on_namespace(CQiOverSocketIO('/cqi_over_sio'))
# endregion SocketIO Namespaces # endregion SocketIO Namespaces
@ -141,25 +141,11 @@ def create_app(config: Config = Config) -> Flask:
# region Add scheduler jobs # region Add scheduler jobs
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']: if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
from .tasks import handle_corpora from .jobs import handle_corpora
scheduler.add_job('handle_corpora', handle_corpora, seconds=3, trigger='interval') scheduler.add_job('handle_corpora', handle_corpora, seconds=3, trigger='interval')
from .tasks import handle_jobs from .jobs import handle_jobs
scheduler.add_job('handle_jobs', handle_jobs, seconds=3, trigger='interval') scheduler.add_job('handle_jobs', handle_jobs, seconds=3, trigger='interval')
# endregion Add scheduler jobs # endregion Add scheduler jobs
return app return app
# def _add_admin_views():
# from flask_admin.contrib.sqla import ModelView
# from . import models
# for v in models.__dict__.values():
# # Check if v is a class
# if not isinstance(v, type):
# continue
# # Check if v is a subclass of db.Model
# if not issubclass(v, db.Model):
# continue
# admin.add_view(ModelView(v, db.session, category='Database'))

View File

@ -1,7 +1,7 @@
from flask import abort, flash, redirect, render_template, url_for from flask import abort, flash, redirect, render_template, url_for
from app import db, hashids from app import db, hashids
from app.models import Avatar, Corpus, Role, User from app.models import Avatar, Corpus, Role, User
from app.users.settings.forms import ( from app.blueprints.users.settings.forms import (
UpdateAvatarForm, UpdateAvatarForm,
UpdatePasswordForm, UpdatePasswordForm,
UpdateNotificationsForm, UpdateNotificationsForm,

View File

@ -10,7 +10,7 @@ from app.models import (
User, User,
UserSettingJobStatusMailNotificationLevel UserSettingJobStatusMailNotificationLevel
) )
from app.services import SERVICES from app.blueprints.services import SERVICES

View File

@ -1,7 +1,7 @@
from flask_wtf.file import FileField, FileRequired from flask_wtf.file import FileField, FileRequired
from wtforms import StringField, ValidationError from wtforms import StringField, ValidationError
from wtforms.validators import InputRequired, Length from wtforms.validators import InputRequired, Length
from app.services import SERVICES from app.blueprints.services import SERVICES
from ..forms import ContributionBaseForm, UpdateContributionBaseForm from ..forms import ContributionBaseForm, UpdateContributionBaseForm

View File

@ -1,6 +1,6 @@
from flask_wtf.file import FileField, FileRequired from flask_wtf.file import FileField, FileRequired
from wtforms import ValidationError from wtforms import ValidationError
from app.services import SERVICES from app.blueprints.services import SERVICES
from ..forms import ContributionBaseForm, UpdateContributionBaseForm from ..forms import ContributionBaseForm, UpdateContributionBaseForm

View File

@ -0,0 +1,18 @@
from flask import Blueprint
from flask_login import login_required
bp = Blueprint('jobs', __name__)
@bp.before_request
@login_required
def before_request():
'''
Ensures that the routes in this package can only be visited by users that
are logged in.
'''
pass
from . import routes, json_routes

View File

@ -1,6 +1,6 @@
from flask import flash, redirect, render_template, url_for from flask import flash, redirect, render_template, url_for
from flask_login import current_user, login_required, login_user from flask_login import current_user, login_required, login_user
from app.auth.forms import LoginForm from app.blueprints.auth.forms import LoginForm
from app.models import Corpus, User from app.models import Corpus, User
from . import bp from . import bp

View File

@ -1,6 +1,6 @@
from flask import g, url_for from flask import g, url_for
from flask_login import current_user from flask_login import current_user
from app.users.settings.routes import settings as settings_route from app.blueprints.users.settings.routes import settings as settings_route
from . import bp from . import bp

View File

@ -1,18 +1,2 @@
from flask import Blueprint from .handle_corpora import job as handle_corpora
from flask_login import login_required from .handle_jobs import job as handle_jobs
bp = Blueprint('jobs', __name__)
@bp.before_request
@login_required
def before_request():
'''
Ensures that the routes in this package can only be visited by users that
are logged in.
'''
pass
from . import routes, json_routes

View File

@ -6,7 +6,7 @@ import os
import shutil import shutil
def task(): def job():
with scheduler.app.app_context(): with scheduler.app.app_context():
_handle_corpora() _handle_corpora()

View File

@ -15,7 +15,7 @@ import os
import shutil import shutil
def task(): def job():
with scheduler.app.app_context(): with scheduler.app.app_context():
_handle_jobs() _handle_jobs()

View File

@ -1,2 +0,0 @@
from .handle_corpora import task as handle_corpora
from .handle_jobs import task as handle_jobs