def create(self, **kw): movie = Movie() movie.title = kw['title'] movie.year = kw['year'] movie.release_date = kw['release_date'] movie.description = kw['description'] movie.genre = kw['genre'] #save the filename to the database movie.picture_filename = kw['picture_filename'].filename DBSession.add(movie) DBSession.flush() #write the picture file to the public directory movie_path = os.path.join(movies_dirname, str(movie.id)) try: os.makedirs(movie_path) except OSError: #ignore if the folder already exists pass movie_path = os.path.join(movie_path, movie.picture_filename) f = file(movie_path, "w") f.write(kw['picture_filename'].value) f.close() flash("Movie was successfully created.") redirect("list")
def create(self, **kw): """Create a movie object and save it to the database.""" movie = Movie() movie.title = kw['title'] movie.year = kw['year'] movie.release_date = kw['release_date'] movie.description = kw['description'] movie.genre = kw['genre'] DBSession.add(movie) flash("Movie was successfully created.") redirect("list")
def list(self): """List all movies in the database""" return dict(movies=DBSession.query(Movie), page='ToscaSample Movie list')
def decolist(self): """List and paginate all movies in the database using the paginate() decorator.""" movies = DBSession.query(Movie) return dict(movies=movies, page='ToscaSample Movie list')
def list(self, page=1): """List and paginate all movies in the database""" movies = DBSession.query(Movie) currentPage = paginate.Page(movies, page, items_per_page=5) return dict(movies=currentPage.items, page='ToscaSample Movie list', currentPage=currentPage)