コード例 #1
0
ファイル: order.py プロジェクト: LetsUnlockiPhone/Servo
def add_device(request, pk, device_id=None, sn=None):
    """
    Adds a device to a service order
    using device_id with existing devices or
    sn for new devices (which should have gone through GSX search)
    """
    order = get_object_or_404(Order, pk=pk)

    if device_id is not None:
        device = Device.objects.get(pk=device_id)

    if sn is not None:
        sn = sn.upper()
        # not using get() since SNs are not unique
        device = Device.objects.filter(sn=sn).first()

        if device is None:
            try:
                device = Device.from_gsx(sn)
                device.save()
            except Exception as e:
                messages.error(request, e)
                return redirect(order)

    try:
        event = order.add_device(device, request.user)
        messages.success(request, event)
    except Exception as e:
        messages.error(request, e)
        return redirect(order)

    if order.customer:
        order.customer.devices.add(device)

    return redirect(order)
コード例 #2
0
ファイル: device.py プロジェクト: luetgendorf/Servo
def choose(request, order_id):
    """
    Choosing a device from within an SRO
    Does GSX lookup in case device is not found locally
    """
    context = {'order': order_id}

    if request.method == "POST":

        query = request.POST.get('q').upper()
        results = Device.objects.filter(Q(sn__iexact=query) | Q(imei=query))

        if len(results) < 1:
            try:
                current_order = request.session.get("current_order_id")
                current_order = Order.objects.get(pk=current_order)
                if current_order and current_order.queue:
                    GsxAccount.default(request.user, current_order.queue)
                else:
                    GsxAccount.default(request.user)
                    results = [Device.from_gsx(query)]
            except Exception as e:
                context['error'] = e
                return render(request, "devices/choose-error.html", context)

        context['results'] = results
        return render(request, "devices/choose-list.html", context)

    return render(request, "devices/choose.html", context)
コード例 #3
0
ファイル: device.py プロジェクト: fpsw/Servo
def choose(request, order_id):
    """
    Choosing a device from within an SRO
    Does GSX lookup in case device is not found locally
    """
    context = {'order': order_id}

    if request.method == "POST":

        query = request.POST.get('q').upper()
        results = Device.objects.filter(Q(sn__iexact=query) | Q(imei=query))

        if len(results) < 1:
            try:
                current_order = request.session.get("current_order_id")
                current_order = Order.objects.get(pk=current_order)
                if current_order and current_order.queue:
                    GsxAccount.default(request.user, current_order.queue)
                else:
                    GsxAccount.default(request.user)
                    results = [Device.from_gsx(query)]
            except Exception as e:
                context['error'] = e
                return render(request, "devices/choose-error.html", context)

        context['results'] = results
        return render(request, "devices/choose-list.html", context)

    return render(request, "devices/choose.html", context)
コード例 #4
0
def add_device(request, pk, device_id=None, sn=None):
    """
    Adds a device to a service order
    using device_id with existing devices or
    sn for new devices (which should have gone through GSX search)
    """
    order = get_object_or_404(Order, pk=pk)

    if device_id is not None:
        device = Device.objects.get(pk=device_id)

    if sn is not None:
        sn = sn.upper()
        # not using get() since SNs are not unique
        device = Device.objects.filter(sn=sn).first()

        if device is None:
            try:
                device = Device.from_gsx(sn)
                device.save()
            except Exception as e:
                messages.error(request, e)
                return redirect(order)

    try:
        event = order.add_device(device, request.user)
        messages.success(request, event)
    except Exception as e:
        messages.error(request, e)
        return redirect(order)

    if order.customer:
        order.customer.devices.add(device)

    return redirect(order)
コード例 #5
0
ファイル: device.py プロジェクト: filipp/Servo
def search_gsx(request, what, param, query):
    """
    The first phase of a GSX search
    """
    title = _(u'Search results for "%s"') % query

    try:
        act = request.session.get("gsx_account")
        act = None
        if act is None:
            GsxAccount.default(user=request.user)
        else:
            act.connect(request.user)
    except gsxws.GsxError as message:
        return render(request, "devices/search_gsx_error.html", locals())

    if request.is_ajax():
        if what == "parts":
            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())

        return get_gsx_search_results(request, what, param, query)

    return render(request, "devices/search_gsx.html", locals())
コード例 #6
0
ファイル: checkin.py プロジェクト: filipp/Servo
def get_remote_device(request, sn):
    try:
        apple_sn_validator(sn)
    except ValidationError:
        return Device(sn=sn, image_url='https://static.servoapp.com/images/na.gif')

    get_gsx_connection(request)

    return Device.from_gsx(sn)
コード例 #7
0
def get_remote_device(request, sn):
    try:
        apple_sn_validator(sn)
    except ValidationError:
        return Device(sn=sn,
                      image_url='https://static.servoapp.com/images/na.gif')

    get_gsx_connection(request)

    return Device.from_gsx(sn)
コード例 #8
0
ファイル: device.py プロジェクト: filipp/Servo
def upload_devices(request):
    """
    User uploads device DB as tab-delimited CSV file
    SN  USERNAME    PASSWORD    NOTES
    """
    gsx_account = None
    form = DeviceUploadForm()

    if request.method == "POST":
        form = DeviceUploadForm(request.POST, request.FILES)

        if form.is_valid():
            i = 0
            df = form.cleaned_data['datafile'].read()

            if form.cleaned_data.get('do_warranty_check'):
                gsx_account = GsxAccount.default(request.user)

            for l in df.split("\r"):
                l = l.decode("latin-1").encode("utf-8")
                row = l.strip().split("\t")

                if gsx_account:
                    try:
                        device = Device.from_gsx(row[0])
                    except Exception, e:
                        messages.error(request, e)
                        break
                else:
                    device = Device.objects.get_or_create(sn=row[0])[0]

                try:
                    device.username = row[1]
                    device.password = row[2]
                    device.notes = row[3]
                except IndexError:
                    pass

                device.save()
                i += 1

                if form.cleaned_data.get("customer"):
                    customer = form.cleaned_data['customer']
                    customer.devices.add(device)

            messages.success(request, _("%d devices imported") % i)

            return redirect(index)
