本文整理匯總了Python中torcms.model.mpost.MPost.query_random方法的典型用法代碼示例。如果您正苦於以下問題:Python MPost.query_random方法的具體用法?Python MPost.query_random怎麽用?Python MPost.query_random使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torcms.model.mpost.MPost
的用法示例。
在下文中一共展示了MPost.query_random方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post_random
# 需要導入模塊: from torcms.model.mpost import MPost [as 別名]
# 或者: from torcms.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('tmpl_torlite/modules/post_list.html',
recs=recs, kwd=kwd)
示例2: CategoryHandler
# 需要導入模塊: from torcms.model.mpost import MPost [as 別名]
# 或者: from torcms.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.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()
示例3: rel_app2post
# 需要導入模塊: from torcms.model.mpost import MPost [as 別名]
# 或者: from torcms.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': 'info',
'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('infor/modules/relation_app2post.html',
relations= rel_recs,
rand_recs = rand_recs,
kwd=kwd, )
示例4: PostHandler
# 需要導入模塊: from torcms.model.mpost import MPost [as 別名]
# 或者: from torcms.model.mpost.MPost import query_random [as 別名]
class PostHandler(BaseHandler):
def initialize(self):
self.init()
self.mpost = MPost()
self.mcat = MCatalog()
self.cats = self.mcat.query_all()
self.mpost_hist = MPostHist()
self.mpost2catalog = MPost2Catalog()
self.mpost2reply = MPost2Reply()
self.mapp2tag = MPost2Label()
self.mrel = MRelation()
self.tmpl_router = 'post'
def get(self, url_str=''):
url_arr = self.parse_url(url_str)
if url_str == '':
self.recent()
elif 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])
elif url_arr[0] == 'ajax_count_plus':
self.ajax_count_plus(url_arr[1])
else:
kwd = {
'info': '頁麵未找到',
}
self.render('html/404.html', kwd=kwd,
userinfo=self.userinfo, )
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 ajax_count_plus(self, uid):
output = {
'status': 1 if self.mpost.update_view_count_by_uid(uid) else 0,
}
return json.dump(output, self)
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,
cfg=config.cfg,
)
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,
cfg=config.cfg, )
def get_random(self):
return self.mpost.query_random()
def wiki(self, uid):
dbdate = self.mpost.get_by_id(uid)
if dbdate:
self.viewit(uid)
#.........這裏部分代碼省略.........