1 | Index: django/contrib/formtools/utils.py
|
---|
2 | ===================================================================
|
---|
3 | --- django/contrib/formtools/utils.py (revisión: 8597)
|
---|
4 | +++ django/contrib/formtools/utils.py (copia de trabajo)
|
---|
5 | @@ -8,32 +8,31 @@
|
---|
6 | from django.forms import BooleanField
|
---|
7 |
|
---|
8 | def security_hash(request, form, *args):
|
---|
9 | - """
|
---|
10 | - Calculates a security hash for the given Form instance.
|
---|
11 | + """
|
---|
12 | + Calculates a security hash for the given Form instance.
|
---|
13 |
|
---|
14 | - This creates a list of the form field names/values in a deterministic
|
---|
15 | - order, pickles the result with the SECRET_KEY setting, then takes an md5
|
---|
16 | - hash of that.
|
---|
17 | - """
|
---|
18 | - # Ensure that the hash does not change when a BooleanField's bound
|
---|
19 | - # data is a string `False' or a boolean False.
|
---|
20 | - # Rather than re-coding this special behaviour here, we
|
---|
21 | - # create a dummy BooleanField and call its clean method to get a
|
---|
22 | - # boolean True or False verdict that is consistent with
|
---|
23 | - # BooleanField.clean()
|
---|
24 | - dummy_bool = BooleanField(required=False)
|
---|
25 | - def _cleaned_data(bf):
|
---|
26 | - if isinstance(bf.field, BooleanField):
|
---|
27 | - return dummy_bool.clean(bf.data)
|
---|
28 | - return bf.data
|
---|
29 | -
|
---|
30 | - data = [(bf.name, _cleaned_data(bf) or '') for bf in form]
|
---|
31 | - data.extend(args)
|
---|
32 | - data.append(settings.SECRET_KEY)
|
---|
33 | -
|
---|
34 | - # Use HIGHEST_PROTOCOL because it's the most efficient. It requires
|
---|
35 | - # Python 2.3, but Django requires 2.3 anyway, so that's OK.
|
---|
36 | - pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
|
---|
37 | -
|
---|
38 | - return md5_constructor(pickled).hexdigest()
|
---|
39 | + This creates a list of the form field names/values in a deterministic
|
---|
40 | + order, pickles the result with the SECRET_KEY setting, then takes an md5
|
---|
41 | + hash of that.
|
---|
42 | + """
|
---|
43 | + # Ensure that the hash does not change when a BooleanField's bound
|
---|
44 | + # data is a string `False' or a boolean False.
|
---|
45 | + # Rather than re-coding this special behaviour here, we
|
---|
46 | + # create a dummy BooleanField and call its clean method to get a
|
---|
47 | + # boolean True or False verdict that is consistent with
|
---|
48 | + # BooleanField.clean()
|
---|
49 | + dummy_bool = BooleanField(required=False)
|
---|
50 | + def _cleaned_data(bf):
|
---|
51 | + if isinstance(bf.field, BooleanField):
|
---|
52 | + return dummy_bool.clean(bf.data)
|
---|
53 | + return bf.data
|
---|
54 |
|
---|
55 | + data = [(bf.name, _cleaned_data(bf) or '') for bf in form]
|
---|
56 | + data.extend(args)
|
---|
57 | + data.append(settings.SECRET_KEY)
|
---|
58 | +
|
---|
59 | + # Use HIGHEST_PROTOCOL because it's the most efficient. It requires
|
---|
60 | + # Python 2.3, but Django requires 2.3 anyway, so that's OK.
|
---|
61 | + pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
|
---|
62 | +
|
---|
63 | + return md5_constructor(pickled).hexdigest()
|
---|
64 | \ Sin fin-de-línea al final del archivo
|
---|