aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2015-12-05 13:00:07 +0200
committerFilipp Lepalaan <filipp@mac.com>2015-12-05 13:00:07 +0200
commit6d5964987eddfe9d4e3dbbcb0142420359259c35 (patch)
tree0efeefeca4aa0c83ae79d7a47bb56dc010684adb
parentc4c4342a80d120c85238315a611a4a85fead79f1 (diff)
downloadServo-6d5964987eddfe9d4e3dbbcb0142420359259c35.tar.gz
Servo-6d5964987eddfe9d4e3dbbcb0142420359259c35.tar.bz2
Servo-6d5964987eddfe9d4e3dbbcb0142420359259c35.zip
Fix issue with uploading POP with GSX repair
-rw-r--r--.gitignore2
-rw-r--r--servo/forms/repairs.py39
-rw-r--r--servo/views/gsx.py10
3 files changed, 28 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 63fa6c4..fd8492b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,8 @@ uploads/devices/*
uploads/return_labels/*
uploads/settings/*
uploads/products/*
+uploads/repairs/*
+uploads/templates/*
backups/*
local_settings.py
local_rules.json
diff --git a/servo/forms/repairs.py b/servo/forms/repairs.py
index 9f3a99d..527d515 100644
--- a/servo/forms/repairs.py
+++ b/servo/forms/repairs.py
@@ -8,20 +8,19 @@ from django_countries import countries
from django.utils.translation import ugettext as _
from servo.models import User, Repair, Template
-from servo.forms import BaseForm, AutocompleteTextarea, DateTimePickerInput, ChoiceField
+from servo.forms import (BaseForm, AutocompleteTextarea, DateTimePickerInput,
+ ChoiceField,)
class ImportForm(BaseForm):
- confirmation = forms.CharField(
- min_length=8,
- max_length=15,
- label=_('Confirmation')
- )
+ confirmation = forms.CharField(min_length=8,
+ max_length=15,
+ label=_('Confirmation'))
class GsxCustomerForm(BaseForm):
firstName = forms.CharField(max_length=100, label=_('First name'))
- lastName = forms.CharField(max_length=100, label=_('Last name'))
+ lastName = forms.CharField(max_length=100, label=_('Last name'))
emailAddress = forms.CharField(max_length=100, label=_('Email'))
primaryPhone = forms.CharField(max_length=100, label=_('Phone'))
addressLine1 = forms.CharField(max_length=100, label=_('Address'))
@@ -60,7 +59,7 @@ class GsxRepairForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
from servo.lib.utils import empty
super(GsxRepairForm, self).__init__(*args, **kwargs)
- repair = kwargs['instance']
+ repair = self.instance
techs = User.techies.filter(location=repair.order.location)
c = [(u.tech_id, u.get_full_name()) for u in techs]
c.insert(0, ('', '-------------------',))
@@ -69,18 +68,18 @@ class GsxRepairForm(forms.ModelForm):
label=_('Technician'))
self.fields['parts'].initial = repair.order.get_parts()
- if not repair.can_mark_complete:
+ if repair.can_mark_complete is False:
del(self.fields['mark_complete'])
del(self.fields['replacement_sn'])
choices = Template.templates()
- for f in ('notes', 'symptom', 'diagnosis'):
+ for f in ('notes', 'symptom', 'diagnosis',):
self.fields[f].widget = AutocompleteTextarea(choices=choices)
-
+
symptom_codes = self.instance.get_symptom_code_choices()
self.fields['symptom_code'] = forms.ChoiceField(choices=symptom_codes,
label=_('Symptom group'))
-
+
if empty(self.instance.symptom_code):
# default to the first choice
self.instance.symptom_code = symptom_codes[0][0]
@@ -88,19 +87,23 @@ class GsxRepairForm(forms.ModelForm):
issue_codes = self.instance.get_issue_code_choices()
self.fields['issue_code'] = forms.ChoiceField(choices=issue_codes,
label=_('Issue code'))
-
+
def clean(self, *args, **kwargs):
cd = super(GsxRepairForm, self).clean(*args, **kwargs)
if self.instance.has_serialized_parts():
if cd.get('mark_complete') and not cd.get('replacement_sn'):
- raise forms.ValidationError(_('Replacement serial number must be set'))
+ error = _('Replacement serial number must be set when completing repair.')
+ raise forms.ValidationError(error)
return cd
def clean_attachment(self):
- MAX_FILESIZE = 10485760 # 10MB
+ MAX_FILESIZE = 10*1024*1024 # 10MB
from django.template.defaultfilters import filesizeformat
- f = self.cleaned_data['attachment']
- if f and f._size > MAX_FILESIZE:
- error = _('Attachment should be no larger than %s') % filesizeformat(MAX_FILESIZE)
+ f = self.cleaned_data.get('attachment')
+ if f and f.size > MAX_FILESIZE:
+ size = filesizeformat(MAX_FILESIZE)
+ error = _('Attachment should be no larger than %s') % size
raise forms.ValidationError(error)
+
+ return f
diff --git a/servo/views/gsx.py b/servo/views/gsx.py
index 493f3cf..2195c45 100644
--- a/servo/views/gsx.py
+++ b/servo/views/gsx.py
@@ -213,7 +213,7 @@ def edit_repair(request, order_id, repair_id):
"""
Edits existing (non-submitted) GSX repair
"""
- order = get_object_or_404(Order, pk=order_id)
+ order = get_object_or_404(Order, pk=order_id)
repair = get_object_or_404(Repair, pk=repair_id)
if request.GET.get('c'):
@@ -257,7 +257,8 @@ def save_repair(request, context):
customer = context['customer']
if len(repair.component_data):
- component_form = GsxComponentForm(request.POST, components=repair.component_data)
+ component_form = GsxComponentForm(request.POST,
+ components=repair.component_data)
if component_form.is_valid():
repair.component_data = component_form.json_data
else:
@@ -269,11 +270,10 @@ def save_repair(request, context):
if customer_form.is_valid():
context['customer_data'] = customer_form.cleaned_data
if repair_form.is_valid():
- parts = repair_form.cleaned_data['parts']
+ repair = repair_form.save(commit=False)
+ repair.set_parts(repair_form.cleaned_data['parts'])
repair.save()
- repair.set_parts(parts)
else:
- logging.debug(repair_form.errors)
raise ValueError(repair_form.errors)
else:
raise ValueError(_("Invalid customer info"))