Exemplo n.º 1
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)
Exemplo n.º 2
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)