diff options
author | Guilherme Salgado <guilherme.salgado@linaro.org> | 2011-02-28 02:37:03 +0000 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2011-03-08 15:26:14 +0800 |
commit | 8639b526494afbe41d27c60e69ce26513c7d3c37 (patch) | |
tree | 80bcf663504060d66959900b35cc8d740c886beb /apps/patchwork/forms.py | |
parent | 479a6a88c41203aca1a1f44253554a4f28d2e248 (diff) | |
download | patchwork-8639b526494afbe41d27c60e69ce26513c7d3c37.tar.bz2 patchwork-8639b526494afbe41d27c60e69ce26513c7d3c37.tar.xz |
forms: Fix archiving/unarchiving of patches on patch lists
It was broken because MultipleBooleanField() was leaking string values instead
of boolens as expected by MultiplePatchForm.
Signed-off-by: Guilherme Salgado <guilherme.salgado@linaro.org>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork/forms.py')
-rw-r--r-- | apps/patchwork/forms.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/apps/patchwork/forms.py b/apps/patchwork/forms.py index 4c811f5..dc7a464 100644 --- a/apps/patchwork/forms.py +++ b/apps/patchwork/forms.py @@ -176,6 +176,24 @@ class MultipleBooleanField(forms.ChoiceField): def is_no_change(self, value): return value == self.no_change_choice[0] + # TODO: Check whether it'd be worth to use a TypedChoiceField here; I + # think that'd allow us to get rid of the custom valid_value() and + # to_python() methods. + def valid_value(self, value): + if value in [v1 for (v1, v2) in self.choices]: + return True + return False + + def to_python(self, value): + if self.is_no_change(value): + return value + elif value == 'True': + return True + elif value == 'False': + return False + else: + raise ValueError('Unknown value: %s' % value) + class MultiplePatchForm(forms.Form): state = OptionalModelChoiceField(queryset = State.objects.all()) archived = MultipleBooleanField() |