当前位置: 首页>>代码示例>>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;未经允许,请勿转载。