コード例 #1
0
def show_performance(performance_id):
    if 'username' not in session:
        return redirect('/login')
    performances_model = PerformancesModel(db.get_connection())
    exists = performances_model.exists(performance_id)
    if not exists[0]:
        return redirect('/performances')
    performance = performances_model.get(performance_id)
    actors_model = ActorsModel(db.get_connection())
    res_actors = []
    actors = performance[4].split(',')
    for actor in actors:
        actor = actor.strip()
        exists = actors_model.exists(actor)
        if exists[0]:
            res_actors.append(exists[1:])
    if session['username'] == ADMIN_NAME:
        admin = True
    else:
        admin = False
    users_model = UsersModel(db.get_connection())
    if str(performance_id) in users_model.get_favourites(
            session['user_id']).split(','):
        in_favourites = True
    else:
        in_favourites = False
    return render_template('performance.html',
                           title=performance[1],
                           performance=performance,
                           actors=res_actors,
                           admin=admin,
                           in_favourites=in_favourites)
コード例 #2
0
def delete_actor(actor_id):
    if 'username' not in session:
        return redirect('/login')
    elif session['username'] != ADMIN_NAME:
        return redirect('/actors')
    actors_model = ActorsModel(db.get_connection())
    actors_model.delete(actor_id)
    return redirect('/actors')
コード例 #3
0
def show_actors():
    if 'username' not in session:
        return redirect('/login')
    actors_model = ActorsModel(db.get_connection())
    actors = actors_model.get_all()
    if session['username'] == ADMIN_NAME:
        admin = True
    else:
        admin = False
    return render_template('actors.html',
                           title='Актёры',
                           actors=actors,
                           admin=admin)
コード例 #4
0
def show_actor(actor_id):
    if 'username' not in session:
        return redirect('/login')
    actors_model = ActorsModel(db.get_connection())
    if not actors_model.exists(actor_id)[0]:
        return redirect('/actors')
    actor = actors_model.get(actor_id)
    if session['username'] == ADMIN_NAME:
        admin = True
    else:
        admin = False
    return render_template('actor.html',
                           title='{} {}'.format(actor[1], actor[2]),
                           actor=actor,
                           admin=admin)
コード例 #5
0
def add_actor():
    if 'username' not in session:
        return redirect('/login')
    elif session['username'] != ADMIN_NAME:
        return redirect('/actors')
    form = ActorForm()
    if form.validate_on_submit():
        name = form.name.data
        surname = form.surname.data
        role = form.role.data
        bio = form.bio.data
        actors_model = ActorsModel(db.get_connection())
        actors_model.insert(name, surname, role, bio)
        return redirect('/actors')
    return render_template('actor_form.html',
                           title='Добавление актёра',
                           form=form)
コード例 #6
0
def edit_actor(actor_id):
    if 'username' not in session:
        return redirect('/login')
    elif session['username'] != ADMIN_NAME:
        return redirect('/actors')
    form = ActorForm()
    actors_model = ActorsModel(db.get_connection())
    if form.validate_on_submit():
        name = form.name.data
        surname = form.surname.data
        role = form.role.data
        bio = form.bio.data
        actors_model.edit(actor_id, name, surname, role, bio)
        return redirect('/actors')
    exists = actors_model.exists(actor_id)
    if not exists[0]:
        return redirect('/actors')
    actor = actors_model.get(actor_id)

    form.name.process_data(actor[1])
    form.surname.process_data(actor[2])
    form.role.process_data(actor[3])
    form.bio.process_data(actor[4])

    return render_template('actor_form.html',
                           title='Редактирование профиля актёра',
                           form=form)
コード例 #7
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')
コード例 #8
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('Дарья', 'Сидорова', 'Певица', 'Биография третьего актёра')