當前位置: 首頁>>代碼示例>>Python>>正文


Python MCatalog.get_by_slug方法代碼示例

本文整理匯總了Python中torcms.model.mcatalog.MCatalog.get_by_slug方法的典型用法代碼示例。如果您正苦於以下問題:Python MCatalog.get_by_slug方法的具體用法?Python MCatalog.get_by_slug怎麽用?Python MCatalog.get_by_slug使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torcms.model.mcatalog.MCatalog的用法示例。


在下文中一共展示了MCatalog.get_by_slug方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: catalog_pager

# 需要導入模塊: from torcms.model.mcatalog import MCatalog [as 別名]
# 或者: from torcms.model.mcatalog.MCatalog import get_by_slug [as 別名]
class catalog_pager(tornado.web.UIModule):
    def render(self, *args, **kwargs):
        self.mpost2catalog = MPost2Catalog()
        self.mcat = MCatalog()

        cat_slug = args[0]
        current = int(args[1])
        # cat_slug 分類
        # current 當前頁麵

        cat_rec = self.mcat.get_by_slug(cat_slug)
        num_of_cat = self.mpost2catalog.catalog_record_number(cat_rec.uid)

        tmp_page_num = int(num_of_cat / config.page_num)

        page_num = tmp_page_num if abs(tmp_page_num - num_of_cat / config.page_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('tmpl_torlite/modules/catalog_pager.html',
                                  kwd = kwd,
                                  cat_slug = cat_slug,
                                  pager_num = page_num,
                                  page_current = current,
                                  )
開發者ID:Sijiu,項目名稱:TorCMS,代碼行數:33,代碼來源:base_modules.py

示例2: CategoryHandler

# 需要導入模塊: from torcms.model.mcatalog import MCatalog [as 別名]
# 或者: from torcms.model.mcatalog.MCatalog import get_by_slug [as 別名]
class CategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mpost2catalog = MPost2Catalog()


    def get(self, url_str=''):
        url_arr = self.parse_url(url_str)

        if len(url_arr) == 1:
            self.list_catalog(url_str)
        elif len(url_arr) == 2:
            self.list_catalog(url_arr[0], url_arr[1])
        else:
            self.render('html/404.html')

    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 = self.mcat.get_by_slug(cat_slug)
        num_of_cat = self.mpost2catalog.count_of_certain_catalog(cat_rec.uid)
        page_num = int(num_of_cat / config.page_num) + 1
        cat_name = cat_rec.name
        kwd = {
            'cat_name': cat_name,
            'cat_slug': cat_slug,
            'unescape': tornado.escape.xhtml_unescape,
            'title': cat_name,
            'current_page': current_page_num
        }

        self.render('doc/catalog/list.html',
                    infos=self.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,
                    cfg = config.cfg,
                    kwd=kwd)

    def get_random(self):
        return self.mpost.query_random()
開發者ID:ivonlee,項目名稱:TorCMS,代碼行數:49,代碼來源:category_handler.py


注:本文中的torcms.model.mcatalog.MCatalog.get_by_slug方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。