コード例 #1
0
def layer(request, id=None):
    if id == None and request.method == "POST":
        data = simplejson.loads(request.raw_post_data)
        l = Layer()
        l.from_json(data)
        return json_response(request, l)
    elif id != None and id != "all":
        l = Layer.objects.get(pk=id)
        return json_response(request, l)
    else:
        layers = Layer.objects.all()
        data = {'layers': [l.to_json() for l in layers]}
        return json_response(request, data)
コード例 #2
0
ファイル: views.py プロジェクト: crschmidt/oam
def layer(request, id=None):
    if id == None and request.method == "POST":
        data = simplejson.loads(request.raw_post_data)
        l = Layer()
        l.from_json(data)
        return json_response(request, l)
    elif id != None and id != "all":
        l = Layer.objects.get(pk=id)
        return json_response(request, l)
    else:
        layers = Layer.objects.all()
        data = {'layers': [
            l.to_json() for l in layers
            ]
        }    
        return json_response(request, data)
コード例 #3
0
ファイル: views.py プロジェクト: fevzidas/oam
def layer(request, id=None):
    @logged_in_or_basicauth()
    def handle_update(request, layer):
        data = simplejson.loads(request.raw_post_data)
        warnings = []
        layer.from_json(data, request.user)
        layer.save()
        return json_response(request, layer)

    if id == None and request.method == "POST":
        l = Layer()
        return handle_update(request, l)
    elif id != None and request.method == "POST":
        l = Layer.objects.get(pk=id)
        return handle_update(request, l)
    elif id != None:
        l = Layer.objects.get(pk=id)
        if request.method == "DELETE":
            i.delete()
            return json_response(request, "")
        return json_response(request, l)
    else:
        layers = Layer.objects.all()
        if 'q' in request.GET:
            for term in request.GET['q'].split(" "):
                layers = layers.filter(name__icontains=term)
        if request.GET.get('output') == "simple":
            layers = layers.annotate(Count('image'))
            data = {
                'layers': [
                    dict(x) for x in layers.values("id", "name", "description",
                                                   "image__count")
                ]
            }
            for l in data['layers']:
                l['image_count'] = l['image__count']
                del l['image__count']

        else:
            data = {'layers': [l.to_json() for l in layers]}
        return json_response(request, data)
コード例 #4
0
ファイル: views.py プロジェクト: aaronr/oam
def layer(request, id=None):
    @logged_in_or_basicauth()
    def handle_update(request, layer):
        data = simplejson.loads(request.raw_post_data)
        warnings = []
        layer.from_json(data, request.user)
        layer.save()
        return json_response(request, layer)
    if id == None and request.method == "POST":
        l = Layer()
        return handle_update(request, l)
    elif id != None and request.method == "POST":
        l = Layer.objects.get(pk=id)
        return handle_update(request, l)
    elif id != None:
        l = Layer.objects.get(pk=id)
        if request.method == "DELETE":
            i.delete()
            return json_response(request, "")
        return json_response(request, l)
    else:
        layers = Layer.objects.all()
        if 'q' in request.GET:
            for term in request.GET['q'].split(" "):
                layers = layers.filter(name__icontains=term)
        if request.GET.get('output') == "simple":
            layers = layers.annotate(Count('image'))
            data = {'layers': 
             [dict(x) for x in layers.values("id", "name", "description", "image__count")]
            }
            for l in data['layers']:
                l['image_count'] = l['image__count']
                del l['image__count']

        else:    
            data = {'layers': [
                l.to_json() for l in layers
                ]
            }    
        return json_response(request, data)