Beispiel #1
0
def post(request):
    """Sets a key to a value on the currently logged in users preferences

    :param key: Key to set
    :type key: str
    :param val: Value to set
    :type val: primitive
    :returns: json
    """
    data = request.POST or json.loads(request.body)['body']
    key = data.get('key', None)
    val = data.get('val', None)
    res = Result()
    if key is not None and val is not None:
        obj, created = UserPref.objects.get_or_create(user=request.user)
        if created:
            obj.data = json.dumps(DefaultPrefs.copy())
            obj.save()
        try:
            val = json.loads(val)
        except (TypeError, ValueError):
            pass
        obj.setKey(key, val)
        obj.save()
        res.append(obj.json())

    return JsonResponse(res.asDict())
Beispiel #2
0
def post(request):
    """Sets a key to a value on the currently logged in users preferences

    :param key: Key to set
    :type key: str
    :param val: Value to set
    :type val: primitive
    :returns: json
    """
    key = request.POST.get('key', None)
    val = request.POST.get('val', None)
    res = Result()
    if key and val:
        obj, created = UserPref.objects.get_or_create(user=request.user)
        if created:
            obj.data = json.dumps(DefaultPrefs.copy())
            obj.save()
        val = json.loads(val)
        obj.setKey(key, val)
        obj.save()
        res.append(obj.json())
        res.isSuccess = True
    else:
        res.isError = True
        res.message = 'No key and value provided'

    return JsonResponse(res)
Beispiel #3
0
def get(request):
    """Gets the currently logged in users preferences

    :returns: json
    """
    res = Result()
    obj, created = UserPref.objects.get_or_create(user=request.user)
    if created:
        obj.data = json.dumps(DefaultPrefs.copy())
        obj.save()
    res.append(obj.json())
    res.isSuccess = True

    return JsonResponse(res)
Beispiel #4
0
def get(request):
    """Gets the currently logged in users preferences

    :returns: json
    """
    res = Result()
    obj, created = UserPref.objects.get_or_create(user=request.user, defaults={'data': json.dumps(DefaultPrefs.copy())})

    data = obj.json()
    data['subscriptions'] = [_.json() for _ in GallerySubscription.objects.filter(user=request.user)]

    res.append(data)

    return JsonResponse(res.asDict())
Beispiel #5
0
def get(request):
    """Gets the currently logged in users preferences

    :returns: json
    """
    res = Result()
    obj, created = UserPref.objects.get_or_create(user=request.user, defaults={'data': json.dumps(DefaultPrefs.copy())})
    res.append(obj.json())

    return JsonResponse(res.asDict())