Cleanup hyperlink rendering implementation

This commit is contained in:
Tom Christie 2015-06-03 11:47:33 +01:00
parent ae704eec58
commit 99e97fa9d3
3 changed files with 6 additions and 5 deletions

View File

@ -1,5 +1,5 @@
{% load rest_framework %}
<!-- <table class="table table-striped">
<table class="table table-striped">
<tbody>
{% for item in value %}
<tr>
@ -9,5 +9,3 @@
{% endfor %}
</tbody>
</table>
-->
{% for item in value %}{% if not forloop.first%}, {% endif %}<a href="{{ item }}">{{item.name}}</a>{% endfor %}

View File

@ -1 +1,2 @@
{% for item in value %}{% if not forloop.first%},{% endif %} {% if item.is_hyperlink %}<a href="{{ item }}">{{item.name}}</a>{% else %}{{ item }}{% endif %}{% endfor %}
{% load rest_framework %}
{% for item in value %}{% if not forloop.first%},{% endif %} {{item|format_value}}{% endfor %}

View File

@ -108,8 +108,10 @@ def add_class(value, css_class):
@register.filter
def format_value(value):
if getattr(value, 'is_hyperlink', False):
return mark_safe('<a href=%s>%s</a>' % (value, escape(value.name)))
if isinstance(value, (int, float, decimal.Decimal, bool, type(None))):
return mark_safe('<code>%s</code>' % value)
return mark_safe('<code>%s</code>' % escape(value))
elif isinstance(value, list):
if any([isinstance(item, (list, dict)) for item in value]):
template = loader.get_template('rest_framework/admin/list_value.html')