Email template query

104 views
Skip to first unread message

Matt B

unread,
Sep 1, 2017, 4:17:16 AM9/1/17
to QATrack+
Hi,

It has been suggested in our department that it would be useful if the email notifications contained a direct link to any tests flagged up as at tolerance or action levels.

i.e. if a test was out of tolerance on our output testlist then there would be a direct link within the email notification to review that particular test list instance.

I'm not sure if its possible or not, but wondered if anyone had a way of implementing this within the email template?

Thanks,

Matt

Randle Taylor

unread,
Sep 5, 2017, 11:20:49 AM9/5/17
to QATrack+
Hi Matt,

There's not great support for this right now, but what you can do is create a custom email template  and then add a line like "Review" in the Failing Tests section of the following :

=== Notifications for {{test_list_instance.test_list.name}} ===

Date      : {{test_list_instance.work_completed }}

{% if failing_tests %}
Failing Tests
=============
{% for test_instance in failing_tests %}
    Value : {{test_instance.value_display}}
    Ref.  : {{test_instance.reference}}
    Tol.  : {{test_instance.tolerance}}
    Review: http://yourservername/qa/session/review/{{test_instance.test_list_instance.pk}}
{% endfor %}
{% endif %}

{% if tolerance_tests %}
Tests at Tolerance
==================
{% for test_instance in tolerance_tests %}
    Value : {{test_instance.value_display}}
    Ref.  : {{test_instance.reference}}
    Tol.  : {{test_instance.tolerance}}
{% endfor %}
{% endif %}




So copy the existing qatrack/notifications/templates/notification_email.txt to e.g. qatrack/notifications/templates/notification_email_custom.txt and modify that file as you see fit.  In local_settings.py set EMAIL_NOTIFICATION_TEMPLATE = "notification_email_custom.txt"  and restart the QATrack service.

Hope that helps,
Randy

Matt B

unread,
Sep 6, 2017, 8:02:08 AM9/6/17
to QATrack+
Thanks,

Would adding this do the same thing: 
Review: session/review/{{test_list_instance.pk}}

Should only a single link be required as the email is all from the same test list instance?

Thanks,

Matt 

Randle Taylor

unread,
Sep 6, 2017, 9:50:26 AM9/6/17
to Matt B, QATrack+
Yes you're right.  Just adding Review: {{http://yourservername/qa/session/review/{{test_list_instance.pk}} at the top would make more sense!

RT

--
You received this message because you are subscribed to the Google Groups "QATrack+" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+unsubscribe@googlegroups.com.
To post to this group, send email to qat...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt B

unread,
Sep 7, 2017, 4:31:51 AM9/7/17
to QATrack+
Another thought. This currently would just produce the link as plan text within the email if i'm not mistaken.
To turn this into a hyperlink, is it as simple as sticking some html into the template:


and then saving as a html file and changing this link in the settings.py file?
Would the rest of the template still render as plain text if saved as a html file?
Sorry, I have no experience in this aspect of things!

Thanks,

Matt
To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+u...@googlegroups.com.

Randle Taylor

unread,
Sep 7, 2017, 7:40:28 AM9/7/17
to Matt B, QATrack+
QATrack+ can't send html emails right now (won't be hard to add) but most email clients will detect links in plain text emails and make them clickable.

RT

To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+unsubscribe@googlegroups.com.
Message has been deleted

conno...@gmail.com

unread,
Dec 4, 2017, 12:27:58 PM12/4/17
to QATrack+
Can any of you elaborate on this part?:

{{test_list_instance.test_list.name}}

It would be very handy to grab the testlist instance like this. How are you accessing it here?

Randle Taylor

unread,
Dec 6, 2017, 9:27:15 AM12/6/17
to conno...@gmail.com, QATrack+
Hi,

The emails are created using the Django template language which is described here: https://docs.djangoproject.com/en/1.7/topics/templates/ .  In that example the {{ test_list_instance.test_list.name }} will be replaced with the actual test list name. So for example if the test list was called Monthly Mechanicals then "Test List: {{ test_list_instance.test_list.name }}" would get rendered as "Test List: Monthly Mechanicals".    Similarly if you wanted to see who completed the test list you could use {{ test_list_instance.modified_by.username }}. 

Does that help?  Let me know if you have any more questions.

Randy

conno...@gmail.com

unread,
Dec 7, 2017, 9:57:43 AM12/7/17
to QATrack+
What I'd really like is if I could get the test instance number, which I could then use to generate an easy link to viewing the data.

For example:

http://servername/qa/session/review/1543/

Is that possible?

Randle Taylor

unread,
Dec 7, 2017, 10:01:30 AM12/7/17
to conno...@gmail.com, QATrack+
You bet.  Putting http://servername/qa/session/review/{{ test_list_instance.id }} should do the trick for you.

