You should use the permission structure setup within DRF. First, get the
`rest_conditions` package. This package will let you use AND, OR etc with
permissions. I wrote a lot of my own permissions also. MOF, a lot of the
imports you see are custom.


For example:

from rest_framework.permissions import IsAuthenticated

from rest_condition import C, And, Or, Not

from inventory.common.api.permissions import (
   IsAdminSuperUser, IsAdministrator, IsDefaultUser, IsAnyUser,
   IsProjectOwner, IsProjectManager, IsProjectDefaultUser,
IsAnyProjectUser,
   IsReadOnly, IsUserActive, CanDelete)
from inventory.common.api.pagination import SmallResultsSetPagination
from inventory.common.api.view_mixins import (
   TrapDjangoValidationErrorCreateMixin,
TrapDjangoValidationErrorUpdateMixin)


class InventoryTypeList(TrapDjangoValidationErrorCreateMixin,
                        ListCreateAPIView):
   """
   InventoryType list endpoint.
   """
   queryset = InventoryType.objects.all()
   serializer_class = InventoryTypeSerializer
   permission_classes = (
       And(IsUserActive, IsAuthenticated,
           Or(IsAdminSuperUser,
              IsAdministrator,
              And(IsReadOnly, IsAnyProjectUser)
              )
           ),
       )
   pagination_class = SmallResultsSetPagination
   lookup_field = 'public_id'

~Carl


On Fri, Aug 23, 2019 at 2:12 PM göktürk sığırtmaç <s.goktur...@gmail.com>
wrote:

> Hello, my UserCreate class is create user via CreateAPIView. I want to
> check. if user is auth, auth user directly to '/' URI.
>
>
> class UserCreate(generics.CreateAPIView):
>
>     def __init__(self):
>         if IsAuthenticated:
>             print("hello")
>             redirect('/')
>
>
>
> code above is working print method but not working redirect method.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/f5775f98-70ff-4e0a-a7f0-c608b7e136eb%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/f5775f98-70ff-4e0a-a7f0-c608b7e136eb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
-------------------------------------------------------------------------------
Carl J. Nobile (Software Engineer)
carl.nob...@gmail.com
-------------------------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAGQqDQLYmtORUCMRw%3DC%2BesMi7-Rjt%2BTG3a-%2BAkocXwbzMcinyw%40mail.gmail.com.

Reply via email to