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.|| """ if 'tagspace' in kwargs: tagspaces = [kwargs.get('tagspace', None)] else: tagspaces = kwargs.get('tagspaces', '') or \ list(TagEngine(self.env).tagspaces) 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] taginfo = {} out = StringIO() out.write('<ul class="listtagged">') # Cull empty names tagged_names = [(tagspace, names) for tagspace, names in engine.get_tagged_names(tags=tags, tagspaces=tagspaces, operation=operation, detailed=True).iteritems() if names] for tagspace, tagspace_names in sorted(tagged_names): if showheadings == 'true': out.write('<lh>%s tags</lh>' % tagspace) for name, tags in sorted(tagspace_names.iteritems()): if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue tags = sorted(tags) taginfo = self._tag_details(taginfo, tags) href, link, title = engine.name_details(tagspace, name) htitle = wiki_to_oneliner(title, self.env) name_tags = ['<a href="%s" title="%s">%s</a>' % (taginfo[tag][0], taginfo[tag][1], tag) for tag in tags] if not name_tags: name_tags = '' else: name_tags = ' (' + ', '.join(sorted(name_tags)) + ')' out.write('<li>%s %s%s</li>\n' % (link, htitle, name_tags)) out.write('</ul>') return out.getvalue()
def render_listtags(self, req, *tags, **kwargs): """ List all tags. ||'''Argument'''||'''Description'''|| ||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.|| ||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.|| ||`shownames=true|false`||Whether to show the objects that tags appear on ''(long)''.|| """ if tags: # Backwards compatibility return self.render_listtagged(req, *tags, **kwargs) page = self._current_page(req) engine = TagEngine(self.env) showpages = kwargs.get('showpages', None) or kwargs.get( 'shownames', 'false') if 'tagspace' in kwargs: tagspaces = [kwargs['tagspace']] else: tagspaces = kwargs.get('tagspaces', []) or \ list(TagEngine(self.env).tagspaces) out = StringIO() out.write('<ul class="listtags">\n') tag_details = {} for tag, names in sorted( engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems()): href, title = engine.get_tag_link(tag) htitle = wiki_to_oneliner(title, self.env, req=req) out.write( '<li><a href="%s" title="%s">%s</a> %s <span class="tagcount">(%i)</span>' % (href, title, tag, htitle, len(names))) if showpages == 'true': out.write('\n') out.write(self.render_listtagged(req, tag, tagspaces=tagspaces)) out.write('</li>\n') out.write('</ul>\n') return out.getvalue()
def render_listtags(self, req, *tags, **kwargs): """ List all tags. ||'''Argument'''||'''Description'''|| ||`tagspace=<tagspace>`||Specify the tagspace the macro should operate on.|| ||`tagspaces=(<tagspace>,...)`||Specify a set of tagspaces the macro should operate on.|| ||`shownames=true|false`||Whether to show the objects that tags appear on ''(long)''.|| """ if tags: # Backwards compatibility return self.render_listtagged(req, *tags, **kwargs) page = self._current_page(req) engine = TagEngine(self.env) showpages = kwargs.get('showpages', None) or kwargs.get('shownames', 'false') if 'tagspace' in kwargs: tagspaces = [kwargs['tagspace']] else: tagspaces = kwargs.get('tagspaces', []) or \ list(TagEngine(self.env).tagspaces) out = StringIO() out.write('<ul class="listtags">\n') tag_details = {} for tag, names in sorted(engine.get_tags(tagspaces=tagspaces, detailed=True).iteritems()): href, title = engine.get_tag_link(tag) htitle = wiki_to_oneliner(title, self.env) out.write('<li><a href="%s" title="%s">%s</a> %s <span class="tagcount">(%i)</span>' % (href, title, tag, htitle, len(names))) if showpages == 'true': out.write('\n') out.write(self.render_listtagged(req, tag, tagspaces=tagspaces)) out.write('</li>\n') out.write('</ul>\n') return out.getvalue()
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() ] if not expression: tagged_names = [(tagspace, names) for tagspace, names in engine.get_tagged_names(tags=tags, tagspaces=tagspaces, operation=operation, detailed=True).iteritems() if names] for tagspace, tagspace_names in sorted(tagged_names): if showheadings == 'true': out.write('<lh>%s tags</lh>' % tagspace) for name, tags in sorted(tagspace_names.iteritems()): if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue tags = sorted(tags) taginfo = self._tag_details(taginfo, tags) href, link, title = engine.name_details(tagspace, name) htitle = wiki_to_oneliner(title, self.env, req=req) name_tags = [ '<a href="%s" title="%s">%s</a>' % (taginfo[tag][0], taginfo[tag][1], tag) for tag in tags ] if not name_tags: name_tags = ''
def remove_tags(self, req, name, tags): ticket = model.Ticket(self.env, name) ticket_tags = self._ticket_tags(ticket) ticket_tags.symmetric_difference_update(tags) ticket['keywords'] = ' '.join(sorted(ticket_tags)) ticket.save_changes(req.authname, None)
def replace_tags(self, req, name, tags): ticket = model.Ticket(self.env, name) ticket['keywords'] = ' '.join(sorted(tags)) ticket.save_changes(req.authname, None)
def add_tags(self, req, name, tags): ticket = model.Ticket(self.env, name) ticket_tags = self._ticket_tags(ticket) ticket_tags.update(tags) ticket['keywords'] = ' '.join(sorted(ticket_tags)) ticket.save_changes(req.authname, 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()] if not expression: tagged_names = [(tagspace, names) for tagspace, names in engine.get_tagged_names(tags=tags, tagspaces=tagspaces, operation=operation, detailed=True).iteritems() if names] for tagspace, tagspace_names in sorted(tagged_names): if showheadings == 'true': out.write('<lh>%s tags</lh>' % tagspace) for name, tags in sorted(tagspace_names.iteritems()): if tagspace == 'wiki' and unicode(name).startswith('tags/'): continue tags = sorted(tags) taginfo = self._tag_details(taginfo, tags) href, link, title = engine.name_details(tagspace, name) htitle = wiki_to_oneliner(title, self.env) name_tags = ['<a href="%s" title="%s">%s</a>' % (taginfo[tag][0], taginfo[tag][1], tag) for tag in tags] if not name_tags: name_tags = '' else: name_tags = ' (' + ', '.join(sorted(name_tags)) + ')'