本文整理汇总了Python中tractags.api.TagSystem.get_resource_url方法的典型用法代码示例。如果您正苦于以下问题:Python TagSystem.get_resource_url方法的具体用法?Python TagSystem.get_resource_url怎么用?Python TagSystem.get_resource_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tractags.api.TagSystem
的用法示例。
在下文中一共展示了TagSystem.get_resource_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TagWikiSyntaxProvider
# 需要导入模块: from tractags.api import TagSystem [as 别名]
# 或者: from tractags.api.TagSystem import get_resource_url [as 别名]
class TagWikiSyntaxProvider(Component):
"""[opt] Provides tag:<expr> links.
This extends TracLinks via WikiFormatting to point at tag queries or
at specific tags.
"""
implements(IWikiSyntaxProvider)
def __init__(self):
self.tag_system = TagSystem(self.env)
# IWikiSyntaxProvider methods
def get_wiki_syntax(self):
"""Additional syntax for quoted tags or tag expression."""
tag_expr = (
r"(%s)" % (WikiParser.QUOTED_STRING)
)
# Simple (tag|tagged):link syntax
yield (r'''(?P<qualifier>tag(?:ged)?):(?P<tag_expr>%s)''' % tag_expr,
lambda f, ns, match: self._format_tagged(
f, match.group('qualifier'), match.group('tag_expr'),
'%s:%s' % (match.group('qualifier'),
match.group('tag_expr'))))
# [(tag|tagged):link with label]
yield (r'''\[tag(?:ged)?:'''
r'''(?P<ltag_expr>%s)\s*(?P<tag_title>[^\]]+)?\]''' % tag_expr,
lambda f, ns, match: self._format_tagged(f, 'tag',
match.group('ltag_expr'),
match.group('tag_title')))
def get_link_resolvers(self):
return [('tag', self._format_tagged),
('tagged', self._format_tagged)]
def _format_tagged(self, formatter, ns, target, label, fullmatch=None):
"""Tag and tag query expression link formatter."""
def unquote(text):
"""Strip all matching pairs of outer quotes from string."""
while re.match(WikiParser.QUOTED_STRING, text):
# Remove outer whitespace after stripped quotation too.
text = text[1:-1].strip()
return text
label = label and unquote(label.strip()) or ''
target = unquote(target.strip())
query = target
# Pop realms from query expression.
all_realms = self.tag_system.get_taggable_realms(formatter.perm)
realms = query_realms(target, all_realms)
if realms:
kwargs = dict((realm, 'on') for realm in realms)
target = re.sub('(^|\W)realm:\S+(\W|$)', ' ', target).strip()
else:
kwargs = {}
tag_res = Resource('tag', target)
if 'TAGS_VIEW' not in formatter.perm(tag_res):
return tag.span(label, class_='forbidden tags',
title=_("no permission to view tags"))
context = formatter.context
href = self.tag_system.get_resource_url(tag_res, context.href, kwargs)
if all_realms and (
target in self.tag_system.get_all_tags(formatter.req) or
not iter_is_empty(self.tag_system.query(formatter.req,
query))):
# At least one tag provider is available and tag exists or
# tags query yields at least one match.
if label:
return tag.a(label, href=href)
return render_resource_link(self.env, context, tag_res)
return tag.a(label+'?', href=href, class_='missing tags',
rel='nofollow')