Ticket #10871: admin-action-input.patch

File admin-action-input.patch, 4.0 KB (added by Jerome Leclanche, 16 years ago)
  • django/contrib/admin/options.py

     
    443443        # Gather actions from the admin site first
    444444        for (name, func) in self.admin_site.actions:
    445445            description = getattr(func, 'short_description', name.replace('_', ' '))
    446             actions.append((func, name, description))
     446            takes_input = hasattr(func, 'takes_input') and getattr(func, 'takes_input') or False
     447            actions.append((func, name, description, takes_input))
    447448       
    448449        # Then gather them from the model admin and all parent classes,
    449450        # starting with self and working back up.
     
    461462        # and sorted by description.
    462463        actions.sort(lambda a,b: cmp(a[2].lower(), b[2].lower()))
    463464        actions = SortedDict([
    464             (name, (func, name, desc))
    465             for func, name, desc in actions
     465            (name, (func, name, desc, input))
     466            for func, name, desc, input in actions
    466467        ])
    467468       
    468469        return actions
     
    473474        tuple (name, description).
    474475        """
    475476        choices = [] + default_choices
    476         for func, name, description in self.get_actions(request).itervalues():
     477        for func, name, description, takes_input in self.get_actions(request).itervalues():
    477478            choice = (name, description % model_format_dict(self.opts))
    478479            choices.append(choice)
    479480        return choices
    480481
    481482    def get_action(self, action):
    482483        """
    483         Return a given action from a parameter, which can either be a calable,
     484        Return a given action from a parameter, which can either be a callable,
    484485        or the name of a method on the ModelAdmin.  Return is a tuple of
    485486        (callable, name, description).
    486487        """
     
    506507            description = func.short_description
    507508        else:
    508509            description = capfirst(action.replace('_', ' '))
    509         return func, action, description
     510       
     511        takes_input = hasattr(func, 'takes_input') and getattr(func, 'takes_input') or False
     512       
     513        return func, action, description, takes_input
    510514
    511515    def construct_change_message(self, request, form, formsets):
    512516        """
     
    680684        # If the form's valid we can handle the action.
    681685        if action_form.is_valid():
    682686            action = action_form.cleaned_data['action']
    683             func, name, description = self.get_actions(request)[action]
     687            func, name, description, takes_input = self.get_actions(request)[action]
    684688
    685689            # Get the list of selected PKs. If nothing's selected, we can't
    686690            # perform an action on it, so bail.
    687691            selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME)
    688692            if not selected:
    689693                return None
     694           
     695            input = takes_input and [request.POST["actioninput"]] or []
     696            response = func(self, request, queryset.filter(pk__in=selected), *input)
    690697
    691             response = func(self, request, queryset.filter(pk__in=selected))
    692 
    693698            # Actions may return an HttpResponse, which will be used as the
    694699            # response from the POST. If not, we'll be a good little HTTP
    695700            # citizen and redirect back to the changelist page.
  • django/contrib/admin/templates/admin/actions.html

     
    11{% load i18n %}
    22<div class="actions">
    33    {% for field in action_form %}<label>{{ field.label }} {{ field }}</label>{% endfor %}
     4    <input type="text" id="actioninput" value="" name="actioninput" size="20"/>
    45    <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button>
    56</div>
Back to Top