예제 #1
0
def index():
    username = session['username'] if 'username' in session else 'Anonymus'
    if username != 'Anonymus':
        image = data_handler_2.get_users_image(username)['image']
        id = data_handler_2.get_id_by_username(username)['id']
        return render_template("main_page.html", username=username, image=image, id=id)
    else:
        return render_template("main_page.html", username=username)
예제 #2
0
def add_new_question(cursor, title, message, image, tag, username):
    date_time = datetime.now()
    if image != '':
        cursor.execute(
            """
                        INSERT INTO question (submission_time, view_number, vote_number, title, message, image)
                        VALUES (%(date_time)s, 0, 0, %(title)s, %(message)s, %(image)s); 
                       """, {
                'date_time': date_time,
                'title': title,
                'message': message,
                'image': image
            })
    else:
        cursor.execute(
            """
                        INSERT INTO question (submission_time, view_number, vote_number, title, message)
                        VALUES (%(date_time)s, 0, 0, %(title)s, %(message)s); 
                       """, {
                'date_time': date_time,
                'title': title,
                'message': message
            })
    add_new_tag(tag)
    last_question_id = get_last_question_id()
    tag_id = get_tag_id_by_tag_name(tag)
    user_id = data_handler_2.get_id_by_username(username)
    cursor.execute(
        """
                    INSERT INTO question_tag (question_id, tag_id) 
                    VALUES (%(last_question_id)s, %(tag_id)s);
                   """, {
            'last_question_id': last_question_id['last_value'],
            'tag_id': tag_id['id']
        })
    cursor.execute(
        """
                    INSERT INTO user_question (question_id, user_id)
                    VALUES (%(last_question_id)s, %(user_id)s)
                   """, {
            'last_question_id': last_question_id['last_value'],
            'user_id': user_id['id']
        })
예제 #3
0
def add_new_comment_answer(cursor, message, answer_id, username):
    date_time = datetime.now()
    cursor.execute(
        """
                    INSERT INTO comment (submission_time, message, answer_id) 
                    VALUES (%(date_time)s, %(message)s, %(answer_id)s)
                   """, {
            'date_time': date_time,
            'message': message,
            'answer_id': answer_id
        })
    last_comment_id = get_last_comment_id()
    user_id = data_handler_2.get_id_by_username(username)
    cursor.execute(
        """
                    INSERT INTO user_comment (comment_id, user_id)
                    VALUES (%(last_comment_id)s, %(user_id)s)
                   """, {
            'last_comment_id': last_comment_id['last_value'],
            'user_id': user_id['id']
        })
예제 #4
0
def add_new_answer(cursor, message, question_id, username):
    date_time = datetime.now()
    cursor.execute(
        """
                    INSERT INTO answer (submission_time, vote_number, question_id, message) 
                    VALUES (%(date_time)s, 0, %(question_id)s, %(message)s)
                   """, {
            'date_time': date_time,
            'question_id': question_id,
            'message': message
        })
    last_answer_id = get_last_answer_id()
    user_id = data_handler_2.get_id_by_username(username)
    cursor.execute(
        """
                    INSERT INTO user_answer (answer_id, user_id)
                    VALUES (%(last_answer_id)s, %(user_id)s)
                   """, {
            'last_answer_id': last_answer_id['last_value'],
            'user_id': user_id['id']
        })