Free and open source ticket system written in python

add more mail templates

+121 -60
+1 -2
.gitignore
··· 154 154 node_modules 155 155 156 156 157 - static/admin 158 - static/colorfield 157 + static/* 159 158 media/* 160 159 .DS_Store
+8 -58
core/migrations/0007_seed_mailtemplates.py
··· 3 3 4 4 def add_initial_templates(apps, schema_editor): 5 5 MailTemplate.objects.create( 6 - event='ticket_status_change', 7 - name='Ticket Status Change', 8 - language='en', 9 - subject='Your ticket status has changed', 10 - content='''\ 11 - Hello {ticket_creator_username}, 12 - 13 - 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}". 14 - 15 - Thank you for your patience. 16 - 17 - Best regards, 18 - [Your Organization Name] 19 - ''' 20 - ) 21 - 22 - MailTemplate.objects.create( 23 - event='new_ticket', 24 - name='New Ticket', 25 - language='en', 26 - subject='Your ticket has been created successfully', 27 - content='''\ 28 - Dear {ticket_creator_username}, 29 - 30 - We're writing to inform you that your ticket #{ticket_id} has been created successfully. 31 - 32 - Details: 33 - Title: {ticket_title} 34 - Category: {ticket_category} 35 - Description: 36 - {ticket_description} 37 - 38 - 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. 39 - 40 - Thank you for reaching out to us. 41 - 42 - Best regards, 43 - [Your Organization Name] 44 - ''' 45 - ) 46 - 47 - MailTemplate.objects.create( 48 - event='ticket_assigned', 49 - name='Ticket Assignment', 6 + event='new_user', 7 + name='New User Account', 50 8 language='en', 51 - subject='A new ticket has been assigned to your team', 9 + subject='Welcome to [Your Organization Name]!', 52 10 content='''\ 53 - Hello Team, 11 + Hello {username}, 54 12 55 - A new ticket has been created with the following details: 56 - 57 - Ticket ID: #{ticket_id} 58 - Title: {ticket_title} 59 - Priority: {ticket_priority} 60 - Category: {ticket_category} 61 - Created By: {ticket_creator_username} 62 - Description: 63 - {ticket_description} 13 + Welcome to [Your Organization Name]! 64 14 65 - Please review the ticket and take appropriate action. 15 + Your account has been successfully created. Here are your account details: 66 16 67 - Thank you for your attention. 17 + Username: {username} 18 + Email Address: {email} 68 19 69 20 Best regards, 70 21 [Your Organization Name] 71 22 ''' 72 23 ) 73 24 74 - 75 25 76 26 class Migration(migrations.Migration): 77 27
+103
ticketing/migrations/0012_seed_mailtemplates.py
··· 1 + from django.db import migrations 2 + from core.models import MailTemplate 3 + 4 + def add_initial_templates(apps, schema_editor): 5 + MailTemplate.objects.create( 6 + event='ticket_status_change', 7 + name='Ticket Status Change', 8 + language='en', 9 + subject='Your ticket status has changed', 10 + content='''\ 11 + Hello {ticket_creator_username}, 12 + 13 + 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}". 14 + 15 + Thank you for your patience. 16 + 17 + Best regards, 18 + [Your Organization Name] 19 + ''' 20 + ) 21 + 22 + MailTemplate.objects.create( 23 + event='new_ticket', 24 + name='New Ticket', 25 + language='en', 26 + subject='Your ticket has been created successfully', 27 + content='''\ 28 + Dear {ticket_creator_username}, 29 + 30 + We're writing to inform you that your ticket #{ticket_id} has been created successfully. 31 + 32 + Details: 33 + Title: {ticket_title} 34 + Category: {ticket_category} 35 + Description: 36 + {ticket_description} 37 + 38 + 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. 39 + 40 + Thank you for reaching out to us. 41 + 42 + Best regards, 43 + [Your Organization Name] 44 + ''' 45 + ) 46 + 47 + MailTemplate.objects.create( 48 + event='ticket_assigned', 49 + name='Ticket Assignment', 50 + language='en', 51 + subject='A new ticket has been assigned to your team', 52 + content='''\ 53 + Hello Team, 54 + 55 + A new ticket has been created with the following details: 56 + 57 + Ticket ID: #{ticket_id} 58 + Title: {ticket_title} 59 + Priority: {ticket_priority} 60 + Category: {ticket_category} 61 + Created By: {ticket_creator_username} 62 + Description: 63 + {ticket_description} 64 + 65 + Please review the ticket and take appropriate action. 66 + 67 + Thank you for your attention. 68 + 69 + Best regards, 70 + [Your Organization Name] 71 + ''' 72 + ) 73 + 74 + MailTemplate.objects.create( 75 + event='new_comment', 76 + name='Comment Created', 77 + language='en', 78 + subject='New Comment on your Ticket: #{ticket_id} - {ticket_title}', 79 + content='''\ 80 + Hello {ticket_creator_username}, 81 + 82 + A new comment has been added to your ticket #{ticket_id} - "{ticket_title}". 83 + 84 + Comment: 85 + {comment_text} 86 + 87 + You can view the full conversation and reply to the comment by logging into your account. 88 + 89 + Thank you for using our ticket system. 90 + 91 + Best regards, 92 + [Your Organization Name] 93 + ''' 94 + ) 95 + 96 + 97 + class Migration(migrations.Migration): 98 + 99 + dependencies = [ 100 + ("ticketing", "0011_alter_fileattachment_file"), 101 + ] 102 + 103 + operations = [migrations.RunPython(add_initial_templates),]
+9
ticketing/models.py
··· 157 157 def __str__(self): 158 158 return f'Comment by {self.user.username} on {self.ticket.title}' 159 159 160 + @receiver(post_save, sender=Comment, dispatch_uid="mail_comment_notification") 161 + def send_mail_comment_notification(sender, instance, created, **kwargs): 162 + if created: 163 + mail_template = MailTemplate.get_template('new_comment', instance.user.language) 164 + if not mail_template: 165 + return None 166 + mail_template.send_mail(instance.ticket.user.email, { 167 + 'ticket_id': instance.ticket.id, 'ticket_title': instance.ticket.title, 'ticket_creator_username': instance.user.username, 168 + 'comment_text': instance.text}) 160 169 161 170 class FileAttachment(models.Model): 162 171 ticket = models.ForeignKey(Ticket, on_delete=models.CASCADE)