def get_gsx_search_results(request, what, param, query): """ The second phase of a GSX search. There should be an active GSX session open at this stage. """ data = {} results = [] query = query.upper() device = Device(sn=query) error_template = "search/results/gsx_error.html" # @TODO: this isn't a GSX search. Move it somewhere else. if what == "orders": try: if param == 'serialNumber': device = Device.objects.get(sn__exact=query) if param == 'alternateDeviceId': device = Device.objects.get(imei__exact=query) except (Device.DoesNotExist, ValueError,): return render(request, "search/results/gsx_notfound.html") orders = device.order_set.all() return render(request, "orders/list.html", locals()) if what == "warranty": # Update wty info if been here before try: device = Device.objects.get(sn__exact=query) device.update_gsx_details() except Exception: try: device = Device.from_gsx(query) except Exception as e: return render(request, error_template, {'message': e}) results.append(device) # maybe it's a device we've already replaced... try: soi = ServiceOrderItem.objects.get(sn__iexact=query) results[0].repeat_service = soi.order except ServiceOrderItem.DoesNotExist: pass if what == "parts": # looking for parts if param == "partNumber": # ... with a part number part = gsxws.Part(partNumber=query) try: partinfo = part.lookup() except gsxws.GsxError, e: return render(request, error_template, {'message': e}) product = Product.from_gsx(partinfo) cache.set(query, product) results.append(product) if param == "serialNumber": # ... with a serial number try: results = device.get_parts() data['device'] = device except Exception, e: return render(request, error_template, {'message': e})