예제 #1
0
def route_add_answer(question_id):
    question = data_handler.get_data_by_question_id('question', question_id)[0]

    if request.method == "POST":

        message = request.form['message']
        image = request.form['image']
        if image == "":
            image = None

        data_handler.add_answer(question_id, message, image)
        return redirect(f"/question/{question_id}")

    return render_template("new-answer.html", question=question)
예제 #2
0
def route_add_answer(question_id):
    if request.method == 'GET':
        question = data_handler.get_data_by_question_id(
            'question', question_id)[0]
        return render_template("new-answer.html",
                               question=question,
                               username=session['username'])

    message = request.form['message']
    image = request.form['image']
    if image == "":
        image = None
    username = session['username']

    data_handler.add_answer(question_id, message, image, username)
    return redirect(f"/question/{question_id}")
예제 #3
0
def route_new_answer(question_id):
    if request.method == 'POST':
        comment = {'message': request.form.get('message'),
                   'submission_time': request.form.get('submission_time'),
                   'vote_number': request.form.get('vote_number'),
                   'image': request.form.get('image'),
                   'question_id': request.form.get('question_id')}
        data_handler.add_answer(comment, question_id)
        return redirect(f'/question/{question_id}')

    return render_template("add_question.html",
                           type='answer',
                           comment_name='Add new answer',
                           form_url=url_for('route_new_answer', question_id=question_id),
                           comment_message='Answer message',
                           question_id=question_id,
                           timestamp=data_handler.date_time_in_timestamp())
예제 #4
0
def question(question_id):
    comments = data_handler.get_comments()
    question_username = data_handler.get_question_user(question_id)

    if request.method == 'POST':
        user_answer = {
            'submission_time': util.get_current_time(),
            'vote_number': 0,
            'question_id': question_id,
            'message': request.form['answer_message'],
            'image': None,
            'user_id': session.get('id')
        }
        data_handler.add_answer(user_answer)
        return redirect(request.url)
    data_handler.view_counter(question_id)
    question = data_handler.get_selected_question(question_id)
    answers = data_handler.get_answers_for_question(question_id)
    return render_template('question.html', question=question, answers=answers, comments=comments,
                           question_username=question_username)
예제 #5
0
def add_new_answer(question_id):
    if request.method == 'POST':
        data_handler.add_answer(question_id, request, send_from_directory, app, session)
        return redirect(url_for('show_answers', question_id=question_id))
    question_data = data_handler.get_one_question(question_id)
    return render_template('answer/create.html', question=question_data, username=session['username'])