1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-11-01 00:25:53 +00:00

Move the remaining template_global into 'template-utils' blueprint

This commit is contained in:
Kfir Hadas 2017-07-22 06:29:38 +03:00
parent 93f94023d1
commit c539795fdc
3 changed files with 8 additions and 9 deletions

View file

@ -1,15 +1,8 @@
from nyaa import api_handler, app, template_utils, views from nyaa import api_handler, app, template_utils, views
from nyaa.backend import get_category_id_map
DEBUG_API = False DEBUG_API = False
@app.template_global()
def category_name(cat_id):
''' Given a category id (eg. 1_2), returns a category name (eg. Anime - English-translated) '''
return ' - '.join(get_category_id_map().get(cat_id, ['???']))
# #################################### BLUEPRINTS #################################### # #################################### BLUEPRINTS ####################################
def register_blueprints(flask_app): def register_blueprints(flask_app):

View file

@ -6,6 +6,7 @@ import flask
from werkzeug.urls import url_encode from werkzeug.urls import url_encode
from nyaa import app from nyaa import app
from nyaa.backend import get_category_id_map
bp = flask.Blueprint('template-utils', __name__) bp = flask.Blueprint('template-utils', __name__)
_static_cache = {} # For static_cachebuster _static_cache = {} # For static_cachebuster
@ -54,6 +55,12 @@ def filter_truthy(input_list):
return [item for item in input_list if item] return [item for item in input_list if item]
@bp.app_template_global()
def category_name(cat_id):
""" Given a category id (eg. 1_2), returns a category name (eg. Anime - English-translated) """
return ' - '.join(get_category_id_map().get(cat_id, ['???']))
# ######################### TEMPLATE FILTERS ######################### # ######################### TEMPLATE FILTERS #########################
@bp.app_template_filter('utc_time') @bp.app_template_filter('utc_time')

View file

@ -4,9 +4,8 @@ import datetime
from email.utils import formatdate from email.utils import formatdate
from tests import NyaaTestCase from tests import NyaaTestCase
from nyaa.routes import category_name
from nyaa.template_utils import (_jinja2_filter_rfc822, _jinja2_filter_rfc822_es, get_utc_timestamp, from nyaa.template_utils import (_jinja2_filter_rfc822, _jinja2_filter_rfc822_es, get_utc_timestamp,
get_display_time, timesince, filter_truthy) get_display_time, timesince, filter_truthy, category_name)
class TestTemplateUtils(NyaaTestCase): class TestTemplateUtils(NyaaTestCase):