Fixed #12903 - Made translating the admin action selection text easier. Thanks to Ramiro Morales for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12968 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2010-04-13 10:29:19 +00:00
parent c3d1267c15
commit 31f7ff1518
6 changed files with 19 additions and 14 deletions

View File

@ -12,17 +12,21 @@
.parent().parent().toggleClass(options.selectedClass, checked); .parent().parent().toggleClass(options.selectedClass, checked);
} }
updateCounter = function() { updateCounter = function() {
var count = $(actionCheckboxes).filter(":checked").length; var sel = $(actionCheckboxes).filter(":checked").length;
$("span._acnt").html(count); $(options.counterContainer).html(interpolate(
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
sel: sel,
cnt: _actions_icnt
}, true));
$(options.allToggle).attr("checked", function() { $(options.allToggle).attr("checked", function() {
if (count == actionCheckboxes.length) { if (sel == actionCheckboxes.length) {
value = true; value = true;
showQuestion(); showQuestion();
} else { } else {
value = false; value = false;
clearAcross(); clearAcross();
} }
return value return value;
}); });
} }
showQuestion = function() { showQuestion = function() {

View File

@ -1,5 +1,5 @@
(function(a){a.fn.actions=function(g){var b=a.extend({},a.fn.actions.defaults,g),e=a(this);checker=function(c){c?showQuestion():reset();a(e).attr("checked",c).parent().parent().toggleClass(b.selectedClass,c)};updateCounter=function(){var c=a(e).filter(":checked").length;a("span._acnt").html(c);a(b.allToggle).attr("checked",function(){if(c==e.length){value=true;showQuestion()}else{value=false;clearAcross()}return value})};showQuestion=function(){a(b.acrossClears).hide();a(b.acrossQuestions).show(); (function(a){a.fn.actions=function(g){var b=a.extend({},a.fn.actions.defaults,g),e=a(this);checker=function(c){c?showQuestion():reset();a(e).attr("checked",c).parent().parent().toggleClass(b.selectedClass,c)};updateCounter=function(){var c=a(e).filter(":checked").length;a(b.counterContainer).html(interpolate(ngettext("%(sel)s of %(cnt)s selected","%(sel)s of %(cnt)s selected",c),{sel:c,cnt:_actions_icnt},true));a(b.allToggle).attr("checked",function(){if(c==e.length){value=true;showQuestion()}else{value=
a(b.allContainer).hide()};showClear=function(){a(b.acrossClears).show();a(b.acrossQuestions).hide();a(b.actionContainer).toggleClass(b.selectedClass);a(b.allContainer).show();a(b.counterContainer).hide()};reset=function(){a(b.acrossClears).hide();a(b.acrossQuestions).hide();a(b.allContainer).hide();a(b.counterContainer).show()};clearAcross=function(){reset();a(b.acrossInput).val(0);a(b.actionContainer).removeClass(b.selectedClass)};a(b.counterContainer).show();a(this).filter(":checked").each(function(){a(this).parent().parent().toggleClass(b.selectedClass); false;clearAcross()}return value})};showQuestion=function(){a(b.acrossClears).hide();a(b.acrossQuestions).show();a(b.allContainer).hide()};showClear=function(){a(b.acrossClears).show();a(b.acrossQuestions).hide();a(b.actionContainer).toggleClass(b.selectedClass);a(b.allContainer).show();a(b.counterContainer).hide()};reset=function(){a(b.acrossClears).hide();a(b.acrossQuestions).hide();a(b.allContainer).hide();a(b.counterContainer).show()};clearAcross=function(){reset();a(b.acrossInput).val(0);a(b.actionContainer).removeClass(b.selectedClass)};
updateCounter();a(b.acrossInput).val()==1&&showClear()});a(b.allToggle).show().click(function(){checker(a(this).attr("checked"));updateCounter()});a("div.actions span.question a").click(function(c){c.preventDefault();a(b.acrossInput).val(1);showClear()});a("div.actions span.clear a").click(function(c){c.preventDefault();a(b.allToggle).attr("checked",false);clearAcross();checker(0);updateCounter()});lastChecked=null;a(e).click(function(c){if(!c)c=window.event;var d=c.target?c.target:c.srcElement;if(lastChecked&& a(b.counterContainer).show();a(this).filter(":checked").each(function(){a(this).parent().parent().toggleClass(b.selectedClass);updateCounter();a(b.acrossInput).val()==1&&showClear()});a(b.allToggle).show().click(function(){checker(a(this).attr("checked"));updateCounter()});a("div.actions span.question a").click(function(c){c.preventDefault();a(b.acrossInput).val(1);showClear()});a("div.actions span.clear a").click(function(c){c.preventDefault();a(b.allToggle).attr("checked",false);clearAcross();checker(0);
a.data(lastChecked)!=a.data(d)&&c.shiftKey==true){var f=false;a(lastChecked).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked);a(e).each(function(){if(a.data(this)==a.data(lastChecked)||a.data(this)==a.data(d))f=f?false:true;f&&a(this).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked)})}a(d).parent().parent().toggleClass(b.selectedClass,d.checked);lastChecked=d;updateCounter()})};a.fn.actions.defaults={actionContainer:"div.actions", updateCounter()});lastChecked=null;a(e).click(function(c){if(!c)c=window.event;var d=c.target?c.target:c.srcElement;if(lastChecked&&a.data(lastChecked)!=a.data(d)&&c.shiftKey==true){var f=false;a(lastChecked).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked);a(e).each(function(){if(a.data(this)==a.data(lastChecked)||a.data(this)==a.data(d))f=f?false:true;f&&a(this).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked)})}a(d).parent().parent().toggleClass(b.selectedClass,
counterContainer:"span.action-counter",allContainer:"div.actions span.all",acrossInput:"div.actions input.select-across",acrossQuestions:"div.actions span.question",acrossClears:"div.actions span.clear",allToggle:"#action-toggle",selectedClass:"selected"}})(django.jQuery); d.checked);lastChecked=d;updateCounter()})};a.fn.actions.defaults={actionContainer:"div.actions",counterContainer:"span.action-counter",allContainer:"div.actions span.all",acrossInput:"div.actions input.select-across",acrossQuestions:"div.actions span.question",acrossClears:"div.actions span.clear",allToggle:"#action-toggle",selectedClass:"selected"}})(django.jQuery);

