Opened 19 years ago
Closed 19 years ago
#3204 closed enhancement (fixed)
[patch] Need ability to pass a RequestContext instance to FormPreview.
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | contrib.formtools | Version: | dev |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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:
# urls.py
(r'^apples/add/$', 'apples.views.add_apple')
# views.py
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('/')
@login_required
@transaction.commit_on_success
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:
@login_required
@transaction.commit_on_success
def add_apple(request):
# Yay!
return ApplePreview(AppleForm, RequestContext(request))(request)
Attachments (1)
Change History (4)
by , 19 years ago
| Attachment: | formpreview.diff added |
|---|
comment:1 by , 19 years ago
| Summary: | Need ability to pass a RequestContext instance to FormPreview. → [patch] Need ability to pass a RequestContext instance to FormPreview. |
|---|
comment:2 by , 19 years ago
comment:3 by , 19 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
If we allow for a
context_instanceargument, as this patch provides, then it becomes necessary to wrap theFormPreviewclass 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
RequestContextby default.