Skip to content

Commit

Permalink
add more mail templates
Browse files Browse the repository at this point in the history
  • Loading branch information
aottr committed Mar 24, 2024
1 parent 395e6a1 commit 3704b3d
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 60 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ cython_debug/
node_modules


static/admin
static/colorfield
static/*
media/*
.DS_Store
66 changes: 8 additions & 58 deletions core/migrations/0007_seed_mailtemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,26 @@

def add_initial_templates(apps, schema_editor):
MailTemplate.objects.create(
event='ticket_status_change',
name='Ticket Status Change',
event='new_user',
name='New User Account',
language='en',
subject='Your ticket status has changed',
subject='Welcome to [Your Organization Name]!',
content='''\
Hello {ticket_creator_username},
Hello {username},
This is to inform you that the status of your ticket #{ticket_id} {ticket_title} has been changed from "{ticket_status_old} to "{ticket_status}".
Welcome to [Your Organization Name]!
Thank you for your patience.
Your account has been successfully created. Here are your account details:
Best regards,
[Your Organization Name]
'''
)

MailTemplate.objects.create(
event='new_ticket',
name='New Ticket',
language='en',
subject='Your ticket has been created successfully',
content='''\
Dear {ticket_creator_username},
We're writing to inform you that your ticket #{ticket_id} has been created successfully.
Details:
Title: {ticket_title}
Category: {ticket_category}
Description:
{ticket_description}
Our team will review your ticket and respond as soon as possible. You can track the status of your ticket by logging into your account.
Thank you for reaching out to us.
Best regards,
[Your Organization Name]
'''
)

MailTemplate.objects.create(
event='ticket_assigned',
name='Ticket Assignment',
language='en',
subject='A new ticket has been assigned to your team',
content='''\
Hello Team,
A new ticket has been created with the following details:
Ticket ID: #{ticket_id}
Title: {ticket_title}
Priority: {ticket_priority}
Category: {ticket_category}
Created By: {ticket_creator_username}
Description:
{ticket_description}
Please review the ticket and take appropriate action.
Thank you for your attention.
Username: {username}
Email Address: {email}
Best regards,
[Your Organization Name]
'''
)



class Migration(migrations.Migration):

dependencies = [
Expand Down
103 changes: 103 additions & 0 deletions ticketing/migrations/0012_seed_mailtemplates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from django.db import migrations
from core.models import MailTemplate

def add_initial_templates(apps, schema_editor):
MailTemplate.objects.create(
event='ticket_status_change',
name='Ticket Status Change',
language='en',
subject='Your ticket status has changed',
content='''\
Hello {ticket_creator_username},
This is to inform you that the status of your ticket #{ticket_id} {ticket_title} has been changed from "{ticket_status_old} to "{ticket_status}".
Thank you for your patience.
Best regards,
[Your Organization Name]
'''
)

MailTemplate.objects.create(
event='new_ticket',
name='New Ticket',
language='en',
subject='Your ticket has been created successfully',
content='''\
Dear {ticket_creator_username},
We're writing to inform you that your ticket #{ticket_id} has been created successfully.
Details:
Title: {ticket_title}
Category: {ticket_category}
Description:
{ticket_description}
Our team will review your ticket and respond as soon as possible. You can track the status of your ticket by logging into your account.
Thank you for reaching out to us.
Best regards,
[Your Organization Name]
'''
)

MailTemplate.objects.create(
event='ticket_assigned',
name='Ticket Assignment',
language='en',
subject='A new ticket has been assigned to your team',
content='''\
Hello Team,
A new ticket has been created with the following details:
Ticket ID: #{ticket_id}
Title: {ticket_title}
Priority: {ticket_priority}
Category: {ticket_category}
Created By: {ticket_creator_username}
Description:
{ticket_description}
Please review the ticket and take appropriate action.
Thank you for your attention.
Best regards,
[Your Organization Name]
'''
)

MailTemplate.objects.create(
event='new_comment',
name='Comment Created',
language='en',
subject='New Comment on your Ticket: #{ticket_id} - {ticket_title}',
content='''\
Hello {ticket_creator_username},
A new comment has been added to your ticket #{ticket_id} - "{ticket_title}".
Comment:
{comment_text}
You can view the full conversation and reply to the comment by logging into your account.
Thank you for using our ticket system.
Best regards,
[Your Organization Name]
'''
)


class Migration(migrations.Migration):

dependencies = [
("ticketing", "0011_alter_fileattachment_file"),
]

operations = [migrations.RunPython(add_initial_templates),]
9 changes: 9 additions & 0 deletions ticketing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def save(self, *args, **kwargs):
def __str__(self):
return f'Comment by {self.user.username} on {self.ticket.title}'

@receiver(post_save, sender=Comment, dispatch_uid="mail_comment_notification")
def send_mail_comment_notification(sender, instance, created, **kwargs):
if created:
mail_template = MailTemplate.get_template('new_comment', instance.user.language)
if not mail_template:
return None
mail_template.send_mail(instance.ticket.user.email, {
'ticket_id': instance.ticket.id, 'ticket_title': instance.ticket.title, 'ticket_creator_username': instance.user.username,
'comment_text': instance.text})

class FileAttachment(models.Model):
ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)
Expand Down

0 comments on commit 3704b3d

Please sign in to comment.