def hcomment_create(humor_id): if g.user_name == None: flash(u'로그인 후 이용해 주세요.', 'danger') return redirect(url_for('log_in')) else: form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): # comment = Comment( # author=form.author.data, # email=form.email.data, # content=form.content.data, # password=form.password.data, # article_id=article_id # ) comment = HumorComment(author=g.user_name, email=form.email.data, content=form.content.data, password=form.password.data, humor=Humor.query.get(humor_id)) db.session.add(comment) db.session.commit() flash(u'댓글을 작성하였습니다.', 'success') return redirect(url_for('humor_detail', id=humor_id)) return render_template('hcomment/create.html', form=form)
def comment_create(article_id): form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): # comment = Comment( # author=form.author.data, # email=form.email.data, # content=form.content.data, # password=form.password.data, # article_id=article_id # ) comment = Comment( author=form.author.data, email=form.email.data, content=form.content.data, password=form.password.data, article=Article.query.get(article_id) ) db.session.add(comment) db.session.commit() flash(u'댓글을 작성하였습니다.', 'success') return redirect(url_for('article_detail', id=article_id)) return render_template('comment/create.html', form=form)
def fcomment_create(faq_id): if g.user_name == None: flash(u'로그인 후 이용해 주세요.', 'danger') return redirect(url_for('log_in')) else: form = CommentForm() if request.method == 'POST': if form.validate_on_submit(): # comment = Comment( # author=form.author.data, # email=form.email.data, # content=form.content.data, # password=form.password.data, # article_id=article_id # ) comment = FAQComment( author=g.user_name, email=form.email.data, content=form.content.data, password=form.password.data, faq=FAQ.query.get(faq_id) ) db.session.add(comment) db.session.commit() flash(u'댓글을 작성하였습니다.', 'success') return redirect(url_for('faq_detail', id=faq_id)) return render_template('fcomment/create.html', form=form)
def comment_create(article_id): form = CommentForm() if request.method == "POST": if form.validate_on_submit(): comment = Comment(author=form.author.data, email=form.email.data, content=form.content.data, password=form.password.data, article_id=article_id) db.session.add(comment) db.session.commit() flash(u'댓글을 작성하였습니다', 'success') return redirect(url_for('article_detail', id=article_id)) return render_template('comment/create.html', form=form)
def comment_update(comment_id): comment = Comment.query.get(comment_id) form = CommentForm(request.form, obj=comment) article_id = comment.article_id if request.method == 'POST': password = request.form['password'] if form.validate_on_submit(): if password == comment.password: form.populate_obj(comment) db.session.commit() flash(u'댓글을 수정하였습니다.', 'success') return redirect(url_for('article_detail', article_id=article_id)) else: flash(u'올바른 비밀번호를 입력해주세요.', 'danger') return redirect(url_for('article_detail', article_id=article_id)) return render_template('comment/update.html', form=form)
def add_comment_to_post(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == 'POST': form = CommentForm(data=request.POST) if form.is_valid(): comment = form.save(commit=False) comment.post = post comment.save() return redirect('post_detail', pk=post.pk) else: form = CommentForm() return render(request, 'apps/comment_form.html', {'form': form})