当前位置: 首页>>代码示例>>Python>>正文


Python permissions.IsAdminUser方法代码示例

本文整理汇总了Python中rest_framework.permissions.IsAdminUser方法的典型用法代码示例。如果您正苦于以下问题:Python permissions.IsAdminUser方法的具体用法?Python permissions.IsAdminUser怎么用?Python permissions.IsAdminUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.permissions的用法示例。


在下文中一共展示了permissions.IsAdminUser方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_permissions

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def get_permissions(self):
        """Define custom permissions for different methods"""

        # at minimum require users to be authenticated
        self.permission_classes = [IsAuthenticated]
        # for PUT requests require users to be admins
        if self.request.method == 'PUT':
            self.permission_classes.append(IsAdminUser)

        return super(viewsets.ViewSet, self).get_permissions() 
开发者ID:BrewCenter,项目名称:BrewCenterAPI,代码行数:12,代码来源:fermentables.py

示例2: get_permissions

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def get_permissions(self):
        if self.action == 'list' or self.action == 'retrieve':
            permission_classes = [permissions.IsAuthenticated]
        else:
            permission_classes = [permissions.IsAdminUser]
        return [permission() for permission in permission_classes] 
开发者ID:82Flex,项目名称:DCRM,代码行数:8,代码来源:user.py

示例3: get_permissions

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def get_permissions(self):
        if self.action == 'partial_update' or self.action == 'update':
            permission_classes = [permissions.IsAdminUser]
        elif self.action == 'list' or self.action == 'retrieve':
            permission_classes = [permissions.IsAuthenticated]
        else:
            permission_classes = [DenyAny]
        return [permission() for permission in permission_classes] 
开发者ID:82Flex,项目名称:DCRM,代码行数:10,代码来源:setting.py

示例4: get_permissions

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def get_permissions(self):
        if self.request.method == 'GET':
            permission_classes = [IsAuthenticated, ]
        else:
            permission_classes = [IsAdminUser, ]

        return [permission() for permission in permission_classes] 
开发者ID:StamusNetworks,项目名称:scirius,代码行数:9,代码来源:rest_api.py

示例5: create

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def create(self, request: Request) -> Response:
        """Creates a recipe."""
        self.logger.debug("Creating recipe")

        # Initialize permission classes
        permission_classes = [IsAuthenticated, IsAdminUser]

        # Get recipe json
        try:
            request_dict = request.data.dict()
            recipe_json = request_dict["json"]
        except KeyError as e:
            message = "Unable to create recipe, {} is required".format(e)
            return Response({"message": message}, 400)

        # Get recipe manager
        app_config = apps.get_app_config(APP_NAME)
        recipe_manager = app_config.coordinator.recipe

        # Create recipe
        message, status = recipe_manager.create_recipe(recipe_json)

        # Build response
        response = {"message": message}

        # Return response
        self.logger.debug("Returning response: {}".format(response))
        return Response(response, status) 
开发者ID:OpenAgricultureFoundation,项目名称:openag-device-software,代码行数:30,代码来源:views.py

示例6: has_permission

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def has_permission(self, request, view):
        if request.method in SAFE_METHODS:
            return True

        return IsAdminUser().has_permission(request, view) 
开发者ID:doccano,项目名称:doccano,代码行数:7,代码来源:permissions.py

示例7: test_viewset_get_queryset_with_IsAdminUser_permission

# 需要导入模块: from rest_framework import permissions [as 别名]
# 或者: from rest_framework.permissions import IsAdminUser [as 别名]
def test_viewset_get_queryset_with_IsAdminUser_permission(self):
        from rest_framework.permissions import IsAdminUser
        setattr(self.view, "permission_classes", (IsAdminUser,))

        request = factory.get(path="/", data="", content_type="application/json")
        force_authenticate(request, user=self.user)
        response = self.view.as_view(actions={"get": "list"})(request)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        force_authenticate(request, user=self.admin_user)
        response = self.view.as_view(actions={"get": "list"})(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK) 
开发者ID:rhblind,项目名称:drf-haystack,代码行数:14,代码来源:test_viewsets.py


注:本文中的rest_framework.permissions.IsAdminUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。