本文整理汇总了Python中webhelpers.html.tags.link_to函数的典型用法代码示例。如果您正苦于以下问题:Python link_to函数的具体用法?Python link_to怎么用?Python link_to使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了link_to函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _link
def _link(pagenr, text):
"""
Create a URL that links to another page
"""
# Let the url_for() from webhelpers create a new link and set
# the variable called 'link_var'. Example:
# You are in '/foo/bar' (controller='foo', action='bar')
# and you want to add a parameter 'pagenr'. Then you
# call the navigator method with link_var='pagenr' and
# the url_for() call will create a link '/foo/bar?pagenr=...'
# with the respective page number added.
# Further kwargs that are passed to the navigator will
# also be added as URL parameters.
arg_dict = {link_var:pagenr}
arg_dict.update(kwargs)
link_url = routes.url_for(**arg_dict)
if ajax_id:
# Return an AJAX link that will update the HTML element
# named by ajax_id.
if framework == 'jquery':
return tags.link_to(text,
onclick="""$('#%s').load('%s'); return false""" % \
(ajax_id, link_url))
else:
raise Exception, "Unsupported Javascript framework: %s" % \
framework
else:
# Return a normal a-href link that will call the same
# controller/action with the link_var set to the new
# page number.
return tags.link_to(text, link_url)
示例2: lnk
def lnk(rev, repo_name):
lazy_cs = False
title_ = None
url_ = '#'
if isinstance(rev, BaseChangeset) or isinstance(rev, AttributeDict):
if rev.op and rev.ref_name:
if rev.op == 'delete_branch':
lbl = _('Deleted branch: %s') % rev.ref_name
elif rev.op == 'tag':
lbl = _('Created tag: %s') % rev.ref_name
else:
lbl = 'Unknown operation %s' % rev.op
else:
lazy_cs = True
lbl = rev.short_id[:8]
url_ = url('changeset_home', repo_name=repo_name,
revision=rev.raw_id)
else:
# changeset cannot be found - it might have been stripped or removed
lbl = rev[:12]
title_ = _('Changeset %s not found') % lbl
if parse_cs:
return link_to(lbl, url_, title=title_, **{'data-toggle': 'tooltip'})
return link_to(lbl, url_, class_='lazy-cs' if lazy_cs else '',
**{'data-raw_id':rev.raw_id, 'data-repo_name':repo_name})
示例3: lnk
def lnk(rev, repo_name):
if isinstance(rev, BaseChangeset) or isinstance(rev, AttributeDict):
lazy_cs = True
if getattr(rev, 'op', None) and getattr(rev, 'ref_name', None):
lazy_cs = False
lbl = '?'
if rev.op == 'delete_branch':
lbl = '%s' % _('Deleted branch: %s') % rev.ref_name
title = ''
elif rev.op == 'tag':
lbl = '%s' % _('Created tag: %s') % rev.ref_name
title = ''
_url = '#'
else:
lbl = '%s' % (rev.short_id[:8])
_url = url('changeset_home', repo_name=repo_name,
revision=rev.raw_id)
title = tooltip(rev.message)
else:
## changeset cannot be found/striped/removed etc.
lbl = ('%s' % rev)[:12]
_url = '#'
title = _('Changeset not found')
if parse_cs:
return link_to(lbl, _url, title=title, class_='tooltip')
return link_to(lbl, _url, raw_id=rev.raw_id, repo_name=repo_name,
class_='lazy-cs' if lazy_cs else '')
示例4: _pagerlink
def _pagerlink(pagenr, text):
"""
Create a URL that links to another page using url_for()
Parameters:
pagenr
Number of the page that the link points to
text
Text to be printed in the A-HREF tag
"""
# Let the url_for() from webhelpers create a new link and set
# the variable called 'link_var'. Example:
# You are in '/foo/bar' (controller='foo', action='bar')
# and you want to add a parameter 'pagenr'. Then you
# call the navigator method with link_var='pagenr' and
# the url_for() call will create a link '/foo/bar?pagenr=...'
# with the respective page number added.
link_params = {}
# Use the instance kwargs from Page.__init__ as URL parameters
link_params.update(self.kwargs)
# Add keyword arguments from pager() to the link as parameters
link_params.update(kwargs)
link_params[link_var] = pagenr
# Create the URL to load a certain page
link_url = routes.url_for(**link_params)
log.debug("link_url(**%r) => %r", link_params, link_url)
# Create the URL to load the page area part of a certain page (AJAX updates)
link_params[partial_var] = 1
partial_url = routes.url_for(**link_params)
log.debug("partial_url(**%r) => %r", link_params, partial_url)
if ajax_id:
# Return an AJAX link that will update the HTML element
# named by ajax_id.
# Degrade gracefully if Javascript is not available by using
# 'partial_url' in the onclick URLs while using 'link_url'
# in the A-HREF URL.
if framework == 'jquery':
return tags.link_to(text, url=link_url,
onclick="""%s$('#%s').load('%s'); return false""" % \
(javascript_before, ajax_id, partial_url), **link_attr)
elif framework == 'yui':
js = """%sYAHOO.util.Connect.asyncRequest('GET','%s',{
success:function(o){YAHOO.util.Dom.get('%s').innerHTML=o.responseText;}
},null); return false;""" % (javascript_before, partial_url, ajax_id)
return tags.link_to(text, url=link_url, onclick=js, **link_attr)
elif framework == 'extjs':
js = """%sExt.get('%s').load({url:'%s'}); return false;""" % (javascript_before, ajax_id, partial_url)
return tags.link_to(text, url=link_url, onclick=js, **link_attr)
else:
raise Exception, "Unsupported Javascript framework: %s" % framework
else:
# Return a normal a-href link that will call the same
# controller/action with the link_var set to the new
# page number.
return tags.link_to(text, link_url, **link_attr)
示例5: bugs_page_link
def bugs_page_link(package):
"""Return the URL to the bug reports page depending on the origin.
For Ubuntu packages it points to edge.launchpad.net while for all other packages it
points to bugs.debian.org."""
if package.origin is not None and package.origin.lower() == "ubuntu":
return tags.link_to("Bug reports", "https://launchpad.net/distros/ubuntu/+source/%s/+bugs" % package.name)
else:
return tags.link_to("Bug reports", "http://bugs.debian.org/%s" % package.name)
示例6: package_page_link
def package_page_link(package):
"""Return the URL to the package page depending on the origin.
For Ubuntu packages it points to packages.ubuntu.com while for all other packages it
points to packages.debian.org."""
if package.origin is not None and package.origin.lower() == "ubuntu":
return tags.link_to("Package page on ubuntu.com", "http://packages.ubuntu.com/%s" % package.name)
else:
return tags.link_to("Package page on debian.org", "http://packages.debian.org/%s" % package.name)
示例7: get_cs_links
def get_cs_links():
revs_limit = 3 #display this amount always
revs_top_limit = 50 #show upto this amount of changesets hidden
revs = action_params.split(',')
repo_name = user_log.repository.repo_name
from rhodecode.model.scm import ScmModel
repo = user_log.repository.scm_instance
message = lambda rev: get_changeset_safe(repo, rev).message
cs_links = []
cs_links.append(" " + ', '.join ([link_to(rev,
url('changeset_home',
repo_name=repo_name,
revision=rev), title=tooltip(message(rev)),
class_='tooltip') for rev in revs[:revs_limit] ]))
compare_view = (' <div class="compare_view tooltip" title="%s">'
'<a href="%s">%s</a> '
'</div>' % (_('Show all combined changesets %s->%s' \
% (revs[0], revs[-1])),
url('changeset_home', repo_name=repo_name,
revision='%s...%s' % (revs[0], revs[-1])
),
_('compare view'))
)
if len(revs) > revs_limit:
uniq_id = revs[0]
html_tmpl = ('<span> %s '
'<a class="show_more" id="_%s" href="#more">%s</a> '
'%s</span>')
if not feed:
cs_links.append(html_tmpl % (_('and'), uniq_id, _('%s more') \
% (len(revs) - revs_limit),
_('revisions')))
if not feed:
html_tmpl = '<span id="%s" style="display:none"> %s </span>'
else:
html_tmpl = '<span id="%s"> %s </span>'
cs_links.append(html_tmpl % (uniq_id, ', '.join([link_to(rev,
url('changeset_home',
repo_name=repo_name, revision=rev),
title=message(rev), class_='tooltip')
for rev in revs[revs_limit:revs_top_limit]])))
if len(revs) > 1:
cs_links.append(compare_view)
return ''.join(cs_links)
示例8: __call__
def __call__(self, repo_name, rev, paths):
if isinstance(paths, str):
paths = safe_unicode(paths)
url_l = [link_to(repo_name, url('files_home',
repo_name=repo_name,
revision=rev, f_path=''))]
paths_l = paths.split('/')
for cnt, p in enumerate(paths_l):
if p != '':
url_l.append(link_to(p, url('files_home',
repo_name=repo_name,
revision=rev,
f_path='/'.join(paths_l[:cnt + 1]))))
return literal('/'.join(url_l))
示例9: link_to_ref
def link_to_ref(repo_name, ref_type, ref_name, rev=None):
"""
Return full markup for a href to changeset_home for a changeset.
If ref_type is branch it will link to changelog.
ref_name is shortened if ref_type is 'rev'.
if rev is specified show it too, explicitly linking to that revision.
"""
txt = short_ref(ref_type, ref_name)
if ref_type == 'branch':
u = url('changelog_home', repo_name=repo_name, branch=ref_name)
else:
u = url('changeset_home', repo_name=repo_name, revision=ref_name)
l = link_to(repo_name + '#' + txt, u)
if rev and ref_type != 'rev':
l = literal('%s (%s)' % (l, link_to(short_id(rev), url('changeset_home', repo_name=repo_name, revision=rev))))
return l
示例10: link_print
def link_print(label, url='', **attrs):
if attrs.has_key('class_'):
attrs['class_'] += ' btn action print'
else:
attrs['class_'] = ' btn action print'
span = '<span><span>' + label + '</span></span>'
return link_to(literal(span), url, **attrs)
示例11: userInfo
def userInfo(self):
checkLogIn(session)
c.site = "Projects"
c.name = session['user_id']
c.menu = genMenu(self)
res = getUserData(c.name)
c.lineData = [("Username", res[0]), ("Name", res[1]),
("Last name", res[2]), ("Email", res[3])]
c.content = render("/line_by_line.html") + html.literal("<br />")
c.header = ["All my projects"]
proj = userProjects(c.name)
c.rows = []
for x in proj:
url_old = urlparse(request.url)
url = url_old.scheme +'://' + url_old.netloc + getProjectUrl(x[0])
c.rows.append((link_to(x[0], url),))
c.style = "width:70%; text-align: left" #XXX: move css to templates
c.content += render("/table.html")
return render("/temp.html")
示例12: __unicode__
def __unicode__(self):
if self.icon:
text = self.icon + u' ' + self.text
else:
text = self.text
return link_to(text, self.href or u'#', **self.kw)
示例13: image_fixups
def image_fixups(content, msgid, archive, richformat, allowimgs):
"Replace the CID links stored messages"
html = local_fromstring(content)
for element, attribute, link, _ in iterlinks(html):
if not link.startswith('cid:'):
if not allowimgs and attribute == 'src':
element.attrib['src'] = '%simgs/blocked.gif' % media_url()
element.attrib['title'] = link
if richformat:
if archive:
displayurl = url('message-preview-archived-with-imgs',
msgid=msgid)
else:
displayurl = url('message-preview-with-imgs',
msgid=msgid)
flash(ugettext('This message contains external'
' images, which have been blocked. ') +
literal(link_to(ugettext('Display images'),
displayurl)))
else:
imgname = link.replace('cid:', '')
if archive:
imgurl = url('messages-preview-archived-img',
img=imgname.replace('/', '__xoxo__'),
msgid=msgid)
else:
imgurl = url('messages-preview-img',
img=imgname.replace('/', '__xoxo__'),
msgid=msgid)
element.attrib['src'] = imgurl
return tostring(html)
示例14: options_td
def options_td(col_num, i, item):
# XXX This module can't depend on 'app_globals' or 'url' or
# external data. Define data within this method or class or
# in a base class.
# Could use HTML.a() instead of link_to().
u = url("/tickets/view", ticket_id=item["id"])
a = link_to(item["options"], u)
return HTML.td(a)
示例15: render
def render(self, **kwargs):
return tags.link_to(
self.field.label(),
self.field.parent.active_request.route_url(
self.field.name[1:],
model=self.field.model.__class__.__name__,
id=self.field.model.id,
)
)