Ticket #4381 (closed task: duplicate)
Opened 5 years ago
Last modified 5 years ago
ticket.query Query cannot be used in macros
| Reported by: | ittayd | Owned by: | jonas |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | ticket system | Version: | 0.10.2 |
| Severity: | normal | Keywords: | |
| Cc: | |||
| Release Notes: | |||
| API Changes: | |||
Description
the object requires 'req' parameter to execute. macros have only hdf and env.
Attachments
Change History
comment:1 Changed 5 years ago by cboos
- Resolution set to duplicate
- Status changed from new to closed
- Type changed from defect to task
comment:2 Changed 5 years ago by anonymous
can you please elaborate? there's little information on how to do single-file plugins. i really don't want to get into the .egg and enabling plugins thing.
comment:3 Changed 5 years ago by cboos
No, there's no need to build an .egg for simple plugins.
See attachment:wiki:ChristianBoos:mantis_tickets.py for an example of self-contained plugin (though this one implements IWikiSyntaxProvider, similar principle for an IWikiMacroProvider).
I'll attach a simple example here later.
comment:4 Changed 5 years ago by cboos
Well, here's a very simple example of a 0.10.x macro:
from StringIO import StringIO from trac.core import * from trac.ticket.query import TicketQueryMacro from trac.wiki.macros import WikiMacroBase from trac.wiki.api import parse_args class SearchTicketsMacro(WikiMacroBase): """Search for the given string in all ticket text fields""" def render_macro(self, formatter, name, content): args, kw = parse_args(content) buf = StringIO() for field in ('summary', 'keywords', 'description'): buf.write(TicketQueryMacro(self.env).render_macro( formatter, 'TicketQuery', '%s=~%s' % (field, args[0]))) return buf.getvalue()
All what's needed is to write the above in a .py file and place that file in you environment's plugins folder.



Old-style macros are deprecated and won't be supported anymore in 0.11.
Look for "new-style" macros, i.e. plugins implementing the IWikiMacroProvider interface or even simpler, inheriting from WikiMacroBase.
See #3958.