]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/forms.py
Use generic email confirmation object
[patchwork] / apps / patchwork / forms.py
index 4c811f547c439dd924db58bb5c8a496b497e78e5..1ff2bd0088c765711a26c176f652337409bc4d56 100644 (file)
@@ -176,7 +176,26 @@ 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 value is None or self.is_no_change(value):
+            return self.no_change_choice[0]
+        elif value == 'True':
+            return True
+        elif value == 'False':
+            return False
+        else:
+            raise ValueError('Unknown value: %s' % value)
+
 class MultiplePatchForm(forms.Form):
+    action = 'update'
     state = OptionalModelChoiceField(queryset = State.objects.all())
     archived = MultipleBooleanField()