Ticket #3204: formpreview.diff

File formpreview.diff, 2.8 KB (added by Vadim Macagon <vadim@…>, 18 years ago)
  • django/contrib/formtools/preview.py

     
    5959
    6060    # METHODS SUBCLASSES SHOULDN'T OVERRIDE ###################################
    6161
    62     def __init__(self, form):
     62    def __init__(self, form, context_instance=None):
    6363        # form should be a Form class, not an instance.
    6464        self.form, self.state = form, {}
     65        self.context_instance = context_instance
    6566
    6667    def __call__(self, request, *args, **kwargs):
    6768        stage = {'1': 'preview', '2': 'post'}.get(request.POST.get(self.unused_name('stage')), 'preview')
     
    9192    def preview_get(self, request):
    9293        "Displays the form"
    9394        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)
    95100
    96101    def preview_post(self, request):
    97102        "Validates the POST data. If valid, displays the preview page. Else, redisplays form."
     
    100105        if f.is_valid():
    101106            context['hash_field'] = self.unused_name('hash')
    102107            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)
    104110        else:
    105             return render_to_response(self.form_template, context)
     111            return render_to_response(self.form_template, context,
     112                                      self.context_instance)
    106113
    107114    def post_post(self, request):
    108115        "Validates the POST data. If valid, calls done(). Else, redisplays form."
     
    112119                return self.failed_hash(request) # Security hash failed.
    113120            return self.done(request, f.clean_data)
    114121        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)
    116127
    117128    # METHODS SUBCLASSES MIGHT OVERRIDE IF APPROPRIATE ########################
    118129
Back to Top