def warranty_new(request):
    user_profile = request.user.userprofile

    warranty = Warranty()
    warranty.save()
    warranty.claim_number = "CWC-{:04d}".format(warranty.pk)
    warranty.save()

    warranty_history = WarrantyHistory(warranty=warranty, user_profile=user_profile, action="New Claim")
    warranty_history.save()

    return HttpResponseRedirect("/warranty/{}/".format(warranty.pk))
def api_warranty_create_claims(request):
    user_profile = request.user.userprofile

    count = int(request.GET.get("count", "10"))

    statuses = ["NEW", "PREAUTHORIZED", "RECEIVED", "AUTHORIZED", "NOTAUTHORIZED", "CLOSED"]
    styles = ["Afina", "Bachelor", "Cali", "Dakota", "Eden", "Faux Nias", "Grace", "Huntington", "Ivana", "Jaida"]
    colors = ["Africa", "Black", "Camo", "Denim", "Emerald", "Flannel", "Gray", "Hope Brown", "Java", "Kameleon"]
    damages = ["Broken Strap", "Crushed", "Curled", "Delaminated Layers", "Discolored", "Toe Post Pulled Out",
               "Torn Strap", "Worn / Cracked Top Sole"]

    return_list = []
    for i in range(1, count + 1):
        year = random.randint(2015, 2016)
        month = 1
        day = random.randint(1, 17)
        if year == 2015:
            month = random.randint(1, 12)
            day = random.randint(1, 28)

        status = statuses[random.randint(0, 5)]
        status_date = datetime.strptime("{}/{}/{}".format(month, day, year), '%m/%d/%Y')
        name = "Name {}".format(i)
        email = "*****@*****.**"
        phone = "Phone {}".format(i)
        address = "Address {}".format(i)
        style = styles[random.randint(0, 9)]
        color = colors[random.randint(0, 9)]
        damage = damages[random.randint(0, 7)]

        warranty = Warranty()
        warranty.save()

        warranty.claim_number = "CWC-{:04d}".format(warranty.pk)
        warranty.status = status
        warranty.status_date = status_date
        warranty.name = name
        warranty.email = email
        warranty.phone = phone
        warranty.address = address
        warranty.style = style
        warranty.color = color
        warranty.damage = damage
        warranty.save()

        warranty_dict = warranty.convert_to_dict()
        return_list.append(warranty_dict)

        warranty_history = WarrantyHistory(warranty=warranty, user_profile=user_profile, action="New claim")
        warranty_history.save()

        if status != "NEW":
            warranty_history = WarrantyHistory(warranty=warranty,
                                               user_profile=user_profile,
                                               action="Set status to {}".format(warranty_dict["statusDescription"]))
            warranty_history.save()

    return HttpResponse(json.dumps(return_list), content_type="application/json")