From a79996b72aafb89a4a4d278c86c94a9cf01847b8 Mon Sep 17 00:00:00 2001 From: Nicolas Joyard <joyard.nicolas@gmail.com> Date: Thu, 2 Jun 2016 07:13:49 +0200 Subject: [PATCH] Add other websites --- memopol/templatetags/memopol_tags.py | 12 +++++++++--- templates/representatives/_representative_block.haml | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/memopol/templatetags/memopol_tags.py b/memopol/templatetags/memopol_tags.py index b01305d1..00817ab4 100644 --- a/memopol/templatetags/memopol_tags.py +++ b/memopol/templatetags/memopol_tags.py @@ -4,17 +4,23 @@ from django.utils.safestring import mark_safe import re register = template.Library() -link = '<a class="{network}-link" href="{url}" target="_blank">{user}</a>' +link = '<a class="{network}-link" href="{url}" target="_blank">{label}</a>' @register.filter def twitter_link(url): return mark_safe(link.format(network='twitter', url=url, - user=re.sub(r'.*/@?([^/]+)', '@\\1', url))) + label=re.sub(r'.*/@?([^/]+)', '@\\1', url))) @register.filter def facebook_link(url): return mark_safe(link.format(network='facebook', url=url, - user=re.sub(r'.*/([^/]+)', '\\1', url))) + label=re.sub(r'.*/([^/]+)', '\\1', url))) + +@register.filter +def website_link(url): + short_url = re.sub(r'^https?://([^/]+).*', '\\1', url) + return mark_safe(link.format(network='website', url=url, + label=short_url)) diff --git a/templates/representatives/_representative_block.haml b/templates/representatives/_representative_block.haml index 63fe335b..ca5797bf 100644 --- a/templates/representatives/_representative_block.haml +++ b/templates/representatives/_representative_block.haml @@ -51,3 +51,9 @@ - elif site.kind == 'facebook' = site.url|facebook_link + - if representative.other_websites|length > 0 + %tr + %th Websites + %td + - for site in representative.other_websites + = site.url|website_link -- GitLab