]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/forms.py
forms: Fix archiving/unarchiving of patches on patch lists
[patchwork] / apps / patchwork / forms.py
index 1c5aeef5394dd4e62de228229eb404de4ce0af31..dc7a46443fa4179171044d1bb8ad6aa29824cc8a 100644 (file)
@@ -45,9 +45,9 @@ class RegistrationForm(RegistrationFormUniqueEmail):
         user.last_name = self.cleaned_data.get('last_name', '')
         user.save()
 
-       # saving the userprofile causes the firstname/lastname to propagate
-       # to the person objects.
-       user.get_profile().save()
+        # saving the userprofile causes the firstname/lastname to propagate
+        # to the person objects.
+        user.get_profile().save()
 
         return user
 
@@ -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()