mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-10 14:14:17 +00:00
apis for locations, location areas, encounters, encounter rates, characteristics, contests, super contests
This commit is contained in:
parent
b099558de2
commit
c1f1f9ace7
7 changed files with 581 additions and 97 deletions
|
@ -51,12 +51,12 @@ router.register(r"ability", AbilityResource)
|
|||
router.register(r"berry", BerryResource)
|
||||
router.register(r"berry-firmness", BerryFirmnessResource)
|
||||
router.register(r"characteristic", CharacteristicResource)
|
||||
router.register(r"contest-type", ContestTypeResource)
|
||||
router.register(r"contest-effect", ContestEffectResource)
|
||||
router.register(r"egg-group", EggGroupResource)
|
||||
|
||||
router.register(r"encounter", EncounterResource) # ?
|
||||
router.register(r"encounter-method", EncounterMethodResource) # ?
|
||||
router.register(r"encounter-slot", EncounterSlotResource) # ?
|
||||
|
||||
router.register(r"encounter-condition", EncounterConditionResource) # ?
|
||||
router.register(r"encounter-condition-value", EncounterConditionValueResource) # ?
|
||||
router.register(r"evolution-chain", EvolutionChainResource)
|
||||
router.register(r"evolution-trigger", EvolutionTriggerResource)
|
||||
router.register(r"generation", GenerationResource)
|
||||
|
@ -67,10 +67,8 @@ router.register(r"item-attribute", ItemAttributeResource)
|
|||
router.register(r"item-fling-effect", ItemFlingEffectResource)
|
||||
router.register(r"item-pocket", ItemPocketResource)
|
||||
router.register(r"language", LanguageResource)
|
||||
|
||||
router.register(r"location", LocationResource)
|
||||
router.register(r"location-area", LocationAreaResource) # ?
|
||||
|
||||
router.register(r"move", MoveResource)
|
||||
router.register(r"move-ailment", MoveMetaAilmentResource)
|
||||
router.register(r"move-category", MoveMetaCategoryResource)
|
||||
|
@ -87,6 +85,7 @@ router.register(r"pokemon-color", PokemonColorResource)
|
|||
router.register(r"pokemon-form", PokemonFormResource)
|
||||
router.register(r"region", RegionResource)
|
||||
router.register(r"stat", StatResource)
|
||||
router.register(r"super-contest-effect", SuperContestEffectResource)
|
||||
router.register(r"type", TypeResource)
|
||||
router.register(r"version", VersionResource)
|
||||
router.register(r"version-group", VersionGroupResource)
|
||||
|
|
|
@ -1626,21 +1626,6 @@ for index, info in enumerate(data):
|
|||
model.save()
|
||||
|
||||
|
||||
clearTable(LocationAreaEncounterRate)
|
||||
data = loadData('location_area_encounter_rates.csv')
|
||||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
model = LocationAreaEncounterRate (
|
||||
location_area = LocationArea.objects.get(pk = int(info[0])),
|
||||
encounter_method = None,
|
||||
version = Version.objects.get(pk = int(info[2])),
|
||||
rate = int(info[3])
|
||||
)
|
||||
model.save()
|
||||
|
||||
|
||||
|
||||
#############
|
||||
# POKEMON #
|
||||
|
@ -2062,6 +2047,28 @@ for index, info in enumerate(data):
|
|||
model.save()
|
||||
|
||||
|
||||
# LocationAreaEncounterRate/EncounterMethod associations
|
||||
"""
|
||||
I tried handling this the same way Berry/Natures are handled
|
||||
but for some odd reason it resulted in a ton of db table issues.
|
||||
It was easy enough to move LocationAreaEncounterRates below
|
||||
Encounter population and for some reason things works now.
|
||||
"""
|
||||
clearTable(LocationAreaEncounterRate)
|
||||
data = loadData('location_area_encounter_rates.csv')
|
||||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
model = LocationAreaEncounterRate (
|
||||
location_area = LocationArea.objects.get(pk = int(info[0])),
|
||||
encounter_method = EncounterMethod.objects.get(pk=info[1]),
|
||||
version = Version.objects.get(pk = int(info[2])),
|
||||
rate = int(info[3])
|
||||
)
|
||||
model.save()
|
||||
|
||||
|
||||
clearTable(EncounterMethodName)
|
||||
data = loadData('encounter_method_prose.csv')
|
||||
|
||||
|
@ -2179,17 +2186,6 @@ for index, info in enumerate(data):
|
|||
model.save()
|
||||
|
||||
|
||||
#Location/Encounter associations
|
||||
data = loadData('location_area_encounter_rates.csv')
|
||||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
laer = LocationAreaEncounterRate.objects.get(pk = int(info[0]))
|
||||
laer.encounter_method = EncounterMethod.objects.get(pk = int(info[1]))
|
||||
laer.save()
|
||||
|
||||
|
||||
|
||||
##############
|
||||
# PAL PARK #
|
||||
|
|
20
pokemon_v2/migrations/0002_auto_20151102_2124.py
Normal file
20
pokemon_v2/migrations/0002_auto_20151102_2124.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pokemon_v2', '0001_squashed_0024_auto_20151027_0023'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='encounterconditionvaluename',
|
||||
name='encounter_condition_value',
|
||||
field=models.ForeignKey(related_name='encounterconditionvaluename', blank=True, to='pokemon_v2.EncounterConditionValue', null=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
20
pokemon_v2/migrations/0003_auto_20151105_0309.py
Normal file
20
pokemon_v2/migrations/0003_auto_20151105_0309.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('pokemon_v2', '0002_auto_20151102_2124'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='supercontesteffectflavortext',
|
||||
name='super_contest_effect',
|
||||
field=models.ForeignKey(related_name='supercontesteffectflavortext', blank=True, to='pokemon_v2.SuperContestEffect', null=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -840,7 +840,7 @@ class EncounterConditionValue(HasEncounterCondition, HasName):
|
|||
|
||||
class EncounterConditionValueName(IsName):
|
||||
|
||||
encounter_condition_value = models.ForeignKey(EncounterConditionValue, blank = True, null = True)
|
||||
encounter_condition_value = models.ForeignKey(EncounterConditionValue, blank = True, null = True, related_name="%(class)s")
|
||||
|
||||
|
||||
class EncounterConditionValueMap(models.Model):
|
||||
|
@ -1116,7 +1116,7 @@ class SuperContestEffect(models.Model):
|
|||
|
||||
class SuperContestEffectFlavorText(IsFlavorText):
|
||||
|
||||
super_contest_effect = models.ForeignKey(SuperContestEffect, blank = True, null = True)
|
||||
super_contest_effect = models.ForeignKey(SuperContestEffect, blank = True, null = True, related_name="%(class)s")
|
||||
|
||||
|
||||
class SuperContestCombo(models.Model):
|
||||
|
|
|
@ -43,17 +43,35 @@ class CharacteristicSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|||
model = Characteristic
|
||||
fields = ('url',)
|
||||
|
||||
class ContestEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = ContestEffect
|
||||
fields = ('url',)
|
||||
|
||||
class ContestTypeSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = ContestType
|
||||
fields = ('url', 'name')
|
||||
|
||||
class EggGroupSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = EggGroup
|
||||
fields = ('name', 'url')
|
||||
|
||||
class EncounterSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
class EncounterConditionSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Encounter
|
||||
fields = ('url',)
|
||||
model = EncounterCondition
|
||||
fields = ('name', 'url')
|
||||
|
||||
class EncounterConditionValueSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = EncounterConditionValue
|
||||
fields = ('name', 'url')
|
||||
|
||||
class EncounterMethodSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
|
@ -61,12 +79,6 @@ class EncounterMethodSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|||
model = EncounterMethod
|
||||
fields = ('name', 'url')
|
||||
|
||||
class EncounterSlotSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = EncounterSlot
|
||||
fields = ('url',)
|
||||
|
||||
class EvolutionTriggerSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
@ -235,6 +247,12 @@ class StatSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|||
model = Stat
|
||||
fields = ('name', 'url')
|
||||
|
||||
class SuperContestEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = SuperContestEffect
|
||||
fields = ('url',)
|
||||
|
||||
class TypeSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
@ -254,6 +272,35 @@ class VersionGroupSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|||
fields = ('name', 'url')
|
||||
|
||||
|
||||
#####################
|
||||
# MAP SERIALIZERS #
|
||||
#####################
|
||||
|
||||
class ItemAttributeMapSerializer(serializers.ModelSerializer):
|
||||
|
||||
item = ItemSummarySerializer()
|
||||
attribute = ItemAttributeSummarySerializer(source='item_attribute')
|
||||
|
||||
class Meta:
|
||||
model = ItemAttributeMap
|
||||
fields = ('item', 'attribute',)
|
||||
|
||||
class VersionGroupRegionSerializer(serializers.ModelSerializer):
|
||||
|
||||
version_group = VersionGroupSummarySerializer()
|
||||
region = RegionSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = ItemAttributeMap
|
||||
fields = ('version_group', 'region',)
|
||||
|
||||
class EncounterConditionValueMapSerializer(serializers.ModelSerializer):
|
||||
|
||||
condition_value = EncounterConditionValueSummarySerializer(source='encounter_condition_value')
|
||||
|
||||
class Meta:
|
||||
model = EncounterConditionValueMap
|
||||
fields = ('condition_value',)
|
||||
|
||||
|
||||
################################
|
||||
|
@ -279,48 +326,93 @@ class CharacteristicDetailSerializer(serializers.ModelSerializer):
|
|||
fields = ('id', 'stat', 'gene_mod_5', 'descriptions')
|
||||
|
||||
|
||||
###########################
|
||||
# ENCOUNTER SERIALIZERS #
|
||||
###########################
|
||||
#########################
|
||||
# CONTEST SERIALIZERS #
|
||||
#########################
|
||||
|
||||
class EncounterMethodNameSerializer(serializers.ModelSerializer):
|
||||
class SuperContestEffectFlavorTextSerializer(serializers.ModelSerializer):
|
||||
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = EncounterMethodName
|
||||
fields = ('name', 'language')
|
||||
model = SuperContestEffectFlavorText
|
||||
fields = ('flavor_text', 'language')
|
||||
|
||||
|
||||
class EncounterMethodDetailSerializer(serializers.ModelSerializer):
|
||||
class SuperContestEffectDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
names = EncounterMethodNameSerializer(many=True, read_only=True, source='encountermethodname')
|
||||
flavor_text_entries = SuperContestEffectFlavorTextSerializer(many=True, read_only=True, source='supercontesteffectflavortext')
|
||||
|
||||
class Meta:
|
||||
model = EncounterMethod
|
||||
fields = ('id', 'name', 'order', 'names')
|
||||
model = SuperContestEffect
|
||||
fields = ('id', 'appeal', 'flavor_text_entries')
|
||||
|
||||
|
||||
class EncounterSlotDetailSerializer(serializers.ModelSerializer):
|
||||
class ContestEffectEffectTextSerializer(serializers.ModelSerializer):
|
||||
|
||||
version_group = VersionGroupSummarySerializer()
|
||||
encounter_method = EncounterMethodSummarySerializer()
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = EncounterSlot
|
||||
fields = ('id', 'slot', 'rarity', 'encounter_method', 'version_group')
|
||||
model = ContestEffectEffectText
|
||||
fields = ('effect', 'language')
|
||||
|
||||
|
||||
class EncounterDetailSerializer(serializers.ModelSerializer):
|
||||
class ContestEffectFlavorTextSerializer(serializers.ModelSerializer):
|
||||
|
||||
# version = VersionSummarySerializer()
|
||||
# location_area = EncounterMethodSummarySerializer()
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = Encounter
|
||||
# fields = ('id', 'slot', 'rarity', 'encounter_method', 'version')
|
||||
model = ContestEffectFlavorText
|
||||
fields = ('flavor_text', 'language')
|
||||
|
||||
|
||||
class ContestEffectDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
effects = ContestEffectEffectTextSerializer(many=True, read_only=True, source='contesteffecteffecttext')
|
||||
flavor_text_entries = ContestEffectFlavorTextSerializer(many=True, read_only=True, source='contesteffectflavortext')
|
||||
|
||||
class Meta:
|
||||
model = ContestEffect
|
||||
fields = ('id', 'appeal', 'jam', 'effects', 'flavor_text_entries')
|
||||
|
||||
|
||||
class ContestTypeNameSerializer(serializers.ModelSerializer):
|
||||
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = ContestTypeName
|
||||
fields = ('name', 'flavor', 'color', 'language')
|
||||
|
||||
|
||||
class ContestTypeDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
names = ContestTypeNameSerializer(many=True, read_only=True, source='contesttypename')
|
||||
|
||||
class Meta:
|
||||
model = ContestType
|
||||
fields = ('id', 'name', 'names')
|
||||
|
||||
|
||||
class SuperContestComboSerializer(serializers.ModelSerializer):
|
||||
|
||||
first_move = MoveSummarySerializer()
|
||||
second_move = MoveSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = SuperContestCombo
|
||||
fields = ('first_move', 'second_move')
|
||||
|
||||
|
||||
class ContestComboSerializer(serializers.ModelSerializer):
|
||||
|
||||
first_move = MoveSummarySerializer()
|
||||
second_move = MoveSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = ContestCombo
|
||||
fields = ('first_move', 'second_move')
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -340,11 +432,23 @@ class RegionNameSerializer(serializers.ModelSerializer):
|
|||
class RegionDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
names = RegionNameSerializer(many=True, read_only=True, source="regionname")
|
||||
version_groups = serializers.SerializerMethodField('get_region_version_groups')
|
||||
|
||||
class Meta:
|
||||
model = Region
|
||||
fields = ('id', 'name', 'names')
|
||||
fields = ('id', 'name', 'names', 'version_groups')
|
||||
|
||||
def get_region_version_groups(self, obj):
|
||||
|
||||
vg_regions = VersionGroupRegion.objects.filter(region=obj)
|
||||
print vg_regions
|
||||
data = VersionGroupRegionSerializer(vg_regions, many=True, context=self.context).data
|
||||
groups = []
|
||||
|
||||
for group in data:
|
||||
groups.append(group['version_group'])
|
||||
|
||||
return groups
|
||||
|
||||
|
||||
############################
|
||||
|
@ -424,9 +528,108 @@ class LanguageDetailSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
|
||||
##########################
|
||||
# LOCATION SERIALIZERS #
|
||||
##########################
|
||||
########################################
|
||||
# LOCATION AND ENCOUNTER SERIALIZERS #
|
||||
########################################
|
||||
|
||||
class EncounterConditionNameSerializer(serializers.ModelSerializer):
|
||||
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = EncounterConditionName
|
||||
fields = ('name', 'language')
|
||||
|
||||
|
||||
class EncounterConditionDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
names = EncounterConditionNameSerializer(many=True, read_only=True, source='encounterconditionname')
|
||||
values = EncounterConditionValueSummarySerializer(many=True, read_only=True, source='encounterconditionvalue')
|
||||
|
||||
class Meta:
|
||||
model = EncounterCondition
|
||||
fields = ('id', 'name', 'values', 'names')
|
||||
|
||||
|
||||
class EncounterConditionValueNameSerializer(serializers.ModelSerializer):
|
||||
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = EncounterConditionValueName
|
||||
fields = ('name', 'language')
|
||||
|
||||
|
||||
class EncounterConditionValueDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
condition = EncounterConditionSummarySerializer(source='encounter_condition')
|
||||
names = EncounterConditionValueNameSerializer(many=True, read_only=True, source='encounterconditionvaluename')
|
||||
|
||||
class Meta:
|
||||
model = EncounterConditionValue
|
||||
fields = ('id', 'name', 'condition', 'names')
|
||||
|
||||
|
||||
class EncounterMethodNameSerializer(serializers.ModelSerializer):
|
||||
|
||||
language = LanguageSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = EncounterMethodName
|
||||
fields = ('name', 'language')
|
||||
|
||||
|
||||
class EncounterMethodDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
names = EncounterMethodNameSerializer(many=True, read_only=True, source='encountermethodname')
|
||||
|
||||
class Meta:
|
||||
model = EncounterMethod
|
||||
fields = ('id', 'name', 'order', 'names')
|
||||
|
||||
|
||||
class EncounterSlotSerializer(serializers.ModelSerializer):
|
||||
|
||||
encounter_method = EncounterMethodSummarySerializer()
|
||||
chance = serializers.IntegerField(source='rarity')
|
||||
|
||||
class Meta:
|
||||
model = EncounterSlot
|
||||
fields = ('id', 'slot', 'chance', 'encounter_method', 'version_group')
|
||||
|
||||
|
||||
class EncounterDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
version = VersionSummarySerializer()
|
||||
location_area = LocationAreaSummarySerializer()
|
||||
pokemon = PokemonSummarySerializer()
|
||||
condition_values = serializers.SerializerMethodField('get_encounter_conditions')
|
||||
|
||||
class Meta:
|
||||
model = Encounter
|
||||
fields = ('min_level', 'max_level', 'version', 'encounter_slot', 'pokemon', 'location_area', 'condition_values')
|
||||
|
||||
def get_encounter_conditions(self, obj):
|
||||
|
||||
condition_values = EncounterConditionValueMap.objects.filter(encounter=obj)
|
||||
data = EncounterConditionValueMapSerializer(condition_values, many=True, context=self.context).data
|
||||
values = []
|
||||
|
||||
for map in data:
|
||||
values.append(map['condition_value'])
|
||||
|
||||
return values
|
||||
|
||||
|
||||
class LocationAreaEncounterRateSerializer(serializers.ModelSerializer):
|
||||
|
||||
encounter_method = EncounterMethodSummarySerializer()
|
||||
version = VersionSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
model = LocationAreaEncounterRate
|
||||
fields = ('rate', 'encounter_method', 'version')
|
||||
|
||||
|
||||
class LocationAreaNameSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
@ -440,11 +643,102 @@ class LocationAreaNameSerializer(serializers.ModelSerializer):
|
|||
class LocationAreaDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
location = LocationSummarySerializer()
|
||||
names = LocationAreaNameSerializer(many=True, read_only=True, source="locationname")
|
||||
|
||||
encounter_method_rates = serializers.SerializerMethodField('get_method_rates')
|
||||
pokemon_encounters = serializers.SerializerMethodField('get_encounters')
|
||||
|
||||
class Meta:
|
||||
model = LocationArea
|
||||
fields = ('id', 'name', 'game_index', 'location', 'names')
|
||||
fields = ('id', 'name', 'game_index', 'location', 'encounter_method_rates', 'pokemon_encounters')
|
||||
|
||||
def get_method_rates (self, obj):
|
||||
|
||||
# Get encounters related to this area and pull out unique encounter methods
|
||||
encounter_rates = LocationAreaEncounterRate.objects.filter(location_area=obj).order_by('encounter_method_id')
|
||||
method_ids = encounter_rates.values('encounter_method_id').distinct()
|
||||
encounter_rate_list = []
|
||||
|
||||
print method_ids
|
||||
|
||||
for id in method_ids:
|
||||
|
||||
encounter_rate_details = OrderedDict()
|
||||
|
||||
# Get each Unique Item by ID
|
||||
encounter_method_object = EncounterMethod.objects.get(pk=id['encounter_method_id'])
|
||||
encounter_method_data = EncounterMethodSummarySerializer(encounter_method_object, context=self.context).data
|
||||
encounter_rate_details['encounter_method'] = encounter_method_data
|
||||
|
||||
# Get Versions associated with each unique item
|
||||
area_encounter_objects = encounter_rates.filter(encounter_method_id=id['encounter_method_id'])
|
||||
serializer = LocationAreaEncounterRateSerializer(area_encounter_objects, many=True, context=self.context)
|
||||
encounter_rate_details['version_details'] = []
|
||||
|
||||
for area_encounter in serializer.data:
|
||||
|
||||
version_detail = OrderedDict()
|
||||
|
||||
version_detail['rate'] = area_encounter['rate']
|
||||
version_detail['version'] = area_encounter['version']
|
||||
|
||||
encounter_rate_details['version_details'].append(version_detail)
|
||||
|
||||
encounter_rate_list.append(encounter_rate_details)
|
||||
|
||||
return encounter_rate_list
|
||||
|
||||
|
||||
def get_encounters (self, obj):
|
||||
|
||||
# get versions for later use
|
||||
version_objects = Version.objects.all()
|
||||
version_data = VersionSummarySerializer(version_objects, many=True, context=self.context).data
|
||||
|
||||
# all encounters associated with location area
|
||||
all_encounters = Encounter.objects.filter(location_area=obj).order_by('pokemon')
|
||||
encounters_list = []
|
||||
|
||||
# break encounters into pokemon groupings
|
||||
for poke in all_encounters.values('pokemon').distinct():
|
||||
|
||||
pokemon_object = Pokemon.objects.get(pk=poke['pokemon'])
|
||||
|
||||
pokemon_detail = OrderedDict()
|
||||
pokemon_detail['pokemon'] = PokemonSummarySerializer(pokemon_object, context=self.context).data
|
||||
pokemon_detail['version_details'] = []
|
||||
|
||||
poke_encounters = all_encounters.filter(pokemon=poke['pokemon']).order_by('version')
|
||||
|
||||
# each pokemon has multiple versions it could be encountered in
|
||||
for ver in poke_encounters.values('version').distinct():
|
||||
|
||||
version_detail = OrderedDict()
|
||||
version_detail['version'] = version_data[ver['version'] - 1]
|
||||
version_detail['max_chance'] = 0
|
||||
version_detail['encounter_details'] = []
|
||||
|
||||
poke_data = EncounterDetailSerializer(poke_encounters.filter(version=ver['version']), many=True, context=self.context).data
|
||||
|
||||
# each version has multiple ways a pokemon can be encountered
|
||||
for encounter in poke_data:
|
||||
|
||||
slot = EncounterSlot.objects.get(pk=encounter['encounter_slot'])
|
||||
slot_data = EncounterSlotSerializer(slot, context=self.context).data
|
||||
del encounter['pokemon']
|
||||
del encounter['encounter_slot']
|
||||
del encounter['location_area']
|
||||
del encounter['version']
|
||||
encounter['chance'] = slot_data['chance']
|
||||
version_detail['max_chance'] += slot_data['chance']
|
||||
encounter['method'] = slot_data['encounter_method']
|
||||
|
||||
version_detail['encounter_details'].append(encounter)
|
||||
|
||||
pokemon_detail['version_details'].append(version_detail)
|
||||
|
||||
encounters_list.append(pokemon_detail)
|
||||
|
||||
return encounters_list
|
||||
|
||||
|
||||
|
||||
class LocationNameSerializer(serializers.ModelSerializer):
|
||||
|
@ -624,16 +918,6 @@ class ItemAttributeDetailSerializer(serializers.ModelSerializer):
|
|||
fields = ('id', 'name', 'names', 'descriptions')
|
||||
|
||||
|
||||
class ItemAttributeMapSerializer(serializers.ModelSerializer):
|
||||
|
||||
item = ItemSummarySerializer()
|
||||
attribute = ItemAttributeSummarySerializer(source='item_attribute')
|
||||
|
||||
class Meta:
|
||||
model = ItemAttributeMap
|
||||
fields = ('item', 'attribute',)
|
||||
|
||||
|
||||
|
||||
###################################
|
||||
# ITEM FLING EFFECT SERIALIZERS #
|
||||
|
@ -1076,6 +1360,8 @@ class MoveDetailSerializer(serializers.ModelSerializer):
|
|||
meta = MoveMetaSerializer(read_only=True, source="movemeta")
|
||||
names = MoveNameSerializer(many=True, read_only=True, source="movename")
|
||||
effect_chance = serializers.IntegerField(source="move_effect_chance")
|
||||
contest_combo_detail = serializers.SerializerMethodField('get_contest_combos')
|
||||
# super_contest_combo_detail = serializers.SerializerMethodField('get_super_contest_combos')
|
||||
|
||||
class Meta:
|
||||
model = Move
|
||||
|
@ -1093,8 +1379,71 @@ class MoveDetailSerializer(serializers.ModelSerializer):
|
|||
'pp',
|
||||
'priority',
|
||||
'type',
|
||||
'contest_combo_detail',
|
||||
# 'super_contest_combo_detail'
|
||||
)
|
||||
|
||||
def get_contest_combos(self, obj):
|
||||
|
||||
normal_before_objects = ContestCombo.objects.filter(first_move=obj)
|
||||
normal_before_data = ContestComboSerializer(normal_before_objects, many=True, context=self.context).data
|
||||
normal_after_objects = ContestCombo.objects.filter(second_move=obj)
|
||||
normal_after_data = ContestComboSerializer(normal_after_objects, many=True, context=self.context).data
|
||||
|
||||
super_before_objects = SuperContestCombo.objects.filter(first_move=obj)
|
||||
super_before_data = SuperContestComboSerializer(super_before_objects, many=True, context=self.context).data
|
||||
super_after_objects = SuperContestCombo.objects.filter(second_move=obj)
|
||||
super_after_data = SuperContestComboSerializer(super_after_objects, many=True, context=self.context).data
|
||||
|
||||
details = OrderedDict()
|
||||
details['normal'] = OrderedDict()
|
||||
details['normal']['use_before'] = None
|
||||
details['normal']['use_after'] = None
|
||||
details['super'] = OrderedDict()
|
||||
details['super']['use_before'] = None
|
||||
details['super']['use_after'] = None
|
||||
|
||||
for combo in normal_before_data:
|
||||
if details['normal']['use_before'] == None:
|
||||
details['normal']['use_before'] = []
|
||||
details['normal']['use_before'].append(combo['second_move'])
|
||||
|
||||
for combo in normal_after_data:
|
||||
if details['normal']['use_after'] == None:
|
||||
details['normal']['use_after'] = []
|
||||
details['normal']['use_after'].append(combo['first_move'])
|
||||
|
||||
for combo in super_before_data:
|
||||
if details['super']['use_before'] == None:
|
||||
details['super']['use_before'] = []
|
||||
details['super']['use_before'].append(combo['second_move'])
|
||||
|
||||
for combo in super_after_data:
|
||||
if details['super']['use_after'] == None:
|
||||
details['super']['use_after'] = []
|
||||
details['super']['use_after'].append(combo['first_move'])
|
||||
|
||||
return details
|
||||
|
||||
# def get_super_contest_combos(self, obj):
|
||||
|
||||
# before_objects = SuperContestCombo.objects.filter(first_move=obj)
|
||||
# before_data = SuperContestComboSerializer(before_objects, many=True, context=self.context).data
|
||||
# after_objects = SuperContestCombo.objects.filter(second_move=obj)
|
||||
# after_data = SuperContestComboSerializer(after_objects, many=True, context=self.context).data
|
||||
|
||||
# details = OrderedDict()
|
||||
# details['use_before'] = []
|
||||
# details['use_after'] = []
|
||||
|
||||
# for combo in before_data:
|
||||
# details['use_before'].append(combo['second_move'])
|
||||
|
||||
# for combo in after_data:
|
||||
# details['use_after'].append(combo['first_move'])
|
||||
|
||||
# return details
|
||||
|
||||
|
||||
|
||||
#################################
|
||||
|
@ -1274,7 +1623,7 @@ class PokemonShapeDetailSerializer(serializers.ModelSerializer):
|
|||
|
||||
class PokemonItemSerializer(serializers.ModelSerializer):
|
||||
|
||||
# version = VersionSummarySerializer()
|
||||
version = VersionSummarySerializer()
|
||||
item = ItemSummarySerializer()
|
||||
|
||||
class Meta:
|
||||
|
@ -1327,6 +1676,8 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
|||
types = PokemonTypeSerializer(many=True, read_only=True, source="pokemontype")
|
||||
forms = PokemonFormSummarySerializer(many=True, read_only=True, source="pokemonform")
|
||||
held_items = serializers.SerializerMethodField('get_pokemon_held_items')
|
||||
# location_area_encounters = serializers.SerializerMethodField('get_encounters')
|
||||
location_areas = serializers.SerializerMethodField('get_areas')
|
||||
|
||||
class Meta:
|
||||
model = Pokemon
|
||||
|
@ -1344,7 +1695,8 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
|||
'types',
|
||||
'forms',
|
||||
'held_items',
|
||||
'moves'
|
||||
'moves',
|
||||
'location_areas'
|
||||
)
|
||||
|
||||
def get_pokemon_moves(self, obj):
|
||||
|
@ -1395,8 +1747,8 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
|||
# Doin held_items pretty much like moves
|
||||
|
||||
# Get all possible Version Groups and Move Methods for later use
|
||||
version_objects = Version.objects.all()
|
||||
version_data = VersionSummarySerializer(version_objects, many=True, context=self.context).data
|
||||
# version_objects = Version.objects.all()
|
||||
# version_data = VersionSummarySerializer(version_objects, many=True, context=self.context).data
|
||||
|
||||
# Get items related to this pokemon and pull out unique Move IDs
|
||||
pokemon_items = PokemonItem.objects.filter(pokemon_id=obj).order_by('item_id')
|
||||
|
@ -1422,7 +1774,7 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
|||
version_detail = OrderedDict()
|
||||
|
||||
version_detail['rarity'] = item['rarity']
|
||||
version_detail['version'] = version_data[item['version'] - 1]
|
||||
version_detail['version'] = item['version']
|
||||
|
||||
pokemon_item_details['version_details'].append(version_detail)
|
||||
|
||||
|
@ -1431,6 +1783,70 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
|||
return item_list
|
||||
|
||||
|
||||
def get_areas(self, obj):
|
||||
|
||||
encounter_objects = Encounter.objects.filter(pokemon_id=obj.id)
|
||||
areas = []
|
||||
|
||||
for encounter in encounter_objects:
|
||||
areas.append(LocationAreaSummarySerializer(encounter.location_area, context=self.context).data)
|
||||
|
||||
return areas
|
||||
|
||||
|
||||
# def get_encounters(self, obj):
|
||||
|
||||
# # get versions for later use
|
||||
# version_objects = Version.objects.all()
|
||||
# version_data = VersionSummarySerializer(version_objects, many=True, context=self.context).data
|
||||
|
||||
# # all encounters associated with location area
|
||||
# all_encounters = Encounter.objects.filter(pokemon=obj).order_by('location_area')
|
||||
# encounters_list = []
|
||||
|
||||
# # break encounters into pokemon groupings
|
||||
# for area in all_encounters.values('location_area').distinct():
|
||||
|
||||
# location_area_object = LocationArea.objects.get(pk=area['location_area'])
|
||||
|
||||
# location_area_detail = OrderedDict()
|
||||
# location_area_detail['location_area'] = LocationAreaSummarySerializer(location_area_object, context=self.context).data
|
||||
# location_area_detail['version_details'] = []
|
||||
|
||||
# area_encounters = all_encounters.filter(location_area=area['location_area']).order_by('version')
|
||||
|
||||
# # each pokemon has multiple versions it could be encountered in
|
||||
# for ver in area_encounters.values('version').distinct():
|
||||
|
||||
# version_detail = OrderedDict()
|
||||
# version_detail['version'] = version_data[ver['version'] - 1]
|
||||
# version_detail['max_chance'] = 0
|
||||
# version_detail['encounter_details'] = []
|
||||
|
||||
# area_data = EncounterDetailSerializer(area_encounters.filter(version=ver['version']), many=True, context=self.context).data
|
||||
|
||||
# # each version has multiple ways a pokemon can be encountered
|
||||
# for encounter in area_data:
|
||||
|
||||
# slot = EncounterSlot.objects.get(pk=encounter['encounter_slot'])
|
||||
# slot_data = EncounterSlotSerializer(slot, context=self.context).data
|
||||
# del encounter['pokemon']
|
||||
# del encounter['encounter_slot']
|
||||
# del encounter['location_area']
|
||||
# del encounter['version']
|
||||
# encounter['chance'] = slot_data['chance']
|
||||
# version_detail['max_chance'] += slot_data['chance']
|
||||
# encounter['method'] = slot_data['encounter_method']
|
||||
|
||||
# version_detail['encounter_details'].append(encounter)
|
||||
|
||||
# location_area_detail['version_details'].append(version_detail)
|
||||
|
||||
# encounters_list.append(location_area_detail)
|
||||
|
||||
# return encounters_list
|
||||
|
||||
|
||||
|
||||
#################################
|
||||
# POKEMON SPECIES SERIALIZERS #
|
||||
|
@ -1768,7 +2184,19 @@ class VersionGroupDetailSerializer(serializers.ModelSerializer):
|
|||
|
||||
generation = GenerationSummarySerializer()
|
||||
versions = VersionSummarySerializer(many=True, read_only=True, source="version")
|
||||
regions = serializers.SerializerMethodField('get_version_group_regions')
|
||||
|
||||
class Meta:
|
||||
model = VersionGroup
|
||||
fields = ('id', 'name', 'order', 'generation', 'versions')
|
||||
fields = ('id', 'name', 'order', 'generation', 'versions', 'regions')
|
||||
|
||||
def get_version_group_regions(self, obj):
|
||||
|
||||
vg_regions = VersionGroupRegion.objects.filter(version_group=obj)
|
||||
data = VersionGroupRegionSerializer(vg_regions, many=True, context=self.context).data
|
||||
regions = []
|
||||
|
||||
for region in data:
|
||||
regions.append(region['region'])
|
||||
|
||||
return regions
|
||||
|
|
|
@ -87,6 +87,20 @@ class CharacteristicResource(PokeapiCommonViewset):
|
|||
list_serializer_class = CharacteristicSummarySerializer
|
||||
|
||||
|
||||
class ContestEffectResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = ContestEffect.objects.all()
|
||||
serializer_class = ContestEffectDetailSerializer
|
||||
list_serializer_class = ContestEffectSummarySerializer
|
||||
|
||||
|
||||
class ContestTypeResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = ContestType.objects.all()
|
||||
serializer_class = ContestTypeDetailSerializer
|
||||
list_serializer_class = ContestTypeSummarySerializer
|
||||
|
||||
|
||||
class EggGroupResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = EggGroup.objects.all()
|
||||
|
@ -94,11 +108,18 @@ class EggGroupResource(PokeapiCommonViewset):
|
|||
list_serializer_class = EggGroupSummarySerializer
|
||||
|
||||
|
||||
class EncounterResource(PokeapiCommonViewset):
|
||||
class EncounterConditionResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = Encounter.objects.all()
|
||||
serializer_class = EncounterDetailSerializer
|
||||
list_serializer_class = EncounterSummarySerializer
|
||||
queryset = EncounterCondition.objects.all()
|
||||
serializer_class = EncounterConditionDetailSerializer
|
||||
list_serializer_class = EncounterConditionSummarySerializer
|
||||
|
||||
|
||||
class EncounterConditionValueResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = EncounterConditionValue.objects.all()
|
||||
serializer_class = EncounterConditionValueDetailSerializer
|
||||
list_serializer_class = EncounterConditionValueSummarySerializer
|
||||
|
||||
|
||||
class EncounterMethodResource(PokeapiCommonViewset):
|
||||
|
@ -108,13 +129,6 @@ class EncounterMethodResource(PokeapiCommonViewset):
|
|||
list_serializer_class = EncounterMethodSummarySerializer
|
||||
|
||||
|
||||
class EncounterSlotResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = EncounterSlot.objects.all()
|
||||
serializer_class = EncounterSlotDetailSerializer
|
||||
list_serializer_class = EncounterSlotSummarySerializer
|
||||
|
||||
|
||||
class EvolutionChainResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = EvolutionChain.objects.all()
|
||||
|
@ -311,6 +325,13 @@ class StatResource(PokeapiCommonViewset):
|
|||
list_serializer_class = StatSummarySerializer
|
||||
|
||||
|
||||
class SuperContestEffectResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = SuperContestEffect.objects.all()
|
||||
serializer_class = SuperContestEffectDetailSerializer
|
||||
list_serializer_class = SuperContestEffectSummarySerializer
|
||||
|
||||
|
||||
class TypeResource(PokeapiCommonViewset):
|
||||
|
||||
queryset = Type.objects.all()
|
||||
|
|
Loading…
Reference in a new issue