def render(self, *args, **kwargs): # kind = kwargs['kind'] if 'kind' in kwargs else '1' catid = kwargs['catid'] if 'catid' in kwargs else '' recs = MCatalog.query_all() return self.render_string('modules/catalog/catalog_list.html', recs=recs, catid=catid)
def test_query_all(self): self.add_message() aa = MCatalog.query_all() tf = False for i in aa: if i.slug == self.slug: tf = True assert tf self.tearDown()
def test_query_by_slug(self): self.add_message() aa = MCatalog.query_by_slug(self.slug) tf = False for i in aa: if i.uid == self.post_id: tf = True assert tf self.tearDown()
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} tmpl = 'list/catalog_list.html' self.render(tmpl, catinfo=cat_rec, infos=MCatalog.query_by_slug(cat_slug), pager=tools.gen_pager_purecss( '/category/{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])