Ticket #17976: 17976-1.diff

File 17976-1.diff, 1.8 KB (added by Claude Paroz, 13 years ago)

Use a module-level function to restore picklability

  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 1fbef98..172bb3c 100644
    a b class TimeInput(Input):  
    487487            pass
    488488        return super(TimeInput, self)._has_changed(self._format_value(initial), data)
    489489
     490
     491# Purposely defined at module level so it is picklable (unlike lambdas or methods)
     492def boolean_check(v):
     493    return not (v is False or v is None or v == '')
     494
    490495class CheckboxInput(Widget):
    491496    def __init__(self, attrs=None, check_test=None):
    492497        super(CheckboxInput, self).__init__(attrs)
    493498        # check_test is a callable that takes a value and returns True
    494499        # if the checkbox should be checked for that value.
    495500        if check_test is None:
    496             self.check_test = lambda v: not (v is False or v is None or v == '')
     501            self.check_test = boolean_check
    497502        else:
    498503            self.check_test = check_test
    499504
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index 6e4a544..2ad0f17 100644
    a b Other than that, the Field subclasses have class-specific options for  
    2525__init__(). For example, CharField has a max_length option.
    2626"""
    2727import datetime
     28import pickle
    2829import re
    2930import os
    3031import warnings
    class FieldsTests(SimpleTestCase):  
    698699        self.assertEqual(False, f.clean('false'))
    699700        self.assertEqual(False, f.clean('FaLsE'))
    700701
     702    def test_boolean_picklable(self):
     703        self.assertIsInstance(pickle.loads(pickle.dumps(BooleanField())), BooleanField)
     704
    701705    # ChoiceField #################################################################
    702706
    703707    def test_choicefield_1(self):
Back to Top