pokemon flavor texts now available

This commit is contained in:
Zane Adickes 2016-02-24 23:55:59 -05:00
parent 08c4e351e2
commit a16e6418e5
3 changed files with 131 additions and 22 deletions

View file

@ -2338,8 +2338,10 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
method_objects = MoveLearnMethod.objects.all()
method_data = MoveLearnMethodSummarySerializer(method_objects, many=True, context=self.context).data
# Get moves related to this pokemon and pull out unique Move IDs
pokemon_moves = PokemonMove.objects.filter(pokemon_id=obj).order_by('level')
# Get moves related to this pokemon and pull out unique Move IDs. Note that it's important to order
# by the same column we're using to determine if the entries are unique. Otherwise distinct() will
# return apparent duplicates.
pokemon_moves = PokemonMove.objects.filter(pokemon_id=obj).order_by('move_id')
move_ids = pokemon_moves.values('move_id').distinct()
move_list = []
@ -2526,6 +2528,17 @@ class PokemonSpeciesDescriptionSerializer(serializers.ModelSerializer):
fields = ('description', 'language')
class PokemonSpeciesFlavorTextSerializer(serializers.ModelSerializer):
flavor_text = serializers.CharField()
language = LanguageSummarySerializer()
version = VersionSummarySerializer()
class Meta:
model = PokemonSpeciesFlavorText
fields = ('flavor_text', 'language', 'version')
class PokemonSpeciesNameSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()
@ -2551,6 +2564,7 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
form_descriptions = PokemonSpeciesDescriptionSerializer(many=True, read_only=True, source="pokemonspeciesdescription")
pokedex_numbers = PokemonDexEntrySerializer(many=True, read_only=True, source="pokemondexnumber")
egg_groups = serializers.SerializerMethodField('get_pokemon_egg_groups')
flavor_text_entries = PokemonSpeciesFlavorTextSerializer(many=True, read_only=True, source="pokemonspeciesflavortext")
genera = serializers.SerializerMethodField('get_pokemon_genera')
generation = GenerationSummarySerializer()
growth_rate = GrowthRateSummarySerializer()
@ -2558,7 +2572,6 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
habitat = PokemonHabitatSummarySerializer(source="pokemon_habitat")
shape = PokemonShapeSummarySerializer(source="pokemon_shape")
evolves_from_species = PokemonSpeciesSummarySerializer()
varieties = PokemonSummarySerializer(many=True, read_only=True, source="pokemon")
varieties = serializers.SerializerMethodField('get_pokemon_varieties')
evolution_chain = EvolutionChainSummarySerializer()
pal_park_encounters = serializers.SerializerMethodField('get_encounters')
@ -2588,6 +2601,7 @@ class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
'names',
'pal_park_encounters',
'form_descriptions',
'flavor_text_entries',
'genera',
'varieties'
)

View file

