def edit_answer(answer_id):
    if request.method == 'GET':
        answer = data_manager.get_answer(answer_id)
        return render_template('edit_answer.html',
                               answer_id=answer_id,
                               answer=answer)
    elif request.method == 'POST':
        answer = data_manager.get_answer(answer_id)
        question_id = answer['question_id']
        edited_answer_message = request.form['message'].replace("'", "''")
        data_manager.update_answer(answer_id, edited_answer_message)
        return redirect(url_for('display_question', question_id=question_id))
Beispiel #2
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 }')
Beispiel #3
0
def search():
    phrase = request.args.get('search_text')
    if phrase == '':
        flash('Insert letters')
        return redirect(request.referrer)
    else:
        search_text = data_manager.search(phrase)
        answers = data_manager.get_answer()
    return render_template('search.html',
                           search_text=search_text,
                           phrase=phrase,
                           answers=answers)
Beispiel #4
0
def show_question(id):
    tags = data_manager.get_all_tags()
    question_t = data_manager.all_question_tag()
    answers = data_manager.get_answer()
    view = data_manager.find_question(id)[0]
    view_no = view.get('view_number', '')
    data_manager.view_question(id, view_no)
    answer_by_question_id = data_manager.find_answer_by_question_id(id)
    question = data_manager.find_question(id)[0]
    comment_id_question = data_manager.get_comments_by_question_id(id)
    tabel_comment = data_manager.get_tabel_comment()
    return render_template('question.html',
                           question=question,
                           answers=answers,
                           answer_by_question_id=answer_by_question_id,
                           comment_id_question=comment_id_question,
                           tabel_comment=tabel_comment,
                           tags=tags,
                           question_t=question_t)
Beispiel #5
0
def edit_answer(answer_id, question_id):
    if session.get('username') is not None:
        answer_user_id = data_manager.find_userid_by_answerid(answer_id)
        if answer_user_id:
            if session['user_id'] == answer_user_id['user_id'] or session['username'] == 'administrator':
                if request.method == "GET":
                    answer = data_manager.get_answer(answer_id)
                    return render_template("edit-answer.html", answer=answer, question_id=question_id)
                elif request.method == "POST":
                    message=request.form['message']
                    data_manager.update_answer(answer_id, message)
                    return redirect(url_for('question_route', id=question_id))
            else:
                flash("You dont have acces", "no_acces")
                return redirect(url_for('question_route', id=question_id))

    else:
        flash('You must login before using features', 'no_user')
        return redirect(url_for('question_route', id=question_id))
def edit_comment(comment_id):
    if request.method == 'GET':
        comment = data_manager.get_comment(comment_id)
        return render_template('edit-comment.html',
                               comment_id=comment_id,
                               comment=comment)
    elif request.method == 'POST':
        comment = data_manager.get_comment(comment_id)
        if comment[0]['question_id']:
            question_id = comment[0]['question_id']
            edited_comment_message = request.form['message'].replace("'", "''")
            data_manager.update_comment(comment_id, edited_comment_message)
            return redirect(
                url_for('display_question', question_id=question_id))
        elif comment[0]['answer_id']:
            answer_id = comment[0]['answer_id']
            edited_comment_message = request.form['message'].replace("'", "''")
            data_manager.update_comment(comment_id, edited_comment_message)
            answer = data_manager.get_answer(answer_id)
            question_id = answer['question_id']
            return redirect(
                url_for('display_question', question_id=question_id))
Beispiel #7
0
def get_answer(answer_id):
    answer = data_manager.get_answer(answer_id)
    return render_template('edit_answer.html', answer=answer)
def answer_vote_down(answer_id):
    data_manager.answer_vote_down(answer_id)
    answer = data_manager.get_answer(answer_id)
    question_id = answer['question_id']
    return redirect(url_for('display_question', question_id=question_id))
def delete_answer(answer_id):
    answer = data_manager.get_answer(answer_id)
    question_id = answer['question_id']
    data_manager.delete_answer(answer_id)
    return redirect(url_for('display_question', question_id=question_id))
Beispiel #10
0
def see_answer_route(answer_id):
    answer=data_manager.get_answer(answer_id)
    answer_comments = data_manager.get_certain_answer_comments(answer_id)
    ans_comm_user_data = data_manager.find_userdata_for_answers_comments(answer_id)
    return render_template("answer-page.html", answer=answer, comments=answer_comments,
                           ans_comm_user_data=ans_comm_user_data)
Beispiel #11
0
def edit_answer(answer_id):
    answer_detail = data_manager.get_answer(answer_id)
    return render_template('edit_answer_form.html', answer_detail=answer_detail)