Ejemplo n.º 1
0
 def create(validated_data):
     comment = Comment(
         name = validated_data['name'],
         email = validated_data['email'],
         likes =0,
         text = validated_data['text'],
         post = validated_data['post']
     )
     comment.save()
     return comment
Ejemplo n.º 2
0
def new_comment(request, id_post):
    if not request.user.is_authenticated():
        return HttpResponse(json.dumps({"error": "You need be logged to comment."}), mimetype="application/json")
    if request.is_ajax():
        if request.method == 'POST':
            post = Post.objects.get_or_none(pk=id_post)  # get_or_none method is on apps.blog.models into GenericManager class
            if post:
                c = Comment(post=post, user=request.user, comment=request.POST.get("comment"))
                c.save()
                response = {"sent": True}
            else:
                response = {"error": "Error, refresh the page"}
        else:
            response = {"error": "Error, the http method is not POST"}
    else:
    	response = {"error": "You are not allowed to be here"}
    return HttpResponse(json.dumps(response), mimetype="application/json")
Ejemplo n.º 3
0
def saveComment(request):
    if request.method == 'POST' and request.user is not None:
        commentObject = Comment()
        commentObject.user = request.user
        commentObject.post_id = request.POST['post_id']
        commentObject.comment = request.POST['comment']
        commentObject.replied_on = request.POST['replyOn']
        commentObject.save()
        response = {
            'message': "Thank you for your valuable comment",
            'code': 200,
            'data': {}
        }
        return HttpResponse(json.dumps(response),
                            content_type="application/json")
    else:
        response = {'message': getApiMsg(201), 'code': 201, 'data': {}}
        return HttpResponse(json.dumps(response),
                            content_type="application/json")
Ejemplo n.º 4
0
async def add_comment(article_id: int, comment: AddCommentItem):
    comment_obj = Comment(detail=comment.detail, img_url=comment.img_url, article_id=article_id)
    session.add(comment_obj)
    session.commit()
    return return_data()