1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-22 09:00:00 +00:00

Move static routes into a blueprint

and update templates

Routes:
* /help
* /rules
* /xmlns/nyaa
* /about (commented out)
This commit is contained in:
Kfir Hadas 2017-07-11 00:13:19 +03:00
parent 7e16616a5d
commit 911fbc317f
6 changed files with 45 additions and 29 deletions

View file

@ -19,7 +19,7 @@ import config
from itsdangerous import BadSignature, URLSafeSerializer
from sqlalchemy.orm import joinedload
from nyaa import api_handler, app, backend, db, forms, models, torrents, utils
from nyaa import api_handler, app, backend, db, forms, models, torrents, utils, views
from nyaa.search import search_db, search_elastic
DEBUG_API = False
@ -452,11 +452,6 @@ def render_rss(label, query, use_elastic, magnet_links=False):
return response
# @app.route('/about', methods=['GET'])
# def about():
# return flask.render_template('about.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if flask.g.user:
@ -1006,24 +1001,17 @@ def timesince(dt, default='just now'):
return default
# #################################### STATIC PAGES ####################################
# #################################### BLUEPRINTS ####################################
def register_blueprints(flask_app):
""" Register the blueprints using the flask_app object """
# API routes
flask_app.register_blueprint(api_handler.api_blueprint, url_prefix='/api')
# Site routes
flask_app.register_blueprint(views.site_bp)
@app.route('/rules', methods=['GET'])
def site_rules():
return flask.render_template('rules.html')
@app.route('/help', methods=['GET'])
def site_help():
return flask.render_template('help.html')
@app.route('/xmlns/nyaa', methods=['GET'])
def xmlns_nyaa():
return flask.render_template('xmlns.html')
# #################################### API ROUTES ####################################
app.register_blueprint(api_handler.api_blueprint, url_prefix='/api')
# When done, this can be moved to nyaa/__init__.py instead of importing this file
register_blueprints(app)

View file

@ -78,8 +78,8 @@
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li {% if request.path == url_for('site_rules') %}class="active"{% endif %}><a href="{{ url_for('site_rules') }}">Rules</a></li>
<li {% if request.path == url_for('site_help') %}class="active"{% endif %}><a href="{{ url_for('site_help') }}">Help</a></li>
<li {% if request.path == url_for('site.rules') %}class="active"{% endif %}><a href="{{ url_for('site.rules') }}">Rules</a></li>
<li {% if request.path == url_for('site.help') %}class="active"{% endif %}><a href="{{ url_for('site.help') }}">Help</a></li>
</ul>
</li>
<li><a href="{% if rss_filter %}{{ url_for('home', page='rss', **rss_filter) }}{% else %}{{ url_for('home', page='rss') }}{% endif %}">RSS</a></li>

View file

@ -1,4 +1,4 @@
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:nyaa="{{ url_for('xmlns_nyaa', _external=True) }}" version="2.0">
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:nyaa="{{ url_for('site.xmlns_nyaa', _external=True) }}" version="2.0">
<channel>
<title>{{ config.SITE_NAME }} - {{ term }} - {% if not magnet_links %}Torrent File{% else %}Magnet URI{% endif %} RSS</title>
<description>RSS Feed for {{ term }}</description>

View file

@ -191,7 +191,7 @@
<div class="modal-body">
<div class="alert alert-warning" role="alert">
Before submitting a report, please check that the torrent
actually breaks <a href="{{ url_for('site_rules') }}">the
actually breaks <a href="{{ url_for('site.rules') }}">the
rules</a>. Useless reports like "download is slow" or
"thanks" can get you banned from the site.
</div>

5
nyaa/views/__init__.py Normal file
View file

@ -0,0 +1,5 @@
from nyaa.views import (
site,
)
site_bp = site.bp

23
nyaa/views/site.py Normal file
View file

@ -0,0 +1,23 @@
import flask
bp = flask.Blueprint('site', __name__)
# @bp.route('/about', methods=['GET'])
# def about():
# return flask.render_template('about.html')
@bp.route('/rules', methods=['GET'])
def rules():
return flask.render_template('rules.html')
@bp.route('/help', methods=['GET'])
def help():
return flask.render_template('help.html')
@bp.route('/xmlns/nyaa', methods=['GET'])
def xmlns_nyaa():
return flask.render_template('xmlns.html')