def ask_question():

    # Displays a page with a form to be filled with the new question

    question = logic.QSTN_DEFAULTS
    mates = logic.get_users_ids()

    return render_template('q_form.html',
                           form_type="new",
                           question=question,
                           mates=mates)
def edit_answer_comment(answ_id):

    cmnt_id = request.form['id']
    answer = logic.get_answer(answ_id)
    comment = logic.get_comment(cmnt_id)
    if answer is None or comment is None:
        abort(404)
    mates = logic.get_users_ids()

    return render_template('cmnt_a_form.html',
                           form_type='edit',
                           comment=comment,
                           answer=answer,
                           mates=mates)
def edit_question_comment(qstn_id):

    cmnt_id = request.form['id']
    question = logic.get_question(qstn_id)
    comment = logic.get_comment(cmnt_id)
    if question is None or comment is None:
        abort(404)
    mates = logic.get_users_ids()

    return render_template('cmnt_q_form.html',
                           form_type='edit',
                           comment=comment,
                           question=question,
                           mates=mates)
def edit_question():

    # Receive form request with the question id and send request to logic
    # to retrive question data.
    # Display a page with the form filled with the question existing data

    qstn_id = int(request.form['id'])
    question = logic.get_question(qstn_id)
    mates = logic.get_users_ids()

    return render_template('q_form.html',
                           form_type="edit",
                           question=question,
                           mates=mates)
def post_answer(qstn_id):

    # Displays a page with a question and a form to be filled with
    # the new answer

    question = logic.get_question(qstn_id)
    if question is None:
        abort(404)
    answer = logic.ANSW_DEFAULTS
    mates = logic.get_users_ids()

    return render_template('ans_form.html',
                           form_type='new',
                           answer=answer,
                           question=question,
                           mates=mates)
def post_comment_to_answer(answ_id):

    # Displays a page with a question and form to be filled with
    # the new comment

    answer = logic.get_answer(answ_id)
    if answer is None:
        abort(404)
    comment = logic.CMNT_DEFAULTS
    mates = logic.get_users_ids()

    return render_template('cmnt_a_form.html',
                           form_type='new',
                           comment=comment,
                           answer=answer,
                           mates=mates)
def post_comment_to_question(qstn_id):

    # Displays a page with a question and a form to be filled with
    # the new comment

    question = logic.get_question(qstn_id)
    if question is None:
        abort(404)
    comment = logic.CMNT_DEFAULTS
    mates = logic.get_users_ids()

    return render_template('cmnt_q_form.html',
                           form_type='new',
                           comment=comment,
                           question=question,
                           mates=mates)
def edit_answer():

    # Receive form request with the answer id and send request to logic
    # to retrive answer data.
    # Display a page with the form filled with the answer existing data

    answ_id = int(request.form['id'])
    qstn_id = int(request.form['question_id'])
    answer = logic.get_answer(answ_id)
    question = logic.get_question(qstn_id)
    mates = logic.get_users_ids()

    return render_template('ans_form.html',
                           form_type="edit",
                           answer=answer,
                           question=question,
                           mates=mates)