當前位置: 首頁>>代碼示例>>Python>>正文


Python permissions.AllowAny方法代碼示例

本文整理匯總了Python中rest_framework.permissions.AllowAny方法的典型用法代碼示例。如果您正苦於以下問題:Python permissions.AllowAny方法的具體用法?Python permissions.AllowAny怎麽用?Python permissions.AllowAny使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.permissions的用法示例。


在下文中一共展示了permissions.AllowAny方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_should_not_cache_for_non_json_responses

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def test_should_not_cache_for_non_json_responses(self):
        """ Verify that the decorator does not cache if the response is not json """
        def key_func(**kwargs):  # pylint: disable=unused-argument
            return 'non_json_cache_key'

        class TestView(views.APIView):
            permission_classes = [permissions.AllowAny]
            renderer_classes = [BrowsableAPIRenderer]  # Non-json responses

            @compressed_cache_response(key_func=key_func)
            def get(self, request, *args, **kwargs):
                return Response('test response')

        view_instance = TestView()
        view_instance.headers = {}  # pylint: disable=attribute-defined-outside-init
        view_instance.dispatch(request=self.request)

        # Verify nothing was cached
        self.assertEqual(cache.get('non_json_cache_key'), None) 
開發者ID:edx,項目名稱:course-discovery,代碼行數:21,代碼來源:test_cache.py

示例2: test_should_not_cache_if_waffled

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def test_should_not_cache_if_waffled(self, waffle_active):
        """ Verify that the decorator does not cache the waffle flag is turned off """
        def key_func(**kwargs):  # pylint: disable=unused-argument
            return self.cache_response_key

        class TestView(views.APIView):
            permission_classes = [permissions.AllowAny]
            renderer_classes = [JSONRenderer]

            @compressed_cache_response(key_func=key_func)
            def get(self, request, *args, **kwargs):
                return Response('test response')

        with override_flag('compressed_cache.TestView.get', active=waffle_active):

            view_instance = TestView()
            view_instance.headers = {}  # pylint: disable=attribute-defined-outside-init
            view_instance.dispatch(request=self.request)

        # Verify nothing was cached
        if waffle_active:
            self.assertIsNot(cache.get(self.cache_response_key), None)
        else:
            self.assertIs(cache.get(self.cache_response_key), None) 
開發者ID:edx,項目名稱:course-discovery,代碼行數:26,代碼來源:test_cache.py

示例3: post

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def post(self, request, format=None):
        serializer = self.serializer_class(data=request.data)

        if serializer.is_valid():
            email = serializer.data['email']

            try:
                user = get_user_model().objects.get(email=email)
                if user.is_verified and user.is_active:
                    password_reset_code = \
                        PasswordResetCode.objects.create_reset_code(user)
                    password_reset_code.send_password_reset_email()
                    content = {'email': email}
                    return Response(content, status=status.HTTP_201_CREATED)

            except get_user_model().DoesNotExist:
                pass

            # Since this is AllowAny, don't give away error.
            content = {'detail': _('Password reset not allowed.')}
            return Response(content, status=status.HTTP_400_BAD_REQUEST)

        else:
            return Response(serializer.errors,
                status=status.HTTP_400_BAD_REQUEST) 
開發者ID:celiao,項目名稱:django-rest-authemail,代碼行數:27,代碼來源:views.py

示例4: get_schema_view

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_schema_view(self):
        view = get_schema_view(
            openapi.Info(
                title="Django Bananas Admin API Schema",
                default_version=BananasVersioning.default_version,
                description="API for django-bananas.js",
                # terms_of_service="https://www.google.com/policies/terms/",
                # license=openapi.License(name="BSD License"),
            ),
            # validators=["flex", "ssv"],
            public=False,
            generator_class=BananasOpenAPISchemaGenerator,
            authentication_classes=(SessionAuthentication,),
            permission_classes=(permissions.AllowAny,),
            patterns=self.urls,
        )
        view.versioning_class = BananasVersioning

        return view 
開發者ID:5monkeys,項目名稱:django-bananas,代碼行數:21,代碼來源:yasg.py

示例5: get_serializer_context

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_serializer_context(self, *args, **kwargs):
        return {"request": self.request}




# class RegisterAPIView(APIView):
#     permission_classes      = [permissions.AllowAny]
#     def post(self, request, *args, **kwargs):
#         if request.user.is_authenticated():
#             return Response({'detail': 'You are already registered and are authenticated.'}, status=400)
#         data = request.data
#         username        = data.get('username') # username or email address
#         email           = data.get('username')
#         password        = data.get('password')
#         password2       = data.get('password2')
#         qs = User.objects.filter(
#                 Q(username__iexact=username)|
#                 Q(email__iexact=username)
#             )
#         if password != password2:
#             return Response({"password": "Password must match."}, status=401)
#         if qs.exists():
#             return Response({"detail": "This user already exists"}, status=401)
#         else:
#             user = User.objects.create(username=username, email=email)
#             user.set_password(password)
#             user.save()
#             # payload = jwt_payload_handler(user)
#             # token = jwt_encode_handler(payload)
#             # response = jwt_response_payload_handler(token, user, request=request)
#             # return Response(response, status=201)
#             return Response({'detail': "Thank you for registering. Please verify your email."}, status=201)
#         return Response({"detail": "Invalid Request"}, status=400) 
開發者ID:codingforentrepreneurs,項目名稱:REST-API,代碼行數:36,代碼來源:views.py

示例6: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_permissions(self):
        if self.action == 'list' or self.action == 'retrieve':
            permission_classes = [permissions.AllowAny]
        else:
            permission_classes = [DenyAny]
        return [permission() for permission in permission_classes] 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:8,代碼來源:package.py

