本文整理匯總了Python中wikidata.PageData.get_by方法的典型用法代碼示例。如果您正苦於以下問題:Python PageData.get_by方法的具體用法?Python PageData.get_by怎麽用?Python PageData.get_by使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wikidata.PageData
的用法示例。
在下文中一共展示了PageData.get_by方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: goto
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def goto(self, title):
page = PageData.get_by(pagename=title)
if page is None:
log.info('New wiki page: [%s]' % title)
PageData(pagename=title, data=u'')
self.content.becomes(Page(title))
示例2: edit
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def edit(self, comp):
content = comp.call(PageEditor(self))
if content is not None:
security.check_permissions('wiki.editor', self)
page = PageData.get_by(pagename=self.title)
page.data = content
示例3: init
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def init(self, url, *args):
title = url[1]
page = PageData.get_by(pagename=title)
if page is None:
raise presentation.HTTPNotFound()
self.goto(title)
示例4: _
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def _(self, user, perm, subject):
if user.has_permission('wiki.admin'):
return True
creator = PageData.get_by(pagename=subject.title).creator
if user.has_permission(perm) and (perm != 'wiki.editor' or (creator is None) or (creator == user.id)):
return True
return common.Denial()
示例5: render
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def render(self, h, comp, *args):
h << h.span('Viewing ') << h.b(self.title) << h.br
page = PageData.get_by(pagename=self.title)
if page.creator:
h << h.i('Created by ', page.creator) << h.br
h << 'You can return to the ' << h.a('FrontPage', href='page/FrontPage')
return h.root
示例6: render
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def render(self, h, comp, *args):
page = PageData.get_by(pagename=self.title)
with h.div:
h << h.pre(page.data)
# This link is added to every page displayed, to be able to edit it
h << h.a("Edit this page").action(self.edit, comp)
return h.root
示例7: render
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def render(self, h, comp, *args):
page = PageData.get_by(pagename=self.title)
content = docutils.core.publish_parts(page.data, writer_name='html')['html_body']
content = wikiwords.sub(r'<wiki>\1</wiki>', content)
html = h.parse_htmlstring(content, fragment=True)[0]
for node in html.getiterator():
if node.tag == 'wiki':
a = h.a(node.text, href='page/' + node.text).action(comp.answer, unicode(node.text))
node.replace(a)
return (html, h.a('Edit this page', href='page/' + self.title).action(self.edit, comp))
示例8: edit
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def edit(self, comp):
content = comp.call(PageEditor(self))
if content is not None:
log.info('New content for page [%s]: [%s...]' % (self.title, content[:50]))
security.check_permissions('wiki.editor', self)
page = PageData.get_by(pagename=self.title)
page.data = content
# If the creator of the page is not already set, set it with the
# current user
if page.creator is None:
page.creator = security.get_user().id
log.debug('New creator for page [%s]: [%s]' % (page.pagename, page.creator))
示例9: goto
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def goto(self, title):
"""Navigate to an other page
In:
- ``title`` -- title of the new page to display
"""
# Retrieve the new page data from the database
page = PageData.get_by(pagename=title)
if page is None:
# The new page doesn't exist, create it in database
PageData(pagename=title, data=u'')
# Permanently replace, into the component graph, the currently
# displayed page by the new one
self.content.becomes(Page(title))
示例10: render
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def render(self, h, comp, *args):
page = PageData.get_by(pagename=self.title)
# Translate the content in ``page.data`` to HTML
content = docutils.core.publish_parts(page.data, writer_name='html')['html_body']
# For each WikiWords found, create a pseudo tag '<wiki>WikiWord</<wiki>'
content = wikiwords.sub(r'<wiki>\1</wiki>', content)
# Parse the HTML into a elements tree
html = h.parse_htmlstring(content, fragment=True)[0]
# Found the '<wiki>' elements into the tree and transform them into active links
for node in html.getiterator():
if node.tag == 'wiki':
# Clicking on a WikiWord will answer the WikiWord unicode string
a = h.a(node.text).action(comp.answer, unicode(node.text))
# Replace the node
node.replace(a)
return (html, h.a('Edit this page').action(self.edit, comp))
示例11: edit
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def edit(self, comp):
"""Edit the content of this page:
1. a page editor is created
2. the page editor temporary replace the page in the component graph
3. it will return (and restore the page) with the new content of the
page
In:
- ``comp`` -- this component
"""
# A ``PageEditor`` object is created for ``self``
# It temporary replaces the current component (the page displayed)
content = comp.call(PageEditor(self))
# ``content`` is the new content for the page
# or ``None`` if the user canceled the modification
if content is not None:
# Retrieve the database object
page = PageData.get_by(pagename=self.title)
# Change the content
page.data = content
示例12: goto
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def goto(self, title):
page = PageData.get_by(pagename=title)
if page is None:
PageData(pagename=title, data=u'')
self.content.becomes(Page(title))
示例13: edit
# 需要導入模塊: from wikidata import PageData [as 別名]
# 或者: from wikidata.PageData import get_by [as 別名]
def edit(self, comp):
content = comp.call(PageEditor(self))
if content is not None:
page = PageData.get_by(pagename=self.title)
page.data = content