View File

@ -1035,14 +1035,12 @@ class ModelAdmin(BaseModelAdmin):
else: else:
action_form = None action_form = None
selection_note = ungettext('of %(count)d selected',
'of %(count)d selected', len(cl.result_list))
selection_note_all = ungettext('%(total_count)s selected', selection_note_all = ungettext('%(total_count)s selected',
'All %(total_count)s selected', cl.result_count) 'All %(total_count)s selected', cl.result_count)
context = { context = {
'module_name': force_unicode(opts.verbose_name_plural), 'module_name': force_unicode(opts.verbose_name_plural),
'selection_note': selection_note % {'count': len(cl.result_list)}, 'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
'selection_note_all': selection_note_all % {'total_count': cl.result_count}, 'selection_note_all': selection_note_all % {'total_count': cl.result_count},
'title': cl.title, 'title': cl.title,
'is_popup': cl.is_popup, 'is_popup': cl.is_popup,

View File

@ -3,7 +3,8 @@
{% for field in action_form %}{% if field.label %}<label>{{ field.label }} {% endif %}{{ field }}{% if field.label %}</label>{% endif %}{% endfor %} {% 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="{{ action_index|default:0 }}">{% trans "Go" %}</button>
{% if actions_selection_counter %} {% if actions_selection_counter %}
<span class="action-counter"><span class="_acnt">0</span> {{ selection_note }}</span> <script type="text/javascript">var _actions_icnt={{ cl.result_count|default_if_none:"0" }};</script>
<span class="action-counter">{{ selection_note }}</span>
{% if cl.result_count != cl.result_list|length %} {% if cl.result_count != cl.result_list|length %}
<span class="all">{{ selection_note_all }}</span> <span class="all">{{ selection_note_all }}</span>
<span class="question"> <span class="question">

View File

@ -6,6 +6,8 @@
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" /> <link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelists.css" />
{% if cl.formset %} {% if cl.formset %}
<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" /> <link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />
{% endif %}
{% if cl.formset or action_form %}
{% url admin:jsi18n as jsi18nurl %} {% url admin:jsi18n as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:'../../jsi18n/' }}"></script> <script type="text/javascript" src="{{ jsi18nurl|default:'../../jsi18n/' }}"></script>
{% endif %} {% endif %}

View File

@ -1443,7 +1443,7 @@ class AdminActionsTest(TestCase):
Check if the selection counter is there. Check if the selection counter is there.
""" """
response = self.client.get('/test_admin/admin/admin_views/subscriber/') response = self.client.get('/test_admin/admin/admin_views/subscriber/')
self.assertContains(response, '<span class="_acnt">0</span> of 2 selected') self.assertContains(response, '0 of 2 selected')
class TestCustomChangeList(TestCase): class TestCustomChangeList(TestCase):