當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。