ticket_notify_email.txt for Jinja2

77 views
Skip to first unread message

Mo

unread,
Nov 22, 2019, 7:37:04 AM11/22/19
to Trac Users
I'm working on a new template for Jinja2 to get a better result on MS Outlook:

https://trac.edgewall.org/wiki/CookBook/Notification/Templates#jinja2
With this template I wonder, why I get the following output for user name "Foo Bar":

--------------------------------------------------------------------------
Reporter:     Foo
Owner:        Foo Bar
...
--------------------------------------------------------------------------

Why gives Reporter and Owner different output formats?

While learning how to write a Jinja2 template, I read https://trac.edgewall.org/wiki/TracNotification#Customizingtheemailsubject
There only a Genshi documentation is linked. The code snippet below also looks like Genshi. Could it be that the wiki needs an update to match the Trac-1.4 version?

Best regards,
- Mo

Jun Omae

unread,
Nov 24, 2019, 10:28:39 PM11/24/19
to trac-...@googlegroups.com
On Fri, Nov 22, 2019 at 9:37 PM Mo <burcheri...@gmail.com> wrote:
>
> I'm working on a new template for Jinja2 to get a better result on MS Outlook:
>
> https://trac.edgewall.org/wiki/CookBook/Notification/Templates#jinja2
> With this template I wonder, why I get the following output for user name "Foo Bar":
>
> --------------------------------------------------------------------------
> Reporter: Foo
> Owner: Foo Bar
> ...
> --------------------------------------------------------------------------
>
> Why gives Reporter and Owner different output formats?

Since Trac 1.2, username in the fields is displayed using full name of the user.
If you don't want the feature, set disable to [trac] show_full_names option.

See https://trac.edgewall.org/ticket/7339.

--
Jun Omae <jun...@gmail.com> (大前 潤)

Mo

unread,
Nov 25, 2019, 6:06:55 AM11/25/19
to Trac Users

Am Montag, 25. November 2019 04:28:39 UTC+1 schrieb Jun Omae:
Since Trac 1.2, username in the fields is displayed using full name of the user.
If you don't want the feature, set disable to [trac] show_full_names option.

See https://trac.edgewall.org/ticket/7339.

So why doesn't this option apply to both fields Reporter and Owner?

Ryan Ollos

unread,
Nov 25, 2019, 10:41:35 AM11/25/19
to Trac Users
In your example, are owner and reporter the same user? I would check first if "Foo" has a full name set in preferences. The fallback is to use username when full name is not set. 

Mo

unread,
Nov 28, 2019, 4:50:37 AM11/28/19
to Trac Users
Am Montag, 25. November 2019 16:41:35 UTC+1 schrieb RjOllos:

In your example, are owner and reporter the same user? I would check first if "Foo" has a full name set in preferences. The fallback is to use username when full name is not set. 

In my example, the owner and reporter is the same user. The account has full name set. show_full_names = enabled is set in the trac.ini. But the fullname in this notification template is only used for the owner, while reporter has the shortname.

Jun Omae

unread,
Nov 28, 2019, 7:19:25 AM11/28/19
to trac-...@googlegroups.com
First, please confirm email of ticket notification without custom template.
By the results, we will be able to find where root cause exists.

Also, I assume the report's value probably is wrapped. When value of
the field is wrapped,
example in https://trac.edgewall.org/wiki/CookBook/Notification/Templates
wouldn't work.

Mo

unread,
Jan 15, 2020, 8:53:04 AM1/15/20
to Trac Users
On Trac-1.4 I followed
https://trac.edgewall.org/wiki/CookBook/Notification/Templates#jinja2

and have a $PROJECT_ENV/templates/ticket_notify_email.txt like this:

${ticket_body_hdr}
# set sel = ('Reporter', 'Owner', 'Type', 'Status', 'Priority', 'Milestone',
             
'Component', 'Severity', 'Resolution', 'Keywords')
# for a in ticket_props.replace('|', '\n').splitlines()[1:-1]|map('trim'):
#   set a = a.split(':', 1)|map('trim')|list
#   if len(a) > 1 and a[0] in sel:
$
{'%-*s  %s'|format(12, a[0] + ':', a[1])}
#   endif
# endfor
# if ticket.new:
$
{ticket.description}
# else:
#   if changes_body:
$
{_('Changes (by %(author)s):', author=change.author)}

$
{changes_body}
#   endif
#   if changes_descr:
#     if not changes_body and not change.comment and change.author:
$
{_('Description changed by %(author)s:', author=change.author)}
#     endif
$
{changes_descr}
--
#   endif
#   if change.comment:

$
{_('Comment:') if changes_body else
  _
('Comment (by %(author)s):', author=change.author)}

$
{change.comment}
#   endif
# endif
$
{'-- '}
$
{_('Ticket URL: <%(link)s>', link=ticket.link)}
$
{project.name} <${project.url or abs_href()}>
$
{project.descr}

which is almost the default template with ${ticket_props} replaced by

