Пример #1
0
def edit_answer(question_id, answer_id):
    data_manager.get_question_by_id(question_id)
    if request.method == 'GET':
        answer = data_manager.get_answer_by_id(answer_id)
        return render_template('edit_answer.html', answer=answer)
    data_manager.edit_answer(answer_id, request.form['message'])
    return redirect('/')
Пример #2
0
def edit_answer(answer_id):
    answer = data_manager.find_answer(answer_id)[0]
    if request.method == 'POST':
        message = request.form.get('message')
        image = request.form.get('image')
        data_manager.edit_answer(answer_id, message, image)
        return redirect('/question/' + str(answer['question_id']))
    return render_template('edit_answer.html', answer=answer)
Пример #3
0
def edit_answer(answer_id):
    answer = data_manager.get_answer_by_id(answer_id)
    if request.method == 'GET':
        return render_template('edit_answer.html', answer=answer)

    answer['message'] = request.form['message']
    data_manager.edit_answer(answer)
    return redirect(
        url_for('detail_question', question_id=answer['question_id']))
Пример #4
0
def edit_answer(answer_id):
    if request.method == 'GET':
        answer = data_manager.get_answer(answer_id)
        return render_template('edit-answer.html', answer=answer)

    data_manager.edit_answer(request.form, answer_id)
    question_id = data_manager.get_question_id_from_answer(answer_id)

    return redirect(f'/question/{ question_id }')
Пример #5
0
def route_edit_answer(answer_id=None):
    answer_datas = data_manager.get_answer_datas(answer_id)
    if request.method == 'POST':
        data_manager.edit_answer(request.form['message'], answer_id)
        question_id = answer_datas[0]['question_id']
        return redirect(
            url_for('get_question_and_answer_and_comments_by_id',
                    question_id=question_id))
    return render_template('/edit_answer.html', datas=answer_datas)
Пример #6
0
def edit_answer(answer_id: int, question_id: int):
    text = request.args.get('text')
    if request.method == 'POST':
        edited_answer = request.form.get('edit')
        data_manager.edit_answer(answer_id, edited_answer)
        return redirect(f'/question/{question_id}')
    return render_template('edit_answer.html',
                           answer_id=answer_id,
                           text=text,
                           question_id=question_id)
Пример #7
0
def edit_answer(question_id, answer_id):
    if request.method == "POST":
        question_id = question_id
        answer_id = answer_id
        message = request.form["message"]
        image = request.form["image"]
        data_manager.edit_answer(answer_id, message, image)
        return redirect("/list/question/" + str(question_id))
    answer = data_manager.get_unique_answer(answer_id)
    return render_template("edit_answer.html", answer=answer, answer_id=answer_id, question_id=question_id)
Пример #8
0
def edit_answer(answer_id):
    answer = data_manager.get_table_by_id(answer_id, "answer")

    if request.method == 'POST':
        my_new_data = request.form.to_dict()
        data_manager.edit_answer(my_new_data)

        return redirect('/question/' + str(my_new_data['question_id']))

    return render_template('edit_answer.html', answer=answer)
Пример #9
0
def edit_answer(answer_id):
    if request.method == "GET":
        answer = data_manager.get_answer_by_id(answer_id)
        return render_template('edit_answer.html', answer=answer)

    question_id = data_manager.get_answer_by_id(answer_id)['question_id']
    edited_answer_data = {
        'message': request.form.get('message'),
        'image': request.form.get('image')
    }
    data_manager.edit_answer(answer_id, edited_answer_data)
    return redirect(url_for('display_question', question_id=question_id))
Пример #10
0
def edit_answer(answer_id):
    answers_list = data_manager.get_answers_by_answer_id(answer_id)
    print(answers_list)
    if request.method == 'POST':
        submission_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        message = request.form['message']
        data_manager.edit_answer(answer_id, submission_time, message)
        return redirect(
            url_for('route_question', question_id=answers_list['question_id']))
    return render_template('update_answer.html',
                           answer_id=answer_id,
                           message=answers_list)
