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


Python mixins.RetrieveModelMixin方法代碼示例

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


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

示例1: create

# 需要導入模塊: from rest_framework import mixins [as 別名]
# 或者: from rest_framework.mixins import RetrieveModelMixin [as 別名]
def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        mobile = serializer.validated_data['mobile']
        list = []
        list.append(mobile)
        code = self.generate_code()
        SendCode.SendMail.delay(code, list)

        code_record = VerifyCode(code=code, mobile=mobile, type='email')
        code_record.save()
        return Response({
            "mobile": mobile
        }, status=status.HTTP_201_CREATED)


# class UserLogViewSet(mixins.CreateModelMixin, mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet): 
開發者ID:xuchaoa,項目名稱:CTF_AWD_Platform,代碼行數:20,代碼來源:views.py

示例2: add_viewset

# 需要導入模塊: from rest_framework import mixins [as 別名]
# 或者: from rest_framework.mixins import RetrieveModelMixin [as 別名]
def add_viewset(table):
    data_index = table.name
    record_data_index = "{}.".format(table.name)
    deleted_data_index = "{}..".format(table.name)

    def retrieve(self, request, *args, **kwargs):
        try:
            res = es.search(index=record_data_index, doc_type="record-data", body={"query": {"term": {"S-data-id": kwargs["pk"]}}}, sort="S-update-time:desc")
        except NotFoundError as exc:
            raise exceptions.NotFound("Document {} was not found in Type data of Index {}".format(kwargs["pk"], record_data_index))
        except TransportError as exc:
            return Response([])
        return Response(res["hits"])
    viewset = type(table.name, (mixins.RetrieveModelMixin, viewsets.GenericViewSet), dict(
        permission_classes=(permissions.IsAuthenticated, ), retrieve=retrieve))
    setattr(views, table.name, viewset)
    return viewset 
開發者ID:open-cmdb,項目名稱:cmdb,代碼行數:19,代碼來源:initialize.py

示例3: add_viewset

# 需要導入模塊: from rest_framework import mixins [as 別名]
# 或者: from rest_framework.mixins import RetrieveModelMixin [as 別名]
def add_viewset(table):
    data_index = table.name
    record_data_index = "{}.".format(table.name)
    deleted_data_index = "{}..".format(table.name)

    def list(self, request, *args, **kwargs):
        page = int(request.query_params.get("page", 1))
        page_size = int(request.query_params.get("page_size", 10))
        try:
            res = es.search(index=deleted_data_index, doc_type="deleted-data", size=page_size, from_=(page-1)*page_size)
        except Exception as exc:
            raise exceptions.APIException("內部錯誤,錯誤類型: {}".format(type(exc)))
        return Response(res["hits"])

    def retrieve(self, request, *args, **kwargs):
        try:
            res = es.get(index=deleted_data_index, doc_type="data", id=kwargs["pk"])
        except NotFoundError as exc:
            raise exceptions.NotFound("Document {} was not found in Type {} of Index {}".format(kwargs["pk"], "data", table.name))
    viewset = type(table.name, (mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet),
                   dict(permission_classes=(c_permissions.TableLevelPermission, ), list=list, retrieve=retrieve))
    setattr(views, table.name, viewset)
    return viewset 
開發者ID:open-cmdb,項目名稱:cmdb,代碼行數:25,代碼來源:initialize.py

示例4: is_list_view

# 需要導入模塊: from rest_framework import mixins [as 別名]
# 或者: from rest_framework.mixins import RetrieveModelMixin [as 別名]
def is_list_view(path, method, view):
    """
    Return True if the given path/method appears to represent a list view.
    """
    if hasattr(view, 'action'):
        # Viewsets have an explicitly defined action, which we can inspect.
        return view.action == 'list'

    if method.lower() != 'get':
        return False
    if isinstance(view, RetrieveModelMixin):
        return False
    path_components = path.strip('/').split('/')
    if path_components and '{' in path_components[-1]:
        return False
    return True 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:18,代碼來源:utils.py


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