本文整理汇总了Python中MoinMoin.Page.Page.url方法的典型用法代码示例。如果您正苦于以下问题:Python Page.url方法的具体用法?Python Page.url怎么用?Python Page.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.Page.Page
的用法示例。
在下文中一共展示了Page.url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: linkto
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
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
示例2: handle_file_attached
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
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)
示例3: handle_file_attached
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def handle_file_attached(event):
"""Handles event sent when a file is attached to a page"""
names = set()
request = event.request
page = Page(request, event.pagename)
subscribers = page.getSubscribers(request, return_users=1)
notification.filter_subscriber_list(event, subscribers, True)
recipients = []
for lang in subscribers:
recipients.extend(subscribers[lang])
attachlink = request.getQualifiedURL(getAttachUrl(event.pagename, event.filename, request))
pagelink = request.getQualifiedURL(page.url(request, {}))
for lang in subscribers.keys():
_ = lambda text: request.getText(text, lang=lang)
data = notification.attachment_added(request, _, event.pagename, event.filename, event.size)
links = [{'url': attachlink, 'description': _("Attachment link")},
{'url': pagelink, 'description': _("Page link")}]
jids = [usr.jid for usr in subscribers[lang]]
data['url_list'] = links
data['action'] = "file_attached"
if send_notification(request, jids, data):
names.update(recipients)
return notification.Success(names)
示例4: linkto
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def linkto(pagename, request, params=""):
from MoinMoin.util import web
_ = request.getText
if not request.cfg.chart_options:
request.formatter = Formatter(request)
return (
request.formatter.sysmsg(1)
+ request.formatter.text(_("Charts are not available!"))
+ request.formatter.sysmsg(0)
)
if _debug:
return draw(pagename, request)
page = Page(request, pagename)
# Create escaped query string from dict and params
querystr = {"action": "chart", "type": "hitcounts"}
querystr = web.makeQueryString(querystr)
querystr = wikiutil.escape(querystr)
if params:
querystr += "&" + params
# TODO: remove escape=0 in 1.4
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
示例5: linkto
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def linkto(pagename, request, params=''):
_ = request.getText
if not request.cfg.chart_options:
return (request.formatter.sysmsg(1) +
request.formatter.text(_('Charts are not available!')) +
request.formatter.sysmsg(0))
if _debug:
return draw(pagename, request)
page = Page(request, pagename)
# Create escaped query string from dict and params
querystr = {'action': 'chart', 'type': 'pagesize'}
querystr = wikiutil.makeQueryString(querystr)
querystr = wikiutil.escape(querystr)
if params:
querystr += '&' + params
data = {'url': page.url(request, querystr)}
data.update(request.cfg.chart_options)
result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"'
' alt="pagesize chart">') % data
return result
示例6: handle_action
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def handle_action(context, pagename, action_name='show'):
""" Actual dispatcher function for non-XMLRPC actions.
Also sets up the Page object for this request, normalizes and
redirects to canonical pagenames and checks for non-allowed
actions.
"""
_ = context.getText
cfg = context.cfg
# pagename could be empty after normalization e.g. '///' -> ''
# Use localized FrontPage if pagename is empty
if not pagename:
context.page = wikiutil.getFrontPage(context)
else:
context.page = Page(context, pagename)
if '_' in pagename and not context.page.exists():
pagename = pagename.replace('_', ' ')
page = Page(context, pagename)
if page.exists():
url = page.url(context)
return context.http_redirect(url)
msg = None
# Complain about unknown actions
if not action_name in get_names(cfg):
msg = _("Unknown action %(action_name)s.") % {
'action_name': wikiutil.escape(action_name), }
# Disallow non available actions
elif action_name[0].isupper() and not action_name in \
get_available_actions(cfg, context.page, context.user):
msg = _("You are not allowed to do %(action_name)s on this page.") % {
'action_name': wikiutil.escape(action_name), }
if not context.user.valid:
# Suggest non valid user to login
msg += " " + _("Login and try again.")
if msg:
context.theme.add_msg(msg, "error")
context.page.send_page()
# Try action
else:
from MoinMoin import action
handler = action.getHandler(context, action_name)
if handler is None:
msg = _("You are not allowed to do %(action_name)s on this page.") % {
'action_name': wikiutil.escape(action_name), }
if not context.user.valid:
# Suggest non valid user to login
msg += " " + _("Login and try again.")
context.theme.add_msg(msg, "error")
context.page.send_page()
else:
handler(context.page.page_name, context)
return context
示例7: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def execute(pagename, request):
log = editlog.EditLog(request)
try:
lastmod = wikiutil.version2timestamp(log.date())
except:
lastmod = 0
timestamp = timefuncs.formathttpdate(lastmod)
etag = "%d" % lastmod
# for 304, we look at if-modified-since and if-none-match headers,
# one of them must match and the other is either not there or must match.
if request.if_modified_since == timestamp:
if request.if_none_match:
if request.if_none_match == etag:
request.emit_http_headers(["Status: 304 Not modified"])
else:
request.emit_http_headers(["Status: 304 Not modified"])
elif request.if_none_match == etag:
if request.if_modified_since:
if request.if_modified_since == timestamp:
request.emit_http_headers(["Status: 304 Not modified"])
else:
request.emit_http_headers(["Status: 304 Not modified"])
else:
# generate an Expires header, using 1d cache lifetime of sisterpages list
expires = timefuncs.formathttpdate(time.time() + 24 * 3600)
httpheaders = [
"Content-Type: text/plain; charset=UTF-8",
"Expires: %s" % expires,
"Last-Modified: %s" % timestamp,
"Etag: %s" % etag,
]
# send the generated XML document
request.emit_http_headers(httpheaders)
baseurl = request.getBaseURL()
if not baseurl.endswith("/"):
baseurl += "/"
# Get list of user readable pages
pages = request.rootpage.getPageList()
pages.sort()
for pn in pages:
p = Page(request, pn)
entry = u"%s %s\r\n" % (request.getQualifiedURL(p.url(request)), p.page_name)
request.write(entry.encode("utf-8"))
示例8: info
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def info(pagename, request):
""" Generate snippet with info on the attachment for page `pagename`. """
_ = request.getText
attach_dir = getAttachDir(request, pagename)
files = []
if os.path.isdir(attach_dir):
files = os.listdir(attach_dir)
page = Page(request, pagename)
link = page.url(request, {'action': action_name})
attach_info = _('There are <a href="%(link)s">%(count)s attachment(s)</a> stored for this page.') % {
'count': len(files),
'link': wikiutil.escape(link)
}
return "\n<p>\n%s\n</p>\n" % attach_info
示例9: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def execute(pagename, request):
log = editlog.EditLog(request)
try:
lastmod = wikiutil.version2timestamp(log.date())
except:
lastmod = 0
timestamp = timefuncs.formathttpdate(lastmod)
etag = "%d" % lastmod
# for 304, we look at if-modified-since and if-none-match headers,
# one of them must match and the other is either not there or must match.
if request.if_modified_since == timestamp:
if request.if_none_match:
if request.if_none_match == etag:
request.status_code = 304
else:
request.status_code = 304
elif request.if_none_match == etag:
if request.if_modified_since:
if request.if_modified_since == timestamp:
request.status_code = 304
else:
request.status_code = 304
else:
# generate an Expires header, using 1d cache lifetime of sisterpages list
expires = time.time() + 24*3600
request.mimetype = 'text/plain'
request.expires = expires
request.last_modified = timestamp
request.headers['Etag'] = etag
# send the generated XML document
# Get list of user readable pages
pages = request.rootpage.getPageList()
pages.sort()
for pn in pages:
p = Page(request, pn)
entry = u"%s %s\r\n" % (request.getQualifiedURL(p.url(request)), p.page_name)
request.write(entry.encode('utf-8'))
示例10: linkto
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def linkto(pagename, request, params=""):
_ = request.getText
if not request.cfg.chart_options:
return text(pagename, request)
if _debug:
return draw(pagename, request)
page = Page(request, pagename)
# Create escaped query string from dict and params
querystr = {"action": "chart", "type": "useragents"}
querystr = wikiutil.makeQueryString(querystr)
querystr = wikiutil.escape(querystr)
if params:
querystr += "&" + params
data = {"url": page.url(request, querystr)}
data.update(request.cfg.chart_options)
result = ('<img src="%(url)s" width="%(width)d" height="%(height)d"' ' alt="useragents chart">') % data
return result
示例11: visit_reference
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def visit_reference(self, node):
"""
Pass links to MoinMoin to get the correct wiki space url. Extract
the url and pass it on to the html4css1 writer to handle. Inline
images are also handled by visit_image. Not sure what the "drawing:"
link scheme is used for, so for now it is handled here.
Also included here is a hack to allow MoinMoin macros. This routine
checks for a link which starts with "<<". This link is passed to the
MoinMoin formatter and the resulting markup is inserted into the
document in the place of the original link reference.
"""
if 'refuri' in node.attributes:
refuri = node['refuri']
prefix = ''
link = refuri
if ':' in refuri:
prefix, link = refuri.lstrip().split(':', 1)
# First see if MoinMoin should handle completely. Exits through add_wiki_markup.
if refuri.startswith('<<') and refuri.endswith('>>'): # moin macro
self.process_wiki_text(refuri)
self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
self.add_wiki_markup()
if prefix == 'drawing':
self.process_wiki_text("[[%s]]" % refuri)
self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
self.add_wiki_markup()
# From here down, all links are handled by docutils (except
# missing attachments), just fixup node['refuri'].
if prefix == 'attachment':
if not AttachFile.exists(self.request, self.request.page.page_name, link):
# Attachment doesn't exist, give to MoinMoin to insert upload text.
self.process_wiki_text("[[%s]]" % refuri)
self.wiki_text = self.fixup_wiki_formatting(self.wiki_text)
self.add_wiki_markup()
# Attachment exists, just get a link to it.
node['refuri'] = AttachFile.getAttachUrl(self.request.page.page_name, link, self.request)
if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
node['classes'].append(prefix)
elif prefix == 'wiki':
wiki_name, page_name = wikiutil.split_interwiki(link)
wikitag, wikiurl, wikitail, err = wikiutil.resolve_interwiki(self.request, wiki_name, page_name)
wikiurl = wikiutil.mapURL(self.request, wikiurl)
node['refuri'] = wikiutil.join_wiki(wikiurl, wikitail)
# Only add additional class information if the reference does
# not have a child image (don't want to add additional markup
# for images with targets).
if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
node['classes'].append('interwiki')
elif prefix != '':
# Some link scheme (http, file, https, mailto, etc.), add class
# information if the reference doesn't have a child image (don't
# want additional markup for images with targets).
# Don't touch the refuri.
if not [i for i in node.children if i.__class__ == docutils.nodes.image]:
node['classes'].append(prefix)
else:
# Default case - make a link to a wiki page.
pagename, anchor = wikiutil.split_anchor(refuri)
page = Page(self.request, wikiutil.AbsPageName(self.formatter.page.page_name, pagename))
node['refuri'] = page.url(self.request, anchor=anchor)
if not page.exists():
node['classes'].append('nonexistent')
html4css1.HTMLTranslator.visit_reference(self, node)
示例12: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
def execute(pagename, request, fieldname='value', titlesearch=0):
_ = request.getText
titlesearch = isTitleSearch(request)
# context is relevant only for full search
if titlesearch:
context = 0
else:
context = int(request.form.get('context', [0])[0])
# Get other form parameters
needle = request.form.get(fieldname, [''])[0]
case = int(request.form.get('case', [0])[0])
regex = int(request.form.get('regex', [0])[0]) # no interface currently
max_context = 1 # only show first `max_context` contexts XXX still unused
# check for sensible search term
striped = needle.strip()
if len(striped) == 0:
err = _('Please use a more selective search term instead '
'of {{{"%s"}}}') % needle
# send http headers
request.http_headers()
Page(request, pagename).send_page(request, msg=err)
return
# search the pages
from MoinMoin import search
query = search.QueryParser(case=case, regex=regex,
titlesearch=titlesearch).parse_query(needle)
results = search.searchPages(request, query)
# directly show a single hit
# XXX won't work with attachment search
# improve if we have one...
if len(results.hits) == 1:
page = Page(request, results.hits[0].page_name)
# TODO: remove escape=0 in 1.4
url = page.url(request, querystr={'highlight': query.highlight_re()},
escape=0)
request.http_redirect(url)
raise MoinMoinNoFooter
# send http headers
request.http_headers()
# This action generate data using the user language
request.setContentLanguage(request.lang)
# Setup for type of search
if titlesearch:
title = _('Title Search: "%s"')
results.sortByPagename()
else:
title = _('Full Text Search: "%s"')
results.sortByWeight()
wikiutil.send_title(request, title % needle, form=request.form,
pagename=pagename)
# Start content (important for RTL support)
formatter = Formatter(request)
request.write(formatter.startContent("content"))
# First search stats
request.write(results.stats(request, formatter))
# Then search results
info = not titlesearch
if context:
output = results.pageListWithContext(request, formatter, info=info,
context=context)
else:
output = results.pageList(request, formatter, info=info)
request.write(output)
# End content and send footer
request.write(formatter.endContent())
wikiutil.send_footer(request, pagename, editable=0, showactions=0,
form=request.form)
示例13: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
#.........这里部分代码省略.........
else:
newrev = rev2
newpage = Page(request, pagename, rev=newrev)
oldlog = oldpage.editlog_entry()
newlog = newpage.editlog_entry()
if not oldlog or not newlog:
# We use "No log entries found." msg because we already have i18n
# for that. Better would "At least one log entry was not found.".
request.theme.add_msg(_("No log entries found."), "error")
currentpage.send_page()
return
edit_count = abs(newrev - oldrev)
# Start output
# This action generates content in the user language
request.setContentLanguage(request.lang)
request.theme.send_title(_('Diff for "%s"') % (pagename, ), pagename=pagename, allow_doubleclick=1)
f = request.formatter
request.write(f.div(1, id="content"))
oldrev = oldpage.get_real_rev()
newrev = newpage.get_real_rev()
title = _('Differences between revisions %d and %d') % (oldrev, newrev)
if edit_count > 1:
title += ' ' + _('(spanning %d versions)') % (edit_count, )
title = f.text(title)
page_url = wikiutil.escape(currentpage.url(request), True)
def enabled(val):
return not val and u' disabled="disabled"' or u''
revert_html = ""
if request.user.may.revert(pagename):
revert_html = """
<form action="%s" method="get">
<div style="text-align:center">
<input name="action" value="revert" type="hidden">
<input name="rev" value="%d" type="hidden">
<input value="%s" type="submit"%s>
</div>
</form>
""" % (page_url, rev2, _("Revert to this revision"), enabled(newrev < currentrev))
other_diff_button_html = """
<td style="border:0;">
<form action="%s" method="get">
<div style="text-align:%s">
<input name="action" value="diff" type="hidden">
<input name="rev1" value="%d" type="hidden">
<input name="rev2" value="%d" type="hidden">
<input value="%s" type="submit"%s>
</div>
</form>
</td>
"""
navigation_html = """
<span class="diff-header">%%s</span>
<table class="diff">
示例14: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
#.........这里部分代码省略.........
result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!')) % from_re)
to_re = args.group('to')
if to_re:
try:
to_match = re.compile(to_re, re.M).search(body, from_pos)
except re.error:
to_match = re.compile(re.escape(to_re), re.M).search(body, from_pos)
if to_match:
to_pos = to_match.start()
else:
result.append(_sysmsg % ('warning', 'Include: ' + _('Nothing found for "%s"!')) % to_re)
if titlesonly:
levelstack = []
for title, level in extract_titles(body[from_pos:to_pos], title_re):
if levelstack:
if level > levelstack[-1]:
result.append(macro.formatter.bullet_list(1))
levelstack.append(level)
else:
while levelstack and level < levelstack[-1]:
result.append(macro.formatter.bullet_list(0))
levelstack.pop()
if not levelstack or level != levelstack[-1]:
result.append(macro.formatter.bullet_list(1))
levelstack.append(level)
else:
result.append(macro.formatter.bullet_list(1))
levelstack.append(level)
result.append(macro.formatter.listitem(1))
result.append(inc_page.link_to(request, title))
result.append(macro.formatter.listitem(0))
while levelstack:
result.append(macro.formatter.bullet_list(0))
levelstack.pop()
continue
if from_pos or to_pos != -1:
inc_page.set_raw_body(body[from_pos:to_pos], modified=True)
##result.append("*** f=%s t=%s ***" % (from_re, to_re))
##result.append("*** f=%d t=%d ***" % (from_pos, to_pos))
if not hasattr(request, "_Include_backto"):
request._Include_backto = this_page.page_name
# do headings
level = None
if args.group('heading') and args.group('hquote'):
heading = args.group('htext') or inc_page.split_title()
level = 1
if args.group('level'):
level = int(args.group('level'))
if print_mode:
result.append(macro.formatter.heading(1, level) +
macro.formatter.text(heading) +
macro.formatter.heading(0, level))
else:
url = inc_page.url(request)
result.extend([
macro.formatter.heading(1, level, id=heading),
macro.formatter.url(1, url, css="include-heading-link"),
macro.formatter.text(heading),
macro.formatter.url(0),
macro.formatter.heading(0, level),
])
# set or increment include marker
this_page._macroInclude_pagelist[inc_name] = \
this_page._macroInclude_pagelist.get(inc_name, 0) + 1
# output the included page
strfile = StringIO.StringIO()
request.redirect(strfile)
try:
inc_page.send_page(content_only=True,
omit_footnotes=True,
count_hit=False)
result.append(strfile.getvalue())
finally:
request.redirect()
# decrement or remove include marker
if this_page._macroInclude_pagelist[inc_name] > 1:
this_page._macroInclude_pagelist[inc_name] = \
this_page._macroInclude_pagelist[inc_name] - 1
else:
del this_page._macroInclude_pagelist[inc_name]
# if no heading and not in print mode, then output a helper link
if editlink and not (level or print_mode):
result.extend([
macro.formatter.div(1, css_class="include-link"),
inc_page.link_to(request, '[%s]' % (inc_name, ), css_class="include-page-link"),
inc_page.link_to(request, '[%s]' % (_('edit'), ), css_class="include-edit-link", querystr={'action': 'edit', 'backto': request._Include_backto}),
macro.formatter.div(0),
])
# XXX page.link_to is wrong now, it escapes the edit_icon html as it escapes normal text
# return include text
return ''.join(result)
示例15: execute
# 需要导入模块: from MoinMoin.Page import Page [as 别名]
# 或者: from MoinMoin.Page.Page import url [as 别名]
#.........这里部分代码省略.........
f = request.formatter
request.write(f.div(1, id="content"))
oldrev = oldpage.get_real_rev()
newrev = newpage.get_real_rev()
revlist = currentpage.getRevList()
# code below assumes that the page exists and has at least
# one revision in the revlist, just bail out if not. Users
# shouldn't really run into this anyway.
if not revlist:
request.write(f.div(0)) # end content div
request.theme.send_footer(pagename)
request.theme.send_closing_html()
return
title = _('Differences between revisions %d and %d') % (oldrev, newrev)
if edit_count > 1:
title += ' ' + _('(spanning %d versions)') % (edit_count, )
title = f.text(title)
# Revision list starts from 2...
if oldrev == min(revlist):
disable_prev = u' disabled="disabled"'
else:
disable_prev = u''
if newrev == max(revlist):
disable_next = u' disabled="disabled"'
else:
disable_next = u''
page_url = wikiutil.escape(currentpage.url(request), True)
revert_html = ""
if request.user.may.revert(pagename):
revert_html = """
<td style="border:0">
<form action="%s" method="get">
<div style="text-align:center">
<input name="action" value="revert" type="hidden">
<input name="rev" value="%d" type="hidden">
<input value="%s" type="submit"%s>
</div>
</form>
</td>
""" % (page_url, rev2, _("Revert to this revision"), disable_next)
navigation_html = """
<span class="diff-header">%s</span>
<table class="diff">
<tr>
<td style="border:0">
<form action="%s" method="get">
<div style="text-align:left">
<input name="action" value="diff" type="hidden">
<input name="rev1" value="%d" type="hidden">
<input name="rev2" value="%d" type="hidden">
<input value="%s" type="submit"%s>
</div>
</form>
</td>
%s
<td style="border:0">
<form action="%s" method="get">