Beispiel #1
0
def edit_performance(performance_id):
    if 'username' not in session:
        return redirect('/login')
    elif session['username'] != ADMIN_NAME:
        return redirect('/performances')
    form = PerformanceForm()
    performances_model = PerformancesModel(db.get_connection())
    if form.validate_on_submit():
        title = form.title.data
        genre = form.genre.data
        time = form.time.data
        actors = form.actors.data
        description = form.description.data
        performances_model.edit(performance_id, title, genre, time, actors,
                                description)
        return redirect('/performances')
    exists = performances_model.exists(performance_id)
    if not exists[0]:
        return redirect('/performances')
    performance = performances_model.get(performance_id)

    form.title.process_data(performance[1])
    form.genre.process_data(performance[2])
    form.time.process_data(
        datetime.datetime.strptime(performance[3], '%d.%m.%Y %H:%M'))
    form.actors.process_data(performance[4])
    form.description.process_data(performance[5])

    return render_template('performance_form.html',
                           title='Изменение данных спектакля',
                           form=form)
Beispiel #2
0
                           title='Избранное',
                           username=session['username'],
                           favourites=res)


@app.route('/favourites/<int:perf_id>/delete')
def delete_from_favourites(perf_id):
    if 'username' not in session:
        return redirect('/login')
    user_id = session['user_id']
    users_model = UsersModel(db.get_connection())
    favourites = users_model.get_favourites(user_id).split(',')
    if str(perf_id) not in favourites:
        return redirect('/performances')
    del favourites[favourites.index(str(perf_id))]
    users_model.edit_favourites(user_id, ','.join(favourites))
    return redirect('/performances')


if __name__ == '__main__':
    db = DataBase()
    ActorsModel(db.get_connection()).init_table()
    PerformancesModel(db.get_connection()).init_table()
    um = UsersModel(db.get_connection())
    um.init_table()

    if not um.exists(ADMIN_NAME)[0]:
        um.insert(ADMIN_NAME, ADMIN_PASSWORD_HASH)

    app.run(port=8080, host='127.0.0.1')
Beispiel #3
0
from db import DataBase, ActorsModel, PerformancesModel, UsersModel

db = DataBase()
actors_model = ActorsModel(db.get_connection())
actors_model.init_table()
performances_model = PerformancesModel(db.get_connection())
performances_model.init_table()
users_model = UsersModel(db.get_connection())
users_model.init_table()

performances_model.insert('Щелкунчик', 'Балет', '2019-04-26 16:00', '1',
                          'Описание первого спектакля')
performances_model.insert('Евгений Онегин', 'Опера', '2019-04-26 20:00', '2,3',
                          'Описание второго спектакля')
performances_model.insert('Травиата', 'Опера', '2019-04-27 16:00', '2,3',
                          'Описание третьего спектакля')

actors_model.insert('Ольга', 'Иванова', 'Балерина', 'Биография первого актёра')
actors_model.insert('Иван', 'Петров', 'Певец', 'Биография второго актёра')
actors_model.insert('Дарья', 'Сидорова', 'Певица', 'Биография третьего актёра')