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)
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 '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(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)
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)
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)