diff options
-rw-r--r-- | servo/models/customer.py | 6 | ||||
-rw-r--r-- | servo/models/device.py | 11 | ||||
-rwxr-xr-x | servo/templates/orders/devices.html | 2 | ||||
-rw-r--r-- | servo/urls/default.py | 1 | ||||
-rw-r--r-- | servo/urls/diagnostics.py | 8 | ||||
-rw-r--r-- | servo/views/diagnostics.py | 19 |
6 files changed, 44 insertions, 3 deletions
diff --git a/servo/models/customer.py b/servo/models/customer.py index a01ebdf..a6609d0 100644 --- a/servo/models/customer.py +++ b/servo/models/customer.py @@ -159,6 +159,12 @@ class Customer(MPTTModel): fmt = phonenumbers.PhoneNumberFormat.NATIONAL return phonenumbers.format_number(n, fmt) + def get_company_name(self): + """Since we don't really have a "company" field in Servo, + climb up the parent tree and return a concated name + """ + return ', '.join([i for i in self.get_parents()]) + def valid_email(self): """ Returns email address or raises ValidationError diff --git a/servo/models/device.py b/servo/models/device.py index 3c162df..b7e1ca3 100644 --- a/servo/models/device.py +++ b/servo/models/device.py @@ -280,6 +280,7 @@ class Device(models.Model): return device def to_gsx(self): + """Returns the corresponding gsxws Product object""" if len(self.imei): return gsxws.Product(self.imei) return gsxws.Product(self.sn) @@ -425,7 +426,15 @@ class Device(models.Model): Fetch GSX iOS or Repair diagnostics based on device type """ GsxAccount.default(user) - return self.to_gsx().diagnostics() + from gsxws.diagnostics import Diagnostics + + if len(self.imei): + diags = Diagnostics(alternateDeviceId=self.imei) + else: + diags = Diagnostics(serialNumber=self.sn) + + diags.shipTo = user.location.gsx_shipto + return diags.fetch() def get_warranty(self): return gsxws.Product(self.sn).warranty() diff --git a/servo/templates/orders/devices.html b/servo/templates/orders/devices.html index 6529735..002906f 100755 --- a/servo/templates/orders/devices.html +++ b/servo/templates/orders/devices.html @@ -82,7 +82,7 @@ <li class="disabled"><a href="#" data-modal="#modal">{% trans "Initiate Diagnostics" %}</a></li> {% endif %} <li><a href="{% url 'devices-diagnostics' device.pk %}" data-modal="#modal">{% trans "Fetch Diagnostics" %}</a></li> - <li><a href="{% url 'devices-diagnostics' device.pk %}" data-modal="#modal">{% trans "Open Diagnostics Console" %}</a></li> + <li><a href="{% url 'diagnostics-fetch_url' %}" target="_blank">{% trans "Open Diagnostics Console" %}</a></li> <li><a href="{% url 'devices-select_test' device.pk %}" data-modal="#modal">{% trans "Select Test" %}</a></li> </ul> </div> diff --git a/servo/urls/default.py b/servo/urls/default.py index 5000e73..81a4575 100644 --- a/servo/urls/default.py +++ b/servo/urls/default.py @@ -19,6 +19,7 @@ urlpatterns = patterns( url(r'^notes/', include('servo.urls.note')), url(r'^sales/', include('servo.urls.sales')), + url(r'^diagnostics/', include('servo.urls.diagnostics')), url(r'^queues/(\d+)/statuses/$', 'servo.views.queue.statuses'), diff --git a/servo/urls/diagnostics.py b/servo/urls/diagnostics.py new file mode 100644 index 0000000..50e6973 --- /dev/null +++ b/servo/urls/diagnostics.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +from django.conf.urls import patterns, url + +urlpatterns = patterns( + "servo.views.diagnostics", + url(r'^fetch_url/$', 'fetch_dc_url', name="diagnostics-fetch_url"), +) diff --git a/servo/views/diagnostics.py b/servo/views/diagnostics.py index 5e2d222..211600d 100644 --- a/servo/views/diagnostics.py +++ b/servo/views/diagnostics.py @@ -38,12 +38,29 @@ class DiagnosticResults(object): def run_test(request, device, test_id): device = get_object_or_404(Device, pk=device) + GsxAccount.default(request.user) + try: - device.run_test(test_id, request) + result = device.run_test(test_id, request) + messages.success(request, result.responseMessage) except Exception as e: messages.error(request, e) + + return redirect(request.session['return_to']) +def fetch_dc_url(request): + from gsxws.diagnostics import Diagnostics + GsxAccount.default(request.user) + ship_to = request.user.location.gsx_shipto + diags = Diagnostics(shipTo=ship_to) + + try: + return redirect(diags.fetch_dc_url()) + except Exception as e: + return messages.error(request, e) + + def select_test(request, pk): """ Fetch test suite selector |