本文整理汇总了Python中torcms.model.mpost.MPost类的典型用法代码示例。如果您正苦于以下问题:Python MPost类的具体用法?Python MPost怎么用?Python MPost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MPost类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_whoosh_database
def build_whoosh_database():
analyzer = ChineseAnalyzer()
schema = Schema(title=TEXT(stored=True, analyzer=analyzer), type=TEXT(stored=True), link=ID(stored=True),
content=TEXT(stored=True, analyzer=analyzer))
ix = create_in(whoosh_database, schema)
writer = ix.writer()
uu = MApp()
tt = uu.get_all()
for rec in tt:
text2 = html2text.html2text(tornado.escape.xhtml_unescape(rec.cnt_html))
writer.add_document(
title=rec.title,
type='<span style="color:red;">[信息]</span>',
link='/info/{0}'.format(rec.uid),
content= text2,
)
mpost = MPost()
recs = mpost.query_all()
for rec in recs:
text2 = html2text.html2text(tornado.escape.xhtml_unescape(rec.cnt_html))
print(text2)
writer.add_document(
title=rec.title,
type='<span style="color:blue;">[文档]</span>',
link='/post/{0}.html'.format(rec.uid),
content=text2
)
writer.commit()
示例2: IndexHandler
class IndexHandler(BaseHandler):
def initialize(self):
self.init()
self.mpost = MPost()
self.mcat = MCatalog()
self.mpage = MPage()
self.mlink = MLink()
def get_current_user(self):
return self.get_secure_cookie("user")
def get(self, input=''):
if input == '':
self.index()
else:
self.render('html/404.html', kwd={}, userinfo=self.userinfo)
def index(self):
cstr = tools.get_uuid()
self.set_cookie('user_pass', cstr)
kwd = {
'cookie_str': cstr
}
self.render('index/index.html',
userinfo=self.userinfo,
catalog_info=self.mcat.query_all(by_order=True),
link=self.mlink.query_all(),
unescape=tornado.escape.xhtml_unescape,
cfg=config.cfg,
view=self.mpost.query_most_pic(20),
kwd=kwd, )
示例3: render
def render(self, current_id):
self.mpost = MPost()
prev_record = self.mpost.get_previous_record(current_id)
if prev_record is None:
outstr = '<a>已经是最后一篇了</a>'
else:
outstr = '''<a href="/post/{0}.html">上一篇</a>'''.format(prev_record.uid, prev_record.title)
return outstr
示例4: post_most_view
class post_most_view(tornado.web.UIModule):
def render(self, num, with_date=True, with_catalog=True):
self.mpost = MPost()
recs = self.mpost.query_most(num)
kwd = {
'with_date': with_date,
'with_catalog': with_catalog,
}
return self.render_string('tmpl_torlite/modules/post_list.html', recs=recs, kwd=kwd)
示例5: render
def render(self, cat_id, num, with_date=True, with_catalog=True):
self.mpost = MPost()
recs = self.mpost.query_cat_random(cat_id, num)
kwd = {
'with_date': with_date,
'with_catalog': with_catalog,
}
return self.render_string('doc/modules/post_list.html',
recs=recs, kwd=kwd)
示例6: initialize
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'
示例7: RelHandler
class RelHandler(BaseHandler):
def initialize(self):
self.init()
self.mapp = MApp()
self.mpost = MPost()
self.rel_post2app = MRelPost2App()
self.rel_app2post = MRelApp2Post()
def get(self, url_str=''):
if len(url_str) > 0:
ip_arr = url_str.split('/')
else:
return False
if len(ip_arr) == 2:
self.add_relation(ip_arr)
def check_app(self, tt, uid):
if tt == 'post':
if False == self.mpost.get_by_id(uid):
return False
if tt == 'app':
if False == self.mapp.get_by_uid(uid):
return False
return True
def add_relation(self, url_arr):
if self.check_app(url_arr[0], url_arr[1]):
pass
else:
return False
last_post_id = self.get_secure_cookie('last_post_uid')
if last_post_id:
last_post_id = last_post_id.decode('utf-8')
last_app_id = self.get_secure_cookie('use_app_uid')
if last_app_id:
last_app_id = last_app_id.decode('utf-8')
if url_arr[0] == 'info':
if last_post_id:
self.rel_post2app.add_relation(last_post_id, url_arr[1], 2)
self.rel_app2post.add_relation(url_arr[1], last_post_id, 1)
if url_arr[0] == 'post':
if last_app_id:
self.rel_app2post.add_relation(last_app_id, url_arr[1], 2)
self.rel_post2app.add_relation(url_arr[1], last_app_id, 1)
示例8: render
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, )
示例9: CategoryHandler
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()
示例10: initialize
def initialize(self):
self.init()
self.mapp = MApp()
self.mpost = MPost()
self.rel_post2app = MRelPost2App()
self.rel_app2post = MRelApp2Post()
示例11: initialize
def initialize(self):
self.init()
self.mpost = MPost()
self.mcat = MCatalog()
self.cats = self.mcat.query_all()
self.mpost2catalog = MPost2Catalog()
示例12: PostHandler
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)
#.........这里部分代码省略.........
示例13: initialize
def initialize(self):
self.init()
self.mpost = MPost()
self.mcat = MCatalog()
self.mpage = MPage()
self.mlink = MLink()