From 5fce1964debb9b68cadf7ce9c50180287b968d90 Mon Sep 17 00:00:00 2001 From: bbe Date: Fri, 30 Oct 2020 19:56:38 +0100 Subject: [PATCH] Add email template "merged" thanks to a migration and add merged_to field into the safe ticket context. --- helpdesk/lib.py | 2 +- .../0034_create_email_template_for_merged.py | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 helpdesk/migrations/0034_create_email_template_for_merged.py diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 7cdfb967..ecc83b21 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -26,7 +26,7 @@ def ticket_template_context(ticket): for field in ('title', 'created', 'modified', 'submitter_email', 'status', 'get_status_display', 'on_hold', 'description', 'resolution', 'priority', 'get_priority_display', - 'last_escalation', 'ticket', 'ticket_for_url', + 'last_escalation', 'ticket', 'ticket_for_url', 'merged_to', 'get_status', 'ticket_url', 'staff_url', '_get_assigned_to' ): attr = getattr(ticket, field, None) diff --git a/helpdesk/migrations/0034_create_email_template_for_merged.py b/helpdesk/migrations/0034_create_email_template_for_merged.py new file mode 100644 index 00000000..24f6896e --- /dev/null +++ b/helpdesk/migrations/0034_create_email_template_for_merged.py @@ -0,0 +1,57 @@ +# Generated by Django 2.2.13 on 2020-10-29 22:34 + +from django.db import migrations + + +def forwards_func(apps, schema_editor): + EmailTemplate = apps.get_model("helpdesk", "EmailTemplate") + db_alias = schema_editor.connection.alias + EmailTemplate.objects.using(db_alias).create( + template_name='merged', + subject='(Merged)', + heading='Ticket merged', + plain_text="""Hello, + +This is a courtesy e-mail to let you know that ticket {{ ticket.ticket }} ("{{ ticket.title }}") by {{ ticket.submitter_email }} has been merged to ticket {{ ticket.merged_to.ticket }}. + +From now on, please answer on this ticket, or you can include the tag {{ ticket.merged_to.ticket }} in your e-mail subject.""", + html="""

Hello,

+ +

This is a courtesy e-mail to let you know that ticket {{ ticket.ticket }} ({{ ticket.title }}) by {{ ticket.submitter_email }} has been merged to ticket {{ ticket.merged_to.ticket }}.

+ +

From now on, please answer on this ticket, or you can include the tag {{ ticket.merged_to.ticket }} in your e-mail subject.

""", + locale='en' + ) + EmailTemplate.objects.using(db_alias).create( + template_name='merged', + subject='(Fusionné)', + heading='Ticket Fusionné', + plain_text="""Bonjour, + +Ce courriel indicatif permet de vous prévenir que le ticket {{ ticket.ticket }} ("{{ ticket.title }}") par {{ ticket.submitter_email }} a été fusionné au ticket {{ ticket.merged_to.ticket }}. + +Veillez à répondre sur ce ticket dorénavant, ou bien inclure la balise {{ ticket.merged_to.ticket }} dans le sujet de votre réponse par mail.""", + html="""

Bonjour,

+ +

Ce courriel indicatif permet de vous prévenir que le ticket {{ ticket.ticket }} ({{ ticket.title }}) par {{ ticket.submitter_email }} a été fusionné au ticket {{ ticket.merged_to.ticket }}.

+ +

Veillez à répondre sur ce ticket dorénavant, ou bien inclure la balise {{ ticket.merged_to.ticket }} dans le sujet de votre réponse par mail.

""", + locale='fr' + ) + + +def reverse_func(apps, schema_editor): + EmailTemplate = apps.get_model("helpdesk", "EmailTemplate") + db_alias = schema_editor.connection.alias + EmailTemplate.objects.using(db_alias).filter(template_name='merged').delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('helpdesk', '0033_ticket_merged_to'), + ] + + operations = [ + migrations.RunPython(forwards_func, reverse_func), + ]