def count_of_user(user_id): ''' Get the cound of views. ''' return TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count')).where( TabCollect.user_id == user_id).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).count()
def query_pager_by_userid(user_id, kind, num=10): recs = TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.kind.alias('post_kind'), TabPost.view_count.alias('post_view_count')).where( (TabCollect.user_id == user_id) & (TabPost.kind == kind)).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).order_by( TabCollect.timestamp.desc()).limit(num) return recs
def query_pager_by_all(user_id, current_page_num=1): recs = TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count')).where( TabCollect.user_id == user_id).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).order_by( TabCollect.timestamp.desc()).paginate( current_page_num, CMS_CFG['list_num']) return recs
def query_recent(user_id, num=10): ''' Collection of recent. ''' return TabCollect.select( TabCollect, TabPost.uid.alias('post_uid'), TabPost.title.alias('post_title'), TabPost.view_count.alias('post_view_count')).where( TabCollect.user_id == user_id).join( TabPost, on=(TabCollect.post_id == TabPost.uid)).order_by( TabCollect.timestamp.desc()).limit(num)