Fixes an issue where the organization home page would throw a 505 when no projects...
[Melange.git] / app / django / contrib / formtools / utils.py
bloba357255522703f87563fef29081ce877a07093fd
1 try:
2 import cPickle as pickle
3 except ImportError:
4 import pickle
6 from django.conf import settings
7 from django.utils.hashcompat import md5_constructor
8 from django.forms import BooleanField
10 def security_hash(request, form, *args):
11 """
12 Calculates a security hash for the given Form instance.
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 """
19 data = [(bf.name, bf.field.clean(bf.data) or '') for bf in form]
20 data.extend(args)
21 data.append(settings.SECRET_KEY)
23 # Use HIGHEST_PROTOCOL because it's the most efficient. It requires
24 # Python 2.3, but Django requires 2.3 anyway, so that's OK.
25 pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
27 return md5_constructor(pickled).hexdigest()