예제 #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(url_for('question.detail', question_id=question_id))
    return render_template('comment/comment_form.html', form=form)
예제 #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('{}#comment_{}'.format(url_for('question.detail', question_id=answer.question.id), comment.id))
    return render_template('comment/comment_form.html', form=form)
예제 #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))
    # 메뉴 리스트
    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)
예제 #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("{}#comment_{}".format(
            url_for("question.detail", question_id=question_id), comment.id))
    return render_template("comment/comment_form.html", form=form)
예제 #5
0
def create_question(question_id, x):
    if x == 0:
        question_0 = Question
        comment_0 = Comment
        xx = 'question.detail'
    elif x == 1:
        question_0 = Question1
        comment_0 = Comment1
        xx = 'question.detail1'
    form = CommentForm()
    question = question_0.query.get_or_404(question_id)
    if request.method == 'POST' and form.validate_on_submit():
        comment = comment_0(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(xx, question_id=question_id), comment.id))
    return render_template('comment/comment_form.html', form=form)
예제 #6
0
def modify_answer(comment_id):
    comment = Comment.query.get_or_404(comment_id)
    form = CommentForm()
    if g.user != comment.user:
        flash('수정권한이 없습니다')
        return redirect(
            url_for('question.detail', question_id=comment.answer.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.answer.question.id))
            return redirect('{}#comment_{}'.format(
                url_for('question.detail', question_id=comment.question.id),
                comment.id))
        else:
            form = CommentForm(obj=comment)
    return render_template('comment/comment_form.html', form=form)
예제 #7
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)
예제 #8
0
def comment_create_answer(request, answer_id):
    answer = get_object_or_404(Answer, pk=answer_id)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.create_date = timezone.now()
            comment.answer = answer
            comment.save()
            return redirect('pybo:detail', question_id=comment.answer.question.id)
    else:
        form = CommentForm()
    context = {'form': form}
    return render(request, 'pybo/comment_form.html', context)
예제 #9
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)
예제 #10
0
def comment_create_question(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.create_date = timezone.now()
            comment.question = question
            comment.save()
            # return redirect('pybo:detail', question_id=question.id)
            return redirect(
                f'{resolve_url("pybo:detail", question_id=comment.question.id)}#comment_{comment.id}'
            )
    else:
        form = CommentForm()
    context = {'form': form}
    return render(request, 'pybo/comment_form.html', context)
예제 #11
0
def comment_modify_answer(request, comment_id):
    comment = get_object_or_404(Comment, pk=comment_id)
    if request.user != comment.author:
        messages.error(request, '댓글 수정 권한이 없습니다')
        return redirect('pybo:detail', question_id=comment.answer.question.id)

    if request.method == "POST":
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.modify_date = timezone.now()
            comment.save()
            return redirect('pybo:detail', question_id=comment.answer.question.id)
    else:
        form = CommentForm(instance=comment)
    context = {'form': form}
    return render(request, 'pybo/comment_form.html', context)
예제 #12
0
def comment_create_question(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    if request.user != question.author:
        messages.error(request, '생성 권한이 없습니다.')

    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.create_date = timezone.now()
            comment.question = question
            comment.save()
            return redirect('pybo:detail', question_id=question.id)
    else:
        form = CommentForm()
    context = {'form': form}
    return render(request, 'pybo/comment_form.html', context)
예제 #13
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)
예제 #14
0
def comment_modify_question(request, comment_id):
    """
    Comment Edit
    """
    comment = get_object_or_404(Comment, pk=comment_id)
    if request.user != comment.author:
        messages.error(request, 'No Permission')
        return redirect('pybo:detail', question_id=comment.question.id)

    if request.method == "POST":
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.modify_date = timezone.now()
            comment.save()
            return redirect('{}#comment_{}'.format(
                resolve_url('pybo:detail', question_id=comment.question.id),
                comment.id))
    else:
        form = CommentForm(instance=comment)
    context = {'form': form}
    return render(request, 'pybo/comment_form.html', context)