example:
`def index(self, request):`
Fatal error: Class don't have attribute user.
This Change work for Django 1.11
but i see that file dont change a lot in Django 2.X
Now i can call the auth:
@user_passes_test(role_client_check, arg_position=0)
def index(self, request):
arg_position can be specific when the first argument isn't "request"
arg_position is a integer with the position of request on view function
I created my own user_passes_test function to solve this feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/29220>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "decorators.py" added.
\django\contrib\auth\decorators.py just one file update
* type: Uncategorized => New feature
Old description:
> I had problems Add my decorations user_passes_test functions, because
> decorator _wrapped_view assume, the first arg is the requests parameter,
> when i call user_passes_test from a view into a class, that not work, it
> take the arg self look like a arg request
>
> example:
> `def index(self, request):`
>
> Fatal error: Class don't have attribute user.
>
> This Change work for Django 1.11
> but i see that file dont change a lot in Django 2.X
>
> Now i can call the auth:
> @user_passes_test(role_client_check, arg_position=0)
> def index(self, request):
>
> arg_position can be specific when the first argument isn't "request"
> arg_position is a integer with the position of request on view function
>
> I created my own user_passes_test function to solve this feature.
New description:
I had problems Add my decorations user_passes_test functions, because
decorator _wrapped_view assume, the first arg is the `request` var
parameter, when i call user_passes_test from a view into a class, that not
work, it take the arg `self` look like a arg `request`
example:
`@user_passes_test(role_client_check)`
`def index(self, request):`
Fatal error: Class don't have attribute user.
The next new change work for Django 1.11
but i see that Django 2.X file, doesn't change a lot
Now i can call the auth:
`@user_passes_test(role_client_check, arg_position=0)`
`def index(self, request):`
`arg_position` can be specific when the first argument isn't "request"
`arg_position` is a integer with the position of request on view function
I created my own user_passes_test function to solve this feature.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:1>
* cc: Oscar Lopez (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:2>
* status: new => closed
* resolution: => invalid
Comment:
It looks like you have misunderstood how this works.
When using a class-based view (CBV) you need to use
[https://docs.djangoproject.com/en/stable/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
UserPassesTestMixin] instead of the `@user_passes_test` decorator.
(Alternatively, you can use `@method_decorator` to make this work - see
https://stackoverflow.com/q/8082670/ - but the using the mixin is
straightforward.)
--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:3>
Comment (by Oscar Lopez):
Oh Yes, i'm Sorry!
--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:4>
Comment (by Oscar Lopez):
Replying to [comment:3 Nick Pope]:
> It looks like you have misunderstood how this works.
>
> When using a class-based view (CBV) you need to use
[https://docs.djangoproject.com/en/stable/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
UserPassesTestMixin] instead of the `@user_passes_test` decorator.
>
> (Alternatively, you can use `@method_decorator` to make this work - see
https://stackoverflow.com/q/8082670/ - but using the mixin is
straightforward.)
Oh y tried django.contrib.auth.mixins.UserPassesTestMixin but this work
only when using class-based views, im going to try the stackoverflow
method
--
Ticket URL: <https://code.djangoproject.com/ticket/29220#comment:5>