本文整理汇总了Python中tractags.api.TagEngine.walk_tagged_names方法的典型用法代码示例。如果您正苦于以下问题:Python TagEngine.walk_tagged_names方法的具体用法?Python TagEngine.walk_tagged_names怎么用?Python TagEngine.walk_tagged_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tractags.api.TagEngine
的用法示例。
在下文中一共展示了TagEngine.walk_tagged_names方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_listtagged
# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import walk_tagged_names [as 别名]
def render_listtagged(self, req, *tags, **kwargs):
""" List tagged objects. Optionally accepts a list of tags to match
against. The special tag '''. (dot)''' inserts the current Wiki page name.
`[[ListTagged(<tag>, ...)]]`
||'''Argument'''||'''Description'''||
||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.||
||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.||
||`operation=intersection|union`||The set operation to perform on the discovered objects.||
||`showheadings=true|false`||List objects under the tagspace they occur in.||
||`expression=<expr>`||Match object tags against the given expression.||
The supported expression operators are: unary - (not); binary +, -
and | (and, and not, or). All values in the expression are treated
as tags. Any tag not in the same form as a Python variable must be
quoted.
eg. Match all objects tagged with ticket and workflow, and not
tagged with wiki or closed.
(ticket+workflow)-(wiki|closed)
If an expression is provided operation is ignored.
"""
if 'tagspace' in kwargs:
tagspaces = [kwargs.get('tagspace', None)]
else:
tagspaces = kwargs.get('tagspaces', '') or \
list(TagEngine(self.env).tagspaces)
expression = kwargs.get('expression', None)
showheadings = kwargs.get('showheadings', 'false')
operation = kwargs.get('operation', 'intersection')
if operation not in ('union', 'intersection'):
raise TracError("Invalid tag set operation '%s'" % operation)
engine = TagEngine(self.env)
page_name = req.hdf.get('wiki.page_name')
if page_name:
tags = [tag == '.' and page_name or tag for tag in tags]
tags = set(tags)
taginfo = {}
out = StringIO()
out.write('<ul class="listtagged">\n')
# If expression was passed as an argument, do a full walk, using the
# expression as the predicate. Silently assumes that failed expressions
# are normal tags.
if expression:
from tractags.expr import Expression
try:
expr = Expression(expression)
except Exception, e:
self.env.log.error("Invalid expression '%s'" % expression, exc_info=True)
tags.update([x.strip() for x in re.split('[+,]', expression) if x.strip()])
expression = None
else:
self.env.log.debug(expr.ast)
tagged_names = {}
tags.update(expr.get_tags())
for tagspace, name, name_tags in engine.walk_tagged_names(tags=tags,
tagspaces=tagspaces, predicate=lambda ts, n, t: expr(t)):
tagged_names.setdefault(tagspace, {})[name] = name_tags
tagged_names = [(tagspace, names) for tagspace, names in tagged_names.iteritems()]