本文整理匯總了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)