diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-11-28 17:57:57 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-11-28 17:57:57 +0200 |
commit | b4857400e13469785df9e34713e0bc55f77759e6 (patch) | |
tree | 0c0043fa4f11cdb5e8576132ad6afdc63ed35517 | |
parent | 57c46eff8a61a56658242306d139e86b84f01f5d (diff) | |
download | Servo-b4857400e13469785df9e34713e0bc55f77759e6.tar.gz Servo-b4857400e13469785df9e34713e0bc55f77759e6.tar.bz2 Servo-b4857400e13469785df9e34713e0bc55f77759e6.zip |
Fix issue with showing GSX repair history
-rw-r--r-- | servo/models/device.py | 24 | ||||
-rw-r--r-- | servo/urls/device.py | 3 | ||||
-rw-r--r-- | servo/views/device.py | 27 |
3 files changed, 47 insertions, 7 deletions
diff --git a/servo/models/device.py b/servo/models/device.py index 85abeb9..d422f92 100644 --- a/servo/models/device.py +++ b/servo/models/device.py @@ -480,8 +480,11 @@ class Device(models.Model): self.pk]) def get_purchase_country(self): - # Return device's purchase country, can be 2-letter code (from checkin) or - # full country name (from GSX) + """ + Returns device's purchase country + can be 2-letter code (from checkin) or + full country name (from GSX) + """ from django_countries import countries if len(self.purchase_country) > 2: @@ -502,6 +505,23 @@ class Device(models.Model): diags.shipTo = request.user.location.gsx_shipto return diags.fetch_suites() + def get_gsx_repairs(self): + """ + Returns this device's GSX repairs, if any + """ + device = gsxws.Product(self.get_sn()) + results = [] + + for i, p in enumerate(device.repairs()): + d = {'purchaseOrderNumber': p.purchaseOrderNumber} + d['repairConfirmationNumber'] = p.repairConfirmationNumber + d['createdOn'] = p.createdOn + d['customerName'] = p.customerName.encode('utf-8') + d['repairStatus'] = p.repairStatus + results.append(d) + + return results + def __unicode__(self): return '%s (%s)' % (self.description, self.sn) diff --git a/servo/urls/device.py b/servo/urls/device.py index 04839dc..2193369 100644 --- a/servo/urls/device.py +++ b/servo/urls/device.py @@ -20,6 +20,9 @@ urlpatterns = patterns( url(r'^(?P<device>\d+)/diags/(?P<test_id>\d+)/run/$', run_test, name="devices-run_test"), + url(r'^(?P<pk>\d+)/repairs/$', 'search_gsx_repairs', + name="devices-search_gsx_repairs"), + url(r'^(?P<pk>\d+)/update_gsx_details/$', "update_gsx_details", name="devices-update_gsx_details"), url(r'^(?P<pk>\d+)/orders/(?P<order_id>\d+)/queue/(?P<queue_id>\d+)/parts/$', diff --git a/servo/views/device.py b/servo/views/device.py index f52af8f..1aebabd 100644 --- a/servo/views/device.py +++ b/servo/views/device.py @@ -45,6 +45,9 @@ def model_from_slug(product_line, model=None): def prep_list_view(request, product_line=None, model=None): + """ + Prepares the basic device list view + """ title = _('Devices') search_hint = "devices" all_devices = Device.objects.all() @@ -75,12 +78,12 @@ def prep_detail_view(request, pk, product_line=None, model=None): if pk is None: device = Device() else: - device = Device.objects.get(pk=pk) + device = get_object_or_404(Device, pk=pk) data = prep_list_view(request, product_line, model) data['device'] = device - data['title'] = device.description + data['title'] = device.description return data @@ -98,7 +101,7 @@ def index(request, product_line=None, model=None): def delete_device(request, product_line, model, pk): - dev = Device.objects.get(pk=pk) + dev = get_object_or_404(Device, pk=pk) if request.method == 'POST': from django.db.models import ProtectedError @@ -132,7 +135,7 @@ def edit_device(request, pk=None, product_line=None, model=None): device.description = model_from_slug(product_line, model) if pk is not None: - device = Device.objects.get(pk=pk) + device = get_object_or_404(Device, pk=pk) form = DeviceForm(instance=device) @@ -202,7 +205,7 @@ def parts(request, pk, order_id, queue_id): """ from decimal import InvalidOperation - device = Device.objects.get(pk=pk) + device = get_object_or_404(Device, pk=pk) order = device.order_set.get(pk=order_id) try: @@ -343,3 +346,17 @@ def update_gsx_details(request, pk): def get_info(request, pk): device = get_object_or_404(Device, pk=pk) return render(request, "devices/get_info.html", locals()) + + +def search_gsx_repairs(request, pk): + """ + Performs async GSX search for this device's GSX repairs + """ + device = get_object_or_404(Device, pk=pk) + + try: + GsxAccount.default(request.user) + results = device.get_gsx_repairs() + return render(request, "devices/search_gsx_repairs.html", results) + except gsxws.GsxError as message: + return render(request, "search/results/gsx_error.html", locals()) |