Ticket #3204: formpreview.diff
File formpreview.diff, 2.8 KB (added by , 18 years ago) |
---|
-
django/contrib/formtools/preview.py
59 59 60 60 # METHODS SUBCLASSES SHOULDN'T OVERRIDE ################################### 61 61 62 def __init__(self, form ):62 def __init__(self, form, context_instance=None): 63 63 # form should be a Form class, not an instance. 64 64 self.form, self.state = form, {} 65 self.context_instance = context_instance 65 66 66 67 def __call__(self, request, *args, **kwargs): 67 68 stage = {'1': 'preview', '2': 'post'}.get(request.POST.get(self.unused_name('stage')), 'preview') … … 91 92 def preview_get(self, request): 92 93 "Displays the form" 93 94 f = self.form(auto_id=AUTO_ID) 94 return render_to_response(self.form_template, {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state}) 95 return render_to_response(self.form_template, 96 {'form': f, 97 'stage_field': self.unused_name('stage'), 98 'state': self.state}, 99 self.context_instance) 95 100 96 101 def preview_post(self, request): 97 102 "Validates the POST data. If valid, displays the preview page. Else, redisplays form." … … 100 105 if f.is_valid(): 101 106 context['hash_field'] = self.unused_name('hash') 102 107 context['hash_value'] = self.security_hash(request, f) 103 return render_to_response(self.preview_template, context) 108 return render_to_response(self.preview_template, context, 109 self.context_instance) 104 110 else: 105 return render_to_response(self.form_template, context) 111 return render_to_response(self.form_template, context, 112 self.context_instance) 106 113 107 114 def post_post(self, request): 108 115 "Validates the POST data. If valid, calls done(). Else, redisplays form." … … 112 119 return self.failed_hash(request) # Security hash failed. 113 120 return self.done(request, f.clean_data) 114 121 else: 115 return render_to_response(self.form_template, {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state}) 122 return render_to_response(self.form_template, 123 {'form': f, 124 'stage_field': self.unused_name('stage'), 125 'state': self.state}, 126 self.context_instance) 116 127 117 128 # METHODS SUBCLASSES MIGHT OVERRIDE IF APPROPRIATE ######################## 118 129