Skip to content

Commit

Permalink
Clean user's personal url from github
Browse files Browse the repository at this point in the history
  • Loading branch information
arku committed Jun 20, 2018
1 parent 7453871 commit b7f89b2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/dashboard/templates/profile_details.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load i18n email_obfuscator %}
{% load humanize %}
{% load clean_url %}
{% load static %}
<!DOCTYPE html>
<html lang="en">
Expand All @@ -26,11 +27,11 @@
</p>
<p class="mb-0">{{ profile.handle }}</p>
<p class="profile-header__links clearfix mt-1">
<a href="{{profile.data.html_url}}?tab=repositories">
<a href="{{profile.data.html_url}}?tab=repositories" target="_blank">
<i class="fab fa-github"></i>
</a>
{% if profile.data.blog and user.is_authenticated %}
<a href="{{ profile.data.blog }}">
<a href="{{profile.data.blog|clean_url}}" target="_blank">
<i class="fas fa-home"></i>
</a>
{% endif %}
Expand Down
40 changes: 40 additions & 0 deletions app/dashboard/templatetags/clean_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""Define the is_in_list template tag to allow if in list checking in templates.
Copyright (C) 2018 Gitcoin Core
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import re
from django import template

register = template.Library()


@register.filter
def clean_url(url):
"""Returns url with the scheme if it isn't already present.
Args:
url (string): A URL.
Usage:
{% '<url>'|clean_url%}
Returns:
string: url with the scheme attached.
"""
pattern = re.compile(r'https?://')
return url if pattern.match(url) else 'http://' + url

0 comments on commit b7f89b2

Please sign in to comment.