def modify(answer_id): menu_id = request.args.get('menu_id', type=int, default=1) answer = Answer.query.get_or_404(answer_id) if g.user != answer.user: flash('수정권한이 없습니다') return redirect( url_for('question.detail', question_id=answer.question.id)) if request.method == 'POST': form = AnswerForm() if form.validate_on_submit(): form.populate_obj(answer) answer.modify_date = datetime.now() db.session.commit() return redirect('{}#answer_{}'.format( url_for('question.detail', question_id=answer.question.id), answer.id)) else: form = AnswerForm(obj=answer) # 메뉴 리스트 menu_list = Menu.query.order_by(Menu.sort_no.asc()) # 메뉴(선택) menu = Menu.query.get_or_404(menu_id) return render_template('answer/answer_form.html', answer=answer, form=form, menu_list=menu_list, menu=menu)
def modify(answer_id): answer = Answer.query.get_or_404(answer_id) # 사용자 글쓴이 일치 확인 if g.user != answer.user: flash('수정권한이 없습니다') return redirect( url_for('question.detail', question_id=answer.question.id)) # POST 방식 if request.method == "POST": form = AnswerForm() if form.validate_on_submit(): # form에 입력된 데이터를 answer에 적용한다. form.populate_obj(answer) answer.modify_date = datetime.now() # 수정일시 저장 db.session.commit() # return redirect(url_for('question.detail', question_id=answer.question.id)) # 답변 수정 후 앵커로 이동하기 위한 redirect 수정 return redirect('{}#answer_{}'.format( url_for('question.detail', question_id=answer.question.id), answer.id)) else: # AnswerForm(obj=answer): 조회한 데이터를 obj 인자로 전달하여 폼을 생성한다. form = AnswerForm(obj=answer) return render_template('answer/answer_form.html', answer=answer, form=form)
def modify(answer_id): answer = Answer.query.get_or_404(answer_id) if g.user != answer.user: flash('수정권한이 없습니다') return redirect(url_for('question.detail', question_id=answer.question.id)) if request.method == "POST": form = AnswerForm() if form.validate_on_submit(): form.populate_obj(answer) answer.updated_at = datetime.now() # 수정일시 저장 db.session.commit() return redirect('{}#answer_{}'.format(url_for('question.detail', question_id=answer.question.id), answer.id)) else: form = AnswerForm(obj=answer) return render_template('answer/answer_form.html', answer=answer, form=form)
def modify(answer_id): answer = Answer.query.get_or_404(answer_id) if g.user != answer.user: flash("수정 권한이 없습니다.") return redirect( url_for("question.detail", question_id=answer.question.id)) if request.method == "POST": form = AnswerForm() if form.validate_on_submit(): form.populate_obj(answer) answer.modify_date = datetime.now() # 수정일시 저장 db.session.commit() return redirect( url_for("question.detail", question_id=answer.question.id)) else: form = AnswerForm(obj=answer) return render_template("answer/answer_form.html", answer=answer, form=form)
def modify(answer_id): answer = Answer.query.get_or_404(answer_id) if g.user != answer.user: flash('수정 권한이 없습니다.') return redirect( url_for('question.detail', question_id=answer.question.id)) if request.method == 'POST': form = AnswerForm() if form.validate_on_submit(): form.populate_obj(answer) answer.modify_date = datetime.now() db.session.commit() return redirect( url_for('question.detail', question_id=answer.question.id)) else: form = AnswerForm(obj=answer) return redirect('{}.#answer_{}'.format( url_for('question.detail', quesiton_id=answer.question.id), answer.id))