@ -1622,6 +1622,25 @@ class APIData():
return pokemon_species_form_description
@classmethod
def setup_pokemon_species_flavor_text_data(self, pokemon_species, flavor_text='pkmn spcs flvr txt'):
version = self.setup_version_data(
name='ver for '+flavor_text)
language = self.setup_language_data(
name='lang for '+flavor_text)
pokemon_species_flavor_text = PokemonSpeciesFlavorText.objects.create (
pokemon_species = pokemon_species,
version = version,
language = language,
flavor_text = flavor_text
)
pokemon_species_flavor_text.save()
return pokemon_species_flavor_text
@classmethod
def setup_pokemon_species_data(self, generation=None, evolves_from_species=None, evolution_chain=None, growth_rate=None, pokemon_color=None, pokemon_habitat=None, pokemon_shape=None, name='pkm spcs', gender_rate=50, capture_rate=20, base_happiness=20, is_baby=False, hatch_counter=10, has_gender_differences=True, forms_switchable=False, order=1):
@ -1849,17 +1868,11 @@ class APIData():
return pokemon_item
@classmethod
def setup_pokemon_move_data(self, pokemon, level=0, order=1):
move = self.setup_move_data(
name='mv for pkmn')
def setup_pokemon_move_data(self, pokemon, move, version_group, level=0, order=1):
move_learn_method = self.setup_move_learn_method_data(
name='mv lrn mthd for pkmn')
version_group = self.setup_version_group_data(
name='ver grp for pkmn')
pokemon_move = PokemonMove.objects.create (
pokemon = pokemon,
version_group = version_group,
@ -3529,6 +3542,7 @@ class APITests(APIData, APITestCase):
pokemon_species = self.setup_pokemon_species_data(evolves_from_species=evolves_from_species, name='base pkmn spcs')
pokemon_species_name = self.setup_pokemon_species_name_data(pokemon_species, name='base pkmn shp name')
pokemon_species_form_description = self.setup_pokemon_species_form_description_data(pokemon_species, description='frm dscr for pkmn spcs')
pokemon_species_flavor_text = self.setup_pokemon_species_flavor_text_data(pokemon_species, flavor_text='flvr txt for pkmn spcs')
pokedex = self.setup_pokedex_data(name='pkdx for pkmn spcs')
pal_park = self.setup_pal_park_data(pokemon_species=pokemon_species)
@ -3597,6 +3611,12 @@ class APITests(APIData, APITestCase):
self.assertEqual(response.data['form_descriptions'][0]['description'], pokemon_species_form_description.description)
self.assertEqual(response.data['form_descriptions'][0]['language']['name'], pokemon_species_form_description.language.name)
self.assertEqual(response.data['form_descriptions'][0]['language']['url'], '{}{}/language/{}/'.format(test_host, api_v2, pokemon_species_form_description.language.pk))
# flavor text params
self.assertEqual(response.data['flavor_text_entries'][0]['flavor_text'], pokemon_species_flavor_text.flavor_text)
self.assertEqual(response.data['flavor_text_entries'][0]['language']['name'], pokemon_species_flavor_text.language.name)
self.assertEqual(response.data['flavor_text_entries'][0]['language']['url'], '{}{}/language/{}/'.format(test_host, api_v2, pokemon_species_flavor_text.language.pk))
self.assertEqual(response.data['flavor_text_entries'][0]['version']['name'], pokemon_species_flavor_text.version.name)
self.assertEqual(response.data['flavor_text_entries'][0]['version']['url'], '{}{}/version/{}/'.format(test_host, api_v2, pokemon_species_flavor_text.version.pk))
# pal park params
self.assertEqual(response.data['pal_park_encounters'][0]['base_score'], pal_park.base_score)
self.assertEqual(response.data['pal_park_encounters'][0]['rate'], pal_park.rate)
@ -3613,9 +3633,22 @@ class APITests(APIData, APITestCase):
pokemon_stat = self.setup_pokemon_stat_data(pokemon=pokemon)
pokemon_type = self.setup_pokemon_type_data(pokemon=pokemon)
pokemon_item = self.setup_pokemon_item_data(pokemon=pokemon)
pokemon_move = self.setup_pokemon_move_data(pokemon=pokemon)
pokemon_sprites = self.setup_pokemon_sprites_data(pokemon=pokemon)
pokemon_game_index = self.setup_pokemon_game_index_data(pokemon=pokemon, game_index=10)
# To test issue #85, we will create one move that has multiple
# learn levels in different version groups. Later, we'll
# assert that we only got one move record back.
pokemon_move = self.setup_move_data(name='mv for pkmn')
pokemon_moves = []
for move in range(0,4):
version_group = self.setup_version_group_data(
name='ver grp '+str(move)+' for pkmn')
new_move = self.setup_pokemon_move_data(
pokemon=pokemon,
move=pokemon_move,
version_group=version_group,
level=move)
pokemon_moves.append(new_move)
encounter_method = self.setup_encounter_method_data(name='encntr mthd for lctn area')
location_area1 = self.setup_location_area_data(name='lctn1 area for base pkmn')
@ -3661,14 +3694,56 @@ class APITests(APIData, APITestCase):
self.assertEqual(response.data['held_items'][0]['version_details'][0]['rarity'], pokemon_item.rarity)
self.assertEqual(response.data['held_items'][0]['version_details'][0]['version']['name'], pokemon_item.version.name)
self.assertEqual(response.data['held_items'][0]['version_details'][0]['version']['url'], '{}{}/version/{}/'.format(test_host, api_v2, pokemon_item.version.pk))
# move params
self.assertEqual(response.data['moves'][0]['move']['name'], pokemon_move.move.name)
self.assertEqual(response.data['moves'][0]['move']['url'], '{}{}/move/{}/'.format(test_host, api_v2, pokemon_move.move.pk))
self.assertEqual(response.data['moves'][0]['version_group_details'][0]['level_learned_at'], pokemon_move.level)
self.assertEqual(response.data['moves'][0]['version_group_details'][0]['version_group']['name'], pokemon_move.version_group.name)
self.assertEqual(response.data['moves'][0]['version_group_details'][0]['version_group']['url'], '{}{}/version-group/{}/'.format(test_host, api_v2, pokemon_move.version_group.pk))
self.assertEqual(response.data['moves'][0]['version_group_details'][0]['move_learn_method']['name'], pokemon_move.move_learn_method.name)
self.assertEqual(response.data['moves'][0]['version_group_details'][0]['move_learn_method']['url'], '{}{}/move-learn-method/{}/'.format(test_host, api_v2, pokemon_move.move_learn_method.pk))
# move params -- Make sure that we only got one move back,
# but that we got all of the distinct version group and learn
# level values. (See issue #85)
# Number of Moves
expected = 1
actual = len(response.data['moves'])
self.assertEqual(expected, actual)
# Move name
expected = pokemon_moves[0].move.name
actual = response.data['moves'][0]['move']['name']
self.assertEqual(expected, actual)
# Move URL
expected = '{}{}/move/{}/'.format(
test_host,
api_v2,
pokemon_moves[0].move.pk)
actual = response.data['moves'][0]['move']['url']
self.assertEqual(expected, actual)
# Numbver of version groups
expected = len(pokemon_moves)
actual = len(response.data['moves'][0]['version_group_details'])
self.assertEqual(expected, actual)
for i in range(0,len(pokemon_moves)):
version = response.data['moves'][0]['version_group_details'][i]
# Learn Level
expected = pokemon_moves[i].level
actual = version['level_learned_at']
self.assertEqual(expected ,actual)
# Version Group Name
expected = pokemon_moves[i].version_group.name
actual = version['version_group']['name']
self.assertEqual(expected, actual)
# Version Group URL
expected = '{}{}/version-group/{}/'.format(
test_host,
api_v2,
pokemon_moves[i].version_group.pk)
actual = version['version_group']['url']
self.assertEqual(expected, actual)
# Learn Method Name
expected = pokemon_moves[i].move_learn_method.name
actual = version['move_learn_method']['name']
self.assertEqual(expected, actual)
# Learn Method URL
expected = '{}{}/move-learn-method/{}/'.format(
test_host,
api_v2,
pokemon_moves[i].move_learn_method.pk)
actual = version['move_learn_method']['url']
self.assertEqual(expected, actual)
# game indices params
self.assertEqual(response.data['game_indices'][0]['game_index'], pokemon_game_index.game_index)
self.assertEqual(response.data['game_indices'][0]['version']['name'], pokemon_game_index.version.name)

View file

@ -2684,6 +2684,18 @@ A Pokemon Species forms the basis for at least one pokemon. Attributes of a Poke
"url": "http://pokeapi.co/api/v2/language/9/"
}
}],
"flavor_text_entries": [
{
"flavor_text": "When the bulb on\nits back grows\nlarge, it appears\fto lose the\nability to stand\non its hind legs.",
"language": {
"name": "en",
"url": "http://localhost:8000/api/v2/language/9/"
},
"version": {
"name": "red",
"url": "http://localhost:8000/api/v2/version/1/"
}
}],
"form_descriptions": [{
"description": "Forms have different stats and movepools. During evolution, Burmy's current cloak becomes Wormadam's form, and can no longer be changed.",
"language": {
@ -2735,7 +2747,8 @@ A Pokemon Species forms the basis for at least one pokemon. Attributes of a Poke
| generation | The generation this pokemon species was introduced in | [NamedAPIResource](#namedapiresource) ([Generation](#generations)) |
| names | The name of this pokemon species listed in different languages | list [Name](#resourcename) |
| pal_park_encounters | A list of encounters that can be had with this pokemon species in pal park | list [PalParkEncounterArea](#palparkencounterarea) |
| form_descriptions | Descriptions of different forms pokemon take on within the pokemon species | list [Description](#description) |
| flavor_text_entries | The flavor text of this flavor text listed in different languages | list [PokemonSpeciesFlavorText](#pokemonspeciesflavortext) |
| form_descriptions | Descriptions of different forms pokemon take on within the pokemon species | list [Description](#description) |
| genera | The genus of this pokemon species listed in multiple languages | [Genus](#genus) |
| varieties | A list of the pokemon that exist within this pokemon species | list [NamedAPIResource](#namedapiresource) ([Pokemon](#pokemon)) |
@ -2761,6 +2774,13 @@ A Pokemon Species forms the basis for at least one pokemon. Attributes of a Poke
| rate | The base rate for encountering the referenced pokemon in this pal park area | integer |
| area | The pal park area where this encounter happens | [NamedAPIResource](#namedapiresource) ([PalParkArea](#pal-park-areas)) |
#### PokemonSpeciesFlavorText
| Name | Description | Data Type |
| ---- | ----------- | --------- |
| flavor_text | The localized flavor text for an api resource in a specific language | string |
| language | The language this name is in | [NamedAPIResource](#namedapiresource) ([Language](#languages)) |
| version | The version this flavor text entry is used in | [NamedAPIResource](#namedapiresource) ([Version](#versions)) |
## Stats
Stats determine certain aspects of battles. Each pokemon has a value for each stat which grows as they gain levels and can be altered momenarily by effects in battles.
@ -3054,8 +3074,8 @@ Languages for translations of api resource information.
| Name | Description | Data Type |
| ---- | ----------- | --------- |
| flavor_text | The localized name for an api resource in a specific language | string |
| language | The language this name is in | [NamedAPIResource](#namedapiresource) ([Language](#languages)) |
| flavor_text | The localized flavor text for an api resource in a specific language | string |
| language | The language this name is in | [NamedAPIResource](#namedapiresource) ([Language](#languages)) |
#### GenerationGameIndex