Example #1
0
def create_question(question_id):
    form = CommentForm()
    question = Question.query.get_or_404(question_id)
    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment(user=g.user,
                          content=form.content.data,
                          create_date=datetime.now(),
                          question=question)
        db.session.add(comment)
        db.session.commit()
        return redirect('{}#comment_{}'.format(
            url_for('question.detail', question_id=question_id), comment.id))
    return render_template('comment/comment_form.html', form=form)
Example #2
0
def create_answer(answer_id):
    form = CommentForm()
    answer = Answer.query.get_or_404(answer_id)
    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment(user=g.user, content=form.content.data, create_date=datetime.now(), answer=answer)
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('question.detail', question_id=answer.question.id))
    # 메뉴 리스트
    menu_list = Menu.query.order_by(Menu.sort_no.asc())
    # 메뉴(선택)
    menu = Menu.query.get_or_404(answer.question.menu_id)
    return render_template('comment/comment_form.html', form=form, menu_list=menu_list, menu=menu)
Example #3
0
def create_answer(answer_id):
    form = CommentForm()
    answer = Answer.query.get_or_404(answer_id)
    if request.method == 'POST' and form.validate_on_submit():
        comment = Comment(user=g.user,
                          content=form.content.data,
                          create_date=datetime.now(),
                          answer=answer)
        db.session.add(comment)
        db.session.commit()
        return redirect(
            url_for('question.detail', question_id=answer.question.id))
    return render_template('comment/comment_form.html', form=form)
Example #4
0
def create_question(question_id):
    form = CommentForm()
    question = Question.query.get_or_404(question_id)
    if request.method == "POST" and form.validate_on_submit():
        comment = Comment(
            user=g.user,
            content=form.content.data,
            create_date=datetime.now(),
            question=question,
        )
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for("question.detail", question_id=question_id))
    return render_template("comment/comment_form.html", form=form)
Example #5
0
def modify_answer(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    if g.user != comment.user:
        flash('수정권한이 없습니다.')
        return redirect(url_for('question.detail', question_id=comment.answer.id))
    if request.method == 'POST':
        form = CommentForm()
        if form.validate_on_submit():
            form.populate_obj(comment)
            comment.modify_date = datetime.now()
            db.session.commit()
            return redirect('{}#comment_{}'.format(url_for('question.detail', question_id=comment.answer.question.id), comment.id))
    else:
        form = CommentForm(obj=comment)
    return render_template('comment/comment_form.html', form=form)
Example #6
0
def modify_question(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    if g.user != comment.user:
        flash("수정 권한이 없습니다.")
        return redirect(
            url_for("question.detail", question_id=comment.question.id))
    if request.method == "POST":
        form = CommentForm()
        if form.validate_on_submit():
            form.populate_obj(comment)
            comment.modify_date = datetime.now()  # 수정일시 저장
            db.session.commit()
            return redirect(
                url_for("question.detail", question_id=comment.question.id))
    else:
        form = CommentForm(obj=comment)
    return render_template("comment/comment_form.html", form=form)
Example #7
0
def modify_answer(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    if g.user != comment.user:
        flash('수정권한이 없습니다')
        return redirect(url_for('question.detail', question_id=comment.answer.id))
    if request.method == 'POST':
        form = CommentForm()
        if form.validate_on_submit():
            form.populate_obj(comment)
            comment.modify_date = datetime.now()  # 수정일시 저장
            db.session.commit()
            return redirect(url_for('question.detail', question_id=comment.answer.question.id))
    else:
        form = CommentForm(obj=comment)
    # 메뉴 리스트
    menu_list = Menu.query.order_by(Menu.sort_no.asc())
    # 메뉴(선택)
    menu = Menu.query.get_or_404(comment.answer.question.menu_id)
    return render_template('comment/comment_form.html', form=form, menu_list=menu_list, menu=menu)
Example #8
0
def create_answer(answer_id, x):
    if x == 0:
        answer_0 = Answer
        comment_0 = Comment
        xx = 'question.detail'
    elif x == 1:
        answer_0 = Answer1
        comment_0 = Comment1
        xx = 'question.detail1'

    form = CommentForm()
    answer = answer_0.query.get_or_404(answer_id)
    if request.method == 'POST' and form.validate_on_submit():
        comment = comment_0(user=g.user,
                            content=form.content.data,
                            create_date=datetime.now(),
                            answer=answer)
        db.session.add(comment)
        db.session.commit()
        return redirect('{}#comment_{}'.format(
            url_for(xx, question_id=answer.question.id), comment.id))
    return render_template('comment/comment_form.html', form=form)
Example #9
0
def modify_question(comment_id, x):
    if x == 0:
        comment_0 = Comment
        xx = 'question.detail'
    elif x == 1:
        comment_0 = Comment1
        xx = 'question.detail1'
    comment = comment_0.query.get_or_404(comment_id)
    if g.user != comment.user:
        flash('수정권한이 없습니다')
        return redirect(url_for(xx, question_id=comment.question.id))
    if request.method == 'POST':
        form = CommentForm()
        if form.validate_on_submit():
            form.populate_obj(comment)
            comment.modify_date = datetime.now()  # 수정일시 저장
            db.session.commit()
            return redirect('{}#comment_{}'.format(
                url_for(xx, question_id=comment.question.id), comment.id))
    else:
        form = CommentForm(obj=comment)
    return render_template('comment/comment_form.html', form=form)