X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/d713c61258bf1fcebea7e21065ac2878f5bf45be..e27419ae0bbaabf7bc9899e0846d8f1cb0af7ee1:/apps/catalogue/templatetags/catalogue_tags.py diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 139aa54ce..ad60962c5 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _ from catalogue.utils import split_tags from catalogue.models import Book, BookMedia, Fragment, Tag +from catalogue.constants import LICENSES register = template.Library() @@ -436,3 +437,16 @@ def custom_pdf_link_li(book): 'book': book, 'NO_CUSTOM_PDF': settings.NO_CUSTOM_PDF, } + + +@register.inclusion_tag("catalogue/snippets/license_icon.html") +def license_icon(license_url): + """Creates a license icon, if the license_url is known.""" + known = LICENSES.get(license_url) + if known is None: + return {} + return { + "license_url": license_url, + "icon": "img/licenses/%s.png" % known['icon'], + "license_description": known['description'], + }