本文整理汇总了Python中r2.models.wiki.WikiRevision.get方法的典型用法代码示例。如果您正苦于以下问题:Python WikiRevision.get方法的具体用法?Python WikiRevision.get怎么用?Python WikiRevision.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.wiki.WikiRevision
的用法示例。
在下文中一共展示了WikiRevision.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GET_policy_page
# 需要导入模块: from r2.models.wiki import WikiRevision [as 别名]
# 或者: from r2.models.wiki.WikiRevision import get [as 别名]
def GET_policy_page(self, page, requested_rev):
if c.render_style == 'compact':
self.redirect('/wiki/' + page)
if page == 'privacypolicy':
wiki_name = g.wiki_page_privacy_policy
pagename = _('privacy policy')
elif page == 'useragreement':
wiki_name = g.wiki_page_user_agreement
pagename = _('user agreement')
elif page == 'contentpolicy':
wiki_name = g.wiki_page_content_policy
pagename = _('content policy')
else:
abort(404)
wp = WikiPage.get(Frontpage, wiki_name)
revs = list(wp.get_revisions())
# collapse minor edits into revisions with reasons
rev_info = []
last_edit = None
for rev in revs:
if rev.is_hidden:
continue
if not last_edit:
last_edit = rev
if rev._get('reason'):
rev_info.append({
'id': str(last_edit._id),
'title': rev._get('reason'),
})
last_edit = None
if requested_rev:
try:
display_rev = WikiRevision.get(requested_rev, wp._id)
except (tdb_cassandra.NotFound, WikiBadRevision):
abort(404)
else:
display_rev = revs[0]
doc_html = wikimarkdown(display_rev.content, include_toc=False)
soup = BeautifulSoup(doc_html.decode('utf-8'))
toc = generate_table_of_contents(soup, prefix='section')
self._number_sections(soup)
self._linkify_headings(soup)
content = PolicyView(
body_html=unsafe(soup),
toc_html=unsafe(toc),
revs=rev_info,
display_rev=str(display_rev._id),
)
return PolicyPage(
pagename=pagename,
content=content,
).render()
示例2: validversion
# 需要导入模块: from r2.models.wiki import WikiRevision [as 别名]
# 或者: from r2.models.wiki.WikiRevision import get [as 别名]
def validversion(self, version, pageid=None):
if not version:
return
try:
r = WikiRevision.get(version, pageid)
if not self.allow_hidden_revision and (r.is_hidden and not c.is_wiki_mod):
self.set_error('HIDDEN_REVISION', code=403)
raise AbortWikiError
return r
except (tdb_cassandra.NotFound, ValueError):
self.set_error('INVALID_REVISION', code=404)
raise AbortWikiError
示例3: validversion
# 需要导入模块: from r2.models.wiki import WikiRevision [as 别名]
# 或者: from r2.models.wiki.WikiRevision import get [as 别名]
def validversion(self, version, pageid=None):
if not version:
return
try:
r = WikiRevision.get(version, pageid)
if r.admin_deleted and not c.user_is_admin:
self.set_error("INVALID_REVISION", code=404)
raise AbortWikiError
if not self.allow_hidden_revision and (r.is_hidden and not c.is_wiki_mod):
self.set_error("HIDDEN_REVISION", code=403)
raise AbortWikiError
return r
except (tdb_cassandra.NotFound, WikiBadRevision):
self.set_error("INVALID_REVISION", code=404)
raise AbortWikiError