Use chevron control for row linking, rather than hyperlinking first item

This commit is contained in:
Tom Christie 2015-06-03 11:15:54 +01:00
parent 90f2e26679
commit 25bb3b1502
3 changed files with 6 additions and 6 deletions

View File

@ -730,12 +730,10 @@ class AdminRenderer(BrowsableAPIRenderer):
columns = [key for key in header.keys() if key != 'url'] columns = [key for key in header.keys() if key != 'url']
details = [key for key in header.keys() if key != 'url'] details = [key for key in header.keys() if key != 'url']
linked = [columns[0]] if columns else []
context['style'] = style context['style'] = style
context['columns'] = columns context['columns'] = columns
context['details'] = details context['details'] = details
context['linked'] = linked
context['results'] = results context['results'] = results
return context return context

View File

@ -1,7 +1,7 @@
{% load rest_framework %} {% load rest_framework %}
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr>{% for column in columns%}<th>{{ column|capfirst }}</th>{% endfor %}</tr> <tr>{% for column in columns%}<th>{{ column|capfirst }}</th>{% endfor %}<th></th></tr>
</thead> </thead>
<tbody> <tbody>
{% for row in results %} {% for row in results %}
@ -9,12 +9,12 @@
{% for key, value in row.items %} {% for key, value in row.items %}
{% if key in columns %} {% if key in columns %}
<td {{ value|add_nested_class }} > <td {{ value|add_nested_class }} >
{% if key in linked %}<a href="{{ row.url }}">{% endif %}
{{ value|format_value }} {{ value|format_value }}
{% if key in linked %}</a>{% endif %}
</td> </td>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<td><a href="{{ row.url }}"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -134,7 +134,9 @@ def format_value(value):
@register.filter @register.filter
def add_nested_class(value): def add_nested_class(value):
if isinstance(value, (list, dict)): if isinstance(value, dict):
return 'class=nested'
if isinstance(value, list) and any([isinstance(item, (list, dict)) for item in value]):
return 'class=nested' return 'class=nested'
return '' return ''