Adding Date Created to email notifications

30 views
Skip to first unread message

ams

unread,
Oct 3, 2013, 10:35:06 AM10/3/13
to trac-...@googlegroups.com
I'm using Trac 1.0.1 with a slightly modified notification.py to allow HTML in ticket notifications.   This part works great, but I'm not clear on how to add additional ticket properties to notifications.   

This snippet on the TracNotification page is taken from ticket_notify_email.txt

--------------------------------------------------------------------------
{% with
   pv = [(a[0].strip(), a[1].strip()) for a in [b.split(':') for b in
         [c.strip() for c in 
          ticket_props.replace('|', '\n').splitlines()[1:-1]] if ':' in b]];
   sel = ['Reporter', 'Owner', 'Type', 'Status', 'Priority', 'Milestone', 
          'Component', 'Severity', 'Resolution', 'Keywords'] %}\
${'\n'.join('%s\t%s' % (format(p[0]+':', ' <12'), p[1]) for p in pv if p[0] in sel)}
{% end %}\
--------------------------------------------------------------------------

This creates a "table" of ticket properties in notifications, but I'm not seeing how to set additional variables.  I tried adding "Time" to the sel array, but no dice.  I'd like to get the ticket Create Date listed in the ticket data (along with Reporter, Owner, Type, ect).  

RjOllos

unread,
Oct 10, 2013, 1:01:12 PM10/10/13
to trac-...@googlegroups.com

The `sel` array is just the labels. We also need to add `ticket.time` to the array of property values, `pv`, so join another list with the pv list: [('Created', format_datetime(ticket.time))].

The result is:

------------------------------
--------------------------------------------
Reporter:       anonymous
Owner:          somebody
Type:           enhancement
Status:         new
Priority:       critical
Milestone:      milestone4
Component:      component1
Resolution:
Keywords:
Created:        10/03/2013 09:47:15 PM
--------------------------------------------------------------------------


Here is the full snippet that you can use to replace $ticket_props, as described in (1):


--------------------------------------------------------------------------
{% with
   pv = [(a[0].strip(), a[1].strip()) for a in [b.split(':') for b in
         [c.strip() for c in
          ticket_props.replace('|', '\n').splitlines()[1:-1]] if ':' in b]] + \
        [('Created', format_datetime(ticket.time))];

   sel = ['Reporter', 'Owner', 'Type', 'Status', 'Priority', 'Milestone',
          'Component', 'Severity', 'Resolution', 'Keywords', 'Created'] %}\

${'\n'.join('%s\t%s' % (format(p[0]+':', ' <12'), p[1]) for p in pv if p[0] in sel)}
{% end %}\
--------------------------------------------------------------------------


Adrya Stembridge

unread,
Oct 10, 2013, 1:28:27 PM10/10/13
to trac-...@googlegroups.com
That worked nicely - thanks.


--
You received this message because you are subscribed to a topic in the Google Groups "Trac Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/trac-users/5Vs3xBNNoX8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to trac-users+...@googlegroups.com.
To post to this group, send email to trac-...@googlegroups.com.
Visit this group at http://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages