当前位置: 首页>>代码示例>>Python>>正文


Python MPost.query_random方法代码示例

本文整理汇总了Python中torlite.model.mpost.MPost.query_random方法的典型用法代码示例。如果您正苦于以下问题:Python MPost.query_random方法的具体用法?Python MPost.query_random怎么用?Python MPost.query_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torlite.model.mpost.MPost的用法示例。


在下文中一共展示了MPost.query_random方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_random

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]
class post_random(tornado.web.UIModule):
    def render(self, num, with_date=True, with_catalog=True):
        self.mpost = MPost()
        recs = self.mpost.query_random(num)
        kwd = {
            'with_date': with_date,
            'with_catalog': with_catalog,
        }
        return self.render_string('tplite/modules/post_list.html', recs=recs, kwd=kwd)
开发者ID:Ryan007,项目名称:TorCMS,代码行数:11,代码来源:core_modules.py

示例2: post_random

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]
class post_random(tornado.web.UIModule):
    def render(self, num, with_date=True, with_catalog=True):
        self.mpost = MPost()
        recs = self.mpost.query_random(num)
        kwd = {
            'with_date': with_date,
            'with_catalog': with_catalog,
        }
        return self.render_string('{0}/modules/post_list.html'.format(config.torlite_template_name), recs=recs, kwd=kwd)
开发者ID:vaveee,项目名称:TorCMS,代码行数:11,代码来源:modef.py

示例3: CategoryHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]
class CategoryHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost2catalog = MPost2Catalog()
        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, input=''):
        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == '':
            pass
        elif len(ip_arr) == 1:
            self.list_catalog(input)
        elif len(ip_arr) == 2:
            self.list_catalog(ip_arr[0], ip_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)

        cat_rec = self.mcat.get_by_slug(cat_slug)
        num_of_cat = self.mpost2catalog.catalog_record_number(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,
        }

        self.render('{0}/catalog/list.html'.format(self.tmpl_name),
                    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,
                    kwd=kwd)

    def get_random(self):
        return self.mpost.query_random()
开发者ID:net4nt,项目名称:TorCMS,代码行数:54,代码来源:category_handler.py

示例4: CategoryHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [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.catalog_record_number(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('{0}/catalog/list.html'.format(self.tmpl_name),
                    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:hitrustnet,项目名称:TorCMS,代码行数:49,代码来源:category_handler.py

示例5: rel_app2post

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]
class rel_app2post(tornado.web.UIModule):
    def render(self, uid, num, ):
        self.mpost = MPost()
        self.relation = MRelApp2Post()
        kwd = {
            'app_f': app_url_name,
            'app_t': 'post',
            'uid': uid,
        }
        rel_recs = self.relation.get_app_relations(uid, num)

        rand_recs = self.mpost.query_random(num - rel_recs.count() + 2)

        return self.render_string('app_theme/modules/relation_app2post.html',
                                  relations= rel_recs,
                                  rand_recs = rand_recs,
                                  kwd=kwd, )
开发者ID:ironhot,项目名称:maplet,代码行数:19,代码来源:extends.py

示例6: CatHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]
class CatHandler(BaseHandler):
    def initialize(self):

        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost2catalog = MPost2Catalog()

    def get(self, input=''):
        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == '':
            pass
        elif len(ip_arr) == 1 :
            self.list_catalog(input)
        elif len(ip_arr) == 2:
            self.list_catalog(ip_arr[0], ip_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)

        cat_rec = self.mcat.get_by_slug(cat_slug)
        num_of_cat = self.mpost2catalog.catalog_record_number(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,
        }

        self.render('tplite/catalog/list.html',
                    infos=self.mpost2catalog.query_pager_by_slug(cat_slug,current_page_num),
                    pager = tools.gen_pager(cat_slug, page_num, current_page_num),
                    kwd=kwd)

    # def view_cat_old(self, cat_slug, cur_p=''):
    #     if cur_p == '':
    #         current = 1
    #     else:
    #         current = int(cur_p)
    #
    #     cat_rec = self.mcat.get_by_slug(cat_slug)
    #     num_of_cat = self.mpost.get_num_by_cat(cat_rec.id_cat)
    #     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,
    #         'pager': tools.gen_pager(cat_slug, page_num, current),
    #         'title': cat_name,
    #     }
    #     for x in self.cats:
    #         if x.slug == cat_slug:
    #             search_str = ',{0},'.format(x.id_cat)
    #     dbdata = self.mpost.query_cat_by_pager(search_str, current)
    #     self.render('tplite/post/all.html',
    #                 kwd = kwd,
    #                 view=dbdata,
    #                 rand_recs = self.get_random(),
    #                 format_date = tools.format_date)



    def get_random(self):
        return self.mpost.query_random()
开发者ID:Geoion,项目名称:TorCMS,代码行数:78,代码来源:cat_handler.py

示例7: PostHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]
class PostHandler(BaseHandler):
    def initialize(self):
        self.init()
        self.muser = MUser()
        self.mpost = MPost()
        self.mcat = MCatalog()
        self.cats = self.mcat.query_all()
        self.mspec = SpesubModel()
        self.specs = self.mspec.get_all()
        self.mpost_hist = MPostHist()
        self.mpost2catalog = MPost2Catalog()
        self.mpost2reply = MPost2Reply()
        self.mapp2tag = MPost2Label()
        self.mrel = MRelation()
        self.tmpl_router = 'post'

        if self.get_current_user():
            self.userinfo = self.muser.get_by_id(self.get_current_user())
        else:
            self.userinfo = None

    def get(self, url_str=''):

        if url_str == '':
            self.recent()
        url_arr = url_str.split('/')

        if len(url_arr) == 1 and url_str.endswith('.html'):
            self.wiki(url_str.split('.')[0])

        elif url_str == 'add_document':
            self.to_add_document()
        elif url_str == 'recent':
            self.recent()
        elif url_str == 'refresh':
            self.refresh()
        elif (url_arr[0] == 'modify'):
            self.to_modify(url_arr[1])
        elif url_arr[0] == 'delete':
            self.delete(url_arr[1])

        else:
            kwd = {
                'info': '页面未找到',
            }
            self.render('html/404.html', kwd=kwd)

    def post(self, url_str=''):
        if url_str == '':
            return
        url_arr = url_str.split('/')

        if len(url_arr) == 1 and url_str.endswith('.html'):
            self.add_post()
        if url_arr[0] == 'modify':
            self.update(url_arr[1])
        elif url_str == 'add_document':
            self.user_add_post()
        elif url_arr[0] == 'add_document':
            self.user_add_post()
        else:
            self.redirect('/html/404.html')

    def recent(self, with_catalog=True, with_date=True):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '最近文档',
            'with_catalog': with_catalog,
            'with_date': with_date,
        }
        self.render('{0}/{1}/post_list.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    view=self.mpost.query_recent(),
                    view_all=self.mpost.query_all(),
                    format_date=tools.format_date,
                    userinfo=self.userinfo,
                    )

    def refresh(self):

        kwd = {
            'pager': '',
            'title': '最近文档',
        }
        self.render('{0}/{1}/post_list.html'.format(self.tmpl_name, self.tmpl_router),
                    kwd=kwd,
                    userinfo=self.userinfo,
                    view=self.mpost.query_dated(10),
                    format_date=tools.format_date,
                    unescape=tornado.escape.xhtml_unescape, )

    def get_random(self):
        return self.mpost.query_random()

    def wiki(self, uid):
        dbdate = self.mpost.get_by_id(uid)
        if dbdate:
            self.mpost.update_view_count_by_uid(dbdate.uid)
            self.viewit(uid)
#.........这里部分代码省略.........
开发者ID:southwestjiaotongunivercity,项目名称:TorCMS,代码行数:103,代码来源:post_handler.py

示例8: PostHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]

#.........这里部分代码省略.........
                    view=self.mpost.query_recent(),
                    # rand_recs=self.get_random(),
                    format_date=tools.format_date, )

    def refresh(self):
        kwd = {
            'pager': '',

            'title': '最近文档',
        }
        self.render('tplite/post/all.html'.format(input),
                    kwd=kwd,
                    view=self.mpost.query_dated(60),
                    format_date=tools.format_date,
                    unescape=tornado.escape.xhtml_unescape, )

    def post_find(self):
        keyword = self.get_argument('keyword')
        self.find(keyword)

    def find(self, keyword):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '查找结果',
        }
        self.render('tplite/post/find_list.html'.format(input),
                    kwd=kwd,
                    view=self.mpost.get_by_keyword(keyword),
        )


    def get_random(self):
        return self.mpost.query_random()

    def view_cat(self, cat_slug):
        for x in self.cats:
            if x.slug == cat_slug:
                search_str = ',{0},'.format(x.id_cat)
        dbdata = self.mpost.query_by_cat(search_str)
        self.render('tplite/post/all.html', view=dbdata, unescape=tornado.escape.xhtml_unescape)

    def wiki(self, uid):
        dbdate = self.mpost.get_by_id(uid)
        if dbdate:
            self.mpost.update_view_count_by_uid(dbdate.uid)
            self.viewit(dbdate)
        else:
            self.to_add(uid)

    @tornado.web.authenticated
    def to_add(self, uid):
        kwd = {
            'cats': self.cats,
            'specs': self.specs,
            'uid': uid,
            'pager': '',
        }
        self.render('tplite/post/addwiki.html', kwd=kwd, tag_infos=self.mcat.query_all(), )

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mpost.get_by_id(uid)
        if self.userinfo.privilege[2] == '1' or raw_data.user_name == self.get_current_user():
            pass
        else:
