Exemplo n.º 1
0
def showTypeJson(type):
    """Show JSON format of entries and details of pokemon with the specified
       type
    """

    all_pokemon_list = session.query(Pokemon).order_by(asc(Pokemon.pokedex_id))
    all_types = session.query(Type).order_by(asc(Type.name))
    pokemon_list = []

    if type.lower() == 'all':
        # Type: All shows all the pokemon
        pokemon_list = all_pokemon_list

    else:
        type_id = get_type_id(string.capwords(type), session)

        # Create a collection of pokemon with the specified type
        if all_pokemon_list:
            for pokemon in all_pokemon_list:
                type_list = list(pokemon.type_list)
                if type_id in type_list:
                    pokemon_list.append(pokemon)

    # Return JSON format of the collection of pokemon
    return jsonify(Pokemon=[(Pokemon_VM(pokemon, session)).serialize
                            for pokemon in pokemon_list])
Exemplo n.º 2
0
def showAllJson():
    """Shows all pokemon entries and details for each in JSON"""

    pokemon_list = session.query(Pokemon).all()

    # Use view model to display readable strings for columns containing
    # pointers to list
    return jsonify(Pokemon=[(Pokemon_VM(pokemon, session)).serialize
                            for pokemon in pokemon_list])
Exemplo n.º 3
0
def showPokemonJson(id):
    """Show JSON format of the details of the pokemon with the specified id"""

    # Get the pokemon
    pokemon = session.query(Pokemon).filter_by(id=id).first()

    if pokemon:
        # Show displayable string
        pokemon_view_model = Pokemon_VM(pokemon, session)

        return jsonify(Pokemon=[pokemon_view_model.serialize])
    else:
        # Return an empty collection
        return jsonify(Pokemon=[])
Exemplo n.º 4
0
def showPokemon(id):
    """Show details page for the pokemon with the specified ID"""

    pokemon = session.query(Pokemon).filter_by(id=id).one()

    # Map the pokemon entry from the database to a structure with displayable
    # properties. Ex. Some entries are pointers to lists. Display
    # comma-separated list of corresponding strings instead
    pokemon_view_model = Pokemon_VM(pokemon, session)

    # If the entry's creator is signed in, the page allows Edits and Deletes
    if 'email' in login_session:
        if login_session['user_id'] == pokemon.user_id:
            return render_template('details_signed_in.html',
                                   pokemon=pokemon_view_model)

    return render_template('details.html', pokemon=pokemon_view_model)