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])
def showType(type): """Show all 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)) # If type specified is "All", use showHome that displays all pokemon if type.lower() == 'all': return redirect(url_for('showHome')) type_id = get_type_id(string.capwords(type), session) # Create a collection of the pokemon with the specified type pokemon_list = [] 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) # Indication for when there are no pokemon found with the specified type if not pokemon_list: flash('There are currently no %s type pokemon in the database.' % type) # Page shown is different when a user is logged-in. Add option is available if 'email' in login_session: return render_template('home_signed_in.html', pokemon_list=pokemon_list, types=all_types, selected_type=string.capwords(type)) else: return render_template('home.html', pokemon_list=pokemon_list, types=all_types, selected_type=string.capwords(type))
def parse_type_list(type_input): """Get the list of types from the comma-separated input""" separated_input = type_input.split(',') type_list = [] if separated_input: # All possible types have been added in the database. # Check each type input now for validity for item in separated_input: type = string.capwords(item.strip()) id = get_type_id(type, session) if (id is not None): type_list.append(id) return type_list
session.add(move_tail_whip) session.add(move_take_down) session.add(move_vine_whip) session.add(move_water_gun) session.add(move_water_pulse) session.add(move_withdraw) session.add(move_worry_seed) session.commit() print('Added initial moves') # Pokemon # BULBASAUR bulbasaur_type_id_list = [] bulbasaur_type_id_list.append(get_type_id('Grass', session)) bulbasaur_type_id_list.append(get_type_id('Poison', session)) bulbasaur_weakness_id_list = [] bulbasaur_weakness_id_list.append(get_type_id('Fire', session)) bulbasaur_weakness_id_list.append(get_type_id('Flying', session)) bulbasaur_weakness_id_list.append(get_type_id('Ice', session)) bulbasaur_weakness_id_list.append(get_type_id('Psychic', session)) bulbasur_move_id_list = [] bulbasur_move_id_list.append(get_move_id('Tackle', session)) bulbasur_move_id_list.append(get_move_id('Growl', session)) bulbasur_move_id_list.append(get_move_id('Leech Seed', session)) bulbasur_move_id_list.append(get_move_id('Vine Whip', session)) bulbasur_move_id_list.append(get_move_id('Poison Powder', session)) bulbasur_move_id_list.append(get_move_id('Sleep Powder', session))