Ejemplo n.º 1
0
 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('/')
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
 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')
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
 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('/')
Ejemplo n.º 8
0
 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
Ejemplo n.º 9
0
 def get(self):
     for post in Session.query(Post).filter_by(read=False):
         post.read = True
     Session.commit()
     Session.close()
     return self.redirect('/')
Ejemplo n.º 10
0
 def get(self, id):
     feed = Session.query(Feed).filter_by(id=id).one()
     return self.render('feed_edit.html', feed=feed)
Ejemplo n.º 11
0
 def get(self):
     posts = Session.query(Post).filter_by(read=False).order_by(
         desc(Post.published))
     return self.render('index.html', posts=posts)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
 def on_finish(self):
     Session.remove()