mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-18 01:09:03 +00:00
Refactor into an app factory [2 of 2] (#322)
* Replace all `from nyaa import app` imports with `app = flask.current_app` (or `from flask import current_app as app` where possible) * Add a separate config object for top-level and class statements as `nyaa.extensions.config` Required because those codes don't have app context at the time of evaluation/execution. * Remove `routes.py` file and register all blueprints in `nyaa/__init__.py` * Refactor `nyaa/__init__.py` into an app factory * Update tools * Update tests (temporary, will be replaced)
This commit is contained in:
@@ -8,7 +8,7 @@ from nyaa.views import ( # isort:skip
|
||||
)
|
||||
|
||||
|
||||
def register(flask_app):
|
||||
def register_views(flask_app):
|
||||
""" Register the blueprints using the flask_app object """
|
||||
flask_app.register_blueprint(account.bp)
|
||||
flask_app.register_blueprint(admin.bp)
|
||||
|
||||
@@ -6,10 +6,11 @@ from ipaddress import ip_address
|
||||
|
||||
import flask
|
||||
|
||||
from nyaa import app, forms, models
|
||||
from nyaa import forms, models
|
||||
from nyaa.extensions import db
|
||||
from nyaa.views.users import get_activation_link
|
||||
|
||||
app = flask.current_app
|
||||
bp = flask.Blueprint('account', __name__)
|
||||
|
||||
|
||||
|
||||
@@ -5,12 +5,13 @@ from datetime import datetime, timedelta
|
||||
import flask
|
||||
from flask_paginate import Pagination
|
||||
|
||||
from nyaa import app, models
|
||||
from nyaa import models
|
||||
from nyaa.search import (DEFAULT_MAX_SEARCH_RESULT, DEFAULT_PER_PAGE, SERACH_PAGINATE_DISPLAY_MSG,
|
||||
_generate_query_string, search_db, search_elastic)
|
||||
from nyaa.utils import chain_get
|
||||
from nyaa.views.account import logout
|
||||
|
||||
app = flask.current_app
|
||||
bp = flask.Blueprint('main', __name__)
|
||||
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ from werkzeug.datastructures import CombinedMultiDict
|
||||
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from nyaa import app, backend, forms, models, torrents
|
||||
from nyaa import backend, forms, models, torrents
|
||||
from nyaa.extensions import db
|
||||
from nyaa.utils import cached_function
|
||||
|
||||
app = flask.current_app
|
||||
bp = flask.Blueprint('torrents', __name__)
|
||||
|
||||
|
||||
|
||||
@@ -5,12 +5,13 @@ from flask_paginate import Pagination
|
||||
|
||||
from itsdangerous import BadSignature, URLSafeSerializer
|
||||
|
||||
from nyaa import app, forms, models
|
||||
from nyaa import forms, models
|
||||
from nyaa.extensions import db
|
||||
from nyaa.search import (DEFAULT_MAX_SEARCH_RESULT, DEFAULT_PER_PAGE, SERACH_PAGINATE_DISPLAY_MSG,
|
||||
_generate_query_string, search_db, search_elastic)
|
||||
from nyaa.utils import chain_get
|
||||
|
||||
app = flask.current_app
|
||||
bp = flask.Blueprint('users', __name__)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user