コード例 #1
0
def mochila(mochila_id):
    if request.method == "GET":
        try:
            return SerializadorMochila(
                Mochila.get(Mochila.id == mochila_id)).data
        except:
            return Response(status=STATUS_NOT_FOUND)
    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        mochila = Mochila.get(Mochila.id == mochila_id)
        serializador = SerializadorMochila(mochila, attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
コード例 #2
0
ファイル: views.py プロジェクト: jcarizza/rest_pyconar_2014
def mochila(mochila_id):
    if request.method == "GET":
        try:
            return SerializadorMochila(Mochila.get(Mochila.id == mochila_id)).data
        except:
            return Response(status=STATUS_NOT_FOUND)
    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        mochila = Mochila.get(Mochila.id == mochila_id)
        serializador = SerializadorMochila(mochila, attrs=attrs)
        serializador.save()
        return Response(
            serializador.data,
            status=STATUS_CREATED,
            mimetype="application/json"
        )
コード例 #3
0
def mochilas():
    if request.method == "GET":
        return Response(SerializadorMochila(Mochila.select(), many=True).data,
                        status=STATUS_OK,
                        mimetype="application/json")
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorMochila(attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
コード例 #4
0
ファイル: views.py プロジェクト: jcarizza/rest_pyconar_2014
def mochilas():
    if request.method == "GET":
        return Response(
            SerializadorMochila(Mochila.select(), many=True).data,
            status=STATUS_OK,
            mimetype="application/json"
        )
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorMochila(attrs=attrs)
        serializador.save()
        return Response(
            serializador.data,
            status=STATUS_CREATED,
            mimetype="application/json"
        )