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/django/contrib/admin/templates/admin/actions.html
+++ b/django/contrib/admin/templates/admin/actions.html
@@ -1,7 +1,8 @@
 {% load i18n %}
+{% load admin_list %}
 <div class="actions">
     {% for field in action_form %}{% if field.label %}<label>{{ field.label }} {% endif %}{{ field }}{% if field.label %}</label>{% endif %}{% endfor %}
-    <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button>
+    <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{% get_action_index %}">{% trans "Go" %}</button>
     {% if actions_selection_counter %}
         <span class="action-counter"><span class="_acnt">0</span> {{ selection_note }}</span>
         {% 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/django/contrib/admin/templates/admin/change_list.html
+++ b/django/contrib/admin/templates/admin/change_list.html
@@ -88,9 +88,9 @@
       {% endif %}
 
       {% block result_list %}
-          {% if action_form and actions_on_top and cl.full_result_count %}{% admin_actions %}{% endif %}
+          {% if action_form and actions_on_top and cl.full_result_count %}{% include "admin/actions.html" %}{% endif %}
           {% result_list cl %}
-          {% if action_form and actions_on_bottom and cl.full_result_count %}{% admin_actions %}{% endif %}
+          {% if action_form and actions_on_bottom and cl.full_result_count %}{% include "admin/actions.html" %}{% endif %}
       {% endblock %}
       {% block pagination %}{% pagination cl %}{% endblock %}
       </form>
diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index b1ab7d5..2f9ff09 100644
--- a/django/contrib/admin/templatetags/admin_list.py
+++ b/django/contrib/admin/templatetags/admin_list.py
@@ -13,7 +13,7 @@ from django.utils.safestring import mark_safe
 from django.utils.text import capfirst
 from django.utils.translation import ugettext as _
 from django.utils.encoding import smart_unicode, force_unicode
-from django.template import Library
+from django.template import Library, Node
 
 
 register = Library()
@@ -267,11 +267,15 @@ def admin_list_filter(cl, spec):
     return {'title': spec.title(), 'choices' : list(spec.choices(cl))}
 admin_list_filter = register.inclusion_tag('admin/filter.html')(admin_list_filter)
 
-def admin_actions(context):
+class GetActionIndexNode(Node):
+    def render(self, context):
+        context['action_index'] = context.get('action_index', -1) + 1
+        return context['action_index']
+
+@register.tag
+def get_action_index(parser, token):
     """
     Track the number of times the action field has been rendered on the page,
     so we know which value to use.
     """
-    context['action_index'] = context.get('action_index', -1) + 1
-    return context
-admin_actions = register.inclusion_tag("admin/actions.html", takes_context=True)(admin_actions)
+    return GetActionIndexNode()
-- 
1.7.0.20.gcb44ed

