X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fforms.py;h=1c5aeef5394dd4e62de228229eb404de4ce0af31;hb=c24e22bb55d5bf6cf523fa9ad3f9b02e07e87566;hp=bc746bd11c580deb3031dbaa1925bf36920d29de;hpb=c1b2c0e5787a1ba487cda222596b0ca7ae94f288;p=patchwork diff --git a/apps/patchwork/forms.py b/apps/patchwork/forms.py index bc746bd..1c5aeef 100644 --- a/apps/patchwork/forms.py +++ b/apps/patchwork/forms.py @@ -80,6 +80,11 @@ class CreateBundleForm(forms.ModelForm): % name) return name +class DeleteBundleForm(forms.Form): + name = 'deletebundleform' + form_name = forms.CharField(initial = name, widget = forms.HiddenInput) + bundle_id = forms.IntegerField(widget = forms.HiddenInput) + class DelegateField(forms.ModelChoiceField): def __init__(self, project, *args, **kwargs): queryset = User.objects.filter(userprofile__in = \ @@ -109,6 +114,7 @@ class UserProfileForm(forms.ModelForm): class OptionalDelegateField(DelegateField): no_change_choice = ('*', 'no change') + to_field_name = None def __init__(self, no_change_choice = None, *args, **kwargs): self.filter = None @@ -135,6 +141,7 @@ class OptionalDelegateField(DelegateField): class OptionalModelChoiceField(forms.ModelChoiceField): no_change_choice = ('*', 'no change') + to_field_name = None def __init__(self, no_change_choice = None, *args, **kwargs): self.filter = None @@ -169,13 +176,12 @@ class MultipleBooleanField(forms.ChoiceField): def is_no_change(self, value): return value == self.no_change_choice[0] -class MultiplePatchForm(PatchForm): +class MultiplePatchForm(forms.Form): state = OptionalModelChoiceField(queryset = State.objects.all()) archived = MultipleBooleanField() def __init__(self, project, *args, **kwargs): - super(MultiplePatchForm, self).__init__(project = project, - *args, **kwargs) + super(MultiplePatchForm, self).__init__(*args, **kwargs) self.fields['delegate'] = OptionalDelegateField(project = project, required = False) @@ -185,7 +191,7 @@ class MultiplePatchForm(PatchForm): raise ValueError("The %s could not be changed because the data " "didn't validate." % opts.object_name) data = self.cleaned_data - # remove 'no change fields' from the data + # Update the instance for f in opts.fields: if not f.name in data: continue @@ -195,10 +201,13 @@ class MultiplePatchForm(PatchForm): continue if field.is_no_change(data[f.name]): - del data[f.name] + continue + + setattr(instance, f.name, data[f.name]) - return forms.save_instance(self, instance, - self._meta.fields, 'changed', commit) + if commit: + instance.save() + return instance class UserPersonLinkForm(forms.Form): email = forms.EmailField(max_length = 200)