Skip to content

Commit

Permalink
fix team mails
Browse files Browse the repository at this point in the history
  • Loading branch information
aottr committed Apr 13, 2024
1 parent 536cfa3 commit c6eb13f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def get_template(cls, event, language='en'):
template = cls.objects.filter(event=event, language='en').first()
return template

def send_mail(self, to, context):
def send_mail(self, to_list: list[str], context):
try:
send_mail(
self.subject.format(**context),
self.content.format(**context),
settings.DEFAULT_FROM_EMAIL,
[to],
to_list,
fail_silently=False,
)
except Exception as e:
Expand Down
25 changes: 12 additions & 13 deletions ticketing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,19 @@ def update_team_assignment(sender, instance, created, **kwargs):
return None

if not instance.category or not instance.category.team:
mail_template = MailTemplate.get_template('ticket_assigned')
if not mail_template:
return None
#TODO send mail to all supporters
return None

# assign team to ticket
instance.assigned_team = instance.category.team
instance.save()
team_addresses = list(Team.objects.filter(access_non_category_tickets=True).values_list('members__email', flat=True))

else:
# assign team to ticket
instance.assigned_team = instance.category.team
instance.save()
team_addresses = list(instance.category.team.members.values_list('email', flat=True))

mail_template = MailTemplate.get_template('ticket_assigned')
if not mail_template:
return None
mail_template.send_mail(instance.category.team.members.values_list('email', flat=True), {

mail_template.send_mail(team_addresses, {
'ticket_id': instance.id, 'ticket_title': instance.title, 'ticket_description': instance.description,
'ticket_priority': instance.get_priority(), 'ticket_category': instance.category.name if instance.category else _('General'),
'ticket_creator_username': instance.user.username})
Expand All @@ -174,7 +173,7 @@ def send_mail_notification(sender, instance, created, **kwargs):
mail_template = MailTemplate.get_template('new_ticket', instance.user.language)
if not mail_template:
return None
mail_template.send_mail(instance.user.email, {
mail_template.send_mail([instance.user.email], {
'ticket_id': instance.id, 'ticket_creator_username': instance.user.username, 'ticket_title': instance.title,
'ticket_description': instance.description, 'ticket_category': instance.category.name if instance.category else _('General')})

Expand All @@ -191,7 +190,7 @@ def send_mail_change_notification(sender, instance: Ticket, update_fields=None,
mail_template = MailTemplate.get_template('ticket_status_change', instance.user.language)
if not mail_template:
return None
mail_template.send_mail(instance.user.email, {
mail_template.send_mail([instance.user.email], {
'ticket_id': instance.id, 'ticket_creator_username': instance.user.username, 'ticket_status': instance.get_status(),
'ticket_status_old': old_instance.get_status(), 'ticket_title': instance.title
})
Expand Down Expand Up @@ -219,7 +218,7 @@ def send_mail_comment_notification(sender, instance, created, **kwargs):
mail_template = MailTemplate.get_template('new_comment', instance.user.language)
if not mail_template:
return None
mail_template.send_mail(instance.ticket.user.email, {
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})

Expand Down

0 comments on commit c6eb13f

Please sign in to comment.