def create_question(question_id): form = CommentForm() question = Question.query.get_or_404(question_id) if request.method == 'POST': form = CommentForm() 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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)