RT

conno...@gmail.com

unread,
Dec 8, 2017, 1:03:07 PM12/8/17
to QATrack+
Great, I'll give that a go. Now that I think about it, it would also be excellent if I could grab the comment associated with that testlist instance. Is that do-able?

Randle Taylor

unread,
Dec 8, 2017, 1:08:38 PM12/8/17
to conno...@gmail.com, QATrack+
Sure thing.  You can access any of the fields or methods on the TestListInstance model so to get the comment you would use {{ test_list_instance.comment }}.

RT

conno...@gmail.com

unread,
Dec 8, 2017, 1:10:52 PM12/8/17
to QATrack+
I've tried getting back some info from {{ test_list_instance.id }} within a test, but getting nothing so far. How exactly should I be using this? I'd like to get the instance ID as a string, then concatenate it onto a another string to create the URL.

Randle Taylor

unread,
Dec 8, 2017, 1:19:49 PM12/8/17
to conno...@gmail.com, QATrack+
You would use it in a template like:

=== Notifications for {{test_list_instance.test_list.name}} ===

Date      : {{test_list_instance.work_completed }}

Anything between brackets {{ }} gets replaced with the underlying variable value.  So that template would be rendered as e.g.:

=== Notifications for Monthly Mechanicals ===

Test List : Monthly Mechanicals
Unit      : Unit 10
Date      : 2017-12-8 9:00

If you want to post your template I can take a look at it to see if something is obviously amiss.

RT


conno...@gmail.com

unread,
Dec 8, 2017, 1:22:18 PM12/8/17
to QATrack+
Well, I'm possibly conflating things a little because I'm not actually hoping to use this in emails. I just saw that instance numbers were brought up here when I searched. I basically want to assign the instance number to a variable, either as a string or int or whatever it comes out as, so within a test I'd have

foo = 1234

where 1234 is the instance number.
Once I have that I can the rest of the stuff I need easily enough.
> To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+u...@googlegroups.com.

Randle Taylor

unread,
Dec 8, 2017, 1:28:29 PM12/8/17
to conno...@gmail.com, QATrack+
Okay, yes that is conflating two ideas :)

What you want to do is not possible in a calculation because the test list instance is not given an ID until you complete it and submit it to the server.  Why do you want the instance id in a variable? Perhaps there is a different method of achieving what you're trying to do?

RT

To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+unsubscribe@googlegroups.com.

conno...@gmail.com

unread,
Dec 8, 2017, 1:39:32 PM12/8/17
to QATrack+
Basically for our ion chamber cross calibrations I'm generating a PDF report of the equipment used, the readings taken and the resulting factors. I'm taking all of the variables and numbers etc in the testlist and putting them into a dictionary. The form template is in HTML, and this HTML is then pulled in as a string, with string formatting and **kwargs used to replace the various {} bits with the relevant data. The populated HTML is then saved, and on the server wkhtmltopdf converts it to PDF, and some bashing pops the PDF out onto a more accessible server elsewhere on our network.

My managers would really like if there was a link on this PDF to the data that was used to generate the form, so maybe a line at the bottom that says something like

"Report generated from data within http://servername/qa/session/review/1234"

Maybe it's possible to save the data then fire off the form by using the edit function. The data would have an instance then?

Randle Taylor

unread,
Dec 8, 2017, 1:54:21 PM12/8/17
to conno...@gmail.com, QATrack+
It might be possible to do while editing but the test list instance is not available within the calculation context so you would need to do a database query to figure out the proper test list instance id.  Something like:


from qatrack.qa.models import TestListInstance

try:
    # should only exist during editing
    test_list_instance = TestListInstance.objects.filter(
        unit_test_collection__unit__number
=META["unit_number"],
        test_list__name
=META['test_list_name'],
        work_started
=META['work_started'],
   
)
    # do something with tes
except TestListInstance.DoesNotExist:
     test_list_instance = None

might work for you.  The workflow obviously isn't great though if you have to go and edit the test list after completing.

Actually this is a perfect use case for a "Post submit hook" feature I plan on implementing (https://bitbucket.org/tohccmedphys/qatrackplus/issues/303/post-submit-hook) but I'm not sure it will make it into the next release.  The idea is that something like generating a pdf report is better done after the test list is completed.

RT



To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+unsubscribe@googlegroups.com.

conno...@gmail.com

unread,
Dec 8, 2017, 2:02:11 PM12/8/17
to QATrack+
Alas, that doesn't seem to work and for some reason prevents all the other composite tests in the list from doing anything. I'll have a think about it and come up with a work around! Thanks for you help!
Reply all
Reply to author
Forward
0 new messages