示例7: test_excluding_fields

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def test_excluding_fields(self):
        @autofilter(exclude_fields=("indexed_int", "indexed_char", ))
        class SampleApiV7(ListAPIView):
            permission_classes = (AllowAny,)
            serializer_class = SampleModelForAutofilterSerializerVer1
            queryset = SampleModelForAutofilter.objects.all()

        self.assertEqual(set(SampleApiV7.filter_fields.keys()), {"id", "fk", "indexed_text", "indexed_url",
                                                                 "indexed_email", "nullable_field", "unique_text"}) 
開發者ID:HealthByRo,項目名稱:drf_tweaks,代碼行數:11,代碼來源:test_autofilter.py

示例8: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_permissions(self):

        if self.request.method in permissions.SAFE_METHODS:
            return (permissions.IsAuthenticated(),)

        if self.request.method == 'POST':
            return (permissions.AllowAny(),)

        return (permissions.IsAuthenticated(), IsAccountOwner(),) 
開發者ID:dkarchmer,項目名稱:django-aws-template,代碼行數:11,代碼來源:api_views.py

示例9: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_permissions(self):
        """
        Instantiates and returns the list of permissions that this view requires.
        """
        if self.action == "create":
            # Allow any user to create an account, but limit other actions to logged-in users.
            permission_classes = [AllowAny]
        else:
            permission_classes = [IsAuthenticated]
        return [permission() for permission in permission_classes] 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:12,代碼來源:views.py

示例10: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_permissions(self):
        """
        The create action are used to register user, we do not require authentication on that
        endpoint.
        """
        if self.action == "create":
            return [AllowAny()]

        return super().get_permissions() 
開發者ID:webkom,項目名稱:lego,代碼行數:11,代碼來源:users.py

示例11: __init__

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def __init__(self):
        if system_layout.current_value is not None:
            raise MiddlewareNotUsed()
        class FarmNotConfiguredView(APIView):
            permission_classes = (AllowAny, )
            def get(self, request):
                raise FarmNotConfiguredError()
            post = get
            put = get
            patch = get
            delete = get
        self.view = FarmNotConfiguredView.as_view() 
開發者ID:OpenAgricultureFoundation,項目名稱:gro-api,代碼行數:14,代碼來源:middleware.py

示例12: test_should_handle_getting_uncompressed_response_from_cache

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def test_should_handle_getting_uncompressed_response_from_cache(self):
        """ Verify that the decorator correctly returns uncompressed responses """
        def key_func(**kwargs):  # pylint: disable=unused-argument
            return self.cache_response_key

        class TestView(views.APIView):
            permission_classes = [permissions.AllowAny]
            renderer_classes = [JSONRenderer]

            @compressed_cache_response(key_func=key_func)
            def get(self, request, *args, **kwargs):
                return Response('test response')

        view_instance = TestView()
        view_instance.headers = {}  # pylint: disable=attribute-defined-outside-init
        uncompressed_cached_response = Response('cached test response')
        view_instance.finalize_response(request=self.request, response=uncompressed_cached_response)
        uncompressed_cached_response.render()

        response_triple = (
            uncompressed_cached_response.rendered_content,
            uncompressed_cached_response.status_code,
            uncompressed_cached_response._headers.copy(),  # pylint: disable=protected-access
        )
        cache.set(self.cache_response_key, response_triple)

        response = view_instance.dispatch(request=self.request)
        self.assertEqual(response.content.decode('utf-8'), '"cached test response"') 
開發者ID:edx,項目名稱:course-discovery,代碼行數:30,代碼來源:test_cache.py

示例13: test_should_handle_getting_compressed_response_from_cache

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def test_should_handle_getting_compressed_response_from_cache(self):
        """ Verify that the decorator correctly returns compressed responses """
        def key_func(**kwargs):  # pylint: disable=unused-argument
            return self.cache_response_key

        class TestView(views.APIView):
            permission_classes = [permissions.AllowAny]
            renderer_classes = [JSONRenderer]

            @compressed_cache_response(key_func=key_func)
            def get(self, request, *args, **kwargs):
                return Response('test response')

        view_instance = TestView()
        view_instance.headers = {}  # pylint: disable=attribute-defined-outside-init
        compressed_cached_response = Response('compressed cached test response')
        view_instance.finalize_response(request=self.request, response=compressed_cached_response)
        compressed_cached_response.render()

        # Rendered content is compressed before response goes into the cache
        response_triple = (
            zlib.compress(compressed_cached_response.rendered_content),
            compressed_cached_response.status_code,
            compressed_cached_response._headers.copy(),  # pylint: disable=protected-access
        )
        cache.set(self.cache_response_key, response_triple)

        response = view_instance.dispatch(request=self.request)
        self.assertEqual(response.content.decode('utf-8'), '"compressed cached test response"') 
開發者ID:edx,項目名稱:course-discovery,代碼行數:31,代碼來源:test_cache.py

示例14: register_permission_classes

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def register_permission_classes():
    permission_classes = [AllowAny, ]
    for klass in getattr(settings, 'REST_AUTH_REGISTER_PERMISSION_CLASSES', tuple()):
        permission_classes.append(import_callable(klass))
    return tuple(permission_classes) 
開發者ID:Tivix,項目名稱:django-rest-auth,代碼行數:7,代碼來源:app_settings.py

示例15: get_permissions

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import AllowAny [as 別名]
def get_permissions(self):
        if self.request.query_params.get('user-only', None):
            self.permission_classes = (AllowAny,)
        return super().get_permissions() 
開發者ID:getway,項目名稱:diting,代碼行數:6,代碼來源:api.py


注:本文中的rest_framework.permissions.AllowAny方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。