Ticket #10871: admin-action-input.patch
File admin-action-input.patch, 4.0 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/options.py
443 443 # Gather actions from the admin site first 444 444 for (name, func) in self.admin_site.actions: 445 445 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)) 447 448 448 449 # Then gather them from the model admin and all parent classes, 449 450 # starting with self and working back up. … … 461 462 # and sorted by description. 462 463 actions.sort(lambda a,b: cmp(a[2].lower(), b[2].lower())) 463 464 actions = SortedDict([ 464 (name, (func, name, desc ))465 for func, name, desc in actions465 (name, (func, name, desc, input)) 466 for func, name, desc, input in actions 466 467 ]) 467 468 468 469 return actions … … 473 474 tuple (name, description). 474 475 """ 475 476 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(): 477 478 choice = (name, description % model_format_dict(self.opts)) 478 479 choices.append(choice) 479 480 return choices 480 481 481 482 def get_action(self, action): 482 483 """ 483 Return a given action from a parameter, which can either be a cal able,484 Return a given action from a parameter, which can either be a callable, 484 485 or the name of a method on the ModelAdmin. Return is a tuple of 485 486 (callable, name, description). 486 487 """ … … 506 507 description = func.short_description 507 508 else: 508 509 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 510 514 511 515 def construct_change_message(self, request, form, formsets): 512 516 """ … … 680 684 # If the form's valid we can handle the action. 681 685 if action_form.is_valid(): 682 686 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] 684 688 685 689 # Get the list of selected PKs. If nothing's selected, we can't 686 690 # perform an action on it, so bail. 687 691 selected = request.POST.getlist(helpers.ACTION_CHECKBOX_NAME) 688 692 if not selected: 689 693 return None 694 695 input = takes_input and [request.POST["actioninput"]] or [] 696 response = func(self, request, queryset.filter(pk__in=selected), *input) 690 697 691 response = func(self, request, queryset.filter(pk__in=selected))692 693 698 # Actions may return an HttpResponse, which will be used as the 694 699 # response from the POST. If not, we'll be a good little HTTP 695 700 # citizen and redirect back to the changelist page. -
django/contrib/admin/templates/admin/actions.html
1 1 {% load i18n %} 2 2 <div class="actions"> 3 3 {% for field in action_form %}<label>{{ field.label }} {{ field }}</label>{% endfor %} 4 <input type="text" id="actioninput" value="" name="actioninput" size="20"/> 4 5 <button type="submit" class="button" title="{% trans "Run the selected action" %}" name="index" value="{{ action_index|default:0 }}">{% trans "Go" %}</button> 5 6 </div>