mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-16 00:09:05 +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:
@@ -14,9 +14,12 @@ from wtforms.validators import (DataRequired, Email, EqualTo, Length, Optional,
|
||||
from wtforms.widgets import Select as SelectWidget # For DisabledSelectField
|
||||
from wtforms.widgets import HTMLString, html_params # For DisabledSelectField
|
||||
|
||||
from nyaa import app, bencode, models, utils
|
||||
from nyaa import bencode, models, utils
|
||||
from nyaa.extensions import config
|
||||
from nyaa.models import User
|
||||
|
||||
app = flask.current_app
|
||||
|
||||
|
||||
class Unique(object):
|
||||
|
||||
@@ -81,7 +84,7 @@ class RegisterForm(FlaskForm):
|
||||
|
||||
password_confirm = PasswordField('Password (confirm)')
|
||||
|
||||
if app.config['USE_RECAPTCHA']:
|
||||
if config['USE_RECAPTCHA']:
|
||||
recaptcha = RecaptchaField()
|
||||
|
||||
|
||||
@@ -195,7 +198,7 @@ class UploadForm(FlaskForm):
|
||||
'%(max)d at most.')
|
||||
])
|
||||
|
||||
if app.config['USE_RECAPTCHA']:
|
||||
if config['USE_RECAPTCHA']:
|
||||
# Captcha only for not logged in users
|
||||
_recaptcha_validator = RecaptchaValidator()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user