def test_count_of_certain_category(self): b = MPost2Catalog.count_of_certain_category(self.tag_id) self.add_message() self.add_P2C() a = MPost2Catalog.count_of_certain_category(self.tag_id) assert b + 1 == a self.tearDown()
def render(self, *args, **kwargs): cat_slug = args[0] current = int(args[1]) # cat_slug 分类 # current 当前页面 tag = kwargs['tag'] if 'tag' in kwargs else "" cat_rec = MCategory.get_by_slug(cat_slug) num_of_cat = MPost2Catalog.count_of_certain_category(cat_rec.uid, tag=tag) pager_cnt = int(num_of_cat / config.CMS_CFG['list_num']) page_num = (pager_cnt if abs(pager_cnt - num_of_cat / config.CMS_CFG['list_num']) < 0.1 else pager_cnt + 1) kwd = { 'page_home': False if current <= 1 else True, 'page_end': False if current >= page_num else True, 'page_pre': False if current <= 1 else True, 'page_next': False if current >= page_num else True, 'tag': tag, } return self.render_string('modules/post/catalog_pager.html', kwd=kwd, cat_slug=cat_slug, pager_num=page_num, page_current=current)
def list_catalog(self, cat_slug, cur_p=''): if cur_p == '': current_page_num = 1 else: current_page_num = int(cur_p) current_page_num = 1 if current_page_num < 1 else current_page_num cat_rec = MCategory.get_by_slug(cat_slug) num_of_cat = MPost2Catalog.count_of_certain_category(cat_rec.uid) page_num = int(num_of_cat / CMS_CFG['list_num']) + 1 cat_name = cat_rec.name kwd = {'cat_name': cat_name, 'cat_slug': cat_slug, 'unescape': tornado.escape.xhtml_unescape, 'title': cat_name, 'router': router_post[cat_rec.kind], 'current_page': current_page_num} if self.kind == 's': tmpl = 'list/catalog_list.html' else: tmpl = 'list/category_list.html' self.render(tmpl, catinfo=cat_rec, infos=MPost2Catalog.query_pager_by_slug(cat_slug, current_page_num), pager=tools.gen_pager_purecss('/category/{0}'.format(cat_slug),page_num, current_page_num), userinfo=self.userinfo, html2text=html2text, unescape=tornado.escape.xhtml_unescape, cfg=CMS_CFG, kwd=kwd, router=router_post[cat_rec.kind])
def render(self, *args, **kwargs): cat_slug = args[0] current = int(args[1]) # cat_slug 分类 # current 当前页面 cat_rec = MCategory.get_by_slug(cat_slug) num_of_cat = MPost2Catalog.count_of_certain_category(cat_rec.uid) tmp_page_num = int(num_of_cat / config.CMS_CFG['list_num']) page_num = (tmp_page_num if abs(tmp_page_num - num_of_cat / config.CMS_CFG['list_num']) < 0.1 else tmp_page_num + 1) kwd = { 'page_home': False if current <= 1 else True, 'page_end': False if current >= page_num else True, 'page_pre': False if current <= 1 else True, 'page_next': False if current >= page_num else True, } return self.render_string('modules_ext/post/catalog_pager.html', kwd=kwd, cat_slug=cat_slug, pager_num=page_num, page_current=current)
def list_catalog(self, cat_slug, **kwargs): ''' listing the posts via category ''' post_data = self.get_post_data() tag = post_data.get('tag', '') def get_pager_idx(): ''' Get the pager index. ''' cur_p = kwargs.get('cur_p') the_num = int(cur_p) if cur_p else 1 the_num = 1 if the_num < 1 else the_num return the_num current_page_num = get_pager_idx() cat_rec = MCategory.get_by_slug(cat_slug) if not cat_rec: return False num_of_cat = MPost2Catalog.count_of_certain_category(cat_rec.uid, tag=tag) page_num = int(num_of_cat / CMS_CFG['list_num']) + 1 cat_name = cat_rec.name kwd = { 'cat_name': cat_name, 'cat_slug': cat_slug, 'title': cat_name, 'router': router_post[cat_rec.kind], 'current_page': current_page_num, 'kind': cat_rec.kind, 'tag': tag } # Todo: review the following codes. if self.order: tmpl = 'list/catalog_list.html' else: tmpl = 'list/category_list_{0}.html'.format(cat_rec.kind) infos = MPost2Catalog.query_pager_by_slug(cat_slug, current_page_num, tag=tag, order=self.order) # ToDo: `gen_pager_purecss` should not use any more. self.render(tmpl, catinfo=cat_rec, infos=infos, pager=tools.gen_pager_purecss('/list/{0}'.format(cat_slug), page_num, current_page_num), userinfo=self.userinfo, html2text=html2text, cfg=CMS_CFG, kwd=kwd, router=router_post[cat_rec.kind])
def list_catalog(self, cat_slug, cur_p=''): ''' listing the posts via category ''' if cur_p == '': current_page_num = 1 else: current_page_num = int(cur_p) current_page_num = 1 if current_page_num < 1 else current_page_num cat_rec = MCategory.get_by_slug(cat_slug) if cat_rec: pass else: return False num_of_cat = MPost2Catalog.count_of_certain_category(cat_rec.uid) page_num = int(num_of_cat / CMS_CFG['list_num']) + 1 cat_name = cat_rec.name kwd = { 'cat_name': cat_name, 'cat_slug': cat_slug, 'unescape': tornado.escape.xhtml_unescape, 'title': cat_name, 'router': router_post[cat_rec.kind], 'current_page': current_page_num, 'kind': cat_rec.kind } # tmpl = 'list/catalog_list.html' # Todo: review the following codes. if self.order: tmpl = 'list/catalog_list.html' else: tmpl = 'list/category_list.html' self.render(tmpl, catinfo=cat_rec, infos=MPost2Catalog.query_pager_by_slug(cat_slug, current_page_num, order=self.order), pager=tools.gen_pager_purecss( '/category/{0}'.format(cat_slug), page_num, current_page_num), userinfo=self.userinfo, html2text=html2text, unescape=tornado.escape.xhtml_unescape, cfg=CMS_CFG, kwd=kwd, router=router_post[cat_rec.kind])
def render(self, *args, **kwargs): tag_slug = args[0] current = int(args[1]) taginfo = MCategory.get_by_slug(tag_slug) num_of_tag = MPost2Catalog.count_of_certain_category(taginfo.uid) page_num = math_ceil(num_of_tag / config.CMS_CFG['list_num']) kwd = { 'page_home': False if current <= 1 else True, 'page_end': False if current >= page_num else True, 'page_pre': False if current <= 1 else True, 'page_next': False if current >= page_num else True, } return self.render_string('modules/post/tag_pager.html', kwd=kwd, cat_slug=tag_slug, pager_num=page_num, page_current=current)
def test_count_of_certain_category(self): MPost2Catalog.count_of_certain_category(self.tag_id) assert True