Commit cdea649e authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

utils.domain{,_link} for tables

parent 8538cd04
......@@ -2,7 +2,7 @@ from django.utils.safestring import mark_safe
import django_tables2 as tables
from . import models
from . import models, utils
class StrippedTable(tables.Table):
......@@ -40,6 +40,9 @@ class ProjectTable(StrippedTable):
def render_name(self, record):
return record.get_link()
def render_homepage(self, value):
return utils.domain_link(value)
class RepoTable(StrippedTable):
ahead = tables.Column(accessor='ahead', orderable=False)
......
......@@ -26,3 +26,16 @@ def api_next(source, req):
if source == SOURCES.gitlab:
if 'X-Next-Page' in req.headers and req.headers['X-Next-Page']:
return int(req.headers['X-Next-Page'])
def domain(url):
"""
Extracts the domain of an url
"""
if '://' in url or url.startswith('//'):
url = url.split('//')[1]
return url.split('/')[0]
def domain_link(url):
dn = domain(url)
return mark_safe(f'<a href="{url}">{dn}</a>')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment