Exemplo n.º 1
0
def add_new__answer_comment(answer_id):
    """Add comment to a given question then render question_details.html"""
    if request.method == 'POST':
        db_query.add_new_comment(answer_id, 'answer_id')
        question_id = db_query.select_query_where('question_id', 'answer',
                                                  'id', answer_id)
        return redirect("/question/{}".format(question_id[0][0]))
Exemplo n.º 2
0
def user_activities(user_id):
    '''Renders user_activity.html with all the activities of a given user'''
    table_header = ["Question", "Answer", "Comment"]
    user_name = db_query.select_query_where('username', 'users', 'id', user_id)
    user_questions = db_query.select_query_where('question.title, question.id',
                                                 'question',
                                                 'question.user_id', user_id)
    user_answers = db_query.user_answers_query(user_id)
    user_question_comments = db_query.user_question_comments_query(user_id)
    user_answer_comments = db_query.user_answer_comments_query(user_id)
    return render_template("user_activity.html",
                           user_name=user_name[0][0],
                           table_header=table_header,
                           user_questions=user_questions,
                           user_answers=user_answers,
                           user_question_comments=user_question_comments,
                           user_answer_comments=user_answer_comments)
Exemplo n.º 3
0
def submit_new_tag(question_id, tag_name):
    '''Adds a new tag to the given question'''
    tag_id = db_query.select_query_where("id", "tag", "name", tag_name)
    try:
        db_query.question_tag_insert_query(question_id, (tag_id[0][0]))
    except:
        return redirect('/question/{}'.format(question_id))
    return redirect('/question/{}'.format(question_id))
Exemplo n.º 4
0
def render_edit_question(question_id):
    """Renders question.html to edit a given question"""
    if request.method == 'GET':
        edit_question_row = db_query.select_query_where(
            '*', 'question', 'id', question_id)
        return render_template("question.html",
                               question_id=question_id,
                               message=edit_question_row[0][5],
                               title=edit_question_row[0][4])
Exemplo n.º 5
0
def add_new_tag(question_id):
    '''Adds new tag to the question'''
    tag_to_add = request.form['tag-text']
    db_query.insert_tag_query(tag_to_add)
    tag_id = db_query.select_query_where("id", "tag", "name", tag_to_add)
    try:
        db_query.question_tag_insert_query(question_id, (tag_id[0][0]))
    except:
        return redirect('/question/{}'.format(question_id))
    return redirect('/question/{}'.format(question_id))