Ticket #12566: 0002-contrib.admin-allow-overriding-of-action-template-at.patch

File 0002-contrib.admin-allow-overriding-of-action-template-at.patch, 3.8 KB (added by Tay Ray Chuan, 15 years ago)

contrib.admin: allow overriding of action template at app-level

  • django/contrib/admin/options.py

    From fd4898a3b928a5a2c9d9a89defdf313aa7c818e4 Mon Sep 17 00:00:00 2001
    From: Tay Ray Chuan <rctay89@gmail.com>
    Date: Sat, 13 Mar 2010 14:50:11 +0800
    Subject: [PATCH 2/3] contrib.admin: allow overriding of action template at app-level
    
    ---
     django/contrib/admin/options.py                    |   22 ++++++++++++++++++++
     .../contrib/admin/templates/admin/change_list.html |    4 +-
     2 files changed, 24 insertions(+), 2 deletions(-)
    
    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 2cda5d5..3924b55 100644
    a b from django.db import models, transaction  
    1313from django.db.models.fields import BLANK_CHOICE_DASH
    1414from django.http import Http404, HttpResponse, HttpResponseRedirect
    1515from django.shortcuts import get_object_or_404, render_to_response
     16from django.template.loader import find_template
    1617from django.utils.decorators import method_decorator
    1718from django.utils.datastructures import SortedDict
    1819from django.utils.functional import update_wrapper
    class ModelAdmin(BaseModelAdmin):  
    211212    # Actions
    212213    actions = []
    213214    action_form = helpers.ActionForm
     215    action_template = None
    214216    actions_on_top = True
    215217    actions_on_bottom = False
    216218    actions_selection_counter = True
    class ModelAdmin(BaseModelAdmin):  
    10341036        if actions:
    10351037            action_form = self.action_form(auto_id=None)
    10361038            action_form.fields['action'].choices = self.get_action_choices(request)
     1039
     1040            # Do this even though self.action_template might be empty to avoid
     1041            # variable-not-defined errors.
     1042            action_template = self.action_template
     1043            if not action_template:
     1044                for t in [
     1045                    'admin/%s/%s/actions.html' % (app_label, opts.object_name.lower()),
     1046                    'admin/%s/actions.html' % app_label,
     1047                    'admin/actions.html'
     1048                ]:
     1049                    try:
     1050                        find_template(t)
     1051
     1052                        # Template file was found; use it.
     1053                        action_template = t
     1054                        break
     1055                    except template.TemplateDoesNotExist:
     1056                        continue
    10371057        else:
    10381058            action_form = None
     1059            action_template = None
    10391060
    10401061        selection_note = ungettext('of %(count)d selected',
    10411062            'of %(count)d selected', len(cl.result_list))
    class ModelAdmin(BaseModelAdmin):  
    10541075            'root_path': self.admin_site.root_path,
    10551076            'app_label': app_label,
    10561077            'action_form': action_form,
     1078            'action_template': action_template,
    10571079            'actions_on_top': self.actions_on_top,
    10581080            'actions_on_bottom': self.actions_on_bottom,
    10591081            'actions_selection_counter': self.actions_selection_counter,
  • 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 0032a23..57e7f60 100644
    a b  
    8888      {% endif %}
    8989
    9090      {% block result_list %}
    91           {% if action_form and actions_on_top and cl.full_result_count %}{% include "admin/actions.html" %}{% endif %}
     91          {% if action_form and actions_on_top and cl.full_result_count %}{% include action_template %}{% endif %}
    9292          {% result_list cl %}
    93           {% if action_form and actions_on_bottom and cl.full_result_count %}{% include "admin/actions.html" %}{% endif %}
     93          {% if action_form and actions_on_bottom and cl.full_result_count %}{% include action_template %}{% endif %}
    9494      {% endblock %}
    9595      {% block pagination %}{% pagination cl %}{% endblock %}
    9696      </form>
Back to Top