Patchwork Make MultipleBooleanField.to_python work when the field value is missing

login
register
mail settings
Submitter Guilherme Salgado
Date April 13, 2011, 4:11 p.m.
Message ID <20110413161107.17837.3529.stgit@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/91062/
State Accepted
Commit c3291f5d18445cd91b540342d31d76254b32376c
Headers show

Comments

Guilherme Salgado - April 13, 2011, 4:11 p.m.
If you write a test for, say, the bundle form of a patch list, you'd still
have to specify the 'no change' value to other form (e.g. the multiple update
one) fields using MultipleBooleanField or else it'd raise a ValueError when
field.clean() is called as part of form._get_errors().

Signed-off-by: Guilherme Salgado <guilherme.salgado@linaro.org>
---
 apps/patchwork/forms.py |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Jeremy Kerr - April 14, 2011, 7:14 a.m.
Hi Guilherme,

> If you write a test for, say, the bundle form of a patch list, you'd still
> have to specify the 'no change' value to other form (e.g. the multiple update
> one) fields using MultipleBooleanField or else it'd raise a ValueError when
> field.clean() is called as part of form._get_errors().

Applied, thanks. Looks like I just hit this with bundle updates too.

Cheers,


Jeremy

Patch

diff --git a/apps/patchwork/forms.py b/apps/patchwork/forms.py
index 2c57c08..e069fe9 100644
--- a/apps/patchwork/forms.py
+++ b/apps/patchwork/forms.py
@@ -187,8 +187,8 @@  class MultipleBooleanField(forms.ChoiceField):
         return False
 
     def to_python(self, value):
-        if self.is_no_change(value):
-            return value
+        if value is None or self.is_no_change(value):
+            return self.no_change_choice[0]
         elif value == 'True':
             return True
         elif value == 'False':