예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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})