diff --git a/.gitignore b/.gitignore index ee98890..382f158 100644 --- a/.gitignore +++ b/.gitignore @@ -154,7 +154,6 @@ cython_debug/ node_modules -static/admin -static/colorfield +static/* media/* .DS_Store \ No newline at end of file diff --git a/core/migrations/0007_seed_mailtemplates.py b/core/migrations/0007_seed_mailtemplates.py index 16a2823..ceba159 100644 --- a/core/migrations/0007_seed_mailtemplates.py +++ b/core/migrations/0007_seed_mailtemplates.py @@ -3,68 +3,19 @@ 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] @@ -72,7 +23,6 @@ def add_initial_templates(apps, schema_editor): ) - class Migration(migrations.Migration): dependencies = [ diff --git a/ticketing/migrations/0012_seed_mailtemplates.py b/ticketing/migrations/0012_seed_mailtemplates.py new file mode 100644 index 0000000..cf1455f --- /dev/null +++ b/ticketing/migrations/0012_seed_mailtemplates.py @@ -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),] diff --git a/ticketing/models.py b/ticketing/models.py index 3bb8c67..1ac579b 100644 --- a/ticketing/models.py +++ b/ticketing/models.py @@ -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)