Example #1
0
def like(request, guid):
    obj = Piece.fromGuid(guid)
    res = Result()
    if obj.like(request):
        emailLike(request, obj)
    else:
        res.message = 'Cannot "like" things more than once'

    res.append(obj.json())

    return JsonResponse(res.asDict())
Example #2
0
def like(request, guid):
    obj = Piece.fromGuid(guid)
    res = Result()
    if obj.like(request):
        emailLike(request, obj)
    else:
        res.isError = True
        res.message = 'Cannot "like" things more than once'

    res.append(obj.json())

    return JsonResponse(res.asDict())
Example #3
0
def group(request, obj_id=None):
    res = Result()

    if request.method == "GET":
        try:
            group = Group.objects.get(pk=obj_id)
            res.append(group.json())
        except ObjectDoesNotExist as err:
            res.isError = True
            res.message = str(err)
    elif request.method == "POST":
        data = json.loads(request.body)["body"]
        user = getUser(request)
        if user:
            items = getObjectsFromGuids(data["guids"])
            gallery = data.get("gallery")
            g = Group()
            g.author = user
            g.title = data.get("title", items[0].title)
            g.thumbnail = items[0].thumbnail
            g.description = data.get("description", items[0].description)
            g.save()
            g.guid = g.getGuid().guid
            g.save()

            if gallery:
                Gallery.objects.get(pk=gallery).groups.add(g)

            for item in items:
                g.appendChild(item)
            res.append(g.json())
        else:
            res.isError = True
            res.message = "No user found to create group"
    elif request.method == "PUT":
        data = json.loads(request.body)["body"]
        g = Group.objects.get(pk=obj_id)
        action = data["action"]
        index = data.get("index")
        item = Piece.fromGuid(data["guid"])
        if action == "append":
            g.appendChild(item)
        elif action == "insert":
            g.insertChild(index, item)
        else:
            g.removeChild(item)
        res.append(g.json())
    else:
        g = Group.objects.get(pk=obj_id)
        g.delete()

    return JsonResponse(res.asDict())
Example #4
0
def data(request, guid):
    obj = Piece.fromGuid(guid)
    if request.method == "GET":
        res = Result()
        res.append(obj.json())

        return JsonResponse(res.asDict())
    elif request.method == "POST":
        return post(request, obj)
    elif request.method == "PUT":
        return put(request, obj)
    elif request.method == "DELETE":
        return delete(request, obj)
Example #5
0
def data(request, guid):
    obj = Piece.fromGuid(guid)
    if request.method == 'GET':
        res = Result()
        res.append(obj.json())

        return JsonResponse(res.asDict())
    elif request.method == 'POST':
        return post(request, obj)
    elif request.method == 'PUT':
        getPutData(request)
        return put(request, obj)
    elif request.method == 'DELETE':
        getPutData(request)
        return delete(request, obj)
Example #6
0
def data(request, guid):
    obj = Piece.fromGuid(guid)
    if request.method == 'GET':
        res = Result()
        res.append(obj.json())

        return JsonResponse(res.asDict())
    elif request.method == 'POST':
        return post(request, obj)
    elif request.method == 'PUT':
        getPutData(request)
        return put(request, obj)
    elif request.method == 'DELETE':
        getPutData(request)
        return delete(request, obj)