def create_comment(request): if request.method == 'POST': comment_text = request.POST.get('comment_text') post_id = request.POST.get('post_id') post = Post.objects.get(pk=post_id) comment_author = SocialUser.objects.get(user=request.user) comment = Comment(author=comment_author, content=comment_text, post=post) comment.save() message = 'Create post successful!' comment_id = comment.id content = comment.content date_created = comment.date_created_formatted date_edited = comment.date_edited author = comment.author.user.socialuser.get_initials comment_like_count = comment.comment_like_count return JsonResponse({'message': message, 'comment_id': comment_id, 'content': content, 'date_created': date_created, 'date_edited': date_edited, 'author': author, 'post_comment_count': post.post_comment_count, 'comment_like_count': comment_like_count}) else: return JsonResponse({'message': "You didn't send with POST method, better luck next time!"})
def create(self, validated_data): try: validated_data['feed'] = Feed.objects.get( id=validated_data['feed']['id'], is_deleted=False) except Rss.DoesNotExist as e: raise exceptions.CustomException( detail=ugettext('Feed does not exist.')) validated_data['user'] = self.context['request'].user comment = Comment(**validated_data) comment.save() return comment
def post(self, request, pk, format=None): comment = request.data.get('comment') author_object = request.data.get('author') author_name = author_object['displayName'] published = request.data.get('published') contentType = request.data.get('contentType') post_object = Post.objects.get(id=pk) new_comment_author = CommentAuthor(id=author_object['id'], host=author_object['host'], displayName=author_name, url=author_object['url'], github=author_object['github']) new_comment_author.save() new_comment = Comment(author=new_comment_author, post_id=post_object, comment=comment, published=published, author_name=author_name, contentType=contentType) new_comment.save() return Response({})
def add_comment(request): if request.method == 'POST': if 'comment' not in request.POST: return HttpResponse(status=400) if 'article' not in request.POST: return HttpResponse(status=400) user = request.user author = user comment = request.POST['comment'] article_pk = int(request.POST['article']) comment_obj = Comment() comment_obj.author = author comment_obj.comment = comment comment_obj.article = News.objects.get(pk=article_pk) comment_obj.save() return HttpResponse(user.first_name + user.last_name, status=200)