def setup_app(command, conf, vars): """Place any commands to setup toscasample here""" load_environment(conf.global_conf, conf.local_conf) # Load the models from toscasample import model print "Creating tables" model.metadata.create_all(bind=config['pylons.app_globals'].sa_engine) movieDatas = [["Into the Wild", 2007], ["The Big Lebowsky", 1998], ["Pulp Fiction", 1994], ["Dead Man", 1995], ["Night on Earth", 1991], ["Genova", 2008], ["Snatch", 2000]] movies = [] for data in movieDatas: movie = Movie() movie.title = data[0] movie.year = data[1] model.DBSession.add(movie) transaction.commit() print "Successfully setup"
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")