diff --git a/nyaa/routes.py b/nyaa/routes.py index dc1c948..3b69898 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -1,15 +1,8 @@ from nyaa import api_handler, app, template_utils, views -from nyaa.backend import get_category_id_map 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 #################################### def register_blueprints(flask_app): diff --git a/nyaa/template_utils.py b/nyaa/template_utils.py index ea89b6b..7053e2d 100644 --- a/nyaa/template_utils.py +++ b/nyaa/template_utils.py @@ -6,6 +6,7 @@ import flask from werkzeug.urls import url_encode from nyaa import app +from nyaa.backend import get_category_id_map bp = flask.Blueprint('template-utils', __name__) _static_cache = {} # For static_cachebuster @@ -54,6 +55,12 @@ def filter_truthy(input_list): 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 ######################### @bp.app_template_filter('utc_time') diff --git a/tests/test_template_utils.py b/tests/test_template_utils.py index bc5cdcf..b529144 100644 --- a/tests/test_template_utils.py +++ b/tests/test_template_utils.py @@ -4,9 +4,8 @@ import datetime from email.utils import formatdate 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, - get_display_time, timesince, filter_truthy) + get_display_time, timesince, filter_truthy, category_name) class TestTemplateUtils(NyaaTestCase):