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"])
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()
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)
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"])
def get_board_info(board): comment_list = Comment.get_list(board.id) return {"board_info": board.as_dict(), "comment_list": comment_list}
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()
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()
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()}
def create_comment(board, content): Comment.insert(board_id=board.id, content=content) return SUCCESS_CREATE_COMMENT.get_response()