Exemple #1
0
def respillInventory(request):
    d = json.loads(bytes.decode(request.body))
    u = request.user
    try:
        e = models.Event.objects.get(ID=int(d["eventID"]))
        if e == models.INV_EVENT:
            return JsonResponse({"error": "invalid: event"}, status=400)
        u.items.filter(event=models.INV_EVENT).delete()
        for i in u.items.filter(event=e):
            if not i.tag:
                iTag = uuid.uuid4()
                while u.items.filter(tag=iTag).exists():
                    iTag = uuid.uuid4()
                i.setTag(uuid.uuid4())
            nI = models.newItem(u, models.INV_EVENT, i.name, i.fandom, i.kind,
                                i.price, i.cost, 0, i.numLeft)
            nI.setImage(i.image)
            nI.setTag(i.tag)
    except models.Event.DoesNotExist as ex:
        return JsonResponse({"error": "couldn't find the event"}, status=400)
    except ValidationError as ex:
        return JsonResponse(
            {"error": "invalid: %s" % ", ".join(ex.message_dict.keys())},
            status=400)
    return JsonResponse({})
Exemple #2
0
def copyInventory(request):
    d = json.loads(bytes.decode(request.body))
    u = request.user
    try:
        e = models.Event.objects.get(ID = int(d["eventID"]))
        if e == models.INV_EVENT:
            return JsonResponse({"error": "invalid: event"}, status = 400)
        for i in u.items.filter(event = models.INV_EVENT):
            nI = None
            if not i.tag:
                iTag = uuid.uuid4()
                while u.items.filter(tag = iTag).exists():
                    iTag = uuid.uuid4()
                i.setTag(uuid.uuid4())
            else:
                nI = u.items.get(Q(event = e) & Q(tag = i.tag))
            if nI:
                nI.setName(i.name)
                nI.setFandom(i.fandom)
                nI.setKind(i.kind)
                nI.setPrice(i.price)
                nI.setCost(i.cost)
                nI.setNumSold(i.numSold)
                #nI.setNumLeft(i.numLeft)
                nI.setImage(i.image)
            else:
                nI = models.newItem(u, e, i.name, i.fandom, i.kind, i.price, i.cost, i.numSold, i.numLeft)
                nI.setImage(i.image)
    except models.Event.DoesNotExist as ex:
        return JsonResponse({"error": "couldn't find the event"}, status = 400)
    except ValidationError as ex:
        return JsonResponse({"error": "invalid: %s" % ", ".join(ex.message_dict.keys())}, status = 400)
    return JsonResponse({})
Exemple #3
0
def newItem(request):
    d = json.loads(bytes.decode(request.body))
    u = request.user
    try:
        e = models.Event.objects.get(ID = int(d["eventID"]))
        f = models.Fandom.objects.get(name__iexact = d["fandom"])
        k = models.Kind.objects.get(name__iexact = d["kind"])
        i = models.newItem(u, e, d["name"], f, k, Decimal(d["price"]), Decimal(d["cost"]), int(d["numSold"]), int(d["numLeft"]))
        if "image" in d:
            i.setImage(d["image"])
    except models.Event.DoesNotExist as ex:
        return JsonResponse({"error": "invalid: event"}, status = 400)
    except models.Fandom.DoesNotExist as ex:
        return JsonResponse({"error": "invalid: fandom"}, status = 400)
    except models.Kind.DoesNotExist as ex:
        return JsonResponse({"error": "invalid: kind"}, status = 400)
    except ValidationError as ex:
        return JsonResponse({"error": "invalid: %s" % ", ".join(ex.message_dict.keys())}, status = 400)
    return JsonResponse({"itemID": i.ID})
Exemple #4
0
def respillInventory(request):
    d = json.loads(bytes.decode(request.body))
    u = request.user
    try:
        e = models.Event.objects.get(ID = int(d["eventID"]))
        if e == models.INV_EVENT:
            return JsonResponse({"error": "invalid: event"}, status = 400)
        u.items.filter(event = models.INV_EVENT).delete()
        for i in u.items.filter(event = e):
            if not i.tag:
                iTag = uuid.uuid4()
                while u.items.filter(tag = iTag).exists():
                    iTag = uuid.uuid4()
                i.setTag(uuid.uuid4())
            nI = models.newItem(u, models.INV_EVENT, i.name, i.fandom, i.kind, i.price, i.cost, 0, i.numLeft)
            nI.setImage(i.image)
            nI.setTag(i.tag)
    except models.Event.DoesNotExist as ex:
        return JsonResponse({"error": "couldn't find the event"}, status = 400)
    except ValidationError as ex:
        return JsonResponse({"error": "invalid: %s" % ", ".join(ex.message_dict.keys())}, status = 400)
    return JsonResponse({})
Exemple #5
0
def newItem(request):
    d = json.loads(bytes.decode(request.body))
    u = request.user
    try:
        e = models.Event.objects.get(ID=int(d["eventID"]))
        f = models.Fandom.objects.get(name__iexact=d["fandom"])
        k = models.Kind.objects.get(name__iexact=d["kind"])
        i = models.newItem(u, e, d["name"], f, k, Decimal(d["price"]),
                           Decimal(d["cost"]), int(d["numSold"]),
                           int(d["numLeft"]))
        if "image" in d:
            i.setImage(d["image"])
    except models.Event.DoesNotExist as ex:
        return JsonResponse({"error": "invalid: event"}, status=400)
    except models.Fandom.DoesNotExist as ex:
        return JsonResponse({"error": "invalid: fandom"}, status=400)
    except models.Kind.DoesNotExist as ex:
        return JsonResponse({"error": "invalid: kind"}, status=400)
    except ValidationError as ex:
        return JsonResponse(
            {"error": "invalid: %s" % ", ".join(ex.message_dict.keys())},
            status=400)
    return JsonResponse({"itemID": i.ID})
Exemple #6
0
def copyInventory(request):
    d = json.loads(bytes.decode(request.body))
    u = request.user
    try:
        e = models.Event.objects.get(ID=int(d["eventID"]))
        if e == models.INV_EVENT:
            return JsonResponse({"error": "invalid: event"}, status=400)
        for i in u.items.filter(event=models.INV_EVENT):
            nI = None
            if not i.tag:
                iTag = uuid.uuid4()
                while u.items.filter(tag=iTag).exists():
                    iTag = uuid.uuid4()
                i.setTag(uuid.uuid4())
            else:
                nI = u.items.get(Q(event=e) & Q(tag=i.tag))
            if nI:
                nI.setName(i.name)
                nI.setFandom(i.fandom)
                nI.setKind(i.kind)
                nI.setPrice(i.price)
                nI.setCost(i.cost)
                nI.setNumSold(i.numSold)
                #nI.setNumLeft(i.numLeft)
                nI.setImage(i.image)
            else:
                nI = models.newItem(u, e, i.name, i.fandom, i.kind, i.price,
                                    i.cost, i.numSold, i.numLeft)
                nI.setImage(i.image)
    except models.Event.DoesNotExist as ex:
        return JsonResponse({"error": "couldn't find the event"}, status=400)
    except ValidationError as ex:
        return JsonResponse(
            {"error": "invalid: %s" % ", ".join(ex.message_dict.keys())},
            status=400)
    return JsonResponse({})