本文整理汇总了Python中wikidata.PageData类的典型用法代码示例。如果您正苦于以下问题:Python PageData类的具体用法?Python PageData怎么用?Python PageData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageData类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: goto
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
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
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: _
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
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
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
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
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
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
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
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
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
def edit(self, comp):
content = comp.call(PageEditor(self))
if content is not None:
page = PageData.get_by(pagename=self.title)
page.data = content