Exemple #1
0
def createWish(request):
    if request.method == 'POST':
        user = request.user
        response = json.loads(request.body)
        if 'WISH' in response:
            wish = Wish()
            wish.user = user
            wish.text = strip_tags(str(response['WISH']))
            wish.status = 0  # Not done; 1 Refused; 2 Accepted
            wish.save()
            data = errorCheckMessage(True, None)
        else:
            data = errorCheckMessage(False, "badFormat")
    else:
        data = errorCheckMessage(False, "badRequest")
    return JsonResponse(data)
Exemple #2
0
def createWish(request):
    if request.method == 'POST':
        user = request.user
        response = json.loads(request.body)
        if checkPermission(["WISH"], user):
            if 'WISH' in response:
                wish = Wish()
                wish.user = user
                wish.text = strip_tags(str(response['WISH']))
                wish.status = 0  # Not done; 1 Refused; 2 Accepted; 3 Read
                wish.save()
                data = errorCheckMessage(True, None, createWish)
            else:
                data = errorCheckMessage(False, ErrorEnum.BAD_FORMAT,
                                         createWish)
        else:
            data = errorCheckMessage(False, ErrorEnum.PERMISSION_ERROR,
                                     createWish, user)
    else:
        data = errorCheckMessage(False, ErrorEnum.BAD_REQUEST, createWish)
    return JsonResponse(data)