Example #1
0
def post_bounty(request):
    if request.method == 'POST' and request.user.is_authenticated: 
        serializer = BountySerializer(data=request.data)
        cb_user = ChowBountyUser.objects.get(user=request.user)
        if serializer.is_valid():
            bounty = serializer.save(cb_user=cb_user)
            for bountyitem in request.data['bountyitem_set']:
                item_serializer = BountyItemSerializer(data = bountyitem)
                if item_serializer.is_valid():
                    item = item_serializer.save(bounty=bounty)
            return HttpResponse(bounty.id)
        else:
            return HttpResponse(serializer.errors)
    else:
        return HttpResponse("No dice")
Example #2
0
def update_bounty(request):
    if request.method == 'POST' and request.user.is_authenticated: 
        try:
            bounty = Bounty.objects.get(pk=request.data['id'])
        except Bounty.DoesNotExist:
            return HttpResponse(status=404)
        serializer = BountySerializer(bounty, data=request.data)
        cb_user = ChowBountyUser.objects.get(user=request.user)
        if serializer.is_valid():
            serializer.save()
            BountyItem.objects.filter(bounty = bounty).delete()
            for bountyitem in request.data['bountyitem_set']:
                item_serializer = BountyItemSerializer(data = bountyitem)
                if item_serializer.is_valid():
                    item = item_serializer.save(bounty=bounty)
            return HttpResponse(bounty.id)
        else:
            return HttpResponse(serializer.errors)
    else:
        return HttpResponse("No dice")