Esempio n. 1
0
def update_question(question_id):
    username = session['username']
    check_for_validation = data_handler.check_user_id_authentication_for_question(username, question_id)
    if check_for_validation:
        if request.method == 'POST':
            question = {'id': question_id,
                        'submission_time': data_handler.date_time(),
                        'view_number': request.form.get('view_number'),
                        'vote_number': request.form.get('vote_number'),
                        'title': request.form.get('title'),
                        'message': request.form.get('message'),
                        'image': request.form.get('image'),
                        }
            data_handler.edit_question_row(question, question_id)
            return redirect(url_for('list_answers', id=question_id, username=username))

        question = data_handler.get_question_for_id(question_id)
        return render_template('add-question.html',
                               question=question,
                               form_url=url_for('update_question', question_id=question_id),
                               page_title='Update Question',
                               button_title='Update',
                               button_page='Return ',
                               username=username
                               )
    else:
        return redirect(url_for('list_answers', id=question_id, username=username))
Esempio n. 2
0
def list_answers(id=None):
    if 'username' in session:
        username = session['username']
        user = data_handler.get_user_id_by_username(username)
        time = request.args.get('time')  # answer comment edit time stamp
        q_c_time = request.args.get('q_c_time')
        question_row = data_handler.get_question_for_id(id)
        answer_row = data_handler.get_answers_for_id(id)
        question_comments = data_handler.get_question_comments(id)
        answer_comments = data_handler.get_answer_comments()
        tags = data_handler.get_all_tag_name_for_question(id)
        q_author = data_handler.get_username_by_question_id(id)
        check_for_valid_question = data_handler.check_user_id_authentication_for_question(username, id)
        if request.method == 'POST':
            answers = {'submission_time': data_handler.date_time(),
                       'vote_number': 0,
                       'question_id': id,
                       'message': request.form.get('answer_message'),
                       'image': request.form.get('image'),
                       'userid': data_handler.get_user_id_by_username(username),
                       }
            data_handler.add_new_answer(answers)
            return redirect(url_for('list_answers', id=id, username=username))
        data_handler.question_view_number_counter(id)
        return render_template('question.html', id=id, question_row=question_row, answer_row=answer_row,
                               question_comments=question_comments, answer_comments=answer_comments, time=time,
                               q_c_time=q_c_time, tags=tags, username=username, user=user, q_author=q_author,
                               check_edit_question=check_for_valid_question)
    else:
        return redirect(url_for('user_login'))
Esempio n. 3
0
def add_question():
    if 'username' in session:
        username = session['username']
        if request.method == 'GET':
            empty_questions = {}
            return render_template('add-question.html',
                                   question=empty_questions,
                                   form_url=url_for('add_question'),
                                   page_title='Add New Question',
                                   button_title='Submit',
                                   button_page='Return',
                                   username=username)

        if request.method == 'POST':
            question = {'submission_time': data_handler.date_time(),
                        'view_number': request.form.get('view_number'),
                        'vote_number': request.form.get('vote_number'),
                        'title': request.form.get('title'),
                        'message': request.form.get('message'),
                        'image': request.form.get('image'),
                        'userid': data_handler.get_user_id_by_username(username),
                        }
            data_handler.add_new_question(question)
            return redirect(url_for('list_of_questions', username=username))
    else:
        return redirect(url_for('user_login'))
Esempio n. 4
0
def edit_answer(answer_id):
    username = session['username']
    check_for_validation = data_handler.check_user_id_authentication_for_answer(username, answer_id)
    id = data_handler.get_question_id_for_answer_id(answer_id)
    if check_for_validation:
        if request.method == 'POST':
            answer = {'id': answer_id,
                      'submission_time': data_handler.date_time(),
                      'vote_number': request.form.get('vote_number'),
                      'question_id': request.form.get('question_id'),
                      'message': request.form.get('message'),
                      'image': request.form.get('image'),
                      }
            data_handler.edit_answer_row(answer, answer_id)
            return redirect(url_for('list_answers', id=id, username=username))

        answer = data_handler.get_answers_id_for_edit(answer_id)
        return render_template('edit-answer.html',
                               answer=answer,
                               form_url=url_for('edit_answer', answer_id=answer_id),
                               page_title='Update Answer',
                               button_title='Update',
                               button_page='Return ',
                               username=username,
                               )
    else:
        return redirect(url_for('list_answers', id=id, username=username))
Esempio n. 5
0
def add_user():
    if request.method == 'POST':
        password = request.form.get('hash')
        hashed = data_handler.hash_password(password)
        user_info = {'username': request.form.get('username'),
                     'hash': hashed,
                     'email': request.form.get('email'),
                     'creation_date': data_handler.date_time(),
                     'status': request.form.get('status'),
                     }
        data_handler.add_user_details_to_database(user_info)
        return redirect('/')

    return render_template('registration.html')
Esempio n. 6
0
def add_question_comment(question_id=None):
    username = session['username']
    comment = data_handler.get_question_for_id(question_id)
    if request.method == 'POST':
        comment = {'submission_time': data_handler.date_time(),
                   'question_id': request.form.get('question_id'),
                   'answer_id': request.form.get('answer_id'),
                   'message': request.form.get('message'),
                   'edited_count': request.form.get('edited_count'),
                   'userid': data_handler.get_user_id_by_username(username),
                   }
        data_handler.add_new_comment(comment)
        return redirect(url_for('list_answers', id=question_id, username=username))
    return render_template('add-question-comment.html', comment=comment, edit_comment=None,
                           button_title="Post New Comment", username=username)
Esempio n. 7
0
def edit_question_comment(comment_id):
    username = session['username']
    question_id = data_handler.get_question_id_by_comment_id(comment_id)
    check_for_validation = data_handler.check_user_id_authentication_for_comment(username, comment_id)
    if request.method == 'POST':
        comment = {'id': comment_id,
                   'submission_time': request.form.get('submission_time'),
                   'question_id': request.form.get('question_id'),
                   'answer_id': request.form.get('answer_id'),
                   'message': request.form.get('message'),
                   'edited_count': request.form.get('edited_count'),
                   }
        data_handler.update_comment(comment)
        q_c_time = data_handler.date_time()
        return redirect(url_for('list_answers', id=question_id, q_c_time=q_c_time, username=username))
    comment = data_handler.get_answer_comment_by_comment_id(comment_id)
    return render_template('add-question-comment.html', edit_comment=comment, comment=None, button_title="Edit Comment",
                           username=username)