From: Radek Czajka Date: Tue, 1 Jul 2014 08:43:03 +0000 (+0200) Subject: More tolerance for bad url metadata. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/e97becbbb360b14527801bfc22c3e1ab3fd288a1?ds=sidebyside More tolerance for bad url metadata. --- diff --git a/apps/catalogue/templatetags/catalogue_tags.py b/apps/catalogue/templatetags/catalogue_tags.py index 2d19493eb..fd8c8c4b9 100644 --- a/apps/catalogue/templatetags/catalogue_tags.py +++ b/apps/catalogue/templatetags/catalogue_tags.py @@ -484,6 +484,11 @@ def class_name(obj): @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