user_passes_test is for decorating functions, not classes

Django Rest Framework has its own system for permissions (and you seem to
be already using it)

http://www.django-rest-framework.org/api-guide/permissions/

Use that instead I think

On Sun, May 3, 2015 at 2:35 PM, Shekar Tippur <[email protected]> wrote:

> Hello,
>
> Here is a decorator that I am trying ot use to restrict access to the
> class to only super users: Can someone please point me to what could be
> wrong. If I take the decorator, I am able to get thro but it is not
> restricted to only super users.
>
> @user_passes_test(lambda u: u.is_superuser)
> class UserViewSet(viewsets.ModelViewSet):
>     permission_classes = [permissions.TokenHasReadWriteScope]
>     queryset = User.objects.all()
>     serializer_class = UserSerializer
>     model=User
>
>
> When I use this, I get the error:
>
> 'type' object is not iterable
>
>
> TypeError at /users/
>
> 'type' object is not iterable
>
> Request Method:GETRequest URL:http://127.0.0.1:8000/users/Django Version:
> 1.8Exception Type:TypeErrorException Value:
>
> 'type' object is not iterable
>
> Exception 
> Location:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rest_framework/views.py
> in get_permissions, line 252Python Executable:
> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4Python
> Version:3.4.3Python Path:
>
> ['/Users/PycharmProjects/screens',
>  '/Users/PycharmProjects/screens',
>  '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
>  '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
>  
> '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
>  
> '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
>  
> '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ee405db3-8ace-4f10-8bc3-a72b81ed9fc2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ee405db3-8ace-4f10-8bc3-a72b81ed9fc2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3jSsyToc9eQjkOYK4BS9LTUgw_SFhQmBHif10POq%2BvKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to