Ticket #10643: 10643.2.diff

File 10643.2.diff, 1.7 KB (added by Andy Durdin, 16 years ago)

Better names in patch

  • django/contrib/formtools/utils.py

     
    1515    order, pickles the result with the SECRET_KEY setting, then takes an md5
    1616    hash of that.
    1717    """
    18 
    19     data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form]
     18    if form.empty_permitted and not form.has_changed():
     19        data = [(bf.name, bf.data or '') for bf in form]
     20    else:
     21        data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form]
    2022    data.extend(args)
    2123    data.append(settings.SECRET_KEY)
    2224
  • tests/regressiontests/forms/tests.py

     
    6767    'widgets_tests': widgets_tests,
    6868}
    6969
     70from django.test import TestCase
     71
     72class FormToolsUtilsTests(TestCase):
     73    def test_security_hash_empty_permitted_form(self):
     74        """Check that formtools.utils.security_hash handles forms with
     75        empty_permitted=True"""
     76        from django import forms
     77
     78        class BlankForm(forms.Form):
     79            name = forms.CharField(max_length=10, required=False)
     80        class NotBlankForm(forms.Form):
     81            name = forms.CharField(max_length=10)
     82        blank_form = BlankForm({})
     83        not_blank_form = NotBlankForm({}, empty_permitted=True)
     84       
     85        from django.contrib.formtools.utils import security_hash
     86        self.assertEqual(security_hash(None, blank_form), security_hash(None, not_blank_form))
     87
    7088if __name__ == "__main__":
    7189    import doctest
    7290    doctest.testmod()
Back to Top