diff --git a/nyaa/routes.py b/nyaa/routes.py index dc6476d..129b26e 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -62,6 +62,12 @@ def filter_truthy(input_list): return [item for item in input_list if item] +@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, ['???'])) + + @app.errorhandler(404) def not_found(error): return flask.render_template('404.html'), 404 diff --git a/nyaa/templates/search_results.html b/nyaa/templates/search_results.html index f169b6f..306ec60 100644 --- a/nyaa/templates/search_results.html +++ b/nyaa/templates/search_results.html @@ -48,11 +48,11 @@ {% set torrents = torrent_query if use_elastic else torrent_query.items %} {% for torrent in torrents %} - {% set cat_id = (torrent.main_category_id|string) + '_' + (torrent.sub_category_id|string) if use_elastic else (torrent.main_category.id|string) + '_' + (torrent.sub_category.id|string) %} + {% set cat_id = use_elastic and ((torrent.main_category_id|string) + '_' + (torrent.sub_category_id|string)) or torrent.sub_category.id_as_string %} {% set icon_dir = config.SITE_FLAVOR %} {% if use_elastic %} - + {% else %} {% endif %}