开发者ID:Geoion,项目名称:TorCMS,代码行数:70,代码来源:post_handler.py

示例9: PostHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]

#.........这里部分代码省略.........
        self.render("tplite/post/find.html", topmenu="", kwd=kwd)

    def recent(self):
        kwd = {"pager": "", "unescape": tornado.escape.xhtml_unescape, "title": "最近文档"}
        self.render(
            "tplite/post/all.html".format(input),
            kwd=kwd,
            view=self.mpost.query_recent(),
            format_date=tools.format_date,
            userinfo=self.userinfo,
        )

    def refresh(self):

        kwd = {"pager": "", "title": "最近文档"}
        self.render(
            "tplite/post/refresh.html",
            kwd=kwd,
            userinfo=self.userinfo,
            view=self.mpost.query_dated(10),
            format_date=tools.format_date,
            unescape=tornado.escape.xhtml_unescape,
        )

    def post_find(self):
        keyword = self.get_argument("keyword")
        self.find(keyword)

    def find(self, keyword):
        kwd = {"pager": "", "unescape": tornado.escape.xhtml_unescape, "title": "查找结果"}
        self.render("tplite/post/find_list.html".format(input), kwd=kwd, view=self.mpost.get_by_keyword(keyword))

    def get_random(self):
        return self.mpost.query_random()

    def view_cat(self, cat_slug):
        for x in self.cats:
            if x.slug == cat_slug:
                search_str = ",{0},".format(x.id_cat)
        dbdata = self.mpost.query_by_cat(search_str)
        self.render("tplite/post/all.html", view=dbdata, unescape=tornado.escape.xhtml_unescape)

    def wiki(self, uid):
        dbdate = self.mpost.get_by_id(uid)
        if dbdate:
            self.mpost.update_view_count_by_uid(dbdate.uid)
            self.viewit(uid)
        else:

            self.to_add(uid)

    def to_add_document(self,):
        kwd = {"pager": "", "cats": self.cats, "specs": self.specs, "uid": ""}
        self.render(
            "tplite/post/addwiki.html", topmenu="", kwd=kwd, tag_infos=self.mcat.query_all(), userinfo=self.userinfo
        )

    @tornado.web.authenticated
    def to_add(self, uid):
        kwd = {"cats": self.cats, "specs": self.specs, "uid": uid, "pager": ""}
        self.render("tplite/post/addwiki.html", kwd=kwd, tag_infos=self.mcat.query_all())

    @tornado.web.authenticated
    def update(self, uid):
        raw_data = self.mpost.get_by_id(uid)
        if self.userinfo.privilege[2] == "1" or raw_data.user_name == self.get_current_user():
开发者ID:Ryan007,项目名称:TorCMS,代码行数:70,代码来源:post_handler.py

示例10: PostHandler

# 需要导入模块: from torlite.model.mpost import MPost [as 别名]
# 或者: from torlite.model.mpost.MPost import query_random [as 别名]

#.........这里部分代码省略.........
                    userinfo=self.userinfo,
        )

    def refresh(self):

        kwd = {
            'pager': '',
            'title': '最近文档',
        }
        self.render('tplite/post/refresh.html',
                    kwd=kwd,
                    userinfo=self.userinfo,
                    view=self.mpost.query_dated(10),
                    format_date=tools.format_date,
                    unescape=tornado.escape.xhtml_unescape, )

    def post_find(self):
        keyword = self.get_argument('keyword')
        self.find(keyword)

    def find(self, keyword):
        kwd = {
            'pager': '',
            'unescape': tornado.escape.xhtml_unescape,
            'title': '查找结果',
        }
        self.render('tplite/post/find_list.html'.format(input),
                    kwd=kwd,
                    view=self.mpost.get_by_keyword(keyword),
        )


    def get_random(self):
        return self.mpost.query_random()

    def view_cat(self, cat_slug):
        for x in self.cats:
            if x.slug == cat_slug:
                search_str = ',{0},'.format(x.id_cat)
        dbdata = self.mpost.query_by_cat(search_str)
        self.render('tplite/post/all.html', view=dbdata, unescape=tornado.escape.xhtml_unescape)

    def wiki(self, uid):
        dbdate = self.mpost.get_by_id(uid)
        if dbdate:
            self.mpost.update_view_count_by_uid(dbdate.uid)
            self.viewit(uid)
        else:

            self.to_add(uid)

    def to_add_document(self, ):
        kwd = {
            'pager': '',
            'cats': self.cats,
            'specs': self.specs,
            'uid': '',

        }
        self.render('tplite/post/addwiki.html', topmenu='',
                    kwd=kwd,
                    tag_infos=self.mcat.query_all(),
                    userinfo = self.userinfo,
        )

开发者ID:smzhao,项目名称:TorCMS,代码行数:68,代码来源:post_handler.py


注:本文中的torlite.model.mpost.MPost.query_random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。