Example #1
0
def upload_webcam(request):
    """
    Generate a random name for the photo and save it to disk, then crop it and extract information
    """
    name = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for x in range(10)) + ".png"
    path = os.path.join(settings.MEDIA_ROOT, name)
    f = open(path, "wb")
    img_string = request.POST['photo'][22:]
    img_data = img_string.decode("base64")
    f.write(img_data)
    f.close()
    img = cv2.imread(path)
    x1, y1, x2, y2 = (int(request.POST['x1']), int(request.POST['y1']),
                      int(request.POST['x2']), int(request.POST['y2']))
    img = img[y1:y2, x1:x2]
    cv2.imwrite(path, img)
    try:
        exp = Expense.from_receipt(path, request.user)
        return redirect(
            reverse('admin:receipts_expense_change', args=(exp.id, )))
    except Exception:
        return render(request, 'receipts/add_photo.html',
                      {'error': "Couldn't find a receipt in the image!"})
Example #2
0
def upload_photo(request):
    image = request.FILES['photo']
    s = FileSystemStorage()
    img = s.save(image.name, image)
    print(s.path(img))
    exp = Expense.from_receipt(s.path(img), request.user)
    return redirect(reverse('admin:receipts_expense_change', args=(exp.id, )))
Example #3
0
def upload_photo(request):
    image = request.FILES['photo']
    s = FileSystemStorage()
    img = s.save(image.name, image)
    print(s.path(img))
    exp = Expense.from_receipt(s.path(img), request.user)
    return redirect(reverse('admin:receipts_expense_change', args=(exp.id,)))
Example #4
0
def add(request):
    print(request.POST)
    print(request.FILES)
    exp = Expense.from_receipt(request.FILES['photo'], request.user)
    print(exp)
    expense = [exp.id, str(exp.date), str(exp.shop), []]
    for item in exp.expenseitem_set.all():
        expense[-1].append((item.name, str(item.price), item.category))
    return JsonResponse(expense)
Example #5
0
def add(request):
    print(request.POST)
    print(request.FILES)
    exp = Expense.from_receipt(request.FILES['photo'], request.user)
    print(exp)
    expense = [exp.id, str(exp.date), str(exp.shop), []]
    for item in exp.expenseitem_set.all():
        expense[-1].append((item.name, str(item.price), item.category))
    return JsonResponse(expense)
Example #6
0
def upload_webcam(request):
    """
    Generate a random name for the photo and save it to disk, then crop it and extract information
    """
    name = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(10)) + ".png"
    path = os.path.join(settings.MEDIA_ROOT, name)
    f = open(path, "wb")
    img_string = request.POST['photo'][22:]
    img_data = img_string.decode("base64")
    f.write(img_data)
    f.close()
    img = cv2.imread(path)
    x1, y1, x2, y2 = (int(request.POST['x1']), int(request.POST['y1']),
                      int(request.POST['x2']), int(request.POST['y2']))
    img = img[y1:y2, x1:x2]
    cv2.imwrite(path, img)
    try:
        exp = Expense.from_receipt(path, request.user)
        return redirect(reverse('admin:receipts_expense_change', args=(exp.id,)))
    except Exception:
        return render(request, 'receipts/add_photo.html', {'error': "Couldn't find a receipt in the image!"})