本文整理汇总了Python中MoinMoin.Page.Page类的典型用法代码示例。如果您正苦于以下问题:Python Page类的具体用法?Python Page怎么用?Python Page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: breadcrumbs
def breadcrumbs(self, d, is_footer=False):
request = self.request
_ = request.getText
user = request.user
if not user.valid:
return ""
items = []
if user.show_page_trail:
trail = user.getTrail()
if trail:
for pagename in trail[::-1]:
try:
interwiki, page = wikiutil.split_interwiki(pagename)
if interwiki != request.cfg.interwikiname and interwiki != 'Self':
link = (
self.request.formatter.interwikilink(
True, interwiki, page) +
self.shortenPagename(page) +
self.request.formatter.interwikilink(
False, interwiki, page))
items.append(link)
continue
else:
pagename = page
except ValueError:
pass
page = Page(request, pagename)
title = page.split_title()
title = self.shortenPagename(title)
link = page.link_to(request, title)
items.append(link)
val = """ <div class="navbar breadcrumb">
<ul class="breadcrumb navbar-left">"""
for i, item in enumerate(items):
if i == 0:
val += '\n <li class="active">%s</li>' % item
else:
val += '\n <li>%s</li>' % item
val += '\n </ul>\n <ul class="breadcrumb navbar-right">'
actions = getattr(request.cfg, 'bootstrap_actions',
self.BREADCRUMB_ACTIONS)
for i, act in enumerate(actions):
if act[0].isupper() and not act in self.available_actions:
continue
val += '\n <li><a href="?action=%s%s">%s</a></li>' % (act, self.rev, self._actiontitle(act))
val += u"""
<li class="toggleCommentsButton" style="display:none;">
<a href="#" class="nbcomment" onClick="toggleComments(); return false;">%s</a>
</li>
%s
</ul>
</div>""" % (_('Comments'), self.actionsmenu(d, is_footer))
return val
示例2: getAttachDir
def getAttachDir(request, pagename, create=0):
""" Get directory where attachments for page `pagename` are stored. """
if request.page and pagename == request.page.page_name:
page = request.page # reusing existing page obj is faster
else:
page = Page(request, pagename)
return page.getPagePath("attachments", check_create=create)
示例3: _do_queued_updates
def _do_queued_updates(self, request, amount=5):
""" Assumes that the write lock is acquired """
self.touch()
writer = xapidx.Index(self.dir, True)
writer.configure(self.prefixMap, self.indexValueMap)
# do all page updates
pages = self.update_queue.pages()[:amount]
for name in pages:
p = Page(request, name)
if request.cfg.xapian_index_history:
for rev in p.getRevList():
self._index_page(writer, Page(request, name, rev=rev), mode='update')
else:
self._index_page(writer, p, mode='update')
self.update_queue.remove([name])
# do page/attachment removals
items = self.remove_queue.pages()[:amount]
for item in items:
_item = item.split('//')
p = Page(request, _item[0])
self._remove_item(writer, p, _item[1])
self.remove_queue.remove([item])
writer.close()
示例4: move_file
def move_file(request, pagename, new_pagename, attachment, new_attachment):
_ = request.getText
newpage = Page(request, new_pagename)
if newpage.exists(includeDeleted=1) and request.user.may.write(new_pagename) and request.user.may.delete(pagename):
new_attachment_path = os.path.join(getAttachDir(request, new_pagename,
create=1), new_attachment).encode(config.charset)
attachment_path = os.path.join(getAttachDir(request, pagename),
attachment).encode(config.charset)
if os.path.exists(new_attachment_path):
upload_form(pagename, request,
msg=_("Attachment '%(new_pagename)s/%(new_filename)s' already exists.") % {
'new_pagename': new_pagename,
'new_filename': new_attachment})
return
if new_attachment_path != attachment_path:
# move file
filesys.rename(attachment_path, new_attachment_path)
_addLogEntry(request, 'ATTDEL', pagename, attachment)
_addLogEntry(request, 'ATTNEW', new_pagename, new_attachment)
upload_form(pagename, request,
msg=_("Attachment '%(pagename)s/%(filename)s' moved to '%(new_pagename)s/%(new_filename)s'.") % {
'pagename': pagename,
'filename': attachment,
'new_pagename': new_pagename,
'new_filename': new_attachment})
else:
upload_form(pagename, request, msg=_("Nothing changed"))
else:
upload_form(pagename, request, msg=_("Page '%(new_pagename)s' does not exist or you don't have enough rights.") % {
'new_pagename': new_pagename})
示例5: macro_RandomQuote
def macro_RandomQuote(macro, pagename=u'FortuneCookies'):
_ = macro.request.getText
if macro.request.user.may.read(pagename):
page = Page(macro.request, pagename)
raw = page.get_raw_body()
else:
raw = ""
# this selects lines looking like a list item
# !!! TODO: make multi-line quotes possible (optionally split by "----" or something)
quotes = raw.splitlines()
quotes = [quote.strip() for quote in quotes]
quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
if not quotes:
return (macro.formatter.highlight(1) +
_('No quotes on %(pagename)s.') % {'pagename': pagename} +
macro.formatter.highlight(0))
quote = random.choice(quotes)
page.set_raw_body(quote, 1)
quote = macro.request.redirectedOutput(page.send_page,
content_only=1, content_id="RandomQuote")
return quote
示例6: pagelink
def pagelink(self, on, pagename="", page=None, **kw):
FormatterBase.pagelink(self, on, pagename, page, **kw)
if page is None:
page = Page(self.request, pagename, formatter=self)
link_text = page.link_to(self.request, on=on, **kw)
self._curr.xml_append(tree.text(U(link_text)))
return ""
示例7: _retrieve_members
def _retrieve_members(self, group_name):
"""
MoinMoin.formatter.groups is used to extract group members from a page.
"""
formatter = Formatter(self.request)
page = Page(self.request, group_name, formatter=formatter)
request_page = getattr(self.request, "page", None)
self.request.page = page
# send_special is set to True because acl of the page should
# not be processed to avoid infinite recursion in the
# following case.
#
# Consider page UserGroup content:
#
# #acl UserGroup:read,write,admin All:read
#
# * ExampleUser
# * TestGroup
#
page.send_page(content_only=True, send_special=True)
if request_page:
self.request.page = request_page
else:
del self.request.page
return formatter.members
示例8: handle_file_attached
def handle_file_attached(event):
"""Sends an email to super users that have subscribed to this event type"""
names = set()
from_address = event.request.cfg.mail_from
request = event.request
page = Page(request, event.pagename)
subscribers = page.getSubscribers(request, return_users=1)
notification.filter_subscriber_list(event, subscribers, False)
recipients = []
for lang in subscribers:
recipients.extend(subscribers[lang])
attachlink = request.getBaseURL() + getAttachUrl(event.pagename, event.filename, request)
pagelink = request.getQualifiedURL(page.url(request, {}))
for lang in subscribers:
emails = []
_ = lambda text: request.getText(text, lang=lang)
links = _("Attachment link: %(attach)s\n" \
"Page link: %(page)s\n") % {'attach': attachlink, 'page': pagelink}
data = notification.attachment_added(request, _, event.pagename, event.filename, event.size)
data['text'] = data['text'] + links
emails = [usr.email for usr in subscribers[lang]]
if send_notification(request, from_address, emails, data):
names.update(recipients)
return notification.Success(names)
示例9: parse
def parse(story):
"""
The main workhorse that does nothing but call MoinMoin to do its dirty
laundry
@param story: A text for conversion
@type story: string
@returns: formatted string
@rtype: string
"""
s = StringIO()
oldstdout = sys.stdout
form = None
page = Page(None)
page.hilite_re = None
request = Request()
request.user = User()
formatter = Formatter(request)
formatter.setPage(page)
sys.stdout = s
Parser(story, request).format(formatter, form)
sys.stdout = oldstdout
result = s.getvalue()
s.close()
return result
示例10: __init__
class PackagePages:
def __init__(self, pagename, request):
self.request = request
self.pagename = pagename
self.page = Page(request, pagename)
def allowed(self):
""" Check if user is allowed to do this. """
return not self.__class__.__name__ in self.request.cfg.actions_excluded
def render(self):
""" Render action
This action returns a wiki page with optional message, or
redirects to new page.
"""
_ = self.request.getText
if 'cancel' in self.request.values:
# User canceled
return self.page.send_page()
try:
if not self.allowed():
self.request.theme.add_msg(_('You are not allowed to edit this page.'), "error")
raise ActionError
elif not self.page.exists():
self.request.theme.add_msg(_('This page is already deleted or was never created!'))
raise ActionError
self.package()
except ActionError, e:
return self.page.send_page()
示例11: linkto
def linkto(pagename, request, params=''):
_ = request.getText
if not request.cfg.chart_options:
request.formatter = Formatter(request)
return text(pagename, request, params)
if _debug:
return draw(pagename, request)
page = Page(request, pagename)
# Create escaped query string from dict and params
querystr = {'action': 'chart', 'type': 'hitcounts'}
querystr = wikiutil.makeQueryString(querystr)
querystr = wikiutil.escape(querystr)
if params:
querystr += '&' + params
# TODO: remove escape=0 in 2.0
data = {'url': page.url(request, querystr, escape=0)}
data.update(request.cfg.chart_options)
result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"'
' alt="hitcounts chart">') % data
return result
示例12: trail
def trail(self, d):
""" Assemble page trail
@param d: parameter dictionary
@rtype: unicode
@return: trail html
"""
request = self.request
user = request.user
if user.valid and user.show_page_trail:
trail = user.getTrail()
if trail:
items = []
# Show all items except the last one which is this page.
for pagename in trail[:-1]:
page = Page(request, pagename)
title = page.split_title(request)
title = self.shortenPagename(title)
link = page.link_to(request, title)
items.append('<li>%s</li>' % link)
html = '''
<ul id="pagetrail">
%s
</ul>''' % '\n'.join(items)
return html
return ''
示例13: username
def username(self, d):
""" Assemble the username / userprefs link
@param d: parameter dictionary
@rtype: string
@return: username html
"""
from MoinMoin.Page import Page
request = self.request
_ = request.getText
userlinks = []
# Add username/homepage link for registered users. We don't care
# if it exists, the user can create it.
if request.user.valid:
homepage = Page(request, request.user.name)
title = homepage.split_title(request)
homelink = homepage.link_to(request, text=title)
userlinks.append(homelink)
# Set pref page to localized Preferences page
prefpage = wikiutil.getSysPage(request, 'UserPreferences')
title = prefpage.split_title(request)
userlinks.append(prefpage.link_to(request, text=title))
else:
# Add prefpage links with title: Login
prefpage = wikiutil.getSysPage(request, 'UserPreferences')
userlinks.append(prefpage.link_to(request, text=_("Login")))
html = '<ul id="username"><li>%s</li></ul>' % '</li>\n<li>'.join(userlinks)
return html
示例14: do_replaceunderlay
def do_replaceunderlay(self, filename, pagename):
"""
Overwrites underlay pages. Implementational detail: This needs to be
kept in sync with the page class.
@param filename: name of the file in the package
@param pagename: page to be overwritten
"""
page = Page(self.request, pagename)
pagedir = page.getPagePath(use_underlay=1, check_create=1)
revdir = os.path.join(pagedir, 'revisions')
cfn = os.path.join(pagedir, 'current')
revstr = '%08d' % 1
if not os.path.exists(revdir):
os.mkdir(revdir)
currentf = open(cfn, 'w')
currentf.write(revstr + "\n")
currentf.close()
pagefile = os.path.join(revdir, revstr)
self._extractToFile(filename, pagefile)
示例15: make_iconlink
def make_iconlink(self, which, d):
"""
Make a link with an icon
@param which: icon id (dictionary key)
@param d: parameter dictionary
@rtype: string
@return: html link tag
"""
page_name, querystr, title, icon = self.button_table[which]
d['title'] = title % d
d['i18ntitle'] = self.request.getText(d['title'], formatted=False)
img_src = self.make_icon(icon, d)
attrs = {'rel': 'nofollow', 'title': d['i18ntitle'], }
if page_name:
page = Page(self.request, page_name % d)
else:
page = d['page']
if self.is_moin_1_5: # Moin 1.5.x
url = wikiutil.quoteWikinameURL(page.page_name)
querystr = wikiutil.makeQueryString(querystr)
if querystr:
url = '%s?%s' % (url, querystr)
html = wikiutil.link_tag(self.request, url, img_src, title="%(i18ntitle)s" % d)
else: # Moin 1.6
rev = d['rev']
if rev and which in ['raw', 'print', ]:
querystr['rev'] = str(rev)
html = page.link_to_raw(self.request, text=img_src, querystr=querystr, **attrs)
return html