|
|
@ -124,3 +124,49 @@ class TargetActionBase(AdminActionBase): |
|
|
|
'target': target_name, |
|
|
|
'target': target_name, |
|
|
|
'failure_count': failure_count} |
|
|
|
'failure_count': failure_count} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeForeignKeyAction(AdminActionBase): |
|
|
|
|
|
|
|
# Subclass:: |
|
|
|
|
|
|
|
# action_name = 'change_fieldname_action' |
|
|
|
|
|
|
|
# field_name_label = _("<field name>") |
|
|
|
|
|
|
|
# title = _("Change <field name>") |
|
|
|
|
|
|
|
# queryset_action_label = _("For the following items the <field name> will be changed:") |
|
|
|
|
|
|
|
# action_button_label = _("Change <field name>") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply(self, queryset, form): |
|
|
|
|
|
|
|
raise NotImplementedError("apply must be implemented by the subclass.") |
|
|
|
|
|
|
|
# Subclass:: |
|
|
|
|
|
|
|
# new_value = form.cleaned_data['new_value'] |
|
|
|
|
|
|
|
# return change_fieldname_state(queryset, new_value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_value_choices_queryset(self, modeladmin, request, queryset): |
|
|
|
|
|
|
|
raise NotImplementedError("get_value_choices_queryset must be implemented by the subclass.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_form_class(self, modeladmin, request, queryset): |
|
|
|
|
|
|
|
class ChooseValueForm(AdminActionBase.BaseForm): |
|
|
|
|
|
|
|
new_value = forms.ModelChoiceField( |
|
|
|
|
|
|
|
label=_("Choose %(field_name)s" % {'field_name': self.field_name_label}), |
|
|
|
|
|
|
|
queryset=self.get_value_choices_queryset(modeladmin, request, queryset), |
|
|
|
|
|
|
|
required=True) |
|
|
|
|
|
|
|
return ChooseValueForm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_message(self, form, count): |
|
|
|
|
|
|
|
new_value = form.cleaned_data['new_value'] |
|
|
|
|
|
|
|
return ngettext( |
|
|
|
|
|
|
|
'Successfully changed %(field_name)s of %(count)d item to %(new_value)s.', |
|
|
|
|
|
|
|
'Successfully changed %(field_name)s of %(count)d items to %(new_value)s.', |
|
|
|
|
|
|
|
count) % { |
|
|
|
|
|
|
|
'field_name': self.field_name_label, |
|
|
|
|
|
|
|
'count': count, |
|
|
|
|
|
|
|
'new_value': new_value} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_failure_message(self, form, count, failure_count): |
|
|
|
|
|
|
|
new_value = form.cleaned_data['new_value'] |
|
|
|
|
|
|
|
return ngettext( |
|
|
|
|
|
|
|
'Successfully changed %(field_name)s of %(count)d item to %(new_value)s, %(failure_count)s failed or skipped.', |
|
|
|
|
|
|
|
'Successfully changed %(field_name)s of %(count)d items to %(new_value)s, %(failure_count)s failed or skipped.', |
|
|
|
|
|
|
|
count) % { |
|
|
|
|
|
|
|
'field_name': self.field_name_label, |
|
|
|
|
|
|
|
'count': count, |
|
|
|
|
|
|
|
'new_value': new_value, |
|
|
|
|
|
|
|
'failure_count': failure_count} |
|
|
|