app/django/contrib/formtools/preview.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
--- a/app/django/contrib/formtools/preview.py	Tue Oct 14 12:36:55 2008 +0000
+++ b/app/django/contrib/formtools/preview.py	Tue Oct 14 16:00:59 2008 +0000
@@ -2,12 +2,14 @@
 Formtools Preview application.
 """
 
+import cPickle as pickle
+
 from django.conf import settings
 from django.http import Http404
 from django.shortcuts import render_to_response
 from django.template.context import RequestContext
-import cPickle as pickle
-import md5
+from django.utils.hashcompat import md5_constructor
+from django.contrib.formtools.utils import security_hash
 
 AUTO_ID = 'formtools_%s' # Each form here uses this as its auto_id parameter.
 
@@ -96,20 +98,12 @@
 
     def security_hash(self, request, form):
         """
-        Calculates the security hash for the given Form instance.
+        Calculates the security hash for the given HttpRequest and Form instances.
 
-        This creates a list of the form field names/values in a deterministic
-        order, pickles the result with the SECRET_KEY setting and takes an md5
-        hash of that.
-
-        Subclasses may want to take into account request-specific information
+        Subclasses may want to take into account request-specific information,
         such as the IP address.
         """
-        data = [(bf.name, bf.data or '') for bf in form] + [settings.SECRET_KEY]
-        # Use HIGHEST_PROTOCOL because it's the most efficient. It requires
-        # Python 2.3, but Django requires 2.3 anyway, so that's OK.
-        pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
-        return md5.new(pickled).hexdigest()
+        return security_hash(request, form)
 
     def failed_hash(self, request):
         "Returns an HttpResponse in the case of an invalid security hash."