Пример #11
0
def edit_answer(answer_id: int):
    answer_data = data_manager.get_answer_by_id(answer_id)
    question_id = data_manager.get_question_id_by_answer_id(answer_id)
    question_id = question_id[0].get('id')
    if request.method == 'POST':
        site_input = [request.form['new-answer']]
        site_input.append(answer_id)
        data_manager.edit_answer(site_input)
        return redirect(
            url_for('show_specific_question', question_id=question_id))
    return render_template('edit_answer.html',
                           answer_data=answer_data,
                           question_id=question_id)
Пример #12
0
def route_answer_edit(answer_id):
    if 'id' not in session:
        return redirect(url_for('route_main'))
    if request.method == "GET":
        answer = data_manager.get_row_from_table('answer', answer_id)
        return render_template("edit_answer.html", answer=answer, answer_id=answer_id)
    if request.method == "POST":
        file = [request.form[item] for item in request.form]
        image = request.files["image"]
        if image.filename != "":
            filename = data_manager.get_name_of_image(image.filename)
            image.save(os.path.join("static", filename))
            file.append(f"/static/{image.filename}")
        data_manager.edit_answer(file, int(answer_id))
        answer = data_manager.get_row_from_table('answer', answer_id)
        return redirect(f"/question/{answer[0]['question_id']}/question")
def route_edit_answer(answer_id):
    if request.method == 'POST':
        answer_to_update = request.form.to_dict()
        question_id = data_manager.get_question_id_for_answer(
            answer_id)['question_id']
        data_manager.edit_answer(answer_to_update)
        return redirect(
            url_for('route_question_detail', question_id=question_id))
    answer = data_manager.get_answer_data(answer_id)
    logged_in = session['user_id']
    owner_id = answer['site_user_id']
    if logged_in == owner_id:
        return render_template('edit_answer.html',
                               answer_id=answer_id,
                               answer=answer)
    else:
        return redirect('https://i.imgflip.com/239qx5.jpg')
Пример #14
0
def answer_edit(answer_id):
    answer = data_manager.get_answer_by_answer_id(answer_id)
    question_id = answer['question_id']
    question = data_manager.get_question_by_question_id(question_id)
    try:
        if request.method == 'GET':
            return render_template('edit-answer.html', answer=answer, question_id=question_id, question=question)
        elif request.method == 'POST':
            submission_time = datetime.now().isoformat(timespec='seconds')
            message = request.form['message']
            image = request.form['image']
            if image == "":
                image = None
            data_manager.edit_answer(submission_time, message, image, answer_id)
            return redirect(f'/question/{question_id}')
    except IndexError:
        abort(404)
Пример #15
0
def update_answer_by_id(answer_id):
    if request.method == 'POST':

        edited_message = request.form['message']
        edited_image = request.form['image']
        submission_time = util.get_timestamp()
        edited_answer = {
            'submission_time': submission_time,
            'message': edited_message,
            'image': edited_image,
            'id': answer_id
        }
        data_manager.edit_answer(edited_answer)

        question_id = request.form['question_id']

        return redirect(
            url_for('display_question_by_id', question_id=question_id))
Пример #16
0
def edit_answer(answer_id):
    answer_user_id = data_manager.get_user_id_by_answer_id(answer_id)
    if session['user_id'] == answer_user_id:
        if request.method == 'POST':
            edited_answer = dict(request.form)
            new_image = save_file(request.files['image_file'])
            edited_answer['image'] = new_image
            edited_answer['id'] = answer_id
            data_manager.edit_answer(edited_answer)

            question_id = data_manager.get_question_id_by_answer_id(answer_id)
            return redirect(url_for('route_question', question_id=question_id))
        question = data_manager.get_question_by_answer_id(answer_id)
        answer_to_edit = data_manager.get_answer_by_answer_id(answer_id)
        return render_template('edit.html',
                               answer_to_edit=answer_to_edit,
                               question=question)
    else:
        return "You don't have permission to edit this answer"
Пример #17
0
def edit_answer(answer_id):
    user_id = session['user_id']['id']
    answer = data_manager.get_answer_to_edit(answer_id)
    if request.method == 'POST':
        if user_id != answer['user_id']:
            return render_template('error.html', error_message='Stop hacking!!!')
        else:
            question_id = data_manager.edit_answer(answer_id, request.form['message'])
            return redirect(url_for('route_show_details', question_id=question_id['question_id']))

    return render_template('edit-answer.html', answer=answer)