<s> """<STR_LIT>""" <EOL> import cPickle as pickle <EOL> from django . conf import settings <EOL> from django . http import Http404 <EOL> from django . shortcuts import render_to_response <EOL> from django . template . context import RequestContext <EOL> from django . utils . hashcompat import md5_constructor <EOL> from django . contrib . formtools . utils import security_hash <EOL> AUTO_ID = '<STR_LIT>' <EOL> class FormPreview ( object ) : <EOL> preview_template = '<STR_LIT>' <EOL> form_template = '<STR_LIT>' <EOL> def __init__ ( self , form ) : <EOL> self . form , self . state = form , { } <EOL> def __call__ ( self , request , * args , ** kwargs ) : <EOL> stage = { '<STR_LIT:1>' : '<STR_LIT>' , '<STR_LIT:2>' : '<STR_LIT>' } . get ( request . POST . get ( self . unused_name ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . parse_params ( * args , ** kwargs ) <EOL> try : <EOL> method = getattr ( self , stage + '<STR_LIT:_>' + request . method . lower ( ) ) <EOL> except AttributeError : <EOL> raise Http404 <EOL> return method ( request ) <EOL> def unused_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> f = self . form . base_fields [ name ] <EOL> except KeyError : <EOL> break <EOL> name += '<STR_LIT:_>' <EOL> return name <EOL> def preview_get ( self , request ) : <EOL> "<STR_LIT>" <EOL> f = self . form ( auto_id = AUTO_ID ) <EOL> return render_to_response ( self . form_template , <EOL> { '<STR_LIT>' : f , '<STR_LIT>' : self . unused_name ( '<STR_LIT>' ) , '<STR_LIT:state>' : self . state } , <EOL> context_instance = RequestContext ( request ) ) <EOL> def preview_post ( self , request ) : <EOL> "<STR_LIT>" <EOL> f = self . form ( request . POST , auto_id = AUTO_ID ) <EOL> context = { '<STR_LIT>' : f , '<STR_LIT>' : self . unused_name ( '<STR_LIT>' ) , '<STR_LIT:state>' : self . state } <EOL> if f . is_valid ( ) : <EOL> self . process_preview ( request , f , context ) <EOL> context [ '<STR_LIT>' ] = self . unused_name ( '<STR_LIT>' ) <EOL> context [ '<STR_LIT>' ] = self . security_hash ( request , f ) <EOL> return render_to_response ( self . preview_template , context , context_instance = RequestContext ( request ) ) <EOL> else : <EOL> return render_to_response ( self . form_template , context , context_instance = RequestContext ( request ) ) <EOL> def post_post ( self , request ) : <EOL> "<STR_LIT>" <EOL> f = self . form ( request . POST , auto_id = AUTO_ID ) <EOL> if f . is_valid ( ) : <EOL> if self . security_hash ( request , f ) != request . POST . get ( self . unused_name ( '<STR_LIT>' ) ) : <EOL> return self . failed_hash ( request ) <EOL> return self . done ( request , f . cleaned_data ) <EOL> else : <EOL> return render_to_response ( self . form_template , <EOL> { '<STR_LIT>' : f , '<STR_LIT>' : self . unused_name ( '<STR_LIT>' ) , '<STR_LIT:state>' : self . state } , <EOL> context_instance = RequestContext ( request ) ) <EOL> def parse_params ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def process_preview ( self , request , form , context ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def security_hash ( self , request , form ) : <EOL> """<STR_LIT>""" <EOL> return security_hash ( request , form ) <EOL> def failed_hash ( self , request ) : <EOL> "<STR_LIT>" <EOL> return self . preview_post ( request ) <EOL> def done ( self , request , cleaned_data ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' % self . __class__ . __name__ ) </s>
