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)
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)