diff options
Diffstat (limited to 'servo')
-rw-r--r-- | servo/lib/utils.py | 5 | ||||
-rw-r--r-- | servo/models/device.py | 8 | ||||
-rw-r--r-- | servo/models/repair.py | 4 | ||||
-rw-r--r-- | servo/views/device.py | 8 | ||||
-rw-r--r-- | servo/views/gsx.py | 2 |
5 files changed, 15 insertions, 12 deletions
diff --git a/servo/lib/utils.py b/servo/lib/utils.py index ac2ee05..20da7d5 100644 --- a/servo/lib/utils.py +++ b/servo/lib/utils.py @@ -48,5 +48,6 @@ def cache_getset(k, v): if cache.get(k): return cache.get(k) - cache.set(k, v()) - return v + val = v() + cache.set(k, val) + return val diff --git a/servo/models/device.py b/servo/models/device.py index ea719a3..993b96b 100644 --- a/servo/models/device.py +++ b/servo/models/device.py @@ -342,9 +342,11 @@ class Device(models.Model): serial_number = wty.serialNumber or sn device = Device(sn=serial_number) - if device.notes == '': - device.notes = wty.notes or '' - device.notes += wty.csNotes or '' + from servo.lib.utils import empty + + if empty(device.notes): + device.notes = wty.notes or '' + device.notes += wty.csNotes or '' device.has_onsite = product.has_onsite device.is_vintage = product.is_vintage diff --git a/servo/models/repair.py b/servo/models/repair.py index 345b69f..8d9ffab 100644 --- a/servo/models/repair.py +++ b/servo/models/repair.py @@ -220,14 +220,14 @@ class Repair(models.Model): def get_symptom_code_choices(self): # @fixme: what if it's someone else ordering the part? self.gsx_account.connect(self.created_by) - ckey = 'symptom_codes-' + self.device.sn + ckey = 'symptom_codes-%s' % self.device.sn si = SymptomIssue(serialNumber=self.device.sn) return cache_getset(ckey, si.fetch) def get_issue_code_choices(self): # @fixme: what if it's someone else ordering the part? self.gsx_account.connect(self.created_by) - ckey = 'issue_codes-' + self.symptom_code + ckey = 'issue_codes-%s' % self.symptom_code si = SymptomIssue(reportedSymptomCode=self.symptom_code) return cache_getset(ckey, si.fetch) diff --git a/servo/views/device.py b/servo/views/device.py index f35bd99..0d517f9 100644 --- a/servo/views/device.py +++ b/servo/views/device.py @@ -292,7 +292,7 @@ def get_gsx_search_results(request, what, param, query): except Exception: try: device = Device.from_gsx(query) - except Exception, e: + except Exception as e: return render(request, error_template, {'message': e}) results.append(device) @@ -356,7 +356,7 @@ def get_gsx_search_results(request, what, param, query): repair = gsxws.Repair(number=query) try: results = repair.lookup() - except gsxws.GsxError, message: + except gsxws.GsxError as message: return render(request, error_template, locals()) return render(request, "devices/search_gsx_%s.html" % what, locals()) @@ -375,7 +375,7 @@ def search_gsx(request, what, param, query): GsxAccount.default(user=request.user) else: act.connect(request.user) - except gsxws.GsxError, message: + except gsxws.GsxError as message: return render(request, "devices/search_gsx_error.html", locals()) if request.is_ajax(): @@ -384,7 +384,7 @@ def search_gsx(request, what, param, query): dev = Device.from_gsx(query) products = dev.get_parts() return render(request, "devices/parts.html", locals()) - except gsxws.GsxError, message: + except gsxws.GsxError as message: return render(request, "search/results/gsx_error.html", locals()) return get_gsx_search_results(request, what, param, query) diff --git a/servo/views/gsx.py b/servo/views/gsx.py index 59030c9..1e20354 100644 --- a/servo/views/gsx.py +++ b/servo/views/gsx.py @@ -295,7 +295,7 @@ def create_repair(request, order_id, device_id, type): from django.utils import timezone order = get_object_or_404(Order, pk=order_id) - device = get_object_or_404(Device, pk=device_id) + device = order.devices.get(pk=device_id) repair = Repair(order=order, created_by=request.user, device=device) timediff = timezone.now() - order.created_at |