#4381 closed task (duplicate)
ticket.query Query cannot be used in macros
| Reported by: | ittayd | Owned by: | Jonas Borgström |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | ticket system | Version: | 0.10.2 |
| Severity: | normal | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
the object requires 'req' parameter to execute. macros have only hdf and env.
Attachments (0)
Change History (4)
comment:1 by , 19 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
| Type: | defect → task |
comment:2 by , 19 years ago
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 by , 19 years ago
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 by , 19 years ago
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
IWikiMacroProviderinterface or even simpler, inheriting from WikiMacroBase.See #3958.