#33299: Create new decorator `request_passes_test` or modify `user_passes_test`
to
send `request` parameter
-------------------------------------+-------------------------------------
Reporter: Iago | Owner: nobody
González |
Type: New | Status: new
feature |
Component: | Version: 3.2
contrib.auth | Keywords: user_passes_test,
Severity: Normal | request, Auth
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
The `user_passes_test` is a little bit limited when used for restricting
the views. For example: you cannot use the Django messages framework,
because you cannot access the `request` object.
I suggest creating a `request_passes_test` to allow the creation of more
advanced restrictions and logic.
Other developers that use Django also need this feature:
[https://stackoverflow.com/questions/11872560/how-to-pass-django-request-
object-in-user-passes-test-decorator-callable-functio]
[https://stackoverflow.com/questions/16375023/show-error-message-when-
decorator-fails]
I will add three solutions for this problem. These were quick solutions
not tested, so they can have some errors; but I'm willing to open a Pull
Request and improve the better approach. My favourite one is the solution
1, because it uses an abstract function that could be reused for creating
both `user_passes_test` and `request_passes_test`. The other 2 solutions
are uglier, but I add them just in case.
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/33299>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.e5980bd4ca62384a2eecfa0bf486fef0%40djangoproject.com.