def comment_edit(comment_id): comment = Comment.query.get(comment_id) if current_user.id != comment.author_id: return redirect("/") if not comment: return redirect("/") # If the script this comment belongs to doesn't exist, delete it. s = Script.query.get(comment.script_id) if not s: db.session().delete(comment) db.session().commit() form = CommentForm(request.form) if not form.validate(): return render_template("comments/edit.html", comment=comment, current_user=current_user, commentForm=form) comment.title = request.form.get("title") comment.content = request.form.get("content") db.session().commit() return redirect(url_for("comment_show", comment_id=comment.id))
def comments_conversation(id): post = Post.query.get(id) if not post: return redirect(url_for("oops", error="Post not found")) if request.method == "GET": return render_template("comments/conversation.html", post=post, form=CommentForm(), **request.args) form = CommentForm(request.form) if not form.validate(): return render_template("comments/conversation.html", post=post, form=form, **request.args) content = re.sub(r"^\s+", "", form.content.data, flags=re.MULTILINE).strip() comment = Comment(content, owner_id=current_user.id, post_id=id) db.session().add(comment) db.session().commit() return redirect( url_for("comments_conversation", id=id, back=request.args.get("back"), back_id=request.args.get("back_id")))
def update_comment(PostId): comment = Comment.query.get(request.form.get("comment_to_update")) if not current_user.id == comment.account.id: p = Post.query.get(PostId) return render_template( "comments/comments.html", PostName=p.postName, Comments=p.comments, PostID=p.id, form=CommentForm(), error="You are trying to edit a comment you did not make!") form = CommentForm(request.form) if not form.validate(): return render_template("comments/updateCommentForm.html", PostId=PostId, CommentId=request.form.get("comment_to_update"), form=form) comment.commentContent = form.comment.data db.session().commit() return redirect(url_for("show_comments", PostId=PostId))
def comments_edit(post_id, comment_id): if request.method == 'GET': return redirect( f'{url_for("posts_details", post_id=post_id)}#{comment_id or ""}') comment = Comment.query.get(comment_id) if (comment.account_id != current_user.id or comment.deleted): return redirect(url_for('posts_details', post_id=post_id)) form = CommentForm(request.form) if not form.validate(): return redirect(url_for('posts_details', post_id=post_id)) parent = Comment.query.get(comment_id) if comment_id else None if parent and not str(parent.post_id) == post_id: return redirect(url_for('posts_details', post_id=post_id)) with session_scope() as session: comment.content = form.content.data session.commit() return redirect( f'{url_for("posts_details", post_id=post_id)}#{comment.id}')
def comments_create(post_id, comment_id): if request.method == 'GET': return redirect( f'{url_for("posts_details", post_id=post_id)}#{comment_id or ""}') form = CommentForm(request.form) if not form.validate(): return redirect(url_for('posts_details', post_id=post_id)) parent = Comment.query.get(comment_id) if comment_id else None if parent and (str(parent.post_id) != post_id or parent.deleted): return redirect(url_for('posts_details', post_id=post_id)) comment = Comment(form.content.data) comment.account_id = current_user.id comment.post_id = post_id comment.parent_id = comment_id with session_scope() as session: session.add(comment) session.commit() return redirect( f'{url_for("posts_details", post_id=post_id)}#{comment.id}')
def comments_edit(comment_id): comment = Comment.query.get(comment_id) if not comment.owner_id == current_user.id: return redirect(url_for("oops", error="Not authorized")) if request.method == "GET": return render_template("comments/edit.html", comment_id=comment_id, form=CommentForm( MultiDict({"content": comment.content})), redir=request.args.get("redir"), redir_id=request.args.get("redir_id")) form = CommentForm(request.form) if not form.validate(): return render_template("comments/edit.html", comment_id=comment_id, form=form, redir=request.args.get("redir"), redir_id=request.args.get("redir_id")) comment.content = form.content.data db.session().commit() return try_redirect("comments_conversation", id=comment.post_id)
def comments_create(submission_id): form = CommentForm(request.form) if form.validate(): comment = Comment(form.text.data) comment.account_id = current_user.id comment.submission_id = submission_id db.session().add(comment) db.session().commit() return redirect(url_for('submissions_view', submission_id=submission_id))
def send_comment(event_id): form = CommentForm(request.form) event = Event.query.get(event_id) if form.validate(): comment = Comment(form.content.data, event.id, current_user.id) db.session().add(comment) db.session().commit() return redirect(url_for('event_show', event_id=event.id))
def comment_edit_post(comment_id): comment = Comment.query.get(comment_id) if(current_user.id != comment.user_id): return threadviews.threads_index() form = CommentForm(request.form) if not form.validate(): return render_template("comments/editcomment.html", comment = comment, form = form) comment.comment_text = form.comment.data db.session().commit() return threadviews.threads_open(comment.thread_id)
def comment_create(recipe_id): form = CommentForm(request.form) if not form.validate(): return render_template("recipes/<recipe_id>/", form=form) c = Comment(form.text.data) c.account_id = current_user.id c.recipe_id = recipe_id db.session().add(c) db.session().commit() return redirect(url_for("recipes/<recipe_id>/"))
def comment_edit(post_id, comment_id): form = CommentForm(request.form) if not form.validate(): return render_template("/posts/post.html", form=PostForm(), post=Post.query.get(post_id), commentform=form) c = Comment.query.get(comment_id) if c.account_id == current_user.id: c.content = form.comment.data db.session().commit() return redirect(url_for('post_specific', post_id=post_id))
def comment_create(recipe_id): form = CommentForm(request.form) if not form.validate(): return redirect(url_for('recipe_get', recipe_id=recipe_id)) c = Comment(form.text.data) c.account_id = current_user.id c.recipe_id = recipe_id db.session().add(c) db.session().commit() return redirect(url_for('recipe_get', recipe_id=recipe_id))
def comment_create(script_id): if not validate_script_id(script_id): return redirect(url_for("script_list")) form = CommentForm(request.form) if not form.validate(): return redirect(url_for("script_show", script_id=script_id)) c = Comment(form.title.data, form.content.data, current_user.id, script_id) db.session().add(c) db.session().commit() return redirect(url_for("script_show", script_id=script_id))
def conversation_view(conversation_id): form = CommentForm(request.form) if not form.validate(): return render_template( "conversations/viewOne.html", t=Conversation.query.get(conversation_id), form=form, conversation_comments=Conversation.find_comments_for_conversation( conversation_id)) return render_template( "conversations/viewOne.html", t=Conversation.query.get(conversation_id), form=form, conversation_comments=Conversation.find_comments_for_conversation( conversation_id))
def comments_create(): form = CommentForm(request.form) threadi = Thread.query.get(form.thread_id.data) if not form.validate(): return redirect(url_for("show_thread", thread_id=threadi.id)) comm = Comment(form.message.data) comm.account_id = current_user.id comm.thread_id = form.thread_id.data db.session().add(comm) db.session().commit() return redirect(url_for("show_thread", thread_id=threadi.id))
def comment_post(thread_id): form = CommentForm(request.form) if not form.validate(): thread = Thread.query.get(thread_id) comments = thread.comments return render_template("threads/showthread.html", form = form, comments = comments, thread = thread, user = thread.user) comment = Comment(form.comment.data) comment.thread_id = thread_id comment.user_id = current_user.id db.session().add(comment) db.session().commit() return threadviews.threads_open(thread_id)
def new_comment(post_id): form = CommentForm(request.form) if not form.validate(): return render_template("/posts/post.html", form=PostForm(), post=Post.query.get(post_id), commentform=form) c = Comment(form.comment.data) c.account_id = current_user.id c.post_id = post_id db.session.add(c) db.session.commit() return redirect(url_for('post_specific', post_id=post_id))
def comment_create(recipe_id): form = CommentForm(request.form) recipe = Recipe.query.get(recipe_id) if not form.validate(): return render_template("comments/new_comment.html", form=form, recipe_id=recipe.id) comment = Comment(form.comment_text.data) comment.account_id = current_user.id comment.recipe_id = recipe.id db.session().add(comment) db.session().commit() return redirect(url_for("recipes_show_single", recipe_id=recipe.id))
def comments_create(matchID): form = CommentForm(request.form) if not form.validate(): return render_template( "comments/list.html", form=form, matches=Match.query.filter_by(id=matchID), comments=Comment.query.filter_by(matchid=matchID)) c = Comment(form.content.data, matchID) c.account_id = current_user.id c.name = current_user.username db.session().add(c) db.session().commit() return render_template("comments/list.html", form=form, matches=Match.query.filter_by(id=matchID), comments=Comment.query.filter_by(matchid=matchID))
def comment_update(comment_id): commentToUpdate = Comment.query.filter_by(id=comment_id).first() recipe_id = commentToUpdate.recipe_id if commentToUpdate.account_id != current_user.id: return login_manager.unauthorized() form = CommentForm(request.form) if not form.validate(): return render_template("recipes/commentedit.html", form=form) form = CommentForm(request.form) commentToUpdate.text = form.text.data db.session().add(commentToUpdate) db.session().commit() return redirect(url_for('recipe_get', recipe_id=recipe_id))
def create_comment(PostId): form = CommentForm(request.form) if not form.validate(): p = Post.query.get(PostId) return render_template("comments/comments.html", PostName=p.postName, Comments=p.comments, PostID=p.id, form=form) newComment = Comment(form.comment.data) newComment.postId = PostId newComment.accountId = current_user.id db.session().add(newComment) db.session().commit() return redirect(url_for("show_comments", PostId=PostId))
def comments_create(conversation_id): form = CommentForm(request.form) if not form.validate(): return render_template( "conversations/viewOne.html", t=Conversation.query.get(conversation_id), form=form, conversation_comments=Conversation.find_comments_for_conversation( conversation_id), error= "Kommentin pituus tulee olla vähintään 1 merkki ja korkeintaan 512 merkkiä." ) t = Comment(form.name.data) t.account_id = current_user.id t.conversation_id = conversation_id db.session().add(t) db.session().commit() return redirect( url_for("conversation_view", conversation_id=conversation_id))
def comment_update(comment_id): if request.method == 'GET': return render_template("comments/update.html", form=CommentForm(request.form), comment_id=comment_id, t=Comment.query.get(comment_id)) form = CommentForm(request.form) if not form.validate(): return render_template("comments/update.html", form=form, comment_id=comment_id, t=Comment.query.get(comment_id)) d = Comment(form.name.data) c = Comment.query.get(comment_id) if current_user.id != c.account_id: return render_template("comments/list.html", comments=Comment.query.all()) uusiNimi = d.name c.name = uusiNimi db.session().commit() return redirect( url_for("conversation_view", conversation_id=c.conversation_id))