Beispiel #1
0
def pokebolas():
    if request.method == "GET":
        return Response(SerializadorPokebola(Pokebola.select(),
                                             many=True).data,
                        status=STATUS_OK,
                        mimetype="application/json")
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorPokebola(attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
Beispiel #2
0
def pokebola(pokebola_id):
    if request.method == "GET":
        try:
            return SerializadorPokebola(
                Pokebola.get(Pokebola.id == pokebola_id)).data
        except:
            return Response(status=STATUS_NOT_FOUND)
    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        pokebola = Pokebola.get(Pokebola.id == pokebola_id)
        serializador = SerializadorPokebola(pokebola, attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
Beispiel #3
0
def pokebola(pokebola_id):
    if request.method == "GET":
        try:
            return SerializadorPokebola(Pokebola.get(Pokebola.id == pokebola_id)).data
        except:
            return Response(status=STATUS_NOT_FOUND)
    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        pokebola = Pokebola.get(Pokebola.id == pokebola_id)
        serializador = SerializadorPokebola(pokebola, attrs=attrs)
        serializador.save()
        return Response(
            serializador.data,
            status=STATUS_CREATED,
            mimetype="application/json"
        )
Beispiel #4
0
def pokebolas():
    if request.method == "GET":
        return Response(
            SerializadorPokebola(Pokebola.select(), many=True).data,
            status=STATUS_OK,
            mimetype="application/json"
        )
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorPokebola(attrs=attrs)
        serializador.save()
        return Response(
            serializador.data,
            status=STATUS_CREATED,
            mimetype="application/json"
        )
Beispiel #5
0
def pokebolas_en_mochila(mochila_id):
    return SerializadorPokebola(
        Pokebola.filter(Pokebola.mochila == mochila_id), many=True).data