Exemple #1
0
def edit_question(question_id):
    if request.method == 'POST':
        new_content = {
            'message': request.form.get('message'),
            'title': request.form.get('title')
        }
        dm.edit_question(question_id, new_content)
        redirect_to = url_for('list_question', question_id=question_id)
        return redirect(redirect_to)
    question_content = dm.get_question(question_id)
    return render_template("edit.html", question_content=question_content)
def edit_question(question_id):
    if request.method == 'GET':
        question = data_manager.get_question(question_id)
        return render_template('edit_question.html',
                               question_id=question_id,
                               question=question)
    elif request.method == 'POST':
        edited_question_title = request.form['title'].replace("'", "''")
        edited_question_message = request.form['message'].replace("'", "''")
        data_manager.update_question(question_id, edited_question_title,
                                     edited_question_message)
        return redirect(url_for('display_question', question_id=question_id))
Exemple #3
0
def question_route(id):
    if request.method == "GET":
        answer_user_data=data_manager.find_username_for_answer(id)

        question_user_data=data_manager.find_username_by_question_id(id)
        quest_comm_user_data = data_manager.find_userdata_for_questions_comments(id)
        question = data_manager.get_question(id)
        answers = data_manager.get_all_answers(id)
        question_comments = data_manager.get_question_comments(id)
        return render_template("question-page.html", to_display=question,q_user_data=question_user_data,
                               a_user_data=answer_user_data, answers_to_display=answers, question_id=id,
                               comments=question_comments, quest_comm_user_data=quest_comm_user_data)
def new_question():
    if request.method == 'GET':
        return render_template('add_question.html')
    elif request.method == 'POST':
        new_question_title = request.form['title'].replace("'", "''")
        new_question_message = request.form['message'].replace("'", "''")
        question_id = data_manager.post_question(new_question_title,
                                                 new_question_message)
        question = data_manager.get_question(question_id)
        answers = data_manager.get_answers_for_question(question_id)
        return render_template('question.html',
                               question_id=question_id,
                               question=question,
                               answers=answers)
def display_question(question_id):
    question_id = int(question_id)
    question = data_manager.get_question(question_id)
    answers = data_manager.get_answers_for_question(question_id)
    answer_id_list = []
    for answer in answers:
        answer_id_list.append(str(answer['id']))
    # answer_id_set = set(answer_id_list)
    comments = data_manager.get_comments_for_question_page(
        question_id, answer_id_list)
    return render_template('question.html',
                           question_id=question_id,
                           question=question,
                           comments=comments,
                           answers=answers)
Exemple #6
0
def edit_route(question_id):
    if session.get('username') is not None:
        question_user_id=data_manager.find_userid_by_questionid(question_id)
        if question_user_id:
            if session['user_id'] == question_user_id['user_id'] or session['username'] == 'administrator':
                if request.method == "GET":
                    question = data_manager.get_question(question_id)
                    return render_template("edit-question.html", question=question, question_id=question_id)
                elif request.method == "POST":
                    title=request.form['title']
                    message=request.form['message']
                    data_manager.update_question("question",title,message,question_id)
                    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))
Exemple #7
0
def get_question(question_id):
    try:
        return dm.get_question(question_id)
    except ValueError as e:
        print(e)
        return []
Exemple #8
0
def list_question(question_id):
    question = dm.get_question(question_id)
    answers = dm.get_answer_for_question(question_id)
    dm.count_views(question_id)
    return render_template("question.html", question=question, answers=answers)