コード例 #1
0
def add_comment_to_answer(answer_id):
    if 'username' not in session:
        return redirect(url_for('login'))
    question_id = request.args.get("question_id")
    if request.method == 'GET':
        return render_template('add_comment_for_answer.html',
                               answer_id=answer_id,
                               question_id=question_id)
    if request.method == 'POST':
        new_comment = {
            'user_id': session['user_id'],
            'question_id': question_id,
            'answer_id': answer_id,
            'message': request.form.get('message'),
            'submission_time': connection.get_submission_time(),
            'edited_count': 0
        }
        connection.insert_comment_answer_to_database(new_comment)
        user_id = session['user_id']
        connection.update_comment_count(user_id)
        return redirect(
            url_for(
                'display_single_question',
                question_id=question_id,
            ))
コード例 #2
0
def add_new_answer(question_id):
    if request.method == 'GET':
        return render_template('add_answer.html', question_id=question_id)
    if request.method == 'POST':
        answer = {'submission_time': connection.get_submission_time(), 'vote_number': 0,
                  'question_id': question_id, 'message': request.form.get('message'),
                  'image': request.form.get('image')}
        connection.insert_answer_to_database(answer)
        return redirect(url_for('display_single_question', question_id=question_id))
コード例 #3
0
def add_new_question():
    if request.method == 'GET':
        return render_template('add_question.html')
    if request.method == 'POST':
        question = {'submission_time': connection.get_submission_time(), 'view_number': 0,
                    'vote_number': 0, 'title': request.form.get('title'),
                    'message': request.form.get('message'), 'image': None}
        connection.insert_question_to_database(question)
        return redirect(url_for('display_questions_list'))
コード例 #4
0
def add_comment_to_question(question_id):
    if request.method == 'GET':
        return render_template('add_comment_for_question.html', question_id=question_id)
    if request.method == 'POST':
        new_comment = {'question_id': question_id, 'answer_id': None,
                       'message': request.form.get('message'), 'submission_time': connection.get_submission_time(),
                       'edited_count': 0}
        connection.insert_comment_question_to_database(new_comment)
    return redirect(url_for('display_single_question', question_id=question_id))
コード例 #5
0
def add_new_question():
    if 'username' not in session:
        return redirect(url_for('login'))
    if request.method == 'GET':
        return render_template('add_question.html')
    if request.method == 'POST':
        question = {
            'user_id': session['user_id'],
            'submission_time': connection.get_submission_time(),
            'view_number': 0,
            'vote_number': 0,
            'title': request.form.get('title'),
            'message': request.form.get('message'),
            'image': request.form.get('image')
        }
        connection.insert_question_to_database(question)
        user_id = session['user_id']
        connection.update_question_count(user_id)
        return redirect(url_for('display_questions_list'))
コード例 #6
0
def add_new_answer(question_id):
    if 'user_id' not in session:
        return redirect(url_for('login'))
    if request.method == 'GET':
        return render_template('add_answer.html', question_id=question_id)
    if request.method == 'POST':
        answer = {
            'user_id': session['user_id'],
            'submission_time': connection.get_submission_time(),
            'vote_number': 0,
            'question_id': question_id,
            'message': request.form.get('message'),
            'image': request.form.get('image'),
            'valid': False
        }
        connection.insert_answer_to_database(answer)
        user_id = session['user_id']
        connection.update_answer_count(user_id)
        return redirect(
            url_for('display_single_question', question_id=question_id))