diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-10-13 22:43:45 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-10-13 22:43:45 +0300 |
commit | e9b0f10c534c10b239301a58f8c00a4effe9adbf (patch) | |
tree | 0e5f1c844e204743b906e4c00c21fc5489b985c7 | |
parent | 5d5415d29daa990d27913da638a6e2bc30afb4e8 (diff) | |
download | Servo-e9b0f10c534c10b239301a58f8c00a4effe9adbf.tar.gz Servo-e9b0f10c534c10b239301a58f8c00a4effe9adbf.tar.bz2 Servo-e9b0f10c534c10b239301a58f8c00a4effe9adbf.zip |
AST 2fixes
-rw-r--r-- | servo/models/device.py | 17 | ||||
-rw-r--r-- | servo/templates/diagnostics/select_test.html | 13 | ||||
-rwxr-xr-x | servo/templates/orders/devices.html | 1 | ||||
-rw-r--r-- | servo/urls/device.py | 20 | ||||
-rw-r--r-- | servo/views/device.py | 70 | ||||
-rw-r--r-- | servo/views/diagnostics.py | 105 |
6 files changed, 150 insertions, 76 deletions
diff --git a/servo/models/device.py b/servo/models/device.py index fdd5614..cf3b861 100644 --- a/servo/models/device.py +++ b/servo/models/device.py @@ -203,7 +203,7 @@ class Device(models.Model): @property def has_warranty(self): - return self.warranty_status in ('ALW', 'APP', 'CBC') + return self.warranty_status in ('ALW', 'APP', 'CBC',) @property def tag_choices(self): @@ -475,6 +475,21 @@ class Device(models.Model): return countries.countries.get(self.purchase_country, '') + def run_test(self, test_id, request): + from gsxws import diagnostics + GsxAccount.default(request.user) + diags = diagnostics.Diagnostics(self.sn) + diags.shipTo = request.user.location.gsx_shipto + diags.diagnosticSuiteId = test_id + return diags.run_test() + + def fetch_tests(self, request): + from gsxws import diagnostics + GsxAccount.default(request.user) + diags = diagnostics.Diagnostics(self.sn) + diags.shipTo = request.user.location.gsx_shipto + return diags.fetch_suites() + def __unicode__(self): return '%s (%s)' % (self.description, self.sn) diff --git a/servo/templates/diagnostics/select_test.html b/servo/templates/diagnostics/select_test.html new file mode 100644 index 0000000..95618f8 --- /dev/null +++ b/servo/templates/diagnostics/select_test.html @@ -0,0 +1,13 @@ +{% extends "modal.html" %} +{% load i18n %} +{% block header %}{% trans "Choose test to run" %}{% endblock header %} +{% block body %} + {% if error %} + <h2>{{ error }}</h2> + {% endif %} + <ul class="nav nav-pills nav-stacked"> + {% for i in tests %} + <li><a href="{% url 'devices-run_test' device.pk i.0 %}">{{ i.1 }}</a></li> + {% endfor %} + </ul> +{% endblock body %} diff --git a/servo/templates/orders/devices.html b/servo/templates/orders/devices.html index 9098cfe..6529735 100755 --- a/servo/templates/orders/devices.html +++ b/servo/templates/orders/devices.html @@ -83,6 +83,7 @@ {% 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 'devices-select_test' device.pk %}" data-modal="#modal">{% trans "Select Test" %}</a></li> </ul> </div> <div class="btn-group"> diff --git a/servo/urls/device.py b/servo/urls/device.py index 132ffbf..defef62 100644 --- a/servo/urls/device.py +++ b/servo/urls/device.py @@ -5,6 +5,8 @@ from django.views.decorators.cache import cache_page from servo.views.order import create from servo.views.device import get_gsx_search_results +from servo.views.diagnostics import diagnostics, select_test, run_test + urlpatterns = patterns( "servo.views.device", @@ -14,9 +16,14 @@ urlpatterns = patterns( url(r'^find/$', "find", name="devices-find"), url(r'^add/$', "edit_device", name="devices-add"), - url(r'^(?P<pk>\d+)/diags/$', 'diagnostics', name="devices-diagnostics"), + url(r'^(?P<pk>\d+)/diags/$', diagnostics, name="devices-diagnostics"), + url(r'^(?P<pk>\d+)/diags/select_test/$', select_test, + name="devices-select_test"), + url(r'^(?P<device>\d+)/diags/(?P<test_id>\d+)/run/$', run_test, + name="devices-run_test"), - url(r'^(?P<pk>\d+)/update_gsx_details/$', "update_gsx_details", name="devices-update_gsx_details"), + 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/$', "parts", name="devices-parts"), @@ -30,7 +37,8 @@ urlpatterns = patterns( url(r'^choose/order/(\d+)/$', 'choose', name="devices-choose"), url(r'^upload/$', 'upload_devices', name="devices-upload_devices"), - url(r'^(?P<device_id>\d+)/orders/create/$', create, name="devices-create_order"), + url(r'^(?P<device_id>\d+)/orders/create/$', create, + name="devices-create_order"), url(r'^(?P<pk>\d+)/get_info/$', 'get_info', name="devices-get_info"), url(r'^(?P<product_line>\w+)/$', "index", name="devices-list_devices"), @@ -41,11 +49,13 @@ urlpatterns = patterns( url(r'^(?P<product_line>\w+)/(?P<model>[\w\-]+)/(?P<pk>\d+)/$', "view_device", name="devices-view_device"), - url(r'^(?P<product_line>\w+)/(?P<model>[\w-]+)/(?P<pk>\d+)/edit/$', "edit_device", + url(r'^(?P<product_line>\w+)/(?P<model>[\w-]+)/(?P<pk>\d+)/edit/$', + "edit_device", name="devices-edit_device"), url(r'^(?P<product_line>\w+)/(?P<model>[\w-]+)/create/$', "edit_device", name="devices-create_device"), - url(r'^(?P<product_line>\w+)/(?P<model>[\w-]+)/(?P<pk>\d+)/delete/$', "delete_device", + url(r'^(?P<product_line>\w+)/(?P<model>[\w-]+)/(?P<pk>\d+)/delete/$', + "delete_device", name="devices-delete_device"), url(r'^search$', 'search', name="devices-search"), diff --git a/servo/views/device.py b/servo/views/device.py index 9a4a6fb..d828e47 100644 --- a/servo/views/device.py +++ b/servo/views/device.py @@ -17,30 +17,6 @@ from servo.models import Device, Order, Product, GsxAccount, ServiceOrderItem from servo.forms.devices import DeviceForm, DeviceUploadForm, DeviceSearchForm -class RepairDiagnosticResults: - pass - - -class DiagnosticResults(object): - def __init__(self, diags): - if not diags.diagnosticTestData: - raise gsxws.GsxError('Missing diagnostic data') - - self.diags = dict(result={}, profile={}, report={}) - - for r in diags.diagnosticTestData.testResult.result: - self.diags['result'][r.name] = r.value - - for r in diags.diagnosticProfileData.profile.unit.key: - self.diags['profile'][r.name] = r.value - - for r in diags.diagnosticProfileData.report.reportData.key: - self.diags['report'][r.name] = r.value - - def __iter__(self): - return iter(self.diags) - - def model_from_slug(product_line, model=None): """ Returns product description for model slug or models dict for @@ -192,52 +168,6 @@ def view_device(request, pk, product_line=None, model=None): return render(request, "devices/view.html", data) -def diagnostics(request, pk): - """ - Fetches MRI diagnostics or initiates iOS diags from GSX - """ - device = get_object_or_404(Device, pk=pk) - - if request.GET.get('a') == 'init': - if request.method == 'POST': - from gsxws import diagnostics - order = request.POST.get('order') - order = device.order_set.get(pk=order) - email = request.POST.get('email') - diag = diagnostics.Diagnostics(serialNumber=device.sn) - diag.emailAddress = email - diag.shipTo = order.location.gsx_shipto - - try: - GsxAccount.default(request.user) - res = diag.initiate() - msg = _('Diagnostics initiated - diags://%s') % res - order.notify("init_diags", msg, request.user) - messages.success(request, msg) - except gsxws.GsxError as e: - messages.error(request, e) - - return redirect(order) - - order = request.GET.get('order') - order = device.order_set.get(pk=order) - customer = order.customer - url = request.path - return render(request, "devices/diagnostic_init.html", locals()) - - if request.GET.get('a') == 'get': - try: - diagnostics = device.get_diagnostics(request.user) - if device.is_ios(): - diagnostics = DiagnosticResults(diagnostics) - return render(request, "devices/diagnostic_ios.html", locals()) - return render(request, "devices/diagnostic_results.html", locals()) - except gsxws.GsxError as e: - return render(request, "devices/diagnostic_error.html", {'error': e}) - - return render(request, "devices/diagnostics.html", locals()) - - def get_gsx_search_results(request, what, param, query): """ The second phase of a GSX search. diff --git a/servo/views/diagnostics.py b/servo/views/diagnostics.py new file mode 100644 index 0000000..5e2d222 --- /dev/null +++ b/servo/views/diagnostics.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +import gsxws + +from django.db.models import Q +from django.contrib import messages + +from django.core.cache import cache +from django.utils.translation import ugettext as _ +from django.shortcuts import render, redirect, get_object_or_404 + + +from servo.models import Device, Order, Product, GsxAccount, ServiceOrderItem + + +class RepairDiagnosticResults: + pass + + +class DiagnosticResults(object): + def __init__(self, diags): + if not diags.diagnosticTestData: + raise gsxws.GsxError('Missing diagnostic data') + + self.diags = dict(result={}, profile={}, report={}) + + for r in diags.diagnosticTestData.testResult.result: + self.diags['result'][r.name] = r.value + + for r in diags.diagnosticProfileData.profile.unit.key: + self.diags['profile'][r.name] = r.value + + for r in diags.diagnosticProfileData.report.reportData.key: + self.diags['report'][r.name] = r.value + + def __iter__(self): + return iter(self.diags) + + +def run_test(request, device, test_id): + device = get_object_or_404(Device, pk=device) + try: + device.run_test(test_id, request) + except Exception as e: + messages.error(request, e) + + +def select_test(request, pk): + """ + Fetch test suite selector + """ + error = None + device = get_object_or_404(Device, pk=pk) + + try: + tests = device.fetch_tests(request) + except Exception as e: + error = e + + return render(request, "diagnostics/select_test.html", locals()) + + +def diagnostics(request, pk): + """ + Fetches MRI diagnostics or initiates iOS diags from GSX + """ + device = get_object_or_404(Device, pk=pk) + + if request.GET.get('a') == 'init': + if request.method == 'POST': + from gsxws import diagnostics + order = request.POST.get('order') + order = device.order_set.get(pk=order) + email = request.POST.get('email') + diag = diagnostics.Diagnostics(serialNumber=device.sn) + diag.emailAddress = email + diag.shipTo = order.location.gsx_shipto + + try: + GsxAccount.default(request.user) + res = diag.initiate() + msg = _('Diagnostics initiated - diags://%s') % res + order.notify("init_diags", msg, request.user) + messages.success(request, msg) + except gsxws.GsxError as e: + messages.error(request, e) + + return redirect(order) + + order = request.GET.get('order') + order = device.order_set.get(pk=order) + customer = order.customer + url = request.path + return render(request, "devices/diagnostic_init.html", locals()) + + if request.GET.get('a') == 'get': + try: + diagnostics = device.get_diagnostics(request.user) + if device.is_ios(): + diagnostics = DiagnosticResults(diagnostics) + return render(request, "devices/diagnostic_ios.html", locals()) + return render(request, "devices/diagnostic_results.html", locals()) + except gsxws.GsxError as e: + return render(request, "devices/diagnostic_error.html", {'error': e}) + + return render(request, "devices/diagnostics.html", locals()) |