本文整理汇总了Python中Sycamore.Page.Page.link_to方法的典型用法代码示例。如果您正苦于以下问题:Python Page.link_to方法的具体用法?Python Page.link_to怎么用?Python Page.link_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sycamore.Page.Page
的用法示例。
在下文中一共展示了Page.link_to方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def execute(macro, args, formatter):
if not formatter:
formatter = macro.formatter
# get number of wanted links
try:
links = max(int(args), 1)
except StandardError:
links = 1
# select the pages from the page list
random_list = wikiutil.getRandomPages(macro.request)
pages = []
while len(pages) < links and random_list:
pagename = random.choice(random_list)
page = Page(pagename, macro.request)
if macro.request.user.may.read(page) and page.exists() and not page.isRedirect():
if page.proper_name()[0:6] != 'Users/' and page.proper_name()[-5:] != '/Talk':
pages.append(page)
# return a single page link
if links == 1:
return pages[0].link_to()
# return a list of page links
pages.sort()
result = [macro.formatter.bullet_list(1)]
for page in pages:
result.append("%s%s%s" %
(macro.formatter.listitem(1), page.link_to(),
macro.formatter.listitem(0)))
result.append(macro.formatter.bullet_list(0))
return ''.join(result)
示例2: do_user_browser
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def do_user_browser(request):
""" Browser for SystemAdmin macro. """
from Sycamore.util.dataset import TupleDataset, Column
from Sycamore.Page import Page
_ = request.getText
data = TupleDataset()
data.columns = [
Column('id', label=('ID'), align='right'),
Column('name', label=('Username')),
Column('email', label=('Email')),
Column('action', label=_('Action')),
]
# Iterate over users
for uid in user.getUserList(self.request.cursor):
account = user.User(request, uid)
userhomepage = Page(account.name, self.request)
if userhomepage.exists():
namelink = userhomepage.link_to()
else:
namelink = account.name
data.addRow((
request.formatter.code(1) + uid + request.formatter.code(0),
request.formatter.rawHTML(namelink),
request.formatter.url('mailto:' + account.email, account.email,
'external', pretty_url=1, unescaped=1),
'',
))
if data:
from Sycamore.widget.browser import DataBrowserWidget
browser = DataBrowserWidget(request)
browser.setData(data)
return browser.toHTML()
# No data
return ''
示例3: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def execute(macro, args, formatter=None):
if not formatter:
formatter = macro.formatter
cursor = macro.request.cursor
cursor.execute("""
SELECT c.propercased_name, count(c.source_pagename) as cnt
FROM (
SELECT curPages.propercased_name, links.source_pagename
FROM curPages LEFT JOIN links on
(links.source_pagename=curPages.name and
links.wiki_id=%(wiki_id)s and
curPages.wiki_id=%(wiki_id)s)
WHERE curPages.wiki_id=%(wiki_id)s
) as c
GROUP BY c.propercased_name ORDER BY cnt""",
{'wiki_id': macro.request.config.wiki_id})
results = cursor.fetchall()
old_count = -1
for entry in results:
name = entry[0]
lower_name = name.lower()
if skip_page(name):
continue
new_count = entry[1]
page = Page(name, macro.request)
if new_count == 0 and page.isRedirect():
continue
if new_count != old_count:
old_count = new_count
macro.request.write(macro.formatter.heading(2, str(new_count)))
else:
macro.request.write(", ")
macro.request.write(page.link_to(know_status=True,
know_status_exists=True))
return ''
示例4: format_page_edits
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def format_page_edits(request, lines, showcomments, bookmark, formatter,
wiki_global=False, grouped_by_wiki=False):
_ = request.getText
d = {} # dict for passing stuff to theme
line = lines[0]
d['show_comments'] = showcomments
pagename = line.pagename
tnow = time.time()
# check whether this page is newer than the user's bookmark
hilite = line.ed_time > (bookmark or line.ed_time)
if wiki_global:
page = Page(line.pagename, request, wiki_name=line.wiki_name)
else:
page = Page(line.pagename, request)
# we can infer 'exists?' from current rc data in some cases
getPageStatus(lines, pagename, request)
html_link = format_page_edit_icon(request, lines, page, hilite, bookmark,
formatter)
# print name of page, with a link to it
force_split = len(page.page_name) > _MAX_PAGENAME_LENGTH
d['rc_tag_html'] = html_link
if wiki_global:
if not grouped_by_wiki:
on_wiki = (' <span class="minorText">(on %s)</span>' %
farm.link_to_wiki(line.wiki_name, formatter))
else:
on_wiki = ''
d['pagelink_html'] = '%s%s' % (
page.link_to(text=pagename, absolute=True), on_wiki)
else:
d['pagelink_html'] = page.link_to(text=pagename)
# print time of change
d['time_html'] = None
if config.changed_time_fmt:
tdiff = int(tnow - line.ed_time) / 60
if tdiff < 1440:
numhrs = int(tdiff/60)
nummins = tdiff%60
txthrs = ""
txttime = ""
if numhrs == 1:
txthrs = '1 hour'
if numhrs > 1:
txthrs = '%s hours' % str(numhrs)
txttime = txthrs
if nummins == 1:
txttime = '%s 1 minute' % str(txthrs)
if nummins > 1:
txttime = '%s %s minutes' % (str(txthrs), str(nummins))
if nummins == 0 and numhrs == 0:
numsecs = int(tnow - line.ed_time) % 60
txttime = '%s second' % str(numsecs)
if numsecs > 1:
txttime = '%ss' % txttime
d['time_html'] = '%s ago' % txttime
else:
d['time_html'] = time.strftime("at %I:%M %p", line.time_tuple)
# print editor name or IP
d['editors'] = []
if config.show_hosts:
for idx in range(len(lines)):
name = getEditor(lines[idx], request)
ip = lines[idx].host
d['editors'].append((name,ip))
comments = []
for idx in range(len(lines)):
comment = Comment(request, lines[idx].comment,
lines[idx].action, page).render()
comments.append(comment)
d['changecount'] = len(lines)
d['comments'] = comments
return request.theme.recentchanges_entry(d)
示例5: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def execute(macro, args, formatter=None):
if not formatter:
formatter = macro.formatter
_ = macro.request.getText
# prevent recursive calls
global _guard
if _guard:
return ""
# flush the request output because orphaned may take time to generate
macro.request.flush()
# delete all linked pages from a dict of all pages
_guard = 1
cursor = macro.request.cursor
cursor.execute(
"""
SELECT curPages.propercased_name
FROM curPages LEFT JOIN links on
(links.destination_pagename=curPages.name and
links.wiki_id=%(wiki_id)s and curPages.wiki_id=%(wiki_id)s
)
WHERE curPages.wiki_id=%(wiki_id)s and
links.destination_pagename is NULL""",
{"wiki_id": macro.request.config.wiki_id},
)
orphanednames_result = cursor.fetchall()
_guard = 0
# check for the extreme case
if not orphanednames_result:
return "<p>%s</p>" % _("No orphaned pages in this wiki.")
# return a list of page links
from Sycamore.Page import Page
redirects = []
pages = []
show_users = showUsers(macro.request)
for entry in orphanednames_result:
name = entry[0]
if name.startswith(config.user_page_prefix) and not show_users:
continue
page = Page(name, macro.request)
is_redirect = False
# if not macro.request.user.may.read(name): continue
if page.isRedirect():
redirects.append(page)
else:
pages.append(page)
# usually 'Orphaned Pages' or something such
pagename = macro.request.getPathinfo()[1:]
if not show_users:
macro.request.write(
'<div style="float: right;">'
'<div class="actionBoxes"><span>'
"%s"
"</span></div></div>" % wikiutil.link_tag(macro.request, pagename + "?show_users=true", "show users")
)
else:
macro.request.write(
'<div style="float: right;">'
'<div class="actionBoxes"><span>'
"%s"
"</span></div></div>" % wikiutil.link_tag(macro.request, pagename, "hide users")
)
macro.request.write(macro.formatter.heading(2, "Orphans"))
macro.request.write(macro.formatter.bullet_list(1))
for page in pages:
macro.request.write(macro.formatter.listitem(1))
macro.request.write(page.link_to(know_status=True, know_status_exists=True))
macro.request.write(macro.formatter.listitem(0))
macro.request.write(macro.formatter.bullet_list(0))
macro.request.write(macro.formatter.heading(2, "Orphaned Redirects"))
macro.request.write(macro.formatter.bullet_list(1))
for page in redirects:
macro.request.write(macro.formatter.listitem(1))
macro.request.write(page.link_to(know_status=True, know_status_exists=True))
macro.request.write(macro.formatter.listitem(0))
macro.request.write(macro.formatter.bullet_list(0))
return "" # macros must return strings
示例6: execute
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def execute(macro, args, formatter=None):
if not formatter:
formatter = macro.formatter
request = macro.request
if args:
# personalized stats
htmltext = []
theuser = user.User(macro.request, name=args.lower())
wiki_info = theuser.getWikiInfo()
if not wiki_info.first_edit_date:
first_edit_date = "<em>unknown</em>"
else:
first_edit_date = request.user.getFormattedDateTime(
wiki_info.first_edit_date)
created_count = wiki_info.created_count
edit_count = wiki_info.edit_count
file_count = wiki_info.file_count
last_page_edited = wiki_info.last_page_edited
last_edit_date = wiki_info.last_edit_date
if not last_edit_date:
last_edit_date = "<em>unknown</em>"
else:
last_edit_date = request.user.getFormattedDateTime(last_edit_date)
if last_page_edited:
htmltext.append(
'<p><h2>%s\'s Statistics</h2></p>'
'<table width=100%% border=0><tr>'
'<td><b>Edits </b></td>'
'<td><b>Pages Created </b></td>'
'<td><b>Files Contributed </b></td>'
'<td><b>First Edit Date </b></td>'
'<td><b>Last Edit </b></td>'
'<td><b>Last Page Edited </b></td></tr>' % args)
htmltext.append('<tr>'
'<td>%s</td><td>%s</td><td>%s</td><td>%s</td>'
'<td>%s</td><td>%s</td>'
'</tr></table>' %
(edit_count, created_count, file_count,
first_edit_date, last_edit_date,
Page(last_page_edited, request).link_to()))
elif edit_count or wiki_info.first_edit_date:
htmltext.append('<p><h2>%s\'s Statistics</h2></p>'
'<table width=100%% border=0><tr>'
'<td><b>Edits </b></td>'
'<td><b>Pages Created </b></td>'
'<td><b>Files Contributed </b></td>'
'<td><b>First Edit Date </b></td>'
'<td><b>Last Edit </b></td>'
'<td><b>Last Page Edited </b></td>'
'</tr>' % args)
htmltext.append('<tr>'
'<td>%s</td><td>%s</td><td>%s</td><td>%s</td>'
'<td>%s</td><td> </td>'
'</tr></table>' %
(edit_count, created_count, file_count,
first_edit_date, last_edit_date))
else:
htmltext.append('<p>' + macro.formatter.highlight(1) +
'The user "%s" has not edited this wiki.' % args +
macro.formatter.highlight(0) + '</p>')
else:
htmltext = []
sort_by = 'edit_count'
if macro.request.form.has_key('sort_by'):
sort_by = macro.request.form['sort_by'][0]
# this is to prevent SQL exploits
if sort_by not in ['edit_count', 'created_count',
'first_edit_date', 'file_count',
'last_edit_date']:
sort_by = 'edit_count'
list = []
cursor = macro.request.cursor
if sort_by == 'first_edit_date':
cursor.execute(
"""SELECT users.propercased_name, userWikiInfo.first_edit_date,
userWikiInfo.created_count, userWikiInfo.edit_count,
userWikiInfo.file_count,
userWikiInfo.last_page_edited,
userWikiInfo.last_edit_date,
userWikiInfo.first_edit_date IS NULL AS join_isnull
FROM userWikiInfo, users
WHERE users.name !='' and userWikiInfo.edit_count > 0 and
users.name=userWikiInfo.user_name and
userWikiInfo.wiki_id=%%(wiki_id)s
ORDER BY join_isnull ASC, %s DESC""" % sort_by,
{'wiki_id':macro.request.config.wiki_id})
elif sort_by == 'last_edit_date':
cursor.execute(
"""SELECT users.propercased_name, userWikiInfo.first_edit_date,
userWikiInfo.created_count, userWikiInfo.edit_count,
userWikiInfo.file_count,
userWikiInfo.last_page_edited,
userWikiInfo.last_edit_date,
userWikiInfo.last_edit_date IS NULL AS edit_isnull
FROM users, userWikiInfo
WHERE users.name !='' and userWikiInfo.edit_count > 0 and
users.name=userWikiInfo.user_name and
#.........这里部分代码省略.........
示例7: checkSpelling
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def checkSpelling(page, request, own_form=1):
"""
Do spell checking, return a tuple with the result.
"""
_ = request.getText
# first check to see if we we're called with a "newwords" parameter
if request.form.has_key('button_newwords'):
_addLocalWords(request)
# load words
wordsdict = _loadDict(request)
localwords = {}
lsw_page = Page(request.config.page_local_spelling_words, request)
if lsw_page.exists():
_loadWordsString(request, localwords, lsw_page.get_raw_body())
# init status vars & load page
badwords = {}
text = page.get_raw_body()
# checker regex and matching substitute function
word_re = re.compile(r'([%s]?[%s]+)' % (
config.upperletters, config.lowerletters))
def checkword(match, wordsdict=wordsdict, badwords=badwords,
localwords=localwords, num_re=re.compile(r'^\d+$')):
word = match.group(1)
if len(word) == 1:
return ""
if not (wordsdict.has_key(word) or
wordsdict.has_key(word.lower()) or
localwords.has_key(word) or
localwords.has_key(word.lower()) ):
if not num_re.match(word):
badwords[word] = 1
return ""
# do the checking
for line in text.encode('utf-8').split('\n'):
if line == '' or line[0] == '#': continue
word_re.sub(checkword, line)
if badwords:
badwords = badwords.keys()
badwords.sort(lambda x,y: cmp(x.lower(), y.lower()))
# build regex recognizing the bad words
badwords_re = r'(^|(?<!\w))(%s)(?!\w)'
badwords_re = badwords_re % ("|".join(map(re.escape, badwords)),)
# XXX UNICODE re.UNICODE !?
badwords_re = re.compile(badwords_re)
lsw_msg = ''
if localwords:
lsw_msg = ' ' + _('(including %(localwords)d %(pagelink)s)') % {
'localwords': len(localwords), 'pagelink': lsw_page.link_to()}
msg = _('The following %(badwords)d words could not be found '
'in the dictionary of '
'%(totalwords)d words%(localwords)s and are '
'highlighted below:') % {
'badwords': len(badwords),
'totalwords': len(wordsdict)+len(localwords),
'localwords': lsw_msg} + "<br>"
# figure out what this action is called
action_name = os.path.splitext(os.path.basename(__file__))[0]
# add a form containing the bad words
if own_form:
msg = msg + (
'<form method="POST" action="%s">'
'<input type="hidden" name="action" value="%s">'
% (page.url(request), action_name,))
checkbox = ('<input type="checkbox" name="newwords" '
'value="%(word)s">%(word)s ')
msg = msg + (
" ".join(map(
lambda w, cb=checkbox: cb % {'word': wikiutil.escape(w),},
badwords)) +
'<p><input type="submit" name="button_newwords" value="%s"></p>' %
_('Add checked words to dictionary')
)
if own_form:
msg = msg + '</form>'
else:
badwords_re = None
msg = _("No spelling errors found!")
return badwords, badwords_re, msg
示例8: render_favorites
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
def render_favorites(local_favoriteList, request, formatter, macro,
wiki_global):
seen_list = []
line_of_text = ''
for page_line in local_favoriteList:
page = Page(page_line.pagename, request,
wiki_name=page_line.wiki_name)
page_line.comment = Comment(request, page_line.comment,
page_line.action, page=page).render()
bookmark = request.user.getFavBookmark(page)
# in the case of uploads/deletes of images, etc we'd like to show
# a useful comment
page_line.time_tuple = request.user.getTime(page_line.ed_time)
day = page_line.time_tuple[0:3]
if not wiki_global:
wiki_link = ''
else:
wiki_link = ('<span class="minorText">(on %s)</span>' %
farm.link_to_wiki(page_line.wiki_name, formatter))
if page_line.ed_time > bookmark:
# We do bold
edit_icon = format_page_edit_icon(request, [page_line], page,
True, bookmark, formatter)
line_of_text = ('<div class="rcpagelink"><span><b>'
'%s</b> %s%s<b>' %
(edit_icon, page.link_to(absolute=True),
wiki_link))
line_of_text = (
line_of_text + " " +
'<span align="right" style="font-size: 12px;">' +
'last modified ')
line_of_text = line_of_text + '%s %s' % (find_month[day[1]],
day[2])
line_of_text = (line_of_text +
time.strftime(" at %I:%M %p</b> by</span>",
page_line.time_tuple) +
'<span class="faveditor">')
if page_line.comment:
line_of_text = (
line_of_text +
' %s</span><span class="favcomment"> (%s)</span>' %
(getEditor(page_line, request), page_line.comment))
else:
line_of_text = (line_of_text +
' %s</span>' % (getEditor(page_line, request)))
line_of_text = (
line_of_text +
'<span style="font-size:12px;"> '
'[<a href="%s/%s?action=favorite&delete=%s&wiki_name=%s">'
'Remove</a>]</span>' %
(request.getScriptname(),
wikiutil.quoteWikiname(
macro.formatter.page.proper_name()),
wikiutil.quoteWikiname(page_line.pagename),
page.wiki_name) +
'</span></div>')
else:
edit_icon = format_page_edit_icon(request, [page_line], page,
False, bookmark, formatter)
# We don't do bold
if page_line.ed_time: # page has been created
line_of_text = ('<div class="rcpagelink"><span>'
'%s %s%s <span class="favtime">'
'last modified ' %
(edit_icon, page.link_to(absolute=True),
wiki_link))
line_of_text = line_of_text + '%s %s' % (find_month[day[1]], day[2])
line_of_text = (
line_of_text +
time.strftime(" at %I:%M %p by</span>",
page_line.time_tuple) +
'<span class="faveditor">')
if page_line.comment:
line_of_text = (line_of_text +
' %s</span><span class="favcomment"> (%s)</span>' %
(getEditor(page_line, request), page_line.comment))
else:
line_of_text = line_of_text + ' %s</span>' % (
getEditor(page_line, request))
line_of_text = (
line_of_text + '<span style="font-size:12px;"> '
'[<a href="%s/%s?action=favorite&delete=%s&wiki_name=%s">'
'Remove</a>]</span>' %
(request.getScriptname(),
wikiutil.quoteWikiname(
macro.formatter.page.proper_name()),
wikiutil.quoteWikiname(page_line.pagename),
page.wiki_name))
line_of_text = line_of_text + '</span></div>'
else: # page has NOT been created
line_of_text = ('<div class="rcpagelink"><span>'
'%s %s%s '
'<span align="right" class="favtime">'
'page has not been created yet</span>' %
(edit_icon, page.link_to(absolute=True),
wiki_link))
#.........这里部分代码省略.........
示例9: display_edits
# 需要导入模块: from Sycamore.Page import Page [as 别名]
# 或者: from Sycamore.Page.Page import link_to [as 别名]
#.........这里部分代码省略.........
if count_result:
totalEdits = count_result[0]
request.cursor.execute("""SELECT count(DISTINCT name) from allPages
where userEdited=%(userid)s""",
{'userid':userid})
count_result = request.cursor.fetchone()
if count_result:
editedPages = count_result[0]
request.cursor.execute("""SELECT count(DISTINCT wiki_id) from allPages
where userEdited=%(userid)s""",
{'userid':userid})
wiki_count_result = request.cursor.fetchone()
if wiki_count_result:
editedWikis = wiki_count_result[0]
request.cursor.execute(
"""SELECT allPages.name, allPages.editTime, allPages.userIP,
allPages.editType, allPages.comment, wikis.name
from allPages, wikis
where allPages.userEdited=%(userid)s and
wikis.id=allPages.wiki_id
order by editTime desc limit 100 offset %(offset)s""",
{'userid':userid, 'offset':offset})
results = request.cursor.fetchall()
if results:
has_edits = True
count = 1
original_wiki = request.config.wiki_name
for edit in results:
this_edit = 1 + totalEdits - count - offset
pagename = edit[0]
mtime = edit[1]
userIp = '<a href="http://revip.info/ipinfo/%s" tooltip="%s">%s</a>' % (edit[2], edit[2], edit[2])
editType = edit[3]
comment = edit[4]
wiki_name = edit[5]
request.switch_wiki(wiki_name)
page = Page(pagename, request, wiki_name=wiki_name)
version = page.date_to_version_number(mtime)
if request.user.may.read(page):
may_read = True
show_page = page.link_to(
querystr='action=diff&version2=%s&version1=%s' %
(version, version-1),
guess_case=True, absolute=True)
formatted_mtime = request.user.getFormattedDateTime(mtime)
comment = Comment(request, comment, editType).render()
else:
may_read = False
show_page = """<em>hidden</em>"""
userIp = '<em>hidden</em>'
comment = '<em>hidden</em>'
formatted_mtime = '<em>hidden</em>'
if config.wiki_farm:
if may_read:
farm_link = farm.link_to_wiki(wiki_name, request.formatter)
else:
farm_link = '<em>hidden</em>'
edits.addRow((show_page,
farm_link,
formatted_mtime,
userIp,
comment))
else:
edits.addRow((show_page,
formatted_mtime,
userIp,
comment))
count += 1
request.switch_wiki(original_wiki)
if has_edits:
request.write('<p>This user has made <b>%d</b> edits to <b>%d</b> '
'pages' % (totalEdits, editedPages ))
if config.wiki_farm:
request.write(' on <b>%s</b> wikis' % editedWikis)
request.write('.</p>')
request.write('<div id="useredits">')
edit_table = DataBrowserWidget(request)
edit_table.setData(edits)
edit_table.render(append=printNextPrev(request, on_pagename, this_edit,
offset_given))
request.write('</div>')
request.write('<script type="text/javascript" src="/wiki/revipbox.js"></script>')
else:
request.write("<p>This user hasn't edited any pages.</p>")