本文整理汇总了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)
示例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)
示例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)