From 3a4b7fe1bafab1ece06cbfdd41739175a27af32c Mon Sep 17 00:00:00 2001
From: Tay Ray Chuan <rctay89@gmail.com>
Date: Sat, 13 Mar 2010 14:29:37 +0800
Subject: [PATCH 1/2] contrib.admin: refactor updating of action_index to not use inclusion tag
---
django/contrib/admin/templates/admin/actions.html | 3 ++-
.../contrib/admin/templates/admin/change_list.html | 4 ++--
django/contrib/admin/templatetags/admin_list.py | 14 +++++++++-----
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/django/contrib/admin/templates/admin/actions.html b/django/contrib/admin/templates/admin/actions.html
index 77c2be0..d9d3098 100644
a
|
b
|
|
1 | 1 | {% load i18n %} |
| 2 | {% load admin_list %} |
2 | 3 | <div class="actions"> |
3 | 4 | {% for field in action_form %}{% if field.label %}<label>{{ field.label }} {% endif %}{{ field }}{% if field.label %}</label>{% endif %}{% endfor %} |
4 | | <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button> |
| 5 | <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{% get_action_index %}">{% trans "Go" %}</button> |
5 | 6 | {% if actions_selection_counter %} |
6 | 7 | <span class="action-counter"><span class="_acnt">0</span> {{ selection_note }}</span> |
7 | 8 | {% if cl.result_count != cl.result_list|length %} |
diff --git a/django/contrib/admin/templates/admin/change_list.html b/django/contrib/admin/templates/admin/change_list.html
index 5593128..a84cac8 100644
a
|
b
|
|
88 | 88 | {% endif %} |
89 | 89 | |
90 | 90 | {% block result_list %} |
91 | | {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %} |
| 91 | {% if action_form and actions_on_top and cl.full_result_count %}{% include "admin/actions.html" %}{% endif %} |
92 | 92 | {% result_list cl %} |
93 | | {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %} |
| 93 | {% if action_form and actions_on_bottom and cl.full_result_count %}{% include "admin/actions.html" %}{% endif %} |
94 | 94 | {% endblock %} |
95 | 95 | {% block pagination %}{% pagination cl %}{% endblock %} |
96 | 96 | </form> |
diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index b1ab7d5..2f9ff09 100644
a
|
b
|
from django.utils.safestring import mark_safe
|
13 | 13 | from django.utils.text import capfirst |
14 | 14 | from django.utils.translation import ugettext as _ |
15 | 15 | from django.utils.encoding import smart_unicode, force_unicode |
16 | | from django.template import Library |
| 16 | from django.template import Library, Node |
17 | 17 | |
18 | 18 | |
19 | 19 | register = Library() |
… |
… |
def admin_list_filter(cl, spec):
|
267 | 267 | return {'title': spec.title(), 'choices' : list(spec.choices(cl))} |
268 | 268 | admin_list_filter = register.inclusion_tag('admin/filter.html')(admin_list_filter) |
269 | 269 | |
270 | | def admin_actions(context): |
| 270 | class GetActionIndexNode(Node): |
| 271 | def render(self, context): |
| 272 | context['action_index'] = context.get('action_index', -1) + 1 |
| 273 | return context['action_index'] |
| 274 | |
| 275 | @register.tag |
| 276 | def get_action_index(parser, token): |
271 | 277 | """ |
272 | 278 | Track the number of times the action field has been rendered on the page, |
273 | 279 | so we know which value to use. |
274 | 280 | """ |
275 | | context['action_index'] = context.get('action_index', -1) + 1 |
276 | | return context |
277 | | admin_actions = register.inclusion_tag("admin/actions.html", takes_context=True)(admin_actions) |
| 281 | return GetActionIndexNode() |