def post(self, id): feed = Session.query(Feed).filter_by(id=id).one() feed.title = self.get_argument('name') feed.url = self.get_argument('url') Session.commit() Session.close() return self.redirect('/')
def get(self, id): # sqlite won't cascade-delete the posts Session.query(Post).filter_by(feed_id=id).delete() Session.query(Feed).filter_by(id=id).delete() Session.commit() Session.close() return self.redirect('/')
def __init__(self, song_id, user_selected): # get song info session = Session() session.begin() song, artist, album = session.query(Song, Artist, Album).outerjoin(Song.song_artist).outerjoin(Song.song_album).filter(Song.id == song_id).one() self.song_id = song.id self.song_title = song.title self.album_id = album.id self.album_name = album.name self.album_has_art = album.art if artist: self.artist_name = artist.name self.artist_id = artist.id else: self.artist_name = 'unknown' self.artist_id = 0 self.track = song.track self.filename = song.path # add history obj = History(song_id, user_selected) session.add(obj) self.history_id = obj.id session.commit() session.close()
def get_error_html(self, status_code, **kwargs): try: self.render('error/%s.html' % status_code) except TemplateNotFound: try: self.render('error/50x.html', status_code=status_code) except TemplateNotFound: self.write('epic fail') Session.close()
def get(self): Session.query(Post).filter( Post.updated <= dt.now() - timedelta(days=max_post_age)).delete() feeds = Session.query(Feed.id).all() Session.close() p = Pool(10) p.map_async(parse_one, (f.id for f in feeds)) p.close() p.join() self.redirect('/') return
def render(self, template, **kwds): try: template = self.env.get_template(template) except TemplateNotFound: raise HTTPError(404) kwds['feeds'] = Session.query(Feed).order_by(Feed.title) self.env.globals['request'] = self.request self.env.globals['static_url'] = self.static_url self.env.globals['xsrf_form_html'] = self.xsrf_form_html self.write(template.render(kwds)) Session.close()
def get_song(self, function, lengths = False): # return a song using the supplied function session = Session() # base query base = session.query(Song.id) # songs with lengths in a sensible range if lengths: base = base.filter(Song.length.between(30, 360)) # add the functional extras base = function(base) # randomise the choices base = base.order_by(sa.func.random()).limit(1) # get the song song = base.first() if song: song_id = song.id else: song_id = None session.close() return song_id
def get(self): for post in Session.query(Post).filter_by(read=False): post.read = True Session.commit() Session.close() return self.redirect('/')