本文整理汇总了Python中Sycamore.Page.Page.url方法的典型用法代码示例。如果您正苦于以下问题:Python Page.url方法的具体用法?Python Page.url怎么用?Python Page.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sycamore.Page.Page
的用法示例。
在下文中一共展示了Page.url方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mapJS
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import url [as 别名]
def mapJS(wiki_name, page_locs, nearby_locs, request):
"""
Create a string containing javascript for google map
page = the page object
place = place object of center of map
nearby = dictionary of nearby places
"""
# pick center point as the first point if there's more than one point
# associated with the page
center = page_locs[0]
pagename = center.pagename
page = Page(pagename, request, wiki_name=wiki_name)
out = """
<script type="text/javascript">
//<![CDATA[
function doLoad() {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(%s,%s),16);
""" % (
center.latitude,
center.longitude,
)
nearbys_processed = {}
i = 0 # for 'a' 'b' labels on markers
if nearby_locs:
for x in nearby_locs:
nearby_page = Page(x.pagename, request, wiki_name=wiki_name)
if (x.pagename, x.latitude, x.longitude) in nearbys_processed:
# only plot a given nearby point once
# (it is sometimes easier to just have repeated nearbys
# in the query, hence we filter them out here)
continue
namestr = """'<b><a href="%s" target=_parent>%s</a></b>""" """<br>%s'""" % (
nearby_page.url(relative=False),
x.pagename.replace("'", "\\" + "'"),
x.address.replace("'", "\\" + "'"),
)
out += """
var point = new GLatLng(%s,%s);
map.addOverlay(createMarker(point,%s, %s));
""" % (
x.latitude,
x.longitude,
i,
namestr,
)
# add it as plotted
nearbys_processed[(x.pagename, x.latitude, x.longitude)] = None
i += 1
for x in page_locs:
namestr = """'<b><a href="%s" target=_parent>%s</a></b>""" """<br>%s'""" % (
page.url(relative=False),
x.pagename.replace("'", "\\" + "'"),
x.address.replace("'", "\\" + "'"),
)
out += (
"var p_point = new GLatLng(%s,%s);\n"
"var myArrow = createArrow(p_point,%s);\n"
"map.addOverlay(myArrow);\n"
"GEvent.trigger(myArrow,'click');" % (x.latitude, x.longitude, namestr)
)
out += """
loaded = true;
}
//]]>
</script>"""
return out
示例2: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import url [as 别名]
def execute(pagename, request):
_ = request.getText
page = Page(pagename, request)
actname = __name__.split('.')[-1]
if not request.user.may.admin(page):
msg = _("You don't have admin permissions on this page, "
"so you cannot change security settings.")
return page.send_page(msg)
if request.form.has_key('button'):
# process save
groups = []
groups_dict = {}
for key in request.form:
if key.endswith('_groupname'):
groups.append(unquoteWikiname(key[:-10]))
else:
if key.endswith('_may_read'):
dowhat = 'read'
groupname = unquoteWikiname(key[:-9])
elif key.endswith('_may_edit'):
dowhat = 'edit'
groupname = unquoteWikiname(key[:-9])
elif key.endswith('_may_delete'):
dowhat = 'delete'
groupname = unquoteWikiname(key[:-11])
elif key.endswith('_may_admin'):
dowhat = 'admin'
groupname = unquoteWikiname(key[:-10])
else:
continue
if not groups_dict.has_key(groupname):
groups_dict[groupname] = [False, False, False, False]
groups_dict[groupname][ACL_RIGHTS_TABLE[dowhat]] = True
# set groups we weren't sent any checkboxes for to
# all false (nothing checked)
groups_no_checks = filter(lambda(groupname): (
groupname not in groups_dict), groups)
for groupname in groups_no_checks:
groups_dict[groupname] = [False, False, False, False]
wikiacl.setACL(pagename, groups_dict, request)
return page.send_page(
msg = _("Security settings sucessfully changed!"))
formhtml = ['<h3>Security settings for "%s":</h3>' % pagename]
button = _("Save")
url = page.url()
d = {'url': url, 'actname': actname, 'button': button}
formhtml.append('<form method="POST" action="%(url)s">\n'
'<input type="hidden" name="action" value="%(actname)s">\n'
% d)
custom_groups = user.getGroupList(request, exclude_special_groups=True)
grouplist = ['All', 'Known'] + custom_groups
for groupname in grouplist:
# "All" and "Known" are a bit condense
if groupname == 'All':
written_groupname = 'Everybody'
elif groupname == 'Known':
written_groupname = 'Logged in people'
else:
written_groupname = groupname
group = wikiacl.Group(groupname, request, fresh=True)
# we want to show the 'change security' option only if
# it makes some sense
show_admin = groupname in custom_groups
formhtml.append('<h6>%s</h6>' % written_groupname)
formhtml.append('<input type="hidden" name="%s_groupname" '
'value="1">' % quoteWikiname(groupname))
if group.may(page, 'read'):
formhtml.append('<input type="checkbox" checked '
'name="%s_may_read" value="1">' %
quoteWikiname(groupname))
else:
formhtml.append('<input type="checkbox" name="%s_may_read" '
'value="1">' % quoteWikiname(groupname))
formhtml.append(' read ')
if group.may(page, 'edit'):
formhtml.append('<input type="checkbox" checked '
'name="%s_may_edit" value="1">' %
quoteWikiname(groupname))
else:
formhtml.append('<input type="checkbox" name="%s_may_edit" '
'value="1">' % quoteWikiname(groupname))
formhtml.append(' edit ')
if group.may(page, 'delete'):
formhtml.append('<input type="checkbox" checked '
'name="%s_may_delete" value="1">' %
quoteWikiname(groupname))
else:
#.........这里部分代码省略.........
示例3: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import url [as 别名]
def execute(pagename, request):
from Sycamore.PageEditor import PageEditor
_ = request.getText
actname = __name__.split('.')[-1]
page = Page(pagename, request)
permanent = False
showrc = True
if not request.user.may.edit(page):
return page.send_page(
msg = _('You are not allowed to revert this page!'))
# check whether the user clicked the delete button
if request.form.has_key('button') and request.form.has_key('ticket'):
# check whether this is a valid deletion request (make outside
# attacks harder by requiring two full HTTP transactions)
if not _checkTicket(request.form['ticket'][0]):
return page.send_page(
msg = _('Please use the interactive user interface to '
'revert pages!'))
# revert the page
if request.form.has_key('version'):
version = int(request.form['version'][0])
oldpg = Page(pagename, request, version=version)
date = oldpg.prev_date
if request.form.has_key('comment'):
entered_comment = request.form['comment'][0]
else:
entered_comment = ''
if len(entered_comment) > wikiaction.MAX_COMMENT_LENGTH:
return page.send_page(msg = _(
'Comments must be less than %s characters long.' %
wikiaction.MAX_COMMENT_LENGTH))
else:
comment = 'v%s' % str(version)
comment = "%sc%s" % (comment, entered_comment)
else:
return
if (request.form.has_key('permanent') and
request.form['permanent'][0] and request.user.may.admin(page)):
permanent = True
if (request.form.has_key('noshowrc') and
request.form['noshowrc'][0]):
showrc = False
pg = PageEditor(pagename, request)
savemsg = revert_to_page(oldpg, request, pg, comment=comment,
permanent=permanent, showrc=showrc)
return pg.send_page(msg=savemsg,
force_regenerate_content=(permanent and not
showrc))
# get version
if request.form.has_key('version'):
version = request.form['version'][0]
else:
return page.send_page(msg= _(
'Please use the interactive user interface to revert pages!'))
oldpg = Page(pagename, request, version=version)
# send revert form
url = page.url()
ticket = _createTicket()
button = _('Revert')
comment_label = _("Reason for the revert:")
if request.user.may.admin(page):
admin_label = (
'<p>Permanently remove newer versions: '
'<input id="noshowrctoggle" type="checkbox" name="permanent" '
'value="1"><span id="noshowrc">'
"Don't log on Recent Changes: "
'<input type="checkbox" name="noshowrc" value="1"></span></p>\n'
'<script type="text/javascript">\n'
"document.getElementById('noshowrc').style.visibility = "
"'hidden';\n"
"document.getElementById('noshowrc').style.paddingLeft = "
"'1em';\n"
"document.getElementById('noshowrctoggle').onclick = "
"function () {\n"
"document.getElementById('noshowrc').style.visibility = "
"document.getElementById('noshowrctoggle').checked ? "
"'visible' : 'hidden'; \n"
"}\n"
"</script>\n"
)
else:
admin_label = ''
formhtml = (
'<form method="GET" action="%(url)s">'
'<input type="hidden" name="action" value="%(actname)s">'
'<input type="hidden" name="ticket" value="%(ticket)s">'
'<input type="hidden" name="version" value="%(version)s">'
'<p>'
'%(comment_label)s'
'</p>'
'<input type="text" name="comment" size="60" maxlength="80">'
'<input type="submit" name="button" value="%(button)s">'
'%(admin_label)s'
#.........这里部分代码省略.........
示例4: testUrl
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import url [as 别名]
def testUrl(self):
"""Test's Page.url()."""
from Sycamore.Page import Page
from Sycamore import farm
list_of_wikis = self._get_list_of_wikis()
# relative, w/o query string
for trial in xrange(0, 200):
pagename = make_random_string(MAX_PAGENAME_LENGTH)
page = Page(pagename, self.request)
pagename = page.proper_name()
pagename_encoded = wikiutil.quoteWikiname(pagename)
proper_url = '/%s' % pagename_encoded
self.assertEqual(proper_url, page.url())
# relative, w/ query string
for trial in xrange(0, 200):
pagename = make_random_string(MAX_PAGENAME_LENGTH)
query = '?'
the_range = random.randint(0, 10)
for i in xrange(0, the_range):
if i < (the_range-1): amperstand = '&'
else: amperstand = ''
query += ('%s=%s%s' %
(make_random_string(50, alphanum_only=True),
make_random_string(50, alphanum_only=True),
amperstand))
page = Page(pagename, self.request)
pagename = page.proper_name()
pagename_encoded = wikiutil.quoteWikiname(pagename)
proper_url = '/%s?%s' % (pagename_encoded, query)
self.assertEqual(proper_url, page.url(querystr = query))
original_wiki_name = self.request.config.wiki_name
# absolute url, switched request
for wiki_trial in xrange(0, 10):
self.request.switch_wiki(random.choice(list_of_wikis))
for trial in xrange(0, 200):
pagename = make_random_string(MAX_PAGENAME_LENGTH)
farm_url = farm.getWikiURL(self.request.config.wiki_name,
self.request)
page = Page(pagename, self.request)
pagename = page.proper_name()
pagename_encoded = wikiutil.quoteWikiname(pagename)
proper_url = '%s%s' % (farm_url, pagename_encoded)
self.assertEqual(proper_url, page.url(relative=False))
for trial in xrange(0, 200):
pagename = make_random_string(MAX_PAGENAME_LENGTH)
farm_url = farm.getWikiURL(self.request.config.wiki_name,
self.request)
query = '?'
the_range = random.randint(0, 10)
for i in xrange(0, the_range):
if i < (the_range-1):
amperstand = '&'
else:
amperstand = ''
query += ('%s=%s%s' %
(make_random_string(50, alphanum_only=True),
make_random_string(50, alphanum_only=True),
amperstand))
page = Page(pagename, self.request)
pagename = page.proper_name()
pagename_encoded = wikiutil.quoteWikiname(pagename)
proper_url = '%s%s?%s' % (farm_url, pagename_encoded, query)
self.assertEqual(proper_url,
page.url(querystr=query, relative=False))
self.request.switch_wiki(original_wiki_name)
# absolute url, non-switched request
for wiki_trial in xrange(0, 10):
wiki_name = random.choice(list_of_wikis)
for trial in xrange(0, 200):
pagename = make_random_string(MAX_PAGENAME_LENGTH)
farm_url = farm.getWikiURL(wiki_name, self.request)
page = Page(pagename, self.request, wiki_name=wiki_name)
pagename = page.proper_name()
pagename_encoded = wikiutil.quoteWikiname(pagename)
proper_url = '%s%s' % (farm_url, pagename_encoded)
self.assertEqual(proper_url, page.url(relative=False))
for trial in xrange(0, 200):
pagename = make_random_string(MAX_PAGENAME_LENGTH)
farm_url = farm.getWikiURL(wiki_name, self.request)
query = '?'
the_range = random.randint(0, 10)
for i in xrange(0, the_range):
if i < (the_range-1):
amperstand = '&'
else:
amperstand = ''
query += ('%s=%s%s' %
(make_random_string(50, alphanum_only=True),
make_random_string(50, alphanum_only=True),
amperstand))
page = Page(pagename, self.request, wiki_name=wiki_name)
pagename = page.proper_name()
#.........这里部分代码省略.........
示例5: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import url [as 别名]
def execute(pagename, request):
"""
Send recent changes as an RSS document
"""
from Sycamore.formatter.text_html import Formatter
formatter = Formatter(request)
page = Page(pagename, request)
wiki_global = False
bookmarks = False
theuser = None
if request.form.has_key('user'):
# bookmarks
username = urllib.unquote_plus(request.form['user'][0])
if request.form.has_key('global') and request.form['global']:
wiki_global = True
theuser = user.User(request, name=username)
if request.form.has_key('bookmarks') and request.form['bookmarks']:
bookmarks = True
if bookmarks and theuser:
if not wiki_global:
rss_init_text = (
'<?xml version="1.0" ?>'
'<rss version="2.0" '
'xmlns:dc="http://purl.org/dc/elements/1.1/">'
'<channel><title>Bookmarks - %s @ %s</title><link>%s</link>'
'<description>Bookmarks for user %s on %s.</description>'
'<language>en-us</language>\n'
'</channel> \n'
'</rss>\n' %
(username, request.config.sitename,
user.getUserLinkURL(request, theuser), username,
request.config.sitename))
else:
rss_init_text = (
'<?xml version="1.0" ?>\n'
'<rss version="2.0" '
'xmlns:dc="http://purl.org/dc/elements/1.1/">'
'<channel><title>Interwiki Bookmarks - %s</title>'
'<link>%s</link>'
'<description>Interwiki bookmarks for user %s</description>'
'<language>en-us</language>\n'
'</channel>\n'
'</rss>\n' %
(username, user.getUserLinkURL(request, theuser), username))
userid = theuser.id
changes = wikidb.getRecentChanges(request, per_page_limit=1,
userFavoritesFor=userid,
wiki_global=wiki_global)
elif pagename.lower() == rc_pagename.lower():
rss_init_text = (
'<?xml version="1.0" ?>\n'
'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">'
'<channel><title>Recent Changes - %s</title><link>%s</link>'
'<description>Recent Changes on %s.</description>'
'<language>en-us</language>\n'
'</channel>\n'
'</rss>\n' %
(request.config.sitename, page.url(relative=False),
request.config.sitename))
# get normal recent changes
changes = wikidb.getRecentChanges(request, total_changes_limit=100)
elif pagename.lower() == interwiki_rc_pagename.lower() and theuser:
wiki_global = True
rss_init_text = (
'<?xml version="1.0" ?>\n'
'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n'
'<channel><title>Interwiki Recent Changes for %s</title>'
'<link>%s</link>'
'<description>Interwiki Recent Changes for %s.</description>'
'<language>en-us</language>\n'
'</channel>\n'
'</rss>\n' %
(theuser.propercased_name, page.url(relative=False),
theuser.propercased_name))
# get interwiki normal recent changes
changes = wikidb.getRecentChanges(request, total_changes_limit=100,
wiki_global=True,
on_wikis=theuser.getWatchedWikis())
else:
rss_init_text = (
'<?xml version="1.0" ?>\n'
'<rss version="2.0" '
'xmlns:dc="http://purl.org/dc/elements/1.1/">'
'<channel><title>Recent Changes for "%s" - %s</title>'
'<link>%s</link>'
'<description>Recent Changes of the page "%s" on %s.</description>'
'<language>en-us</language>\n'
'</channel>\n'
'</rss>\n' %
(pagename, request.config.sitename, page.url(relative=False),
pagename, request.config.sitename))
# get page-specific recent changes
changes = wikidb.getRecentChanges(request, page=pagename.lower())
rss_dom = xml.dom.minidom.parseString(rss_init_text)
channel = rss_dom.getElementsByTagName("channel")[0]
original_wiki = request.config.wiki_name
for line in changes:
#.........这里部分代码省略.........