From e97becbbb360b14527801bfc22c3e1ab3fd288a1 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 1 Jul 2014 10:43:03 +0200 Subject: [PATCH] More tolerance for bad url metadata. --- apps/catalogue/templatetags/catalogue_tags.py | 5 +++++ 1 file changed, 5 insertions(+) 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 -- 2.20.1