Opened 7 years ago

Closed 7 years ago

#3204 closed enhancement (fixed)

[patch] Need ability to pass a RequestContext instance to FormPreview.

Reported by: Vadim Macagon <vadim@…> Owned by: adrian
Component: contrib.formtools Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I tried using the FormPreview class in django.contrib.formtools.preview today. But my templates rely on a RequestContext as opposed to just the plain Context produced by all the render_to_response() calls used by FormPreview.

Here's what I'm currently doing:


(r'^apples/add/$', 'apples.views.add_apple')


class ApplePreview(FormPreview):
    preview_template = 'apples/preview.html'
    form_template = 'apples/form.html'
    def done(self, request, clean_data):
        # create apple object and save to db
        # ...
        return HttpResponseRedirect('/')

def add_apple(request):
    # ARGH! Can't pass in a RequestContext!
    return ApplePreview(AppleForm)(request)

So I suggest modifying FormPreview slightly so that the initialization method takes an optional context_instance arg that can be passed to all the render_to_response calls in preview_get(), preview_post() and post_post(). I've attached a diff with the suggested changes. With these changes I can write this:

def add_apple(request):
    # Yay!
    return ApplePreview(AppleForm, RequestContext(request))(request)

Attachments (1)

formpreview.diff (2.8 KB) - added by Vadim Macagon <vadim@…> 7 years ago.

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by Vadim Macagon <vadim@…>

comment:1 Changed 7 years ago by Vadim Macagon <vadim@…>

  • Summary changed from Need ability to pass a RequestContext instance to FormPreview. to [patch] Need ability to pass a RequestContext instance to FormPreview.

comment:2 Changed 7 years ago by adrian

If we allow for a context_instance argument, as this patch provides, then it becomes necessary to wrap the FormPreview class within a view. It's intended to be used directly *as* a view rather than being wrapped.

A better way of adding the functionality, then, would just be to use RequestContext by default.

comment:3 Changed 7 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [4259]) Fixed #3204 -- Changed FormPreview to use RequestContext

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.