Merge pull request #428 from jflesch/master

Fix form translations
This commit is contained in:
Jonathan Barratt 2016-10-20 12:16:31 +07:00 committed by GitHub
commit af893bdcc8

View File

@ -15,7 +15,7 @@ from django import forms
from django.forms import extras from django.forms import extras
from django.core.files.storage import default_storage from django.core.files.storage import default_storage
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy as _
try: try:
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
User = get_user_model() User = get_user_model()
@ -77,7 +77,7 @@ class EditTicketForm(CustomFieldMixin, forms.ModelForm):
class Meta: class Meta:
model = Ticket model = Ticket
exclude = ('created', 'modified', 'status', 'on_hold', 'resolution', 'last_escalation', 'assigned_to') exclude = ('created', 'modified', 'status', 'on_hold', 'resolution', 'last_escalation', 'assigned_to')
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
""" """
Add any custom fields that are defined to the form Add any custom fields that are defined to the form
@ -101,7 +101,7 @@ class EditTicketForm(CustomFieldMixin, forms.ModelForm):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
for field, value in self.cleaned_data.items(): for field, value in self.cleaned_data.items():
if field.startswith('custom_'): if field.startswith('custom_'):
field_name = field.replace('custom_', '', 1) field_name = field.replace('custom_', '', 1)
@ -112,7 +112,7 @@ class EditTicketForm(CustomFieldMixin, forms.ModelForm):
cfv = TicketCustomFieldValue(ticket=self.instance, field=customfield) cfv = TicketCustomFieldValue(ticket=self.instance, field=customfield)
cfv.value = value cfv.value = value
cfv.save() cfv.save()
return super(EditTicketForm, self).save(*args, **kwargs) return super(EditTicketForm, self).save(*args, **kwargs)
@ -228,7 +228,7 @@ class TicketForm(CustomFieldMixin, forms.Form):
except User.DoesNotExist: except User.DoesNotExist:
t.assigned_to = None t.assigned_to = None
t.save() t.save()
for field, value in self.cleaned_data.items(): for field, value in self.cleaned_data.items():
if field.startswith('custom_'): if field.startswith('custom_'):
field_name = field.replace('custom_', '', 1) field_name = field.replace('custom_', '', 1)
@ -251,7 +251,7 @@ class TicketForm(CustomFieldMixin, forms.Form):
} }
f.save() f.save()
files = [] files = []
if self.cleaned_data['attachment']: if self.cleaned_data['attachment']:
import mimetypes import mimetypes
@ -265,9 +265,9 @@ class TicketForm(CustomFieldMixin, forms.Form):
) )
a.file.save(file.name, file, save=False) a.file.save(file.name, file, save=False)
a.save() a.save()
if file.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000): if file.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:
files.append([a.filename, a.file]) files.append([a.filename, a.file])
@ -276,7 +276,7 @@ class TicketForm(CustomFieldMixin, forms.Form):
context = safe_template_context(t) context = safe_template_context(t)
context['comment'] = f.comment context['comment'] = f.comment
messages_sent_to = [] messages_sent_to = []
if t.submitter_email: if t.submitter_email:
@ -443,9 +443,9 @@ class PublicTicketForm(CustomFieldMixin, forms.Form):
) )
a.file.save(file.name, file, save=False) a.file.save(file.name, file, save=False)
a.save() a.save()
if file.size < getattr(settings, 'MAX_EMAIL_ATTACHMENT_SIZE', 512000): if file.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.
files.append([a.filename, a.file]) files.append([a.filename, a.file])
@ -549,7 +549,7 @@ class TicketCCForm(forms.ModelForm):
users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD) users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
else: else:
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD) users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
self.fields['user'].queryset = users self.fields['user'].queryset = users
class Meta: class Meta:
model = TicketCC model = TicketCC
exclude = ('ticket',) exclude = ('ticket',)