refactoring single-letter variables into better names

This commit is contained in:
Alex Barcelo 2016-10-30 20:43:05 +01:00
parent 681a1893bd
commit cce12181f0

View File

@ -194,19 +194,19 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form):
self.customfield_to_field(field, instanceargs) self.customfield_to_field(field, instanceargs)
def _create_ticket(self): def _create_ticket(self):
q = Queue.objects.get(id=int(self.cleaned_data['queue'])) queue = Queue.objects.get(id=int(self.cleaned_data['queue']))
t = Ticket(title=self.cleaned_data['title'], ticket = Ticket(title=self.cleaned_data['title'],
submitter_email=self.cleaned_data['submitter_email'], submitter_email=self.cleaned_data['submitter_email'],
created=timezone.now(), created=timezone.now(),
status=Ticket.OPEN_STATUS, status=Ticket.OPEN_STATUS,
queue=q, queue=queue,
description=self.cleaned_data['body'], description=self.cleaned_data['body'],
priority=self.cleaned_data['priority'], priority=self.cleaned_data['priority'],
due_date=self.cleaned_data['due_date'], due_date=self.cleaned_data['due_date'],
) )
return t, q return ticket, queue
def _create_custom_fields(self, ticket): def _create_custom_fields(self, ticket):
for field, value in self.cleaned_data.items(): for field, value in self.cleaned_data.items():
@ -219,15 +219,15 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form):
cfv.save() cfv.save()
def _create_follow_up(self, ticket, title, user=None): def _create_follow_up(self, ticket, title, user=None):
f = FollowUp(ticket=ticket, followup = FollowUp(ticket=ticket,
title=title, title=title,
date=timezone.now(), date=timezone.now(),
public=True, public=True,
comment=self.cleaned_data['body'], comment=self.cleaned_data['body'],
) )
if user: if user:
f.user = user followup.user = user
return f return followup
def _attach_files_to_follow_up(self, followup): def _attach_files_to_follow_up(self, followup):
attachments = [] attachments = []
@ -235,20 +235,20 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form):
import mimetypes import mimetypes
attachment = self.cleaned_data['attachment'] attachment = self.cleaned_data['attachment']
filename = attachment.name.replace(' ', '_') filename = attachment.name.replace(' ', '_')
a = Attachment( att = Attachment(
followup=followup, followup=followup,
filename=filename, filename=filename,
mime_type=mimetypes.guess_type(filename)[0] or 'application/octet-stream', mime_type=mimetypes.guess_type(filename)[0] or 'application/octet-stream',
size=attachment.size, size=attachment.size,
) )
a.file.save(attachment.name, attachment, save=False) att.file.save(attachment.name, attachment, save=False)
a.save() att.save()
if attachment.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000): if attachment.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000):
# Only files smaller than 512kb (or as defined in # Only files smaller than 512kb (or as defined in
# settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email. # settings.MAX_EMAIL_ATTACHMENT_SIZE) are sent via email.
try: try:
attachments.append([a.filename, a.file]) attachments.append([att.filename, att.file])
except NotImplementedError: except NotImplementedError:
pass pass
return attachments return attachments
@ -342,29 +342,33 @@ class TicketForm(AbstractTicketForm):
Writes and returns a Ticket() object Writes and returns a Ticket() object
""" """
t, q = self._create_ticket() ticket, queue = self._create_ticket()
if self.cleaned_data['assigned_to']: if self.cleaned_data['assigned_to']:
try: try:
u = User.objects.get(id=self.cleaned_data['assigned_to']) u = User.objects.get(id=self.cleaned_data['assigned_to'])
t.assigned_to = u ticket.assigned_to = u
except User.DoesNotExist: except User.DoesNotExist:
t.assigned_to = None ticket.assigned_to = None
t.save() ticket.save()
self._create_custom_fields(t) self._create_custom_fields(ticket)
if self.cleaned_data['assigned_to']: if self.cleaned_data['assigned_to']:
title = _('Ticket Opened & Assigned to %(name)s') % { title = _('Ticket Opened & Assigned to %(name)s') % {
'name': t.get_assigned_to or _("<invalid user>") 'name': ticket.get_assigned_to or _("<invalid user>")
} }
else: else:
title = _('Ticket Opened') title = _('Ticket Opened')
f = self._create_follow_up(t, title=title, user=user) followup = self._create_follow_up(ticket, title=title, user=user)
f.save() followup.save()
files = self._attach_files_to_follow_up(f) files = self._attach_files_to_follow_up(followup)
self._send_messages(ticket=t, queue=q, followup=f, files=files, user=user) self._send_messages(ticket=ticket,
return t queue=queue,
followup=followup,
files=files,
user=user)
return ticket
class PublicTicketForm(AbstractTicketForm): class PublicTicketForm(AbstractTicketForm):
@ -388,19 +392,22 @@ class PublicTicketForm(AbstractTicketForm):
""" """
Writes and returns a Ticket() object Writes and returns a Ticket() object
""" """
t, q = self._create_ticket() ticket, queue = self._create_ticket()
if q.default_owner and not t.assigned_to: if queue.default_owner and not ticket.assigned_to:
t.assigned_to = q.default_owner ticket.assigned_to = queue.default_owner
t.save() ticket.save()
self._create_custom_fields(t) self._create_custom_fields(ticket)
f = self._create_follow_up(t, title=_('Ticket Opened Via Web')) followup = self._create_follow_up(ticket, title=_('Ticket Opened Via Web'))
f.save() followup.save()
files = self._attach_files_to_follow_up(f) files = self._attach_files_to_follow_up(followup)
self._send_messages(ticket=t, queue=q, followup=f, files=files) self._send_messages(ticket=ticket,
return t queue=queue,
followup=followup,
files=files)
return ticket
class UserSettingsForm(forms.Form): class UserSettingsForm(forms.Form):