Beispiel #1
0
 def get_item_and_children(id):
     """ Get an item
         Make sure everything we will need loads, since we are caching
         TODO: Still not playing nice with cache
     """
     item = Item.query.options(
                              db.joinedload('user'),
                              db.joinedload('votes'),
                             ).get_or_404(id)
     return item
Beispiel #2
0
 def ranked_posts(page):
     """ Returns the top ranked posts by post_score
         (Kinda) Load all necessary sub-queries so we can cache
         TODO: This should be an combined with post_score to be a 
               sqlalchemy query, but I keep breaking that =(
     """
     items = Item.query.options(db.joinedload('user'), 
                               db.joinedload('votes')
                              ).filter_by(kind = 'post').order_by(Item.timestamp.desc())
     items_paged = items.paginate(page)
     start = items_paged.per_page * (items_paged.page - 1)
     end = items_paged.per_page + start
     items_paged.items = sorted(items, 
                                key=lambda x: x.post_score, 
                                reverse=True)[start:end]
     #items_paged.adf
     return {'items' : items_paged.items, 
             'has_next' : items_paged.has_next,
             'next_num' : items_paged.next_num,
             }