コード例 #1
0
ファイル: server.py プロジェクト: PhoenixWings7/Quiz-Maker
def new_quiz_route():
    if request.method == "GET":
        username = user_functions.user_logged_in()
        if not username:
            flash(VALIDATION_MESSAGES["no user logged in"])
            return redirect(url_for("main_page"))
        answer_ids = data_handler.ANSWER_NAMES
        return render_template(TEMPLATES_ROUTES["new quiz start"], answer_ids=answer_ids, username=username)

    if request.method == "POST":
        quiz_title = request.form["quiz_title"]

        username = user_functions.user_logged_in()
        if not username:
            flash(VALIDATION_MESSAGES["no user logged in"])
            return redirect(url_for("main_page"))

        if not data_handler.validate_title(quiz_title):
            flash(VALIDATION_MESSAGES["invalid title"])
            return redirect(url_for("new_quiz_route"))

        user_id = data_handler.get_user_id(username)
        if not user_id:
            flash(VALIDATION_MESSAGES["user not in database"])
            return redirect(url_for("main_page"))
        title_uniqueness_validation = data_handler.add_quiz_title_to_database(quiz_title, user_id)

        if not title_uniqueness_validation:
            flash(VALIDATION_MESSAGES["title not unique"])
            return redirect(url_for("new_quiz_route"))

        quiz_id = data_handler.get_quiz_id(quiz_title)

        return redirect(url_for("next_question_form", quiz_title=quiz_title, quiz_id=quiz_id))
コード例 #2
0
def route_list_questions():
    if request.method == "POST":
        username = session["username"]
        user_id = data_handler.get_user_id(session["username"])
        time = data_handler.get_the_current_date()
        if request.files['file']:
            file = request.files['file']
            file.save(path + "/static/images/" + file.filename)
            data_handler.write_question(time, 0, 0, request.form.get("title"), request.form.get("message"),
                                        file.filename,user_id)
        else:
            data_handler.write_question(time, 0, 0, request.form.get("title"), request.form.get("message"), None,user_id)
        stories = data_handler.read_questions()
        return render_template('questions.html', username=username,stories=stories, fancy_word=None)
    if request.method == "GET":
        username = session["username"]
        column = "submission_time"
        direction = "DESC"
        opportunities = ["submission_time","vote_number","view_number","title","message"]
        if request.args.get("order_by") in opportunities:
            column = request.args.get("order_by")
        if request.args.get("direction") in opportunities:
            direction = request.args.get("direction")
        stories = data_handler.read_questions(column,direction)
        return render_template('questions.html', username=username,stories=stories, fancy_word=None)
コード例 #3
0
def show_user_page():
    username = session["username"]
    user_id = data_handler.get_user_id(session["username"])
    user_questions = data_handler.get_user_questions(user_id)
    user_answers = data_handler.get_user_answers(user_id)
    user_data=data_handler.get_user_data(user_id)
    answer_comments = data_handler.read_comments()
    return render_template('user_page.html', user_data=user_data, username=username, user_questions=user_questions,answer_comments=answer_comments, user_answers=user_answers,fancy_word=None)
コード例 #4
0
def route_new_question_comment(question_id):
    if request.method == "GET":
        username = session["username"]
        return render_template("add_new_question_comment.html", id=question_id,username=username)
    if request.method == "POST":
        user_id = data_handler.get_user_id(session["username"])
        time = data_handler.get_the_current_date()
        data_handler.write_question_comments(question_id, request.form.get("message"), time,user_id)
        return redirect(url_for("route_list_answers", question_id=question_id))
コード例 #5
0
def get_boards():
    """
    All the boards
    """
    user_id = None
    if 'username' in session:
        user_id = data_handler.get_user_id(session['username'])

        return data_handler.get_boards(user_id['id'])
    return data_handler.get_boards(user_id)
コード例 #6
0
def route_list_answers(question_id=None):
    if request.method == "GET":
        data_handler.increase_view_number(question_id)
        answers = data_handler.read_answers(question_id)
        question_comments = data_handler.read_question_comments(question_id)
        answer_comments = data_handler.read_comments()
        question_title = data_handler.get_question_title(question_id)
        image = data_handler.get_image(question_id)
        user_id = data_handler.get_user_id_with_question_id(question_id)
        question_user_name = data_handler.get_username_of_a_question(user_id)
        username = session["username"]
        return render_template("answer.html",username=username,image=image, question_user_name=question_user_name,
                               question_title=question_title,question_id=question_id,answers=answers,
                               question_comments=question_comments,
                               answer_comments=answer_comments)
    if request.method == "POST":
        user_id = data_handler.get_user_id(session["username"])
        time = data_handler.get_the_current_date()
        if request.files['file']:
            file = request.files['file']
            file.save(path + "/static/images/" + file.filename)
            data_handler.write_answer(time, 0, question_id, request.form.get("message"), file.filename,user_id)
        data_handler.write_answer(time, 0, question_id, request.form.get("message"), None,user_id)
        return redirect(url_for("route_list_answers", question_id=question_id))
コード例 #7
0
def add_private_board():
    if request.method == 'POST':
        title = request.form['private_board_title']
        user_id = data_handler.get_user_id(session['username'])
        data_handler._insert_private_board(title, user_id['id'])
        return redirect(url_for('index'))