Ticket #12566: 0001-contrib.admin-refactor-updating-of-action_index-to-n.patch

File 0001-contrib.admin-refactor-updating-of-action_index-to-n.patch, 3.8 KB (added by Tay Ray Chuan, 9 years ago)

contrib.admin: refactor updating of action_index to not use inclusion tag

  • django/contrib/admin/templates/admin/actions.html

    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  
    11{% load i18n %}
     2{% load admin_list %}
    23<div class="actions">
    34    {% 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>
    56    {% if actions_selection_counter %}
    67        <span class="action-counter"><span class="_acnt">0</span> {{ selection_note }}</span>
    78        {% if cl.result_count != cl.result_list|length %}
  • django/contrib/admin/templates/admin/change_list.html

    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  
    8888      {% endif %}
    8989
    9090      {% 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 %}
    9292          {% 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 %}
    9494      {% endblock %}
    9595      {% block pagination %}{% pagination cl %}{% endblock %}
    9696      </form>
  • django/contrib/admin/templatetags/admin_list.py

    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 
    1313from django.utils.text import capfirst
    1414from django.utils.translation import ugettext as _
    1515from django.utils.encoding import smart_unicode, force_unicode
    16 from django.template import Library
     16from django.template import Library, Node
    1717
    1818
    1919register = Library()
    def admin_list_filter(cl, spec): 
    267267    return {'title': spec.title(), 'choices' : list(spec.choices(cl))}
    268268admin_list_filter = register.inclusion_tag('admin/filter.html')(admin_list_filter)
    269269
    270 def admin_actions(context):
     270class 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
     276def get_action_index(parser, token):
    271277    """
    272278    Track the number of times the action field has been rendered on the page,
    273279    so we know which value to use.
    274280    """
    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()
Back to Top