+
+
+@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'],
+ }
+
+
+@register.simple_tag
+def related_tag_name(tag, lang=None):
+ return _related_tag_name(tag, lang)
+
+
+@register.filter
+def class_name(obj):
+ return obj.__class__.__name__
+
+
+@register.simple_tag
+def source_name(url):
+ url = url.lstrip()
+ netloc = urlparse(url).netloc
+ if not netloc:
+ netloc = urlparse('http://' + url).netloc
+ if not netloc:
+ return ''
+ source, created = Source.objects.get_or_create(netloc=netloc)
+ return source.name or netloc