Пример #1
0
def create_schema():
    creation_script_file = 'data/db_schema/01_create_schema.sql'
    with open(creation_script_file) as schema_script:
        with establish_connection() as conn, \
                conn.cursor() as cursor:
            try:
                sql_to_run = schema_script.read()
                cursor.execute(sql_to_run)
                print("Database schema created")
            except Exception as ex:
                print("Schema creation failed")
                print(ex.args)
Пример #2
0
def init_db():
    init_conn = get_connection_data('postgres')
    db_name = os.environ.get('MY_PSQL_DBNAME')

    with establish_connection(connection_data=init_conn) as conn:
        with conn.cursor() as cursor:
            try:
                drop_statement = 'DROP DATABASE IF EXISTS "{}";'.format(
                    db_name)
                create_statement = 'CREATE DATABASE "{}";'.format(db_name)
                cursor.execute(drop_statement)
                cursor.execute(create_statement)
                print("Database created")
            except Exception as ex:
                print("Database creation failed")
                print(ex.args)
Пример #3
0
def registration():
    try:
        if request.method == "POST":
            name = request.form['name']
            email = request.form['email']
            username = request.form['username']
            password = request.form['password']
            confirm_pw = request.form['confirm']
            if password == confirm_pw:
                password = pw_hash.hash_pw(password)
                data_manager.reg_new_user(data_manager.establish_connection(), name, email, username, password)
            else:
                message = "Passwords don't match. Try again."
                return render_template('main.html', message=message)
    except psycopg2.IntegrityError:
        return redirect('/')
    return render_template('main.html')
Пример #4
0
def youtube_link(show_id):
    link = request.form["youtube_link"]
    link = link.replace("watch?v=", "embed/")
    data_manager.youtube_link(data_manager.establish_connection(), link, show_id)
    return redirect(url_for("detailed", show_id=show_id))
Пример #5
0
def restore_deleted_show():
    show_id = request.form['deletedShowId']
    data_manager.restore(data_manager.establish_connection(), show_id)
    return redirect(url_for("deleted_page"))
Пример #6
0
def delete_show(show_id):
    data_manager.delete(data_manager.establish_connection(), show_id)
    return redirect("/")