コード例 #1
0
ファイル: answer_views.py プロジェクト: dhfmepd/flask-pybo
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)
コード例 #2
0
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)
コード例 #3
0
def create(question_id):
    # question 객체 조회
    question = Question.query.get_or_404(question_id)

    # answer form
    form = AnswerForm()
    if form.validate_on_submit():
        # request: 브라우저에서 요청한 데이터를 확인할 수 있는 객체
        # form 형식으로 전달된 데이터 중 항목명이 'content' 인 데이터
        content = request.form['content']

        # 질문에 달릴 답변 객체 생성
        # user 필드 반영 - g.user
        answer = Answer(content=content,
                        create_date=datetime.now(),
                        user=g.user)
        question.answer_set.append(answer)
        db.session.commit()

        # return redirect(url_for('question.detail', question_id=question_id))

        # 답변 생성 후 앵커로 이동하기 위한 redirect 수정
        return redirect('{}#answer_{}'.format(
            url_for('question.detail', question_id=question_id), answer.id))

    return render_template('question/question_detail.html',
                           question=question,
                           form=form)
コード例 #4
0
ファイル: answer_views.py プロジェクト: anifilm/webapp
def create(question_id):
    form = AnswerForm()
    question = Question.query.get_or_404(question_id)
    if form.validate_on_submit():
        content = request.form["content"]
        answer = Answer(content=content, create_date=datetime.now())
        question.answer_set.append(answer)
        db.session.commit()
        return redirect(url_for("question.detail", question_id=question_id))
    return render_template("question/question_detail.html",
                           question=question,
                           form=form)
コード例 #5
0
def detail(question_id):
    form = AnswerForm()
    question = Question.query.get_or_404(question_id)
    if form.validate_on_submit():
        content = request.form['content']
        # --------------------------------- [edit] ---------------------------------- #
        answer = Answer(content=content, create_date=datetime.now(), user=g.user)
        # --------------------------------------------------------------------------- #
        question.answer_set.append(answer)
        db.session.commit()
        return redirect(url_for('question.detail', question_id=question_id))
    return render_template('question/question_detail.html', question=question, form=form)
コード例 #6
0
ファイル: answer_views.py プロジェクト: hanho5120/Pybore
def create(question_id):
    form = AnswerForm()
    question = Question.query.get_or_404(question_id)

    if form.validate_on_submit():
        content = request.form['content']
        answer = Answer(question = question, content=content,create_date=datetime.now())
        db.session.add(answer)
        db.session.commit()
        return redirect(url_for('question.detail',question_id=question_id))

    return render_template('question/detail.html',question=question,form=form)
コード例 #7
0
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)
コード例 #8
0
ファイル: answer_views.py プロジェクト: anifilm/webapp
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)
コード例 #9
0
def create(question_id):
    form = AnswerForm()
    question = Question.query.get_or_404(question_id)

    # 입력값이 존재할 경우
    if form.validate_on_submit():
        content = request.form['content']  # request : form 에서 전달된 객체
        answer = Answer(content=content,
                        create_date=datetime.now(),
                        user=g.user)
        question.answer_set.append(answer)
        db.session.commit()
        return redirect('{}#answer_{}'.format(
            url_for('question.detail', question_id=question_id), answer.id))

    # 입력값이 존재하지 않을 경우
    return render_template('question/question_detail.html',
                           question=question,
                           form=form)
コード例 #10
0
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))
コード例 #11
0
ファイル: answer_views.py プロジェクト: hyo250/pybo
def create(question_id):  #()안에 인자값 필수. 몇번에 대한 답인지를 표시해야. int뒤의 것과 동일.
    #form.py 수정 후
    form = AnswerForm()
    question = Question.query.get_or_404(question_id)

    if form.validate_on_submit():  #form에 오류없으면 아래 코드실행해서 등록시켜라.
        #print(request)

        content = request.form['content']
        #answer=Answer(content=content, create_date=datetime.now())
        #방법1)
        # question.answer_set.append(answer)
        # db.session.commit()
        #방법2)
        answer = Answer(question=question,
                        content=content,
                        create_date=datetime.now())
        db.session.add(answer)
        db.session.commit()

        return redirect(url_for('question.detail', question_id=question_id))
    return render_template('question/detail.html',
                           question=question,
                           form=form)  #form에 문제있으면 다시 질문페이지가 뜨게 해라 .