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 __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 post(self): name = self.get_argument('name') url = self.get_argument('url') feed = Feed() feed.title = name feed.url = url Session.add(feed) Session.commit() return self.render('index.html')
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(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 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('/')
def get(self, id): feed = Session.query(Feed).filter_by(id=id).one() return self.render('feed_edit.html', feed=feed)
def get(self): posts = Session.query(Post).filter_by(read=False).order_by( desc(Post.published)) return self.render('index.html', posts=posts)
from schema import Session session = Session() # Create random tasks for i in map(str, range(10)): t = Task(name="testTask"+i, rtt=120, definition="echo 'hello world from task "+i+"!';") session.add(t) session.commit() # Create some nodes for i in map(str, range(5)): n = Node(name="testNode"+i, resource="CPU=%d,RAM=%d,DISK=%d"%(randint(1,4), randint(1,4), [128,256,512,1024][randint(0,3)]), rtt=randint(1,14)*10, stats="") session.add(n) session.commit() # Create some requests for i in range(20): t = session.query(Task).all()[randint(0,session.query(Task).count()-1)] r = TaskRequest(task_id=t.id, resource="CPU=%d,RAM=%d,DISK=%d"%(randint(1,4), randint(1,4), [128,256,512,1024][randint(0,3)]), rtt=randint(1,14)*10, stats="") session.add(r)
def on_finish(self): Session.remove()