Esempio n. 1
0
def get_by_code(request, code):
    device_id = request.GET['device_id']

    product = logic.get_by_code(code=code)

    result = logic.serialize_product(product)

    Query.objects.create(client=device_id, product=product,
                         was_verified=result['verified'],
                         was_590=code.startswith('590'),
                         was_plScore=result['plScore'] is not None)

    if product:
        product.increment_query_count()
        if product.company:
            product.company.increment_query_count()

    return JsonResponse(result)
Esempio n. 2
0
def get_by_code(request, code):
    device_id = request.GET['device_id']

    product = logic.get_by_code(code=code)

    result = logic.serialize_product(product)

    Query.objects.create(client=device_id,
                         product=product,
                         was_verified=result['verified'],
                         was_590=code.startswith('590'),
                         was_plScore=result['plScore'] is not None)

    if product:
        product.increment_query_count()
        if product.company:
            product.company.increment_query_count()

    return JsonResponse(result)
Esempio n. 3
0
 def get_object(self):
     code = self.kwargs['pk']
     return get_by_code(code=code)
Esempio n. 4
0
 def test_should_create_new_when_missing(self):
     self.assertEqual(0, Product.objects.count())
     response = get_by_code(TEST_EAN13)
     self.assertEqual(response.name, None)
     self.assertEqual(1, Product.objects.count())
Esempio n. 5
0
 def test_should_read_existing_object(self):
     Product(code=TEST_EAN13, name="NAME").save()
     response = get_by_code(TEST_EAN13)
     self.assertEqual(response.name, "NAME")