Code

Opened 3 years ago

Closed 4 months ago

Last modified 4 months ago

#16380 closed New feature (fixed)

admin_list_filter should pass the spec to the template

Reported by: hvdklauw Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: bruno@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If the admin_list_filter inclusion tag also passed the spec object to the admin/filter.html template we could write custom filterspec's that have attributes that influence the way the filterspec is displayed (in a dropdown with javascript for instance).

Right now you have to override the change_list.html, and create your own template tag to do this and then still override the admin/filter.html to actually change how it's displayed.

Attachments (1)

16380.diff (613 bytes) - added by hvdklauw 3 years ago.

Download all attachments as: .zip

Change History (9)

Changed 3 years ago by hvdklauw

comment:1 Changed 3 years ago by hvdklauw

  • Easy pickings set
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 3 years ago by jezdez

  • Easy pickings unset
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

While this is an interesting idea, this needs an actual example and tests.

comment:3 Changed 3 years ago by hvdklauw

Example admin/filter.html

{% load i18n %}
<h3>{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</h3>
{% if spec.field.related and choices|length > 5 %}
<select class="filter_choice">
    {% for choice in choices %}
        <option value="{{ choice.query_string|iriencode }}"{% if choice.selected %} selected='selected'{% endif %}>{{ choice.display|safe }}</option>
    {% endfor %}
</select>
{% else %}
<ul>
{% for choice in choices %}
    <li{% if choice.selected %} class="selected"{% endif %}>
    <a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
{% endfor %}
</ul>
{% endif %}

And this little bit of javascript somewhere on document.ready:

$(".filter_choice").change(function() {
          location.href = $(this).val();
        });

comment:4 Changed 3 years ago by jezdez

Nice! Let's put something like that in the docs.

comment:5 Changed 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

comment:6 Changed 4 months ago by bruno@…

  • Cc bruno@… added

This ticket could be closed, admin_list_filter is now (in v1.6 at least) a simple_tag that uses the spec's template AND pass the spec to the template (cf https://github.com/django/django/blob/master/django/contrib/admin/templatetags/admin_list.py line 409).

comment:7 Changed 4 months ago by bmispelon

  • Resolution set to fixed
  • Status changed from new to closed

Hi,

Thanks for digging up these old out-of-date tickets
FYI, you don't need special permmissions to close a ticket here and you can do so yourself.

Putting the commit id in the comment when you close a ticket will help us double check.

In this case, this issue appears to have been fixed in 4dbeb4bca4638ff851a2f4844d262dbe1652f7b5.

Thanks.

comment:8 Changed 4 months ago by bruno@…

@bmispelon: ok will do next time.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.