Opened 16 years ago
Closed 10 years ago
#8690 closed New feature (fixed)
FormPreview should pass request to parse_params
Reported by: | Bob Thomas | Owned by: | nobody |
---|---|---|---|
Component: | contrib.formtools | Version: | dev |
Severity: | Normal | Keywords: | formpreview |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
It would be very useful to have request data in parse_params. The example given is to capture something like a user_id, but the main thing I would want to do here is to verify that the current user has permission to access the URL given. Of course, adding a parameter breaks backwards compatibility, so this is a similar request to #7222.
Attachments (2)
Change History (13)
by , 16 years ago
Attachment: | params.diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|---|
Keywords: | formpreview added |
comment:2 by , 16 years ago
Forgot to mention, FormWizard's version of parse_params includes the request parameter.
comment:3 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
This unfortunately introduces a subtle backwards-incompatibility: if parse_params
is defined in the old way (parse_params(*args, **kw)
), then args[0]
will become request
with this patch, thereby breaking user code. So we need to make sure this is really a vital change before we make that change.
comment:4 by , 16 years ago
I'm aware of the incompatibility (I mentioned it in the description), and it is unfortunate. We could define a new function like parse_request_params
that passes request as the first argument (and calls parse_params
without it), but I think that's a bit ugly.
This will only affect users that:
- Are overriding parse_params
- Are using unnamed args
Personally, I only use named arguments in URLconfs, but I can't speak for the rest of the community.
by , 16 years ago
Patch that tries to provide backwards compatibility. No tests and no docs yet, they can be added if idea isn't deeemed wrong
comment:5 by , 16 years ago
This works for me. Should we also add a DeprecationWarning for users who define parse_params the old way? Something like:
import warnings warnings.warn( message = "Defining parse_params without the request parameter is deprecated. Define it as parse_params(self, request, *args, **kwargs) instead.", category = DeprecationWarning, stacklevel = 2 )
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:9 by , 12 years ago
Triage Stage: | Design decision needed → Accepted |
---|
comment:10 by , 11 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Patch needs improvement: | set |
comment:11 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
formtools has been extracted into its own repository (https://github.com/django/django-formtools/). Because of this, the issue tracking for this package has been moved to GitHub issues. I'm going to close this ticket, but I've created a GitHub issue to replace it where the conversation can continue: https://github.com/django/django-formtools/issues/22. Thanks!
Add request parameter to parse_params