コード例 #9
0
def device_from_product(request, pk, item_id):
    """
    Turns a SOI into a device and attaches it to this order
    """
    order = get_object_or_404(Order, pk=pk)
    soi = ServiceOrderItem.objects.get(pk=item_id)

    try:
        GsxAccount.default(request.user, order.queue)
        device = Device.from_gsx(soi.sn, user=request.user)
        device.save()
        event = order.add_device(device, request.user)
        messages.success(request, event)
    except Exception as e:
        messages.error(request, e)

    return redirect(order)
コード例 #10
0
ファイル: order.py プロジェクト: LetsUnlockiPhone/Servo
def device_from_product(request, pk, item_id):
    """
    Turns a SOI into a device and attaches it to this order
    """
    order = get_object_or_404(Order, pk=pk)
    soi = ServiceOrderItem.objects.get(pk=item_id)

    try:
        GsxAccount.default(request.user, order.queue)
        device = Device.from_gsx(soi.sn, user=request.user)
        device.save()
        event = order.add_device(device, request.user)
        messages.success(request, event)
    except Exception as e:
        messages.error(request, e)

    return redirect(order)
コード例 #11
0
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())
コード例 #12
0
ファイル: device.py プロジェクト: luetgendorf/Servo
def upload_devices(request):
    """
    User uploads device DB as tab-delimited CSV file
    SN  USERNAME    PASSWORD    NOTES
    """
    gsx_account = None
    form = DeviceUploadForm()
    title = _('Upload devices')

    if request.GET.get('c'):
        customer = Customer.objects.get(pk=request.GET['c'])
        title = _('Upload devices for %s') % customer.name
        form.fields['customer'].initial = request.GET['c']

    if request.method == "POST":
        form = DeviceUploadForm(request.POST, request.FILES)

        if form.is_valid():
            import django_excel as excel
            import pyexcel.ext.xls  # import it to handle xls file
            import pyexcel.ext.xlsx  # import it to handle xlsx file

            counter, errors = 0, 0
            datafile = form.cleaned_data['datafile']
            sheet = datafile.get_sheet()

            if sheet.row[0][0] == 'SN':
                del (sheet.row[0])  # skip header row

            if form.cleaned_data.get('do_warranty_check'):
                gsx_account = GsxAccount.default(request.user)

            for row in sheet:
                if not len(row[0]):
                    continue  # skip empty rows

                if gsx_account:
                    try:
                        device = Device.from_gsx(row[0])
                    except Exception as e:
                        messages.error(request, e)
                        break
                else:
                    device = Device.objects.get_or_create(sn=row[0])[0]

                device.username = row[1]
                device.password = row[2]
                device.notes = row[3]

                device.save()
                counter += 1

                if form.cleaned_data.get("customer"):
                    cid = form.cleaned_data['customer']
                    customer = Customer.objects.get(pk=cid)
                    customer.devices.add(device)

            messages.success(request, _("%d devices imported") % counter)

            return redirect(index)

    data = {'form': form, 'action': request.path, 'title': title}
    return render(request, "devices/upload_devices.html", data)
コード例 #13
0
ファイル: device.py プロジェクト: fpsw/Servo
def upload_devices(request):
    """
    User uploads device DB as tab-delimited CSV file
    SN  USERNAME    PASSWORD    NOTES
    """
    gsx_account = None
    form = DeviceUploadForm()
    title = _('Upload devices')

    if request.GET.get('c'):
        customer = Customer.objects.get(pk=request.GET['c'])
        title = _('Upload devices for %s') % customer.name
        form.fields['customer'].initial = request.GET['c']

    if request.method == "POST":
        form = DeviceUploadForm(request.POST, request.FILES)

        if form.is_valid():
            import django_excel as excel
            import pyexcel.ext.xls # import it to handle xls file
            import pyexcel.ext.xlsx # import it to handle xlsx file

            counter, errors = 0, 0
            datafile = form.cleaned_data['datafile']
            sheet = datafile.get_sheet()

            if sheet.row[0][0] == 'SN':
                del(sheet.row[0]) # skip header row

            if form.cleaned_data.get('do_warranty_check'):
                gsx_account = GsxAccount.default(request.user)

            for row in sheet:
                if not len(row[0]):
                    continue # skip empty rows

                if gsx_account:
                    try:
                        device = Device.from_gsx(row[0])
                    except Exception as e:
                        messages.error(request, e)
                        break
                else:
                    device = Device.objects.get_or_create(sn=row[0])[0]

                device.username = row[1]
                device.password = row[2]
                device.notes = row[3]

                device.save()
                counter += 1

                if form.cleaned_data.get("customer"):
                    cid = form.cleaned_data['customer']
                    customer = Customer.objects.get(pk=cid)
                    customer.devices.add(device)

            messages.success(request, _("%d devices imported") % counter)

            return redirect(index)

    data = {'form': form, 'action': request.path, 'title': title}
    return render(request, "devices/upload_devices.html", data)
コード例 #14
0
ファイル: search.py プロジェクト: LetsUnlockiPhone/Servo
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())
コード例 #15
0
ファイル: device.py プロジェクト: filipp/Servo
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})