# set sel = ('Reporter', 'Owner', 'Type', 'Status', 'Priority', 'Milestone',
             'Component', 'Severity', 'Resolution', 'Keywords')
# for a in ticket_props.replace('|', '\n').splitlines()[1:-1]|map('trim'):
#   set a = a.split(':', 1)|map('trim')|list
#   if len(a) > 1 and a[0] in sel:
${'%-*s  %s'|format(12, a[0] + ':', a[1])}
#   endif
# endfor

But is has no effect. Is the file and location correct? I also deployed by trac-admin, not sure if required.

Jun Omae

unread,
Jan 15, 2020, 10:25:04 AM1/15/20
to trac-...@googlegroups.com
First, please share ticket notification mail without custom template.

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/ac0deaeb-7474-473a-9dda-c4acb9df79e3%40googlegroups.com.

Steel Rides

unread,
Apr 16, 2021, 5:29:49 PM4/16/21
to Trac Users
@Mo, did you figure out where the ticket_notify_email.txt is supposed to be to allow modifications?

RjOllos

unread,
Apr 16, 2021, 5:47:24 PM4/16/21
to Trac Users
On Friday, April 16, 2021 at 2:29:49 PM UTC-7 steel...@raidoh.com wrote:
@Mo, did you figure out where the ticket_notify_email.txt is supposed to be to allow modifications?

The template should be in $env/templates, but there are other options as well if you want to share the template among environments:



There are three more options in the [inherit] section, templates_dir for sharing global templates, htdocs_dir for sharing global htdocs and plugins_dir, for sharing plugins. Those options can be specified in the shared configuration file, and in fact, configuration files can even be chained if you specify another [inherit] file there.

Note that the templates found in the templates/ directory of the TracEnvironment have precedence over those found in [inherit] templates_dir. In turn, the latter have precedence over the installed templates, so be careful about what you put there. Notably, if you override a default template, refresh your modifications when you upgrade to a new version of Trac. The preferred way to perform TracInterfaceCustomization is to write a custom plugin doing an appropriate ITemplateStreamFilter transformation. 

Ryan

Steel Rides

unread,
Apr 19, 2021, 10:52:01 AM4/19/21
to Trac Users
Hi Ryan,
Thanks for the response, but I don't think that's the issue. I'd put ticket_notify_email.txt in $ENV/templates and the file and templates directory are both the same permissions as the rest of the files. I'm only working with a single environment. I'd added the directories under [inherit] before I realized they were for this purpose, but removing them didn't make any change. So far, I've only replaced the 2nd line per the Jinja2 instructions and swapped the Target URL to the bottom of the footer to check whether it's functioning as expected, but the emails all show up the same. Is there a .py file in the dist-package/trac directory I can look at to check where it's looking?
Here's my txt file,/var/lib/trac/projects/ticket_notify_email.txt
${ticket_body_hdr}
--------------------------------------------------------------------------
#set sel = ('Reporter', 'Owner', 'Type', 'Status', 'Priority', 'Milestone','Component', 'Severity', 'Resolution', 'Keywords')
#for a in ticket_props.replace('|', '\n').splitlines()[1:-1]|map('trim'):

#  set a = a.split(':', 1)|map('trim')|list
#  if len(a) > 1 and a[0] in sel:
${'%-*s  %s'|format(12, a[0] + ':', a[1])}
#  endif
#endfor
--------------------------------------------------------------------------

# if ticket.new:
${ticket.description}
# else:
#   if changes_body:
${_('Changes (by %(author)s):', author=change.author)}

${changes_body}
#   endif
#   if changes_descr:
#     if not changes_body and not change.comment and change.author:
${_('Description changed by %(author)s:', author=change.author)}
#     endif
${changes_descr}
--
#   endif
#   if change.comment:

${_('Comment:') if changes_body else
  _('Comment (by %(author)s):', author=change.author)}

${change.comment}
#   endif
# endif
${'-- '}
${project.name} <${project.url or abs_href()}>
${project.descr}
${_('Ticket URL: <%(link)s>', link=ticket.link)}

RjOllos

unread,
Apr 19, 2021, 7:58:24 PM4/19/21
to Trac Users
On Monday, April 19, 2021 at 7:52:01 AM UTC-7 steel...@raidoh.com wrote:
Hi Ryan,
Thanks for the response, but I don't think that's the issue. I'd put ticket_notify_email.txt in $ENV/templates and the file and templates directory are both the same permissions as the rest of the files. I'm only working with a single environment. I'd added the directories under [inherit] before I realized they were for this purpose, but removing them didn't make any change. So far, I've only replaced the 2nd line per the Jinja2 instructions and swapped the Target URL to the bottom of the footer to check whether it's functioning as expected, but the emails all show up the same. Is there a .py file in the dist-package/trac directory I can look at to check where it's looking?

The templates are loaded by Chrome._load_jinja_template:

Ryan
Reply all
Reply to author
Forward
0 new messages