def create_user_data(): passwd = hash_password(request.form.get('password')) user_data = { 'user_name': request.form.get('username'), 'password': passwd, 'registration_time': util.create_timestamp() } return user_data
def edit_comment(cursor, comment_id, message): sub_time = util.convert_timestamp(util.create_timestamp()) cursor.execute( sql.SQL("""UPDATE comment SET submission_time={sub_time}, message={msg}, edited_count = COALESCE(edited_count, 0) + 1 WHERE id = {comment_id}; """).format(sub_time=sql.Literal(str(sub_time)), msg=sql.Literal(message), comment_id=sql.Literal(comment_id)))
def create_new_answer_data(question_id): new_answer_data = { "submission_time": util.create_timestamp(), "vote_number": "0", "question_id": question_id, "message": request.form.get('message'), "image": "n/a", "user_id": get_user_id() } return new_answer_data
def create_new_question_data(): new_question_data = { "submission_time": util.create_timestamp(), "view_number": "0", "vote_number": "0", "title": request.form.get('title'), "message": request.form.get('message'), "user_id": get_user_id() } return new_question_data
def create_new_comment_data(answer_id, question_id): new_comment_data = { "question_id": question_id, "answer_id": answer_id, "message": request.form.get('message'), "submission_time": util.create_timestamp(), "edited_count": 0, "user_id": get_user_id() } return new_comment_data
def save_user_registration(cursor, user_name, password): hashed_password = hash_password(password) sub_time = util.convert_timestamp(util.create_timestamp()) cursor.execute( sql.SQL( """INSERT INTO users(name, password, submission_time, reputation) VALUES ({user_name}, {hashed_password}, {submission_time}, 0) """).format(user_name=sql.Literal(user_name), hashed_password=sql.Literal(hashed_password), submission_time=sql.Literal(str(sub_time))))
def new_comment(cursor, comment_type, data_id, comment, user_id): sub_time = util.convert_timestamp(util.create_timestamp()) cursor.execute( sql.SQL( """INSERT INTO comment ({com_type}, user_id, message, submission_time) VALUES ({id_number}, {user_id}, {msg}, {sub_time}); """).format(com_type=sql.SQL(comment_type), id_number=sql.SQL(data_id), user_id=sql.Literal(user_id), msg=sql.Literal(comment), sub_time=sql.Literal(str(sub_time))))
def add_answer(cursor, user_id, question_id, answer_text, image_name): sub_time = util.convert_timestamp(util.create_timestamp()) cursor.execute( sql.SQL( """INSERT INTO answer (user_id,submission_time, vote_number, question_id, message, image) VALUES ({user_id}, {sub_time}, 0, {question_id}, {message}, {image}); """).format(user_id=sql.Literal(user_id), sub_time=sql.Literal(str(sub_time)), question_id=sql.Literal(question_id), message=sql.Literal(answer_text), image=sql.Literal(image_name)))
def create_new_question(cursor, user_id, title, message, image): sub_time = util.convert_timestamp(util.create_timestamp()) cursor.execute( sql.SQL( """INSERT INTO question (user_id, submission_time, view_number, vote_number, title, message, image) VALUES ({user_id},{sub_time}, 0, 0, {title}, {message}, {image}); """).format(user_id=sql.Literal(user_id), sub_time=sql.Literal(str(sub_time)), title=sql.Literal(title), message=sql.Literal(message), image=sql.Literal(image))) cursor.execute( sql.SQL("""SELECT id FROM question WHERE id=(SELECT max(id) FROM question) """)) data = cursor.fetchone() return data