Exemple #1
0
def pokemons():
    if request.method == "GET":
        return Response(SerializadorPokemon(Pokemon.select(), many=True).data,
                        status=STATUS_OK,
                        mimetype="application/json")
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorPokemon(attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
Exemple #2
0
def pokemon(pokemon_id):
    if request.method == "GET":
        try:
            obj = Pokemon.get(Pokemon.id == pokemon_id)
            return SerializadorPokemon(obj).data
        except Pokemon.DoesNotExist:
            return Response(status=STATUS_NOT_FOUND)

    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        pokebola = Pokemon.get(Pokemon.id == pokemon_id)
        serializador = SerializadorPokemon(pokebola, attrs=attrs)
        serializador.save()
        return Response(serializador.data,
                        status=STATUS_CREATED,
                        mimetype="application/json")
Exemple #3
0
def pokemons():
    if request.method == "GET":
        return Response(
            SerializadorPokemon(Pokemon.select(), many=True).data,
            status=STATUS_OK,
            mimetype="application/json"
        )
    elif request.method == "POST":
        attrs = json.loads(request.data.decode("utf8"))
        serializador = SerializadorPokemon(attrs=attrs)
        serializador.save()
        return Response(
            serializador.data,
            status=STATUS_CREATED,
            mimetype="application/json"
        )
Exemple #4
0
def pokemon(pokemon_id):
    if request.method == "GET":
        try:
            obj = Pokemon.get(Pokemon.id == pokemon_id)
            return SerializadorPokemon(obj).data
        except Pokemon.DoesNotExist:
            return Response(status=STATUS_NOT_FOUND)

    elif request.method == "PUT":
        attrs = json.loads(request.data.decode("utf8"))
        pokebola = Pokemon.get(Pokemon.id == pokemon_id)
        serializador = SerializadorPokemon(pokebola, attrs=attrs)
        serializador.save()
        return Response(
            serializador.data,
            status=STATUS_CREATED,
            mimetype="application/json"
        )