def add_cartoon(): image = None file = request.files['file'] if file and allowed_file(file.filename): image = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], image)) title = request.form['title'] release_year = int(request.form['release_year']) country = request.form['country'] method_of_creation = request.form['method_of_creation'] director = request.form['director'] genres = request.form['genres'] brief_description = request.form['brief_description'] certificate = request.form['certificate'] duration = request.form['duration'] runtime = request.form['runtime'] tags = request.form['tags'] trailer = request.form['trailer'] uuid_id = str(uuid.uuid4()) cartoon = Cartoon(uuid_id, image, title, release_year, country, method_of_creation, director, genres, brief_description, certificate, duration, runtime, tags, trailer) db_cartoons.add_cartoon(db_cartoons.open_db(db_url), cartoon) return redirect(url_for('index_cartoons'))
def export_csv_cartoons(): cartoons = db_cartoons.get_cartoons(db_cartoons.open_db(db_url)) content = io.StringIO() writer = csv.writer(content) for cartoon in cartoons: writer.writerow([ cartoon.id, cartoon.title, cartoon.release_year, cartoon.country, cartoon.method_of_creation, cartoon.director, cartoon.genres, cartoon.brief_description, cartoon.certificate, cartoon.duration, cartoon.runtime, cartoon.tags, cartoon.trailer ]) response = make_response(content.getvalue()) response.headers['Content-Type'] = 'application/octet-stream' response.headers[ 'Content-Disposition'] = 'inline; filename=exported_cartoons.csv' return response
def index_cartoons(): cartoons = db_cartoons.get_cartoons(db_cartoons.open_db(db_url)) return render_template('index_cartoons.html', cartoons=cartoons)
def remove_cartoon(id): db_cartoons.remove_cartoon(db_cartoons.open_db(db_url), id) return redirect(url_for('index'))
def remove_cartoon_form(id): cartoon = db_cartoons.get_cartoons_by_id(db_cartoons.open_db(db_url), id) return render_template('remove_cartoon.html', cartoon=cartoon)
def details_cartoon_by_id(id): cartoon = db_cartoons.get_cartoons_by_id(db_cartoons.open_db(db_url), id) return render_template('details_cartoons.html', cartoon=cartoon)