Skip to content

Commit

Permalink
Misc: Add url formatter filter
Browse files Browse the repository at this point in the history
This allows to render URLs nicely and reduces space they consume
(stripping protocol prefix and trailing slash).
  • Loading branch information
nijel committed Sep 23, 2020
1 parent c81ee72 commit d09b785
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
29 changes: 29 additions & 0 deletions weblate/accounts/templatetags/urlformat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright © 2012 - 2020 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <https://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""Provide user friendly names for social authentication methods."""

from django import template

register = template.Library()


@register.filter
def urlformat(content):
"""Nicely formats URL for display."""
return content.split("://", 1)[-1].strip("/")
7 changes: 4 additions & 3 deletions weblate/templates/accounts/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load i18n %}
{% load humanize %}
{% load icons %}
{% load urlformat %}

{% block breadcrumbs %}
<li><a href="{% url "user_list" %}">{% trans "Users" %}</a></li>
Expand Down Expand Up @@ -64,7 +65,7 @@ <h3>{{ page_user }}</h3>
<p>
{% if page_profile.website %}
<span class="middle-dot-divider">
<span class="profile-icon">{% icon "link.svg" %}</span> <a href="{{ page_profile.website }}" rel="ugc">{{ page_profile.website }}</a>
<span class="profile-icon">{% icon "link.svg" %}</span> <a href="{{ page_profile.website }}" rel="ugc">{{ page_profile.website | urlformat }}</a>
</span>
{% endif %}
{% if page_profile.public_email %}
Expand All @@ -79,7 +80,7 @@ <h3>{{ page_user }}</h3>
{% endif %}
{% if page_profile.fediverse %}
<span class="middle-dot-divider">
<span class="profile-icon">{% icon "fediverse.svg" %}</span> <a href="{{ page_profile.fediverse }}" rel="ugc">{{ page_profile.fediverse }}</a>
<span class="profile-icon">{% icon "fediverse.svg" %}</span> <a href="{{ page_profile.fediverse }}" rel="ugc">{{ page_profile.fediverse | urlformat }}</a>
</span>
{% endif %}
{% if page_profile.github %}
Expand All @@ -89,7 +90,7 @@ <h3>{{ page_user }}</h3>
{% endif %}
{% if page_profile.codesite %}
<span class="middle-dot-divider">
<span class="profile-icon">{% icon "source.svg" %}</span> <a href="{{ page_profile.codesite }}" rel="ugc">{{ page_profile.codesite }}</a>
<span class="profile-icon">{% icon "source.svg" %}</span> <a href="{{ page_profile.codesite }}" rel="ugc">{{ page_profile.codesite | urlformat }}</a>
</span>
{% endif %}
{% if page_profile.twitter %}
Expand Down
4 changes: 3 additions & 1 deletion weblate/templates/project_info.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{% load i18n %}
{% load permissions %}
{% load translations %}
{% load urlformat %}

<tr>
<th>{% trans "Project website" %}</th>
<td colspan="2"><a href="{{ object.web }}">{{ object.web }}</a></td>
<td colspan="2"><a href="{{ object.web }}">{{ object.web | urlformat }}</a></td>
</tr>

{% if object.mail %}
Expand Down

0 comments on commit d09b785

Please sign in to comment.