Ticket #13166: modeladmin-12962.diff

File modeladmin-12962.diff, 3.5 KB (added by Paul Smith, 14 years ago)

Initial patch - needs tests, better warnings

  • django/contrib/admin/options.py

     
    732732
    733733            # Get the list of selected PKs. If nothing's selected, we can't
    734734            # perform an action on it, so bail. Except we want to perform
    735             # the action explicitely on all objects.
     735            # the action explicitly on all objects.
    736736            selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
    737737            if not selected and not select_across:
    738738                # Reminder that something needs to be selected or nothing will happen
     
    756756        else:
    757757            msg = _("No action selected.")
    758758            self.message_user(request, msg)
     759            return None
    759760
    760761    @csrf_protect_m
    761762    @transaction.commit_on_success
     
    974975            return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1')
    975976
    976977        # If the request was POSTed, this might be a bulk action or a bulk edit.
    977         # Try to look up an action or confirmation first, but if this isn't an
    978         # action the POST will fall through to the bulk edit check, below.
    979         if actions and request.method == 'POST' and (helpers.ACTION_CHECKBOX_NAME in request.POST or 'index' in request.POST):
    980             response = self.response_action(request, queryset=cl.get_query_set())
    981             if response:
    982                 return response
     978        # Try to look up an action or confirmation first, but if this isn't an action the POST
     979        # will fall through to the bulk edit check, below.
    983980
     981        action_failed = False
     982
     983        # Actions with no confirmation
     984        if actions and request.method == 'POST' and 'index' in request.POST and '_save' not in request.POST:
     985            if len(request.POST.get(helpers.ACTION_CHECKBOX_NAME, [])):
     986                response = self.response_action(request, queryset=cl.get_query_set())
     987                if response:
     988                    return response
     989                else:
     990                    action_failed = True
     991            else:
     992                msg = _("Items must be selected in order to perform actions on them. No items have been changed.")
     993                self.message_user(request, msg)
     994                action_failed = True
     995
     996        # Actions with confirmation
     997        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:
     998            if len(request.POST.get(helpers.ACTION_CHECKBOX_NAME, [])):
     999                response = self.response_action(request, queryset=cl.get_query_set())
     1000                if response:
     1001                    return response
     1002                else:
     1003                    action_failed = True
     1004
     1005
    9841006        # If we're allowing changelist editing, we need to construct a formset
    9851007        # for the changelist given all the fields to be edited. Then we'll
    9861008        # use the formset to validate/process POSTed data.
    9871009        formset = cl.formset = None
    9881010
    9891011        # Handle POSTed bulk-edit data.
    990         if request.method == "POST" and self.list_editable:
     1012        if request.method == "POST" and self.list_editable and '_save' in request.POST and not action_failed:
    9911013            FormSet = self.get_changelist_formset(request)
    9921014            formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list)
    9931015            if formset.is_valid():
Back to Top