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


Python ModelResource.dispatch_list方法代码示例

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


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

示例1: dispatch_list

# 需要导入模块: from tastypie.resources import ModelResource [as 别名]
# 或者: from tastypie.resources.ModelResource import dispatch_list [as 别名]
    def dispatch_list(self, request, **kwargs):
        self.method_check(request, allowed=['get', 'post'])
        self.is_authenticated(request)
        self.throttle_check(request)

        if 'content_type' in kwargs and 'object_id' in kwargs and request.method=="POST":
            data = json.loads(request.body)
            if 'tag' in data:
                tag_obj, created = Tag.objects.get_or_create(name=data['tag'], slug=slugify(data['tag']))

                params = kwargs.copy()
                del params['resource_name']
                del params['api_name']
                params['tag'] = tag_obj
                params['content_type'] = ContentType.objects.get(model=kwargs['content_type'])

                tagged_item, created = self._meta.queryset.model.objects.get_or_create(**params)

                bundle = self.build_bundle(obj=tagged_item, request=request)
                bundle = self.full_dehydrate(bundle)
                bundle = self.alter_detail_data_to_serialize(request, bundle)

                return self.create_response(request,
                                            bundle,
                                            response_class=http.HttpCreated,
                                            location=self.get_resource_uri(bundle))

        return ModelResource.dispatch_list(self, request, **kwargs)
开发者ID:SimonSarazin,项目名称:dataserver,代码行数:30,代码来源:api.py

示例2: dispatch_list

# 需要导入模块: from tastypie.resources import ModelResource [as 别名]
# 或者: from tastypie.resources.ModelResource import dispatch_list [as 别名]
    def dispatch_list(self, request, **kwargs):
        """ Handle the dispatching of GFKs. """

        self.method_check(request, allowed=["get", "post"])
        self.is_authenticated(request)
        self.throttle_check(request)

        if "content_type" in kwargs and "object_id" in kwargs and request.method == "POST":
            data = json.loads(request.body)

            if "profile_id" in data:
                profile = get_object_or_404(Profile, pk=data["profile_id"])

            else:
                profile = request.user.profile

            objectprofilelink_item, created = ObjectProfileLink.objects.get_or_create(  # NOQA
                profile=profile,
                content_type=ContentType.objects.get(model=kwargs["content_type"]),
                object_id=kwargs["object_id"],
                level=data["level"],
                detail=data["detail"],
                isValidated=data["isValidated"],
            )
            bundle = self.build_bundle(obj=objectprofilelink_item, request=request)
            bundle = self.full_dehydrate(bundle)
            bundle = self.alter_detail_data_to_serialize(request, bundle)

            return self.create_response(
                request, bundle, response_class=http.HttpCreated, location=self.get_resource_uri(bundle)
            )

        return ModelResource.dispatch_list(self, request, **kwargs)
开发者ID:14mmm,项目名称:dataserver,代码行数:35,代码来源:api.py

示例3: dispatch_list

# 需要导入模块: from tastypie.resources import ModelResource [as 别名]
# 或者: from tastypie.resources.ModelResource import dispatch_list [as 别名]
    def dispatch_list(self, request, **kwargs):
        self.method_check(request, allowed=['get', 'post'])
        self.is_authenticated(request)
        self.throttle_check(request)

        if 'content_type' in kwargs and 'object_pk' in kwargs and request.method=="POST":
            data = json.loads(request.body)
            commented_item, created = Comment.objects.get_or_create(comment=data['comment_text'],
                                            user=request.user,
                                            user_name=request.user.username,
                                            content_type=ContentType.objects.get(model=kwargs['content_type']),
                                            object_pk=kwargs['object_pk'],
                                            site_id=settings.SITE_ID,
                                            submit_date=datetime.datetime.now())
            bundle = self.build_bundle(obj=commented_item, request=request)
            bundle = self.full_dehydrate(bundle)
            bundle = self.alter_detail_data_to_serialize(request, bundle)

            return self.create_response(request,
                                        bundle,
                                        response_class=http.HttpCreated,
                                        location=self.get_resource_uri(bundle))

        return ModelResource.dispatch_list(self, request, **kwargs)
开发者ID:14mmm,项目名称:dataserver,代码行数:26,代码来源:api.py


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