def summary(self, id): movie = DBSession.query(Movie).filter_by(id=id).first() if movie is None: override_template(self.summary, 'genshi:cotufa.templates.movie-imdb') # emulate 'Movie' object with basic info movie = Movie.lightweight_instance_for(IMDb(), id) return {'movie': movie}
def add(self, id): import urllib2 movie = DBSession.query(Movie).filter_by(id=id).first() if movie is None: lw = Movie.lightweight_instance_for(IMDb(), id) # Construct Movie object movie = Movie(id=lw['id'], title=lw['title'], year=lw['year']) for at in lw['attributes']: movie.attributes.append(at) for d in lw['directors']: movie.people.append(MovieRole(person=Person.get_or_create(d['id'], d['name']), role_type=u'director')) for w in lw['writers']: movie.people.append(MovieRole(person=Person.get_or_create(w['id'], w['name']), role_type=u'writer')) for c in lw['cast']: movie.people.append(MovieRole(person=Person.get_or_create(c['id'], c['person']), role_type=u'cast', character=c['character'])) # Fetch cover image if lw['cover_url'] is not None: cover = urllib2.urlopen(lw['cover_url']) movie.cover = cover.read() cover.close() DBSession.add(movie) flash(u'%s has been added to the list.' % movie.title) redirect(url('/movies'))