예제 #1
0
파일: comments.py 프로젝트: Ryuno-Ki/dyapos
def comment(request):    
	"""Post a comment on a presentation"""

	if request.method == "POST":
		form = CommentForm(request.POST)
		if form.is_valid():
			presentation_id = form.cleaned_data["presentation_id"]
			comment = form.cleaned_data["comment"]
			user_id = request.user.id  #get the ID of the user that posted the comment
			c = Comment(user_id=user_id,
						presentation_id=presentation_id,
						comment=comment,
						)
			c.save()

	#Reload the same page
	return HttpResponseRedirect(request.META["HTTP_REFERER"])
예제 #2
0
 def comment(self, db, board):
   from main.models.comment import Comment
   comment = Comment(
       board_id=board.id,
       content="example comment content"
   )
   db.session.add(comment)
   db.session.commit()
   yield comment
   db.session.delete(comment)
   db.session.commit()
예제 #3
0
def post_comment(request):
    if request.method == 'POST':
        comment = Comment()
        comment.author = request.user
        comment.parent_post = Post.objects.filter(id=request.POST.get("post-id", "")).first()
        comment.comment_content = request.POST.get("comment-text", "")
        comment.save()
        return HttpResponseRedirect("/posts/?id=" + request.POST.get("post-id", ""))
    else:
        return posts(request)
예제 #4
0
def comment(request, id):
    """Post a comment on a presentation
	Args:
		id (int): Presesentation ID
	"""

    if request.method == "POST":
        try:
            presentation = Presentation.objects.get(pk=id)
            form = CommentForm(request.POST)
            if form.is_valid():
                comment = Comment(user_id=request.user.id,
                                  presentation_id=presentation.id,
                                  comment=form.cleaned_data["comment"]).save()
        except ObjectDoesNotExist:
            pass

    return HttpResponseRedirect(request.META["HTTP_REFERER"])
예제 #5
0
def get_board_info(board):
    comment_list = Comment.get_list(board.id)
    return {"board_info": board.as_dict(), "comment_list": comment_list}
예제 #6
0
def delete_comment(board, comment_id):
    comment = Comment.get(comment_id, board.id)
    if not comment:
        return ERROR_COMMENT_NOT_FOUND.get_response()
    Comment.delete(comment)
    return SUCCESS_DELETE_COMMENT.get_response()
예제 #7
0
def update_comment(board, comment_id, content):
    comment = Comment.get(comment_id, board.id)
    if not comment:
        return ERROR_COMMENT_NOT_FOUND.get_response()
    comment.update(content)
    return SUCCESS_UPDATE_COMMENT.get_response()
예제 #8
0
def get_comment_info(board, comment_id):
    comment = Comment.get(comment_id, board.id)
    if not comment:
        return ERROR_COMMENT_NOT_FOUND.get_response()

    return {"comment_info": comment.as_dict()}
예제 #9
0
def create_comment(board, content):
    Comment.insert(board_id=board.id, content=content)
    return SUCCESS_CREATE_COMMENT.get_response()