mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Cleanup hyperlink rendering implementation
This commit is contained in:
parent
ae704eec58
commit
99e97fa9d3
|
@ -1,5 +1,5 @@
|
||||||
{% load rest_framework %}
|
{% load rest_framework %}
|
||||||
<!-- <table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in value %}
|
{% for item in value %}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -9,5 +9,3 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
-->
|
|
||||||
{% for item in value %}{% if not forloop.first%}, {% endif %}<a href="{{ item }}">{{item.name}}</a>{% endfor %}
|
|
||||||
|
|
|
@ -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 %}
|
||||||
|
|
|
@ -108,8 +108,10 @@ def add_class(value, css_class):
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def format_value(value):
|
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))):
|
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):
|
elif isinstance(value, list):
|
||||||
if any([isinstance(item, (list, dict)) for item in value]):
|
if any([isinstance(item, (list, dict)) for item in value]):
|
||||||
template = loader.get_template('rest_framework/admin/list_value.html')
|
template = loader.get_template('rest_framework/admin/list_value.html')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user