Fix AttributeError while staff user does a mass update in some tickets using the Close (Send E-mail) action.

This commit is contained in:
msaelices 2017-08-21 01:26:45 +02:00
parent 1b00086d6e
commit f931dd4dba
2 changed files with 36 additions and 26 deletions

View File

@ -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

View File

@ -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 = []