Help with query form

12 views
Skip to first unread message

Christopher Nelson

unread,
Mar 28, 2013, 4:02:03 PM3/28/13
to trac...@googlegroups.com
Working on my query augmentation
(http://trac.edgewall.org/ticket/10983), I've hit a brick wall. I
have a more complete example which starts to support augmenting the
query form. I get the plugin's fields in the "And" and "Or" drop downs
and they add items in the Filters frame but when I click Update, the
plugin fields have no effect and they disappear from the Filters
section.

I've added code to process_request in trac/ticket/query.py but even at
the beginning of that function, my plugin fields are already missing.
I'm guessing there's magic in the query template or query.js but I
can't find it. Can someone point me at what gets executed when I click
Update?

Chris
--
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Christopher Nelson

unread,
Apr 1, 2013, 11:51:18 AM4/1/13
to trac...@googlegroups.com
OK. Everyone is back from Easter and I still need help. I read the
Genshi introduction and tutorial and I sort of understand the weird
py: syntax a little better but I still don't see where /query is
discarding my custom fields. It would help if I could log things
along the way to see what values are used or what happens in what
order. What's the Genshi equivalent of "self.env.log.debug()"?

Ethan Jucovy

unread,
Apr 2, 2013, 11:49:19 AM4/2/13
to trac...@googlegroups.com
On Mon, Apr 1, 2013 at 11:51 AM, Christopher Nelson <chris.ne...@gmail.com> wrote:
> I've added code to process_request in trac/ticket/query.py but even at
> the beginning of that function, my plugin fields are already missing.

When you say the fields are "missing" at the beginning of process_request, what variable are they missing from?  Do you mean that they're actually absent from req.args? 

It would help if I could log things
along the way to see what values are used or what happens in what
order.  What's the Genshi equivalent of "self.env.log.debug()"?

I can't come up with any built-in way to do it, but you can add the Python logging object to the template context and then just call it from your templates.  Here's a patch to trac/web/chrome.py that will insert "chrome.logging" into all template contexts, which you can then just use like ${chrome.logging.debug("foo")} in the templates: https://gist.github.com/ejucovy/5293261

If you want to post the current patches and sample code you're working with somewhere,  I'd be happy to try to look into it as well.

-Ethan

Christopher Nelson

unread,
Apr 2, 2013, 1:37:08 PM4/2/13
to trac...@googlegroups.com
> On Mon, Apr 1, 2013 at 11:51 AM, Christopher Nelson
> <chris.ne...@gmail.com> wrote:
>>
>> > I've added code to process_request in trac/ticket/query.py but even at
>> > the beginning of that function, my plugin fields are already missing.
>
> When you say the fields are "missing" at the beginning of process_request,
> what variable are they missing from? Do you mean that they're actually
> absent from req.args?

Yes. But after cleaning this up to post, I find that it is in args
but has no effect. I'll try to track it down a bit more from this new
clue.


>> It would help if I could log things
>> along the way to see what values are used or what happens in what
>> order. What's the Genshi equivalent of "self.env.log.debug()"?
>
> I can't come up with any built-in way to do it, but you can add the Python
> logging object to the template context and then just call it from your
> templates. Here's a patch to trac/web/chrome.py that will insert
> "chrome.logging" into all template contexts, which you can then just use
> like ${chrome.logging.debug("foo")} in the templates:
> https://gist.github.com/ejucovy/5293261

Thanks. But now that I see it in `query.py`, I may not have to worry
about debugging templates.

> If you want to post the current patches and sample code you're working with
> somewhere, I'd be happy to try to look into it as well.

Thanks. I updated http://trac.edgewall.org/ticket/10983#comment:17
but let's see what the next hour brings.

Christopher Nelson

unread,
Apr 2, 2013, 3:04:19 PM4/2/13
to trac...@googlegroups.com
> Thanks. I updated http://trac.edgewall.org/ticket/10983#comment:17
> but let's see what the next hour brings.

Progress! My custom constraints have effect on the query and don't
completely disappear. But when Update redirects to
".../query?foo-id=3&owner=admin...", the filters section doesn't end
up with my "Foo ID" custom constraint for 3, it ends up with "Ticket".
I suspect this is in the template:

{{{
<form id="query" method="post" action="${href.query()}"
py:with="field_names = sorted(fields.iterkeys(),
key=lambda name: fields[name].label.lower())">
<fieldset id="filters">
<legend class="foldable">Filters</legend>
<table summary="Query filters">
<tbody py:for="clause_num, constraints in
enumerate(clauses or [{}])"
py:with="clause_pre = '%d_' % clause_num">
<tr style="${'display: none' if clause_num == 0 else None}">
}}}

where `fields` doesn't include my custom constraints so the template
has nothing to match `?foo-id`. Maybe I need to add my custom
constraint names to `fields` earlier (or get them passed to the
template some how).

Christopher Nelson

unread,
Apr 3, 2013, 11:38:43 AM4/3/13
to trac...@googlegroups.com
I think I have this working well now. I hope to update
http://trac.edgewall.org/ticket/10983 this afternoon.

Christopher Nelson

unread,
Apr 3, 2013, 1:46:19 PM4/3/13
to trac...@googlegroups.com
> I think I have this working well now. I hope to update
> http://trac.edgewall.org/ticket/10983 this afternoon.

There's a working patch on t.e.o now. You can use custom constraints
by name in [[TicketQuery()]] (e.g., foo-text=<ticketid>) or pick
custom constraints in a Custom Query (/query).
Reply all
Reply to author
Forward
0 new messages