Ticket #13166: modeladmin-13166-js-warnings-i18n.diff

File modeladmin-13166-js-warnings-i18n.diff, 16.2 KB (added by Aymeric Augustin, 14 years ago)
  • django/contrib/admin/media/js/actions.min.js

     
    1 (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=
     1(function(a){a.fn.actions=function(h){var b=a.extend({},a.fn.actions.defaults,h),e=a(this),f=false;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=
    22false;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)};
    33a(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);
    4 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,
    5 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);
     4updateCounter()});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 g=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))g=g?false:true;g&&a(this).attr("checked",d.checked).parent().parent().toggleClass(b.selectedClass,d.checked)})}a(d).parent().parent().toggleClass(b.selectedClass,
     5d.checked);lastChecked=d;updateCounter()});a("form#changelist-form table#result_list tr").find("td:gt(0) :input").change(function(){f=true});a('form#changelist-form button[name="index"]').click(function(){if(f)return(answer=confirm(gettext("You have unsaved changes on individual editable fields. If you run this action, your unsaved changes will be lost.")))?true:false});a('form#changelist-form input[name="_save"]').click(function(){var c=false;a("div.actions select option:selected").each(function(){if(a(this).val()!=
     6"")c=true});if(c&&!f)return(answer=confirm(gettext("You have selected an action, and you haven't made any changes on individual fields. You're probably looking for the Go button rather than the Save button.")))?true:false;if(c&&f)return(answer=confirm(gettext("You have selected an action, but you haven't saved your changes to individual fields yet. Please click OK to save. You'll need to re-run the action.")))?true:false})};a.fn.actions.defaults={actionContainer:"div.actions",counterContainer:"span.action-counter",
     7allContainer:"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);
  • django/contrib/admin/media/js/actions.js

     
    22        $.fn.actions = function(opts) {
    33                var options = $.extend({}, $.fn.actions.defaults, opts);
    44                var actionCheckboxes = $(this);
     5                var list_editable_changed = false;
    56                checker = function(checked) {
    67                        if (checked) {
    78                                showQuestion();
     
    100101                        lastChecked = target;
    101102                        updateCounter();
    102103                });
     104                $('form#changelist-form table#result_list tr').find('td:gt(0) :input').change(function() {
     105                    list_editable_changed = true;
     106                });
     107                $('form#changelist-form button[name="index"]').click(function(event) {
     108                    if (list_editable_changed) {
     109                        answer = confirm(gettext("You have unsaved changes on individual editable fields. If you run this action, your unsaved changes will be lost."));
     110                        if (answer) { return true }
     111                        else { return false };
     112                    }
     113                });
     114                $('form#changelist-form input[name="_save"]').click(function(event) {
     115                    var action_changed = false;
     116                    $('div.actions select option:selected').each(function() {
     117                        if ($(this).val() != "") {
     118                            action_changed = true;
     119                        }
     120                    });
     121                    if (action_changed && !list_editable_changed) {
     122                        answer = confirm(gettext("You have selected an action, and you haven't made any changes on individual fields. You're probably looking for the Go button rather than the Save button."));
     123                        if (answer) { return true }
     124                        else { return false };
     125                    }
     126                    if (action_changed && list_editable_changed) {
     127                        answer = confirm(gettext("You have selected an action, but you haven't saved your changes to individual fields yet. Please click OK to save. You'll need to re-run the action."));
     128                        if (answer) { return true }
     129                        else { return false };
     130                    }
     131                });
    103132        }
    104133        /* Setup plugin defaults */
    105134        $.fn.actions.defaults = {
  • django/contrib/admin/options.py

     
    737737
    738738            # Get the list of selected PKs. If nothing's selected, we can't
    739739            # perform an action on it, so bail. Except we want to perform
    740             # the action explicitely on all objects.
     740            # the action explicitly on all objects.
    741741            selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
    742742            if not selected and not select_across:
    743743                # Reminder that something needs to be selected or nothing will happen
     
    761761        else:
    762762            msg = _("No action selected.")
    763763            self.message_user(request, msg)
     764            return None
    764765
    765766    @csrf_protect_m
    766767    @transaction.commit_on_success
     
    979980            return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1')
    980981
    981982        # If the request was POSTed, this might be a bulk action or a bulk edit.
    982         # Try to look up an action or confirmation first, but if this isn't an
    983         # action the POST will fall through to the bulk edit check, below.
    984         if actions and request.method == 'POST' and (helpers.ACTION_CHECKBOX_NAME in request.POST or 'index' in request.POST):
    985             response = self.response_action(request, queryset=cl.get_query_set())
    986             if response:
    987                 return response
     983        # Try to look up an action or confirmation first, but if this isn't an action the POST
     984        # will fall through to the bulk edit check, below.
    988985
     986        action_failed = False
     987
     988        # Actions with no confirmation
     989        if actions and request.method == 'POST' and 'index' in request.POST and '_save' not in request.POST:
     990            if len(request.POST.get(helpers.ACTION_CHECKBOX_NAME, [])):
     991                response = self.response_action(request, queryset=cl.get_query_set())
     992                if response:
     993                    return response
     994                else:
     995                    action_failed = True
     996            else:
     997                msg = _("Items must be selected in order to perform actions on them. No items have been changed.")
     998                self.message_user(request, msg)
     999                action_failed = True
     1000
     1001        # Actions with confirmation
     1002        if actions and request.method == 'POST' and helpers.ACTION_CHECKBOX_NAME in request.POST and 'index' not in request.POST and '_save' not in request.POST:
     1003            if len(request.POST.get(helpers.ACTION_CHECKBOX_NAME, [])):
     1004                response = self.response_action(request, queryset=cl.get_query_set())
     1005                if response:
     1006                    return response
     1007                else:
     1008                    action_failed = True
     1009
     1010
    9891011        # If we're allowing changelist editing, we need to construct a formset
    9901012        # for the changelist given all the fields to be edited. Then we'll
    9911013        # use the formset to validate/process POSTed data.
    9921014        formset = cl.formset = None
    9931015
    9941016        # Handle POSTed bulk-edit data.
    995         if request.method == "POST" and self.list_editable:
     1017        if request.method == "POST" and self.list_editable and '_save' in request.POST and not action_failed:
    9961018            FormSet = self.get_changelist_formset(request)
    9971019            formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list)
    9981020            if formset.is_valid():
  • django/contrib/admin/templates/admin/change_list.html

     
    8585        {% endif %}
    8686      {% endblock %}
    8787     
    88       <form action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
     88      <form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
    8989      {% if cl.formset %}
    9090        {{ cl.formset.management_form }}
    9191      {% endif %}
  • django/contrib/admin/templates/admin/change_list_results.html

     
    11{% if results %}
    2 <table cellspacing="0">
     2<table cellspacing="0" id="result_list">
    33<thead>
    44<tr>
    55{% for header in result_headers %}<th{{ header.class_attrib }}>
  • tests/regressiontests/admin_views/tests.py

     
    10911091            "form-2-alive": "checked",
    10921092            "form-2-gender": "1",
    10931093            "form-2-id": "3",
     1094
     1095            "_save": "Save",
    10941096        }
    10951097        response = self.client.post('/test_admin/admin/admin_views/person/',
    10961098                                    data, follow=True)
     
    11111113            "form-2-alive": "checked",
    11121114            "form-2-gender": "1",
    11131115            "form-2-id": "3",
     1116
     1117            "_save": "Save",
    11141118        }
    11151119        self.client.post('/test_admin/admin/admin_views/person/', data)
    11161120
     
    11301134            "form-1-id": "3",
    11311135            "form-1-gender": "1",
    11321136            "form-1-alive": "checked",
     1137
     1138            "_save": "Save",
    11331139        }
    11341140        self.client.post('/test_admin/admin/admin_views/person/?gender__exact=1', data)
    11351141
     
    11421148            "form-MAX_NUM_FORMS": "0",
    11431149
    11441150            "form-0-id": "1",
    1145             "form-0-gender": "1"
     1151            "form-0-gender": "1",
     1152
     1153            "_save": "Save",
    11461154        }
    11471155        self.client.post('/test_admin/admin/admin_views/person/?q=mauchly', data)
    11481156
     
    11581166            "form-0-id": "2",
    11591167            "form-0-alive": "1",
    11601168            "form-0-gender": "2",
     1169
     1170            # Ensure that the form processing understands this as a list_editable "Save"
     1171            # and not an action "Go".
     1172            "_save": "Save",
    11611173        }
    11621174        response = self.client.post('/test_admin/admin/admin_views/person/', data)
    11631175        self.assertContains(response, "Grace is not a Zombie")
     
    11721184            "form-0-id": "2",
    11731185            "form-0-alive": "1",
    11741186            "form-0-gender": "2",
     1187
     1188            "_save": "Save",
    11751189        }
    11761190        response = self.client.post('/test_admin/admin/admin_views/person/', data)
    11771191        non_form_errors = response.context['cl'].formset.non_form_errors()
     
    12071221            "form-3-order": "0",
    12081222            "form-3-id": "4",
    12091223            "form-3-collector": "1",
     1224
     1225            # Ensure that the form processing understands this as a list_editable "Save"
     1226            # and not an action "Go".
     1227            "_save": "Save",
    12101228        }
    12111229        response = self.client.post('/test_admin/admin/admin_views/category/', data)
    12121230        # Successful post will redirect
     
    12181236        self.failUnlessEqual(Category.objects.get(id=3).order, 1)
    12191237        self.failUnlessEqual(Category.objects.get(id=4).order, 0)
    12201238
     1239    def test_list_editable_action_submit(self):
     1240        # List editable changes should not be executed if the action "Go" button is
     1241        # used to submit the form.
     1242        data = {
     1243            "form-TOTAL_FORMS": "3",
     1244            "form-INITIAL_FORMS": "3",
     1245            "form-MAX_NUM_FORMS": "0",
     1246
     1247            "form-0-gender": "1",
     1248            "form-0-id": "1",
     1249
     1250            "form-1-gender": "2",
     1251            "form-1-id": "2",
     1252
     1253            "form-2-alive": "checked",
     1254            "form-2-gender": "1",
     1255            "form-2-id": "3",
     1256
     1257            "index": "0",
     1258            "_selected_action": [u'3'],
     1259            "action": [u'', u'delete_selected'],
     1260        }
     1261        self.client.post('/test_admin/admin/admin_views/person/', data)
     1262
     1263        self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, True)
     1264        self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 1)
     1265
     1266    def test_list_editable_action_choices(self):
     1267        # List editable changes should be executed if the "Save" button is
     1268        # used to submit the form - any action choices should be ignored.
     1269        data = {
     1270            "form-TOTAL_FORMS": "3",
     1271            "form-INITIAL_FORMS": "3",
     1272            "form-MAX_NUM_FORMS": "0",
     1273
     1274            "form-0-gender": "1",
     1275            "form-0-id": "1",
     1276
     1277            "form-1-gender": "2",
     1278            "form-1-id": "2",
     1279
     1280            "form-2-alive": "checked",
     1281            "form-2-gender": "1",
     1282            "form-2-id": "3",
     1283
     1284            "_save": "Save",
     1285            "_selected_action": [u'1'],
     1286            "action": [u'', u'delete_selected'],
     1287        }
     1288        self.client.post('/test_admin/admin/admin_views/person/', data)
     1289
     1290        self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
     1291        self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2)
     1292
     1293
     1294
     1295
    12211296class AdminSearchTest(TestCase):
    12221297    fixtures = ['admin-views-users','multiple-child-classes']
    12231298
Back to Top