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 device has been serviced before try: device = Device.objects.get(sn__exact=query) device.update_gsx_details() except Exception: try: device = Device.from_gsx(query, user=request.user) 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 as e: return render(request, error_template, {'message': e}) product = Product.from_gsx(partinfo) cache.set(query, product) results.append(product) if param == "serialNumber": try: dev = Device.from_gsx(query) products = dev.get_parts() return render(request, "devices/parts.html", locals()) except gsxws.GsxError as message: return render(request, "search/results/gsx_error.html", locals()) if param == "productName": product = gsxws.Product(productName=query) parts = product.parts() for p in parts: results.append(Product.from_gsx(p)) if what == "repairs": # Looking for GSX repairs if param == "serialNumber": # ... with a serial number try: device = gsxws.Product(query) #results = device.repairs() for i, p in enumerate(device.repairs()): d = {'purchaseOrderNumber': p.purchaseOrderNumber} d['repairConfirmationNumber'] = p.repairConfirmationNumber d['createdOn'] = p.createdOn # @TODO: move the encoding hack to py-gsxws d['customerName'] = p.customerName.encode('utf-8') d['repairStatus'] = p.repairStatus results.append(d) except gsxws.GsxError as e: return render(request, "search/results/gsx_notfound.html") elif param == "dispatchId": # ... with a repair confirmation number repair = gsxws.Repair(number=query) try: results = repair.lookup() except gsxws.GsxError as message: return render(request, error_template, locals()) return render(request, "devices/search_gsx_%s.html" % what, locals())
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 device has been serviced before try: device = Device.objects.get(sn__exact=query) device.update_gsx_details() except Exception: try: device = Device.from_gsx(query, user=request.user) 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 as e: return render(request, error_template, {'message': e}) product = Product.from_gsx(partinfo) cache.set(query, product) results.append(product) if param == "serialNumber": try: dev = Device.from_gsx(query) products = dev.get_parts() return render(request, "devices/parts.html", locals()) except gsxws.GsxError as message: return render(request, "search/results/gsx_error.html", locals()) if param == "productName": product = gsxws.Product(productName=query) parts = product.parts() for p in parts: results.append(Product.from_gsx(p)) if what == "repairs": # Looking for GSX repairs if param == "serialNumber": # ... with a serial number try: device = gsxws.Product(query) #results = device.repairs() for i, p in enumerate(device.repairs()): d = {'purchaseOrderNumber': p.purchaseOrderNumber} d['repairConfirmationNumber'] = p.repairConfirmationNumber d['createdOn'] = p.createdOn # @TODO: move the encoding hack to py-gsxws d['customerName'] = p.customerName.encode('utf-8') d['repairStatus'] = p.repairStatus results.append(d) except gsxws.GsxError as e: return render(request, "search/results/gsx_notfound.html") elif param == "dispatchId": # ... with a repair confirmation number repair = gsxws.Repair(number=query) try: results = repair.lookup() except gsxws.GsxError as message: return render(request, error_template, locals()) return render(request, "devices/search_gsx_%s.html" % what, locals())