Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/swh_templatetags.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | def urlize_header_links(text): | ||||
Args | Args | ||||
text: Text whose content contains Link header value | text: Text whose content contains Link header value | ||||
Returns: | Returns: | ||||
The text transformed with html link if any link is found. | The text transformed with html link if any link is found. | ||||
The text as is otherwise. | The text as is otherwise. | ||||
""" | """ | ||||
links = text.split(",") | ret = re.sub( | ||||
ret = "" | r'<(http[^<>]+)>; rel="([^,]+)"', r'<<a href="\1">\1</a>>; rel="\2"\n', text | ||||
for i, link in enumerate(links): | ).replace("\n,", "\n") | ||||
ret += re.sub(r"<(http.*)>", r'<<a href="\1">\1</a>>', link) | return ret[:-1] | ||||
# add one link per line and align them | |||||
if i != len(links) - 1: | |||||
ret += "\n " | |||||
return ret | |||||
@register.filter | @register.filter | ||||
def jsonify(obj): | def jsonify(obj): | ||||
"""Utility function for converting a django template variable | """Utility function for converting a django template variable | ||||
to JSON in order to use it in script tags. | to JSON in order to use it in script tags. | ||||
Args | Args | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |