def get(self): """List of sites""" table = Visit.__table__ attr = Visit.domain countcol = func.count(1) sites_query = ( self.db .query(attr, countcol.label('count')) .group_by(attr) .filter(in_last_month()) .order_by(desc(countcol))) sites = sites_query[:20] subquery = sites_query.subquery() all_ = (self.db.query(func.sum(subquery.c.count)) .select_from(subquery) .scalar()) self.render('sites.html', sites=sites, all_=all_)
def get(self, query): """Sites matching query""" table = Visit.__table__ attr = Visit.domain countcol = func.count(1) sites_query = ( self.db .query(attr.label('host'), countcol.label('count')) .filter(attr.like('%%%s%%' % query)) .filter(in_last_month()) .group_by(attr) .order_by(desc(countcol))) sites = sites_query[:20] subquery = sites_query.subquery() all_ = (self.db.query(func.sum(subquery.c.count)) .select_from(subquery) .scalar()) self.render('sites_table.html', sites=sites, all_=all_)