]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/forms.py
forms.MultiplePatchForm: remove no-change fields on clean()
[patchwork] / apps / patchwork / forms.py
index 10c93a42b199946034a4acdbe97dd626b6d1e1b0..2c137e3c027618e12ff223755272f4451813689e 100644 (file)
@@ -114,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
@@ -185,6 +186,21 @@ class MultiplePatchForm(PatchForm):
         self.fields['delegate'] = OptionalDelegateField(project = project,
                 required = False)
 
+    def _clean_fields(self):
+        super(MultiplePatchForm, self)._clean_fields()
+        # remove optional fields
+        opts = self.instance._meta
+        for f in opts.fields:
+            if not f.name in self.cleaned_data:
+                continue
+
+            field = self.fields.get(f.name, None)
+            if field is None:
+                continue
+
+            if field.is_no_change(self.cleaned_data[f.name]):
+                del self.cleaned_data[f.name]
+
     def save(self, instance, commit = True):
         opts = instance.__class__._meta
         if self.errors: