def top_last_month(cls, key, ids=None, num=None):
 cur_month = datetime.date.today().replace(day=1)
 last_month = decrement_month(cur_month)
 q = Session.query(cls).filter((cls.date == last_month)).filter((cls.interval == 'month')).order_by(desc(cls.date), desc(cls.pageview_count))
 if ids:
  q = q.filter(getattr(cls, key).in_(ids))
 else:
  num = (num or 55)
  q = q.limit(num)
 return [(getattr(r, key), (r.unique_count, r.pageview_count)) for r in q.all()]

def top_last_month ( cls , key , ids = None , num = None ) : cur_month = datetime . date . today ( ) . replace ( day = 1 ) last_month = decrement_month ( cur_month ) q = Session . query ( cls ) . filter ( ( cls . date == last_month ) ) . filter ( ( cls . interval == 'month' ) ) . order_by ( desc ( cls . date ) , desc ( cls . pageview_count ) ) if ids : q = q . filter ( getattr ( cls , key ) . in_ ( ids ) ) else : num = ( num or 55 ) q = q . limit ( num ) return [ ( getattr ( r , key ) , ( r . unique_count , r . pageview_count ) ) for r in q . all ( ) ]
aggregate a listing of the top items last month .