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 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 test_query_pager_by_slug(self): kwargs = {'slug': 'awer'} self.add_message(**kwargs) self.add_P2C() a = MPost2Catalog.query_pager_by_slug(kwargs['slug']) assert a[0].uid == self.post_id self.tearDown()
def viewinfo(self, postinfo): ''' In infor. :param postinfo: :return: ''' self.redirect_kind(postinfo) ###################################################### if DB_CFG['kind'] == 's': cat_enum1 = [] else: ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else '' ext_catid2 = postinfo.extinfo[ 'def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else [] ###################################################### catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) catalog_infors = None if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag_id) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) catalog_infors = MPost2Catalog.query_pager_by_slug(catinfo.slug, current_page_num=1, order=True) kwd = self._the_view_kwd(postinfo) MPost.update_misc(postinfo.uid, count=True) if self.get_current_user(): MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) tmpl = 'post_{0}/leaf_view.html'.format(self.kind) logger.info('The Info Template: {0}'.format(tmpl)) self.render(tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, userinfo=self.userinfo, catinfo=catinfo, pcatinfo=p_catinfo, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=MPost2Label.get_by_uid(postinfo.uid), catalog_infos=catalog_infors, cat_enum=cat_enum1)
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 viewinfo(self, postinfo): ''' In infor. :param postinfo: :return: ''' logger.warning('info kind:{0} '.format(postinfo.kind)) # If not, there must be something wrong. if postinfo.kind == self.kind: pass else: self.redirect('/{0}/{1}'.format(router_post[postinfo.kind], postinfo.uid), permanent=True) ###################################################### if DB_CFG['kind'] == 's': cat_enum1 = [] else: ext_catid = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else '' ext_catid2 = postinfo.extinfo['def_cat_uid'] if 'def_cat_uid' in postinfo.extinfo else None cat_enum1 = MCategory.get_qian2(ext_catid2[:2]) if ext_catid else [] ###################################################### catinfo = None p_catinfo = None post2catinfo = MPost2Catalog.get_first_category(postinfo.uid) catalog_infors = None if post2catinfo: catinfo = MCategory.get_by_uid(post2catinfo.tag.uid) if catinfo: p_catinfo = MCategory.get_by_uid(catinfo.pid) catalog_infors = MPost2Catalog.query_pager_by_slug(catinfo.slug, current_page_num=1, order=True) kwd = { 'pager': '', 'url': self.request.uri, 'daohangstr': '', 'signature': postinfo.uid, 'tdesc': '', 'eval_0': MEvaluation.app_evaluation_count(postinfo.uid, 0), 'eval_1': MEvaluation.app_evaluation_count(postinfo.uid, 1), 'login': 1 if self.get_current_user() else 0, 'has_image': 0, 'parentlist': MCategory.get_parent_list(), 'parentname': '', 'catname': '', 'router': router_post[postinfo.kind] } MPost.update_misc(postinfo.uid, count=True) if self.get_current_user(): MUsage.add_or_update(self.userinfo.uid, postinfo.uid, postinfo.kind) tmpl = 'post_{0}/leaf_view.html'.format(self.kind) logger.info('The Info Template: {0}'.format(tmpl)) self.render(tmpl, kwd=dict(kwd, **self.ext_view_kwd(postinfo)), postinfo=postinfo, userinfo=self.userinfo, catinfo=catinfo, pcatinfo=p_catinfo, unescape=tornado.escape.xhtml_unescape, ad_switch=random.randint(1, 18), tag_info=MPost2Label.get_by_uid(postinfo.uid), catalog_infos=catalog_infors, cat_enum=cat_enum1)
def test_query_pager_by_slug(self): slug = 'aaaa' MPost2Catalog.query_pager_by_slug(slug) assert True