Edgewall Software
Modify

Opened 3 years ago

Last modified 13 months ago

#12575 new enhancement

Please improve documentation at TracNotification#Customizingthee-mailcontent

Reported by: korn-trac.edgewall.org@… Owned by:
Priority: normal Milestone: next-stable-1.2.x
Component: notification Version:
Severity: normal Keywords: bitesized, msoutlook documentation
Cc: Branch:
Release Notes:
API Changes:

Description (last modified by Jun Omae)

From TracNotification#Customizingthee-mailcontent it's not immediately obvious that the template can reference arbitrary ticket fields; in particular, the example given to better support Outlook actually implies that the best way to get at them is to parse them out of ticket_props.

According to comment:7:ticket:9494, the template can just reference e.g. $ticket.product.

I think the documentation should enumerate the variables that are available to the template, and that the Outlook example should be updated to use such direct references (because, as reported in #9494, the example doesn't work when text wrapping occurs in the ticket_props table).

Attachments (0)

Change History (7)

comment:1 by Jun Omae, 3 years ago

Description: modified (diff)
Summary: Please improve documentation at https://trac.edgewall.org/wiki/TracNotification#Customizingthee-mailcontentPlease improve documentation at TracNotification#Customizingthee-mailcontent

Anyone can modify wiki pages including the TracNotification. Please feel free to improve and contribute.

comment:2 by András Korn <korn-trac.edgewall.org@…>, 3 years ago

I would, but I don't know what to write, since I neither know what variables are available to the template, nor whether the approach suggested in #9494 is the right one.

I can provide an outline for someone who knows the specifics to fill in, if that helps.

in reply to:  2 comment:3 by Ryan J Ollos, 3 years ago

Keywords: bitesized added
Milestone: next-stable-1.0.x

Replying to András Korn <korn-trac.edgewall.org@…>:

I can provide an outline for someone who knows the specifics to fill in, if that helps.

Which Trac version are you on? The notification system will change significantly in the forthcoming Trac 1.2 (see also #12205), but that may actually not affect the template formatting behavior. We might see additional changes with the switch to Jinja2.

I'll assume Trac 1.0.12, but any 1.0.x should be the same. I think the fields you want to consider are defined here: tags/trac-1.0.12/trac/ticket/notification.py@:265-271#L252. Documenting those would require additional study of the source code.

Is there something specific you are trying to do, but having trouble with?

comment:4 by korn-trac.edgewall.org@…, 3 years ago

Yes, I'm on 1.0.12.

There no longer is anything specific I want to do; what I wanted was similar to the Outlook example, and my problem was that ticket_props got wrapped to 75 characters wide, so that field names and field values were no longer on the same line, so that the example didn't work (the field names were printed, but the example code couldn't extract the values).

Eventually, with some help from a more python-savvy friend, I ended up with this monstrosity:

$ticket_body_hdr
--------------------------------------------------------------------------
{% with

   a = zip(*[(v[0].strip(), v[1].strip()) for v in [ l.split('|') for l in ticket_props.splitlines() ] if len(v) == 2])
   sel = ['Component', 'Some custom field', 'Some other custom field',
          'A third custom field', 'A fourth custom field']
   k = lambda (h, o), n: (n[:-1], o) if n == '' or n[-1] == ':' else (h, o + ['%s:\t%s' % (h, n)]) if h in sel else (h, o) %}\
${'\n'.join(reduce(k, a[0] + a[1], (None, []))[1])}
{% end %}\
--------------------------------------------------------------------------

I also found the lines you highlighted in tags/trac-1.0.12/trac/ticket/notification.py@:265-271#L252, but that's not the information I am (was) looking for. What I would have needed was the (hopefully correct) knowledge that instead of parsing the ticket properties out of the formatted ticket_props, I could just have done something like:

---------------------------------------------------------------------------
#if ticket.component
Component: $ticket.component
#end
#if ticket.somecustomfield
Some custom field: $ticket.somecustomfield
#end
#if ticket.someothercustomfield
Some other custom field: $ticket.someothercustomfield
#end
etc. etc.
---------------------------------------------------------------------------

Unfortunately, I only found #9494 (which has the above, more robust solution) while checking whether the bug report I wanted to submit would be a duplicate.

Last edited 3 years ago by Ryan J Ollos (previous) (diff)

comment:5 by Ryan J Ollos, 3 years ago

Milestone: next-stable-1.0.xnext-stable-1.2.x

Moved ticket assigned to next-stable-1.0.x since maintenance of 1.0.x is coming to a close. Please move the ticket back if it's critical to fix on 1.0.x.

comment:6 by Peter Suter, 3 years ago

Keywords: msoutlook added

comment:7 by anonymous, 13 months ago

Keywords: documentation added

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned. Next status will be 'new'.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.