Beispiel #1
0
def edit_question(question_id):
    question = Question.query.get_or_404(question_id)
    if question.author != current_user:
        abort(403)
    form = QuestionForm()
    if form.validate_on_submit():
        question.title = form.title.data
        question.message = form.question.data
        if form.picture.data:
            picture_file = save_picture(form.picture.data, 'upload',
                                        (1024, 720))
            question.image = picture_file
        db.session.commit()
        flash("Question edited", "success")
        return redirect(
            url_for("questions.show_question", question_id=question_id))
    elif request.method == "GET":
        form.title.data = question.title
        form.question.data = question.message
    return render_template("questions/ask_question.html",
                           form=form,
                           title="Edit Question",
                           legend='Edit Your Question',
                           question=question,
                           edit=True)
Beispiel #2
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data, 'profile_pics', (125, 125))
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Account updated!", "success")
        return redirect(url_for("account"))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template("users/account.html", form=form)
Beispiel #3
0
def ask_question():
    form = QuestionForm()
    if form.validate_on_submit():
        question = Question(title=form.title.data,
                            message=form.question.data,
                            author=current_user)
        if form.picture.data:
            question.image = save_picture(form.picture.data, "upload",
                                          (1280, 720))
        db.session.add(question)
        db.session.commit()
        flash("Question asked!", "success")
        return redirect(url_for("questions.list_questions"))
    return render_template("questions/ask_question.html",
                           form=form,
                           title="Ask Question",
                           legend='Ask a Question!',
                           edit=False)
Beispiel #4
0
def post_an_answer(question_id):
    form = \
        AnswerForm()
    if form.validate_on_submit():
        answer = Answer(message=form.answer.data,
                        author=current_user,
                        question_id=question_id)
        if form.picture.data:
            answer.image = save_picture(form.picture.data, "upload",
                                        (1280, 720))
        db.session.add(answer)
        db.session.commit()
        flash("Answer posted!", "success")
        return redirect(
            url_for("questions.show_question", question_id=question_id))
    return render_template("answers/post_an_answer.html",
                           form=form,
                           title="Answer",
                           legend='Answer your mate!',
                           edit=False)
Beispiel #5
0
def edit_answer(answer_id):
    answer = Answer.query.get_or_404(answer_id)
    if answer.author != current_user:
        abort(403)
    form = AnswerForm()
    if form.validate_on_submit():
        answer.message = form.answer.data
        if form.picture.data:
            picture_file = save_picture(form.picture.data, 'upload',
                                        (1024, 720))
            answer.image = picture_file
        db.session.commit()
        flash("Answer edited", "success")
        return redirect(
            url_for("questions.show_question", question_id=answer.question_id))
    elif request.method == "GET":
        form.answer.data = answer.message
    return render_template("answers/post_an_answer.html",
                           form=form,
                           title="Edit Answer",
                           legend='Edit Answer',
                           answer=answer,
                           edit=True)