コード例 #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")
コード例 #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")
コード例 #3
0
ファイル: views.py プロジェクト: jcarizza/rest_pyconar_2014
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"
        )
コード例 #4
0
ファイル: views.py プロジェクト: jcarizza/rest_pyconar_2014
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"
        )