Skip to content

Commit 99e97fa

Browse files
committed
Cleanup hyperlink rendering implementation
1 parent ae704ee commit 99e97fa

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load rest_framework %}
2-
<!-- <table class="table table-striped">
2+
<table class="table table-striped">
33
<tbody>
44
{% for item in value %}
55
<tr>
@@ -9,5 +9,3 @@
99
{% endfor %}
1010
</tbody>
1111
</table>
12-
-->
13-
{% for item in value %}{% if not forloop.first%}, {% endif %}<a href="{{ item }}">{{item.name}}</a>{% endfor %}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
{% for item in value %}{% if not forloop.first%},{% endif %} {% if item.is_hyperlink %}<a href="{{ item }}">{{item.name}}</a>{% else %}{{ item }}{% endif %}{% endfor %}
1+
{% load rest_framework %}
2+
{% for item in value %}{% if not forloop.first%},{% endif %} {{item|format_value}}{% endfor %}

rest_framework/templatetags/rest_framework.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ def add_class(value, css_class):
108108

109109
@register.filter
110110
def format_value(value):
111+
if getattr(value, 'is_hyperlink', False):
112+
return mark_safe('<a href=%s>%s</a>' % (value, escape(value.name)))
111113
if isinstance(value, (int, float, decimal.Decimal, bool, type(None))):
112-
return mark_safe('<code>%s</code>' % value)
114+
return mark_safe('<code>%s</code>' % escape(value))
113115
elif isinstance(value, list):
114116
if any([isinstance(item, (list, dict)) for item in value]):
115117
template = loader.get_template('rest_framework/admin/list_value.html')

0 commit comments

Comments
 (0)