From f931dd4dba8a3b77f6dff5ede3ae7c21790de2ac Mon Sep 17 00:00:00 2001 From: msaelices Date: Mon, 21 Aug 2017 01:26:45 +0200 Subject: [PATCH] Fix `AttributeError` while staff user does a mass update in some tickets using the `Close (Send E-mail)` action. --- helpdesk/lib.py | 58 ++++++++++++++++++++++++----------------- helpdesk/views/staff.py | 4 +-- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/helpdesk/lib.py b/helpdesk/lib.py index 53e2fe9a..befbacff 100644 --- a/helpdesk/lib.py +++ b/helpdesk/lib.py @@ -191,6 +191,38 @@ def apply_query(queryset, params): return queryset +def ticket_template_context(ticket): + context = {} + + 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', + 'get_status', 'ticket_url', 'staff_url', '_get_assigned_to' + ): + attr = getattr(ticket, field, None) + if callable(attr): + context[field] = '%s' % attr() + else: + context[field] = attr + context['assigned_to'] = context['_get_assigned_to'] + + return context + + +def queue_template_context(queue): + context = {} + + for field in ('title', 'slug', 'email_address', 'from_address', 'locale'): + attr = getattr(queue, field, None) + if callable(attr): + context[field] = attr() + else: + context[field] = attr + + return context + + def safe_template_context(ticket): """ Return a dictionary that can be used as a template context to render @@ -207,32 +239,10 @@ def safe_template_context(ticket): """ context = { - 'queue': {}, - 'ticket': {} + 'queue': queue_template_context(ticket.queue), + 'ticket': ticket_template_context(ticket), } - queue = ticket.queue - - for field in ('title', 'slug', 'email_address', 'from_address', 'locale'): - attr = getattr(queue, field, None) - if callable(attr): - context['queue'][field] = attr() - else: - context['queue'][field] = attr - - 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', - 'get_status', 'ticket_url', 'staff_url', '_get_assigned_to' - ): - attr = getattr(ticket, field, None) - if callable(attr): - context['ticket'][field] = '%s' % attr() - else: - context['ticket'][field] = attr - context['ticket']['queue'] = context['queue'] - context['ticket']['assigned_to'] = context['ticket']['_get_assigned_to'] return context diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 6d11e147..f01dd6f8 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -31,7 +31,7 @@ from helpdesk.forms import ( ) from helpdesk.lib import ( send_templated_mail, query_to_dict, apply_query, safe_template_context, - process_attachments, + process_attachments, queue_template_context, ) from helpdesk.models import ( Ticket, Queue, FollowUp, TicketChange, PreSetReply, Attachment, SavedSearch, @@ -696,7 +696,7 @@ def mass_update(request): # Send email to Submitter, Owner, Queue CC context = safe_template_context(t) context.update(resolution=t.resolution, - queue=t.queue) + queue=queue_template_context(t.queue)) messages_sent_to = []