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
|
| 13 | 13 | from django.db.models.fields import BLANK_CHOICE_DASH |
| 14 | 14 | from django.http import Http404, HttpResponse, HttpResponseRedirect |
| 15 | 15 | from django.shortcuts import get_object_or_404, render_to_response |
| | 16 | from django.template.loader import find_template |
| 16 | 17 | from django.utils.decorators import method_decorator |
| 17 | 18 | from django.utils.datastructures import SortedDict |
| 18 | 19 | from django.utils.functional import update_wrapper |
| … |
… |
class ModelAdmin(BaseModelAdmin):
|
| 211 | 212 | # Actions |
| 212 | 213 | actions = [] |
| 213 | 214 | action_form = helpers.ActionForm |
| | 215 | action_template = None |
| 214 | 216 | actions_on_top = True |
| 215 | 217 | actions_on_bottom = False |
| 216 | 218 | actions_selection_counter = True |
| … |
… |
class ModelAdmin(BaseModelAdmin):
|
| 1034 | 1036 | if actions: |
| 1035 | 1037 | action_form = self.action_form(auto_id=None) |
| 1036 | 1038 | 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 |
| 1037 | 1057 | else: |
| 1038 | 1058 | action_form = None |
| | 1059 | action_template = None |
| 1039 | 1060 | |
| 1040 | 1061 | selection_note = ungettext('of %(count)d selected', |
| 1041 | 1062 | 'of %(count)d selected', len(cl.result_list)) |
| … |
… |
class ModelAdmin(BaseModelAdmin):
|
| 1054 | 1075 | 'root_path': self.admin_site.root_path, |
| 1055 | 1076 | 'app_label': app_label, |
| 1056 | 1077 | 'action_form': action_form, |
| | 1078 | 'action_template': action_template, |
| 1057 | 1079 | 'actions_on_top': self.actions_on_top, |
| 1058 | 1080 | 'actions_on_bottom': self.actions_on_bottom, |
| 1059 | 1081 | 'actions_selection_counter': self.actions_selection_counter, |
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
|
|
| 88 | 88 | {% endif %} |
| 89 | 89 | |
| 90 | 90 | {% 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 %} |
| 92 | 92 | {% 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 %} |
| 94 | 94 | {% endblock %} |
| 95 | 95 | {% block pagination %}{% pagination cl %}{% endblock %} |
| 96 | 96 | </form> |