mirror of
https://github.com/sb745/NyaaV3.git
synced 2025-03-12 13:56:55 +02:00

* forms: replace re._pattern_type with re.Pattern Python 3.7 removed re._pattern_type and replaced it with re.Pattern. * readme: update for Python 3.7 * Update requirements Also remove some unused ones which were neither a direct dependency nor a dependency of our dependencies. * account: force ASCII usernames on login form Our database doesn't like it when we check for unicode data in a column that stores ASCII data, so let's stop it before it gets that far. * Move travis CI to Python 3.7 * travis: use xenial dist * fix newer linter warnings Apparently bare excepts are literally Hitler, and we have some new import sorting rules. Hooray! * requirements: remove six This is a dependency for sqlalchemy-utils, but we ourselves don't depend on it directly because we've never been on Python 2 ever. * Update requirements.txt
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import flask
|
|
|
|
from nyaa.views import ( # isort:skip
|
|
account,
|
|
admin,
|
|
main,
|
|
site,
|
|
torrents,
|
|
users,
|
|
)
|
|
|
|
|
|
def _maintenance_mode_hook():
|
|
''' Blocks POSTs, unless MAINTENANCE_MODE_LOGINS is True and the POST is for a login. '''
|
|
if flask.request.method == 'POST':
|
|
allow_logins = flask.current_app.config['MAINTENANCE_MODE_LOGINS']
|
|
endpoint = flask.request.endpoint
|
|
|
|
if not (allow_logins and endpoint == 'account.login'):
|
|
message = 'Site is currently in maintenance mode.'
|
|
|
|
# In case of an API request, return a plaintext error message
|
|
if endpoint.startswith('api.'):
|
|
resp = flask.make_response(message, 405)
|
|
resp.headers['Content-Type'] = 'text/plain'
|
|
return resp
|
|
else:
|
|
# Otherwise redirect to the target page and flash a message
|
|
flask.flash(flask.Markup(message), 'danger')
|
|
try:
|
|
target_url = flask.url_for(endpoint)
|
|
except Exception:
|
|
# Non-GET-able endpoint, try referrer or default to home page
|
|
target_url = flask.request.referrer or flask.url_for('main.home')
|
|
return flask.redirect(target_url)
|
|
|
|
|
|
def register_views(flask_app):
|
|
""" Register the blueprints using the flask_app object """
|
|
# Add our POST blocker first
|
|
if flask_app.config['MAINTENANCE_MODE']:
|
|
flask_app.before_request(_maintenance_mode_hook)
|
|
|
|
flask_app.register_blueprint(account.bp)
|
|
flask_app.register_blueprint(admin.bp)
|
|
flask_app.register_blueprint(main.bp)
|
|
flask_app.register_blueprint(site.bp)
|
|
flask_app.register_blueprint(torrents.bp)
|
|
flask_app.register_blueprint(users.bp)
|