2015-09-12 04:53:46 +00:00
|
|
|
from collections import OrderedDict
|
2016-02-16 06:31:19 +00:00
|
|
|
import json
|
2018-10-20 00:05:10 +00:00
|
|
|
from django.urls import reverse
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
# pylint: disable=redefined-builtin
|
2015-09-06 02:10:13 +00:00
|
|
|
|
2018-10-20 00:05:10 +00:00
|
|
|
# PokeAPI v2 serializers in order of dependency
|
2015-02-22 17:11:40 +00:00
|
|
|
|
2018-10-20 00:05:10 +00:00
|
|
|
from .models import *
|
2015-02-22 17:11:40 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
#########################
|
|
|
|
# SUMMARY SERIALIZERS #
|
|
|
|
#########################
|
|
|
|
|
|
|
|
# Summary serializers are just for list and reference behavior
|
|
|
|
|
|
|
|
# Putting summary serializers up top so there are no conflicts
|
|
|
|
# with reference accross models due to script running order
|
|
|
|
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
class AbilitySummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Ability
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class BerryFirmnessSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = BerryFirmness
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-11-10 19:20:06 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
class BerryFlavorSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = BerryFlavor
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class BerrySummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Berry
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class CharacteristicSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Characteristic
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("url",)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class ContestEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ContestEffect
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("url",)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class ContestTypeSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ContestType
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class EggGroupSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = EggGroup
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class EncounterConditionSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = EncounterCondition
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class EncounterConditionValueSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-29 17:45:58 +00:00
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = EncounterConditionValue
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class EncounterMethodSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = EncounterMethod
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class EvolutionTriggerSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = EvolutionTrigger
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class EvolutionChainSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = EvolutionChain
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("url",)
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class GenerationSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Generation
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class GenderSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Gender
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class GrowthRateSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = GrowthRate
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class ItemPocketSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ItemPocket
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class ItemCategorySummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ItemCategory
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-23 04:56:01 +00:00
|
|
|
class ItemAttributeSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-23 04:56:01 +00:00
|
|
|
model = ItemAttribute
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class ItemFlingEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ItemFlingEffect
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class ItemSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class LanguageSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Language
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class LocationSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Location
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class LocationAreaSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = LocationArea
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class MachineSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-11-08 21:26:02 +00:00
|
|
|
model = Machine
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("url",)
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class MoveBattleStyleSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-11-08 21:26:02 +00:00
|
|
|
model = MoveBattleStyle
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class MoveDamageClassSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = MoveDamageClass
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class MoveMetaAilmentSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = MoveMetaAilment
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class MoveMetaCategorySummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = MoveMetaCategory
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class MoveTargetSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = MoveTarget
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class MoveSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Move
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class MoveLearnMethodSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = MoveLearnMethod
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class NatureSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Nature
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class PalParkAreaSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PalParkArea
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class PokeathlonStatSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokeathlonStat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class PokedexSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Pokedex
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonColorSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokemonColor
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonHabitatSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokemonHabitat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonShapeSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokemonShape
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Pokemon
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonSpeciesSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2016-03-05 08:26:51 +00:00
|
|
|
class Meta:
|
2015-10-06 17:01:32 +00:00
|
|
|
model = PokemonSpecies
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class PokemonFormSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = PokemonForm
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class RegionSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Region
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class StatSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Stat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class SuperContestEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = SuperContestEffect
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("url",)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class TypeSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Type
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class VersionSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Version
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class VersionGroupSummarySerializer(serializers.HyperlinkedModelSerializer):
|
2015-10-06 17:01:32 +00:00
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = VersionGroup
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "url")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
#####################
|
|
|
|
# MAP SERIALIZERS #
|
|
|
|
#####################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
class BerryFlavorMapSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
berry = BerrySummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
flavor = BerryFlavorSummarySerializer(source="berry_flavor")
|
2015-11-10 19:20:06 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = BerryFlavorMap
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("potency", "berry", "flavor")
|
2015-11-10 19:20:06 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class ItemAttributeMapSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
item = ItemSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
attribute = ItemAttributeSummarySerializer(source="item_attribute")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemAttributeMap
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = (
|
|
|
|
"item",
|
|
|
|
"attribute",
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
class MoveMetaStatChangeSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
stat = StatSummarySerializer()
|
|
|
|
move = MoveSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveMetaStatChange
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("change", "move", "stat")
|
2015-11-16 19:23:41 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
class NaturePokeathlonStatSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
pokeathlon_stat = PokeathlonStatSummarySerializer()
|
|
|
|
nature = NatureSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = NaturePokeathlonStat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("max_change", "nature", "pokeathlon_stat")
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
class PokemonAbilitySerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
pokemon = PokemonSummarySerializer()
|
|
|
|
ability = AbilitySummarySerializer()
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonAbility
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("is_hidden", "slot", "ability", "pokemon")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
class PokemonDexEntrySerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
entry_number = serializers.IntegerField(source="pokedex_number")
|
|
|
|
pokedex = PokedexSummarySerializer()
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonDexNumber
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("entry_number", "pokedex")
|
2015-11-26 01:18:35 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
class PokemonTypeSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
pokemon = PokemonSummarySerializer()
|
|
|
|
type = TypeSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonType
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("slot", "pokemon", "type")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
class PokedexVersionGroupSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
pokedex = PokedexSummarySerializer()
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokedexVersionGroup
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("pokedex", "version_group")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class VersionGroupMoveLearnMethodSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
move_learn_method = MoveLearnMethodSummarySerializer()
|
2015-09-11 12:15:45 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-11-08 21:26:02 +00:00
|
|
|
model = ItemAttributeMap
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("version_group", "move_learn_method")
|
2015-09-11 12:15:45 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class VersionGroupRegionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
region = RegionSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemAttributeMap
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = (
|
|
|
|
"version_group",
|
|
|
|
"region",
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class EncounterConditionValueMapSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
condition_value = EncounterConditionValueSummarySerializer(
|
|
|
|
source="encounter_condition_value"
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterConditionValueMap
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("condition_value",)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-09-11 12:15:45 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
################################
|
|
|
|
# CHARACTERISTIC SERIALIZERS #
|
|
|
|
################################
|
2015-09-11 12:15:45 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class CharacteristicDescriptionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-09-11 12:15:45 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = CharacteristicDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CharacteristicDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = CharacteristicDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="characteristicdescription"
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
highest_stat = StatSummarySerializer(source="stat")
|
2020-02-17 20:58:07 +00:00
|
|
|
gene_modulo = serializers.IntegerField(source="gene_mod_5")
|
|
|
|
possible_values = serializers.SerializerMethodField("get_values")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Characteristic
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = (
|
|
|
|
"id",
|
|
|
|
"gene_modulo",
|
|
|
|
"possible_values",
|
|
|
|
"highest_stat",
|
|
|
|
"descriptions",
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_values(self, obj):
|
|
|
|
|
|
|
|
mod = obj.gene_mod_5
|
|
|
|
values = []
|
2018-10-20 00:05:10 +00:00
|
|
|
while mod <= 30:
|
2015-11-16 03:29:30 +00:00
|
|
|
values.append(mod)
|
|
|
|
mod += 5
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
return values
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
#########################
|
|
|
|
# CONTEST SERIALIZERS #
|
|
|
|
#########################
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class SuperContestEffectFlavorTextSerializer(serializers.ModelSerializer):
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = SuperContestEffectFlavorText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("flavor_text", "language")
|
2015-09-11 12:15:45 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class SuperContestEffectDetailSerializer(serializers.ModelSerializer):
|
2015-09-10 23:02:06 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_text_entries = SuperContestEffectFlavorTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="supercontesteffectflavortext"
|
|
|
|
)
|
|
|
|
moves = MoveSummarySerializer(many=True, read_only=True, source="move")
|
2015-09-10 04:03:18 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = SuperContestEffect
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "appeal", "flavor_text_entries", "moves")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class ContestEffectEffectTextSerializer(serializers.ModelSerializer):
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = ContestEffectEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("effect", "language")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class ContestEffectFlavorTextSerializer(serializers.ModelSerializer):
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-11-05 14:55:14 +00:00
|
|
|
model = ContestEffectFlavorText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("flavor_text", "language")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestEffectDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
effect_entries = ContestEffectEffectTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="contesteffecteffecttext"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_text_entries = ContestEffectFlavorTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="contesteffectflavortext"
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContestEffect
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "appeal", "jam", "effect_entries", "flavor_text_entries")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestTypeNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContestTypeName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "color", "language")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestTypeDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = ContestTypeNameSerializer(
|
|
|
|
many=True, read_only=True, source="contesttypename"
|
|
|
|
)
|
|
|
|
berry_flavor = BerryFlavorSummarySerializer(read_only=True, source="berryflavor")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContestType
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "berry_flavor", "names")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SuperContestComboSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
first_move = MoveSummarySerializer()
|
|
|
|
second_move = MoveSummarySerializer()
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class Meta:
|
|
|
|
model = SuperContestCombo
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("first_move", "second_move")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ContestComboSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
first_move = MoveSummarySerializer()
|
|
|
|
second_move = MoveSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContestCombo
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("first_move", "second_move")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2015-09-11 12:15:45 +00:00
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
########################
|
|
|
|
# REGION SERIALIZERS #
|
|
|
|
########################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
class RegionNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = RegionName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RegionDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
names = RegionNameSerializer(many=True, read_only=True, source="regionname")
|
2015-11-16 03:29:30 +00:00
|
|
|
locations = LocationSummarySerializer(many=True, read_only=True, source="location")
|
2020-02-17 20:58:07 +00:00
|
|
|
version_groups = serializers.SerializerMethodField("get_region_version_groups")
|
2015-11-16 03:29:30 +00:00
|
|
|
pokedexes = PokedexSummarySerializer(many=True, read_only=True, source="pokedex")
|
|
|
|
main_generation = GenerationSummarySerializer(read_only=True, source="generation")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Region
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"locations",
|
|
|
|
"main_generation",
|
|
|
|
"names",
|
|
|
|
"pokedexes",
|
|
|
|
"version_groups",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
def get_region_version_groups(self, obj):
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
vg_regions = VersionGroupRegion.objects.filter(region=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
data = VersionGroupRegionSerializer(
|
|
|
|
vg_regions, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
groups = []
|
|
|
|
|
|
|
|
for group in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
groups.append(group["version_group"])
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
return groups
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
############################
|
|
|
|
# GENERATION SERIALIZERS #
|
|
|
|
############################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
class GenerationNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = GenerationName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GenerationDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
main_region = RegionSummarySerializer(source="region")
|
2015-09-12 04:53:46 +00:00
|
|
|
names = GenerationNameSerializer(many=True, read_only=True, source="generationname")
|
2015-11-16 03:29:30 +00:00
|
|
|
abilities = AbilitySummarySerializer(many=True, read_only=True, source="ability")
|
|
|
|
moves = MoveSummarySerializer(many=True, read_only=True, source="move")
|
2016-03-05 11:40:41 +00:00
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspecies"
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
types = TypeSummarySerializer(many=True, read_only=True, source="type")
|
2020-02-17 20:58:07 +00:00
|
|
|
version_groups = VersionGroupSummarySerializer(
|
|
|
|
many=True, read_only=True, source="versiongroup"
|
|
|
|
)
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Generation
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"abilities",
|
|
|
|
"main_region",
|
|
|
|
"moves",
|
|
|
|
"names",
|
|
|
|
"pokemon_species",
|
|
|
|
"types",
|
|
|
|
"version_groups",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
########################
|
|
|
|
# GENDER SERIALIZERS #
|
|
|
|
########################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class GenderDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_species_details = serializers.SerializerMethodField("get_species")
|
|
|
|
required_for_evolution = serializers.SerializerMethodField("get_required")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = Gender
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "pokemon_species_details", "required_for_evolution")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_species(self, obj):
|
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
species_objects = []
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
if obj.name == "female":
|
2015-11-16 03:29:30 +00:00
|
|
|
species_objects = PokemonSpecies.objects.filter(gender_rate__gt=0)
|
2020-02-17 20:58:07 +00:00
|
|
|
elif obj.name == "male":
|
2015-11-16 03:29:30 +00:00
|
|
|
species_objects = PokemonSpecies.objects.filter(gender_rate__range=[0, 7])
|
2020-02-17 20:58:07 +00:00
|
|
|
elif obj.name == "genderless":
|
2015-11-16 03:29:30 +00:00
|
|
|
species_objects = PokemonSpecies.objects.filter(gender_rate=-1)
|
|
|
|
|
|
|
|
details = []
|
|
|
|
|
|
|
|
for species in species_objects:
|
|
|
|
detail = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
detail["rate"] = species.gender_rate
|
|
|
|
detail["pokemon_species"] = PokemonSpeciesSummarySerializer(
|
|
|
|
species, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
details.append(detail)
|
|
|
|
|
|
|
|
return details
|
|
|
|
|
|
|
|
def get_required(self, obj):
|
|
|
|
|
|
|
|
evo_objects = PokemonEvolution.objects.filter(gender=obj)
|
|
|
|
species_list = []
|
|
|
|
|
|
|
|
for evo in evo_objects:
|
2016-03-05 11:40:41 +00:00
|
|
|
species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
evo.evolved_species, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
species_list.append(species)
|
|
|
|
|
|
|
|
return species_list
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
#############################
|
|
|
|
# GROWTH RATE SERIALIZERS #
|
|
|
|
#############################
|
|
|
|
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
class ExperienceSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
class Meta:
|
|
|
|
model = Experience
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("level", "experience")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
class GrowthRateDescriptionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = GrowthRateDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GrowthRateDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = GrowthRateDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="growthratedescription"
|
|
|
|
)
|
2015-10-03 03:40:21 +00:00
|
|
|
levels = ExperienceSerializer(many=True, read_only=True, source="experience")
|
2016-03-05 11:40:41 +00:00
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspecies"
|
|
|
|
)
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = GrowthRate
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "formula", "descriptions", "levels", "pokemon_species")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
##########################
|
|
|
|
# LANGUAGE SERIALIZERS #
|
|
|
|
##########################
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class LanguageNameSerializer(serializers.ModelSerializer):
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
language = LanguageSummarySerializer(source="local_language")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = LanguageName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class LanguageDetailSerializer(serializers.ModelSerializer):
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = LanguageNameSerializer(
|
|
|
|
many=True, read_only=True, source="languagename_language"
|
|
|
|
)
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = Language
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "official", "iso639", "iso3166", "names")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
########################################
|
|
|
|
# LOCATION AND ENCOUNTER SERIALIZERS #
|
|
|
|
########################################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
class EncounterConditionNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterConditionName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterConditionDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
names = EncounterConditionNameSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="encounterconditionname"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
values = EncounterConditionValueSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="encounterconditionvalue"
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterCondition
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "values", "names")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterConditionValueNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterConditionValueName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterConditionValueDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
condition = EncounterConditionSummarySerializer(source="encounter_condition")
|
2016-03-05 11:40:41 +00:00
|
|
|
names = EncounterConditionValueNameSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="encounterconditionvaluename"
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterConditionValue
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "condition", "names")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterMethodNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterMethodName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterMethodDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = EncounterMethodNameSerializer(
|
|
|
|
many=True, read_only=True, source="encountermethodname"
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterMethod
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "order", "names")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterSlotSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
encounter_method = EncounterMethodSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
chance = serializers.IntegerField(source="rarity")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EncounterSlot
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "slot", "chance", "encounter_method", "version_group")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EncounterDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version = VersionSummarySerializer()
|
|
|
|
location_area = LocationAreaSummarySerializer()
|
|
|
|
pokemon = PokemonSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
condition_values = serializers.SerializerMethodField("get_encounter_conditions")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Encounter
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"min_level",
|
|
|
|
"max_level",
|
|
|
|
"version",
|
|
|
|
"encounter_slot",
|
|
|
|
"pokemon",
|
|
|
|
"location_area",
|
|
|
|
"condition_values",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
def get_encounter_conditions(self, obj):
|
|
|
|
|
|
|
|
condition_values = EncounterConditionValueMap.objects.filter(encounter=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
data = EncounterConditionValueMapSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
condition_values, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
values = []
|
|
|
|
|
|
|
|
for map in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
values.append(map["condition_value"])
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
|
|
|
class LocationAreaEncounterRateSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
encounter_method = EncounterMethodSummarySerializer()
|
|
|
|
version = VersionSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = LocationAreaEncounterRate
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("rate", "encounter_method", "version")
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
class LocationAreaNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-29 17:45:58 +00:00
|
|
|
model = LocationAreaName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class LocationAreaDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
location = LocationSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
encounter_method_rates = serializers.SerializerMethodField("get_method_rates")
|
|
|
|
pokemon_encounters = serializers.SerializerMethodField("get_encounters")
|
|
|
|
names = LocationAreaNameSerializer(
|
|
|
|
many=True, read_only=True, source="locationareaname"
|
|
|
|
)
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-10-29 17:45:58 +00:00
|
|
|
class Meta:
|
|
|
|
model = LocationArea
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"game_index",
|
|
|
|
"encounter_method_rates",
|
|
|
|
"location",
|
|
|
|
"names",
|
|
|
|
"pokemon_encounters",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
def get_method_rates(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
# Get encounters related to this area and pull out unique encounter methods
|
2016-03-05 11:40:41 +00:00
|
|
|
encounter_rates = LocationAreaEncounterRate.objects.filter(
|
2020-02-17 20:58:07 +00:00
|
|
|
location_area=obj
|
|
|
|
).order_by("encounter_method_id")
|
|
|
|
method_ids = encounter_rates.values("encounter_method_id").distinct()
|
2015-11-05 14:55:14 +00:00
|
|
|
encounter_rate_list = []
|
|
|
|
|
|
|
|
for id in method_ids:
|
|
|
|
|
|
|
|
encounter_rate_details = OrderedDict()
|
|
|
|
|
|
|
|
# Get each Unique Item by ID
|
2020-02-17 20:58:07 +00:00
|
|
|
encounter_method_object = EncounterMethod.objects.get(
|
|
|
|
pk=id["encounter_method_id"]
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
encounter_method_data = EncounterMethodSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
encounter_method_object, context=self.context
|
|
|
|
).data
|
|
|
|
encounter_rate_details["encounter_method"] = encounter_method_data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
# Get Versions associated with each unique item
|
2016-03-05 11:40:41 +00:00
|
|
|
area_encounter_objects = encounter_rates.filter(
|
2020-02-17 20:58:07 +00:00
|
|
|
encounter_method_id=id["encounter_method_id"]
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
serializer = LocationAreaEncounterRateSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
area_encounter_objects, many=True, context=self.context
|
|
|
|
)
|
|
|
|
encounter_rate_details["version_details"] = []
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
for area_encounter in serializer.data:
|
|
|
|
|
|
|
|
version_detail = OrderedDict()
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
version_detail["rate"] = area_encounter["rate"]
|
|
|
|
version_detail["version"] = area_encounter["version"]
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
encounter_rate_details["version_details"].append(version_detail)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
encounter_rate_list.append(encounter_rate_details)
|
|
|
|
|
|
|
|
return encounter_rate_list
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
def get_encounters(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
# get versions for later use
|
|
|
|
version_objects = Version.objects.all()
|
2016-03-05 11:40:41 +00:00
|
|
|
version_data = VersionSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
version_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
# all encounters associated with location area
|
2020-02-17 20:58:07 +00:00
|
|
|
all_encounters = Encounter.objects.filter(location_area=obj).order_by("pokemon")
|
2015-11-05 14:55:14 +00:00
|
|
|
encounters_list = []
|
|
|
|
|
|
|
|
# break encounters into pokemon groupings
|
2020-02-17 20:58:07 +00:00
|
|
|
for poke in all_encounters.values("pokemon").distinct():
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_object = Pokemon.objects.get(pk=poke["pokemon"])
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
pokemon_detail = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_detail["pokemon"] = PokemonSummarySerializer(
|
|
|
|
pokemon_object, context=self.context
|
|
|
|
).data
|
|
|
|
pokemon_detail["version_details"] = []
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
poke_encounters = all_encounters.filter(pokemon=poke["pokemon"]).order_by(
|
|
|
|
"version"
|
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
# each pokemon has multiple versions it could be encountered in
|
2020-02-17 20:58:07 +00:00
|
|
|
for ver in poke_encounters.values("version").distinct():
|
2015-11-05 14:55:14 +00:00
|
|
|
version_detail = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
version_detail["version"] = version_data[ver["version"] - 1]
|
|
|
|
version_detail["max_chance"] = 0
|
|
|
|
version_detail["encounter_details"] = []
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
poke_data = EncounterDetailSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
poke_encounters.filter(version=ver["version"]),
|
|
|
|
many=True,
|
|
|
|
context=self.context,
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
# each version has multiple ways a pokemon can be encountered
|
|
|
|
for encounter in poke_data:
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
slot = EncounterSlot.objects.get(pk=encounter["encounter_slot"])
|
2015-11-05 14:55:14 +00:00
|
|
|
slot_data = EncounterSlotSerializer(slot, context=self.context).data
|
2020-02-17 20:58:07 +00:00
|
|
|
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"]
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
version_detail["encounter_details"].append(encounter)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_detail["version_details"].append(version_detail)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
encounters_list.append(pokemon_detail)
|
|
|
|
|
|
|
|
return encounters_list
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class LocationGameIndexSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = LocationGameIndex
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("game_index", "generation")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LocationNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = LocationName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LocationDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
region = RegionSummarySerializer()
|
2015-10-29 17:45:58 +00:00
|
|
|
names = LocationNameSerializer(many=True, read_only=True, source="locationname")
|
2016-03-05 11:40:41 +00:00
|
|
|
game_indices = LocationGameIndexSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="locationgameindex"
|
|
|
|
)
|
|
|
|
areas = LocationAreaSummarySerializer(
|
|
|
|
many=True, read_only=True, source="locationarea"
|
|
|
|
)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Location
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "region", "names", "game_indices", "areas")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
2015-09-10 04:03:18 +00:00
|
|
|
#########################
|
|
|
|
# ABILITY SERIALIZERS #
|
|
|
|
#########################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class AbilityEffectTextSerializer(serializers.ModelSerializer):
|
2015-09-10 04:03:18 +00:00
|
|
|
|
2015-09-11 12:15:45 +00:00
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
2015-09-10 04:03:18 +00:00
|
|
|
class Meta:
|
2015-10-27 13:36:33 +00:00
|
|
|
model = AbilityEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("effect", "short_effect", "language")
|
2015-09-10 04:03:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbilityFlavorTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-11-28 14:30:55 +00:00
|
|
|
flavor_text = serializers.CharField()
|
2015-09-11 12:15:45 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-09-12 04:53:46 +00:00
|
|
|
version_group = VersionGroupSummarySerializer()
|
2015-09-10 04:03:18 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AbilityFlavorText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("flavor_text", "language", "version_group")
|
2015-09-10 04:03:18 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class AbilityChangeEffectTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AbilityChangeEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = (
|
|
|
|
"effect",
|
|
|
|
"language",
|
|
|
|
)
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbilityChangeSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
2016-03-05 11:40:41 +00:00
|
|
|
effect_entries = AbilityChangeEffectTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="abilitychangeeffecttext"
|
|
|
|
)
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AbilityChange
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("version_group", "effect_entries")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-09-10 04:03:18 +00:00
|
|
|
class AbilityNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-09-11 12:15:45 +00:00
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
2015-09-10 04:03:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = AbilityName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-10 04:03:18 +00:00
|
|
|
|
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
class AbilityDetailSerializer(serializers.ModelSerializer):
|
2015-09-10 04:03:18 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
effect_entries = AbilityEffectTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="abilityeffecttext"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_text_entries = AbilityFlavorTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="abilityflavortext"
|
|
|
|
)
|
2015-09-10 04:03:18 +00:00
|
|
|
names = AbilityNameSerializer(many=True, read_only=True, source="abilityname")
|
2015-09-12 04:53:46 +00:00
|
|
|
generation = GenerationSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
effect_changes = AbilityChangeSerializer(
|
|
|
|
many=True, read_only=True, source="abilitychange"
|
|
|
|
)
|
|
|
|
pokemon = serializers.SerializerMethodField("get_ability_pokemon")
|
2015-09-11 12:15:45 +00:00
|
|
|
|
2015-09-09 04:28:33 +00:00
|
|
|
class Meta:
|
|
|
|
model = Ability
|
2015-09-10 04:03:18 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"is_main_series",
|
|
|
|
"generation",
|
|
|
|
"names",
|
|
|
|
"effect_entries",
|
|
|
|
"effect_changes",
|
|
|
|
"flavor_text_entries",
|
|
|
|
"pokemon",
|
2015-09-10 04:03:18 +00:00
|
|
|
)
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_ability_pokemon(self, obj):
|
|
|
|
|
|
|
|
pokemon_ability_objects = PokemonAbility.objects.filter(ability=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
data = PokemonAbilitySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_ability_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
pokemon = []
|
|
|
|
|
|
|
|
for poke in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del poke["ability"]
|
2015-11-16 03:29:30 +00:00
|
|
|
pokemon.append(poke)
|
|
|
|
|
|
|
|
return pokemon
|
|
|
|
|
2015-11-28 14:30:55 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
######################
|
|
|
|
# STAT SERIALIZERS #
|
|
|
|
######################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class StatNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class Meta:
|
|
|
|
model = StatName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class StatDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
names = StatNameSerializer(many=True, read_only=True, source="statname")
|
2015-10-18 23:01:33 +00:00
|
|
|
move_damage_class = MoveDamageClassSummarySerializer()
|
2016-03-05 11:40:41 +00:00
|
|
|
characteristics = CharacteristicSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="characteristic"
|
|
|
|
)
|
|
|
|
affecting_moves = serializers.SerializerMethodField("get_moves_that_affect")
|
|
|
|
affecting_natures = serializers.SerializerMethodField("get_natures_that_affect")
|
2015-10-18 23:01:33 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class Meta:
|
|
|
|
model = Stat
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"game_index",
|
|
|
|
"is_battle_only",
|
|
|
|
"affecting_moves",
|
|
|
|
"affecting_natures",
|
|
|
|
"characteristics",
|
|
|
|
"move_damage_class",
|
|
|
|
"names",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
def get_moves_that_affect(self, obj):
|
|
|
|
|
|
|
|
stat_change_objects = MoveMetaStatChange.objects.filter(stat=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
stat_changes = MoveMetaStatChangeSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
stat_change_objects, many=True, context=self.context
|
|
|
|
).data
|
|
|
|
changes = OrderedDict([("increase", []), ("decrease", [])])
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
for change in stat_changes:
|
2020-02-17 20:58:07 +00:00
|
|
|
del change["stat"]
|
|
|
|
if change["change"] > 0:
|
|
|
|
changes["increase"].append(change)
|
2015-11-16 19:23:41 +00:00
|
|
|
else:
|
2020-02-17 20:58:07 +00:00
|
|
|
changes["decrease"].append(change)
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
return changes
|
|
|
|
|
|
|
|
def get_natures_that_affect(self, obj):
|
|
|
|
|
|
|
|
increase_objects = Nature.objects.filter(increased_stat=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
increases = NatureSummarySerializer(
|
|
|
|
increase_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 19:23:41 +00:00
|
|
|
decrease_objects = Nature.objects.filter(decreased_stat=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
decreases = NatureSummarySerializer(
|
|
|
|
decrease_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 19:23:41 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
return OrderedDict([("increase", increases), ("decrease", decreases)])
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
#############################
|
|
|
|
# ITEM POCKET SERIALIZERS #
|
|
|
|
#############################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class ItemPocketNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ItemPocketDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
names = ItemPocketNameSerializer(many=True, read_only=True, source="itempocketname")
|
2020-02-17 20:58:07 +00:00
|
|
|
categories = ItemCategorySummarySerializer(
|
|
|
|
many=True, read_only=True, source="itemcategory"
|
|
|
|
)
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemPocket
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "categories", "categories", "names")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# ITEM CATEGORY SERIALIZERS #
|
|
|
|
###############################
|
|
|
|
class ItemCategoryNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ItemCategoryDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = ItemCategoryNameSerializer(
|
|
|
|
many=True, read_only=True, source="itemcategoryname"
|
|
|
|
)
|
2015-10-03 03:40:21 +00:00
|
|
|
pocket = ItemPocketSummarySerializer(source="item_pocket")
|
2015-11-16 03:29:30 +00:00
|
|
|
items = ItemSummarySerializer(many=True, read_only=True, source="item")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemCategory
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "items", "names", "pocket")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-23 04:56:01 +00:00
|
|
|
################################
|
|
|
|
# ITEM ATTRIBUTE SERIALIZERS #
|
|
|
|
################################
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class ItemAttributeNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemAttributeName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
|
|
|
|
2015-10-23 04:56:01 +00:00
|
|
|
class ItemAttributeDescriptionSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
2015-10-23 04:56:01 +00:00
|
|
|
model = ItemAttributeDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-23 04:56:01 +00:00
|
|
|
class ItemAttributeDetailSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = ItemAttributeNameSerializer(
|
|
|
|
many=True, read_only=True, source="itemattributename"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = ItemAttributeDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="itemattributedescription"
|
|
|
|
)
|
|
|
|
items = serializers.SerializerMethodField("get_attribute_items")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-23 04:56:01 +00:00
|
|
|
model = ItemAttribute
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "descriptions", "items", "names")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_attribute_items(self, obj):
|
|
|
|
|
|
|
|
item_map_objects = ItemAttributeMap.objects.filter(item_attribute=obj)
|
|
|
|
items = []
|
|
|
|
|
|
|
|
for map in item_map_objects:
|
|
|
|
item_obj = Item.objects.get(pk=map.item.id)
|
|
|
|
item = ItemSummarySerializer(item_obj, context=self.context).data
|
|
|
|
items.append(item)
|
|
|
|
|
|
|
|
return items
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-23 04:56:01 +00:00
|
|
|
###################################
|
|
|
|
# ITEM FLING EFFECT SERIALIZERS #
|
|
|
|
###################################
|
2015-11-16 03:29:30 +00:00
|
|
|
class ItemFlingEffectEffectTextSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
2015-11-16 03:29:30 +00:00
|
|
|
model = ItemFlingEffectEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("effect", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ItemFlingEffectDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
effect_entries = ItemFlingEffectEffectTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="itemflingeffecteffecttext"
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
items = ItemSummarySerializer(many=True, read_only=True, source="item")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemFlingEffect
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "effect_entries", "items")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# ITEM SERIALIZERS #
|
|
|
|
#######################
|
|
|
|
class ItemFlavorTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
text = serializers.CharField(source="flavor_text")
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemFlavorText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("text", "version_group", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class ItemEffectTextSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
2015-10-27 13:36:33 +00:00
|
|
|
model = ItemEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("effect", "short_effect", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class ItemGameIndexSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemGameIndex
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("game_index", "generation")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class ItemNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ItemName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2016-02-16 06:31:19 +00:00
|
|
|
class ItemSpritesSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ItemSprites
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("sprites",)
|
2016-02-16 06:31:19 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class ItemDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
names = ItemNameSerializer(many=True, read_only=True, source="itemname")
|
2020-02-17 20:58:07 +00:00
|
|
|
game_indices = ItemGameIndexSerializer(
|
|
|
|
many=True, read_only=True, source="itemgameindex"
|
|
|
|
)
|
|
|
|
effect_entries = ItemEffectTextSerializer(
|
|
|
|
many=True, read_only=True, source="itemeffecttext"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_text_entries = ItemFlavorTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="itemflavortext"
|
|
|
|
)
|
2015-10-03 03:40:21 +00:00
|
|
|
category = ItemCategorySummarySerializer(source="item_category")
|
2015-10-23 04:56:01 +00:00
|
|
|
attributes = serializers.SerializerMethodField("get_item_attributes")
|
2015-10-03 03:40:21 +00:00
|
|
|
fling_effect = ItemFlingEffectSummarySerializer(source="item_fling_effect")
|
2020-02-17 20:58:07 +00:00
|
|
|
held_by_pokemon = serializers.SerializerMethodField(source="get_held_by_pokemon")
|
|
|
|
baby_trigger_for = serializers.SerializerMethodField(source="get_baby_trigger_for")
|
|
|
|
sprites = serializers.SerializerMethodField("get_item_sprites")
|
|
|
|
machines = serializers.SerializerMethodField("get_item_machines")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"cost",
|
|
|
|
"fling_power",
|
|
|
|
"fling_effect",
|
|
|
|
"attributes",
|
|
|
|
"category",
|
|
|
|
"effect_entries",
|
|
|
|
"flavor_text_entries",
|
|
|
|
"game_indices",
|
|
|
|
"names",
|
|
|
|
"held_by_pokemon",
|
|
|
|
"sprites",
|
|
|
|
"baby_trigger_for",
|
|
|
|
"machines",
|
2015-10-03 03:40:21 +00:00
|
|
|
)
|
|
|
|
|
2016-06-25 16:45:20 +00:00
|
|
|
def get_item_machines(self, obj):
|
|
|
|
|
|
|
|
machine_objects = Machine.objects.filter(item=obj)
|
|
|
|
|
|
|
|
machines = []
|
|
|
|
|
|
|
|
for machine_object in machine_objects:
|
|
|
|
|
|
|
|
machine_data = MachineSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
machine_object, context=self.context
|
|
|
|
).data
|
2016-06-25 16:45:20 +00:00
|
|
|
|
|
|
|
version_group_data = VersionGroupSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
machine_object.version_group, context=self.context
|
|
|
|
).data
|
2016-06-25 16:45:20 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
machines.append(
|
|
|
|
{"machine": machine_data, "version_group": version_group_data}
|
|
|
|
)
|
2016-06-25 16:45:20 +00:00
|
|
|
|
|
|
|
return machines
|
|
|
|
|
2016-02-16 06:31:19 +00:00
|
|
|
def get_item_sprites(self, obj):
|
|
|
|
|
|
|
|
sprites_object = ItemSprites.objects.get(item_id=obj)
|
|
|
|
sprites_data = ItemSpritesSerializer(sprites_object, context=self.context).data
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites_data = json.loads(sprites_data["sprites"])
|
|
|
|
host = "raw.githubusercontent.com/PokeAPI/sprites/master/"
|
2016-02-16 06:31:19 +00:00
|
|
|
|
2018-10-20 00:05:10 +00:00
|
|
|
for key in sprites_data:
|
2016-02-16 06:31:19 +00:00
|
|
|
if sprites_data[key]:
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites_data[key] = (
|
|
|
|
"https://" + host + sprites_data[key].replace("/media/", "")
|
|
|
|
)
|
2016-02-16 06:31:19 +00:00
|
|
|
|
|
|
|
return sprites_data
|
|
|
|
|
2015-10-23 04:56:01 +00:00
|
|
|
def get_item_attributes(self, obj):
|
|
|
|
|
|
|
|
item_attribute_maps = ItemAttributeMap.objects.filter(item=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
serializer = ItemAttributeMapSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
item_attribute_maps, many=True, context=self.context
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
data = serializer.data
|
2015-10-23 04:56:01 +00:00
|
|
|
|
|
|
|
attributes = []
|
|
|
|
|
|
|
|
for map in data:
|
|
|
|
attribute = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
attribute["name"] = map["attribute"]["name"]
|
|
|
|
attribute["url"] = map["attribute"]["url"]
|
2015-10-23 04:56:01 +00:00
|
|
|
attributes.append(attribute)
|
|
|
|
|
|
|
|
return attributes
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_held_by_pokemon(self, obj):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_items = PokemonItem.objects.filter(item=obj).order_by("pokemon_id")
|
|
|
|
pokemon_ids = pokemon_items.values("pokemon_id").distinct()
|
2015-11-16 03:29:30 +00:00
|
|
|
pokemon_list = []
|
|
|
|
|
|
|
|
for id in pokemon_ids:
|
|
|
|
|
|
|
|
item_pokemon_details = OrderedDict()
|
|
|
|
|
|
|
|
# Get each Unique Item by ID
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_object = Pokemon.objects.get(pk=id["pokemon_id"])
|
|
|
|
pokemon_data = PokemonSummarySerializer(
|
|
|
|
pokemon_object, context=self.context
|
|
|
|
).data
|
|
|
|
item_pokemon_details["pokemon"] = pokemon_data
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
# Get Versions associated with each unique item
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_item_objects = pokemon_items.filter(pokemon_id=id["pokemon_id"])
|
2016-03-05 11:40:41 +00:00
|
|
|
serializer = PokemonItemSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_item_objects, many=True, context=self.context
|
|
|
|
)
|
|
|
|
item_pokemon_details["version_details"] = []
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
for pokemon in serializer.data:
|
|
|
|
version_detail = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
version_detail["rarity"] = pokemon["rarity"]
|
|
|
|
version_detail["version"] = pokemon["version"]
|
|
|
|
item_pokemon_details["version_details"].append(version_detail)
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
pokemon_list.append(item_pokemon_details)
|
|
|
|
|
|
|
|
return pokemon_list
|
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
def get_baby_trigger_for(self, obj):
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
chain_object = EvolutionChain.objects.get(baby_trigger_item=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
data = EvolutionChainSummarySerializer(
|
|
|
|
chain_object, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
except EvolutionChain.DoesNotExist:
|
|
|
|
data = None
|
|
|
|
|
|
|
|
return data
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
########################
|
|
|
|
# NATURE SERIALIZERS #
|
|
|
|
########################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class NatureBattleStylePreferenceSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
move_battle_style = MoveBattleStyleSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = NatureBattleStylePreference
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = (
|
|
|
|
"low_hp_preference",
|
|
|
|
"high_hp_preference",
|
|
|
|
"move_battle_style",
|
|
|
|
)
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class NatureNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = NatureName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NatureDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
names = NatureNameSerializer(many=True, read_only=True, source="naturename")
|
2015-10-27 13:36:33 +00:00
|
|
|
decreased_stat = StatSummarySerializer()
|
|
|
|
increased_stat = StatSummarySerializer()
|
2015-11-16 03:29:30 +00:00
|
|
|
likes_flavor = BerryFlavorSummarySerializer()
|
|
|
|
hates_flavor = BerryFlavorSummarySerializer()
|
|
|
|
berries = BerrySummarySerializer(many=True, read_only=True, source="berry")
|
2020-02-17 20:58:07 +00:00
|
|
|
pokeathlon_stat_changes = serializers.SerializerMethodField("get_pokeathlon_stats")
|
2016-03-05 11:40:41 +00:00
|
|
|
move_battle_style_preferences = NatureBattleStylePreferenceSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="naturebattlestylepreference"
|
|
|
|
)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Nature
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"decreased_stat",
|
|
|
|
"increased_stat",
|
|
|
|
"likes_flavor",
|
|
|
|
"hates_flavor",
|
|
|
|
"berries",
|
|
|
|
"pokeathlon_stat_changes",
|
|
|
|
"move_battle_style_preferences",
|
|
|
|
"names",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
def get_pokeathlon_stats(self, obj):
|
|
|
|
|
|
|
|
pokeathlon_stat_objects = NaturePokeathlonStat.objects.filter(nature=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
pokeathlon_stats = NaturePokeathlonStatSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokeathlon_stat_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
for stat in pokeathlon_stats:
|
2020-02-17 20:58:07 +00:00
|
|
|
del stat["nature"]
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
return pokeathlon_stats
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
#######################
|
|
|
|
# BERRY SERIALIZERS #
|
|
|
|
#######################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class BerryFirmnessNameSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-06 17:01:32 +00:00
|
|
|
model = BerryFirmnessName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class BerryFirmnessDetailSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = BerryFirmnessNameSerializer(
|
|
|
|
many=True, read_only=True, source="berryfirmnessname"
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
berries = BerrySummarySerializer(many=True, read_only=True, source="berry")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = BerryFirmness
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "berries", "names")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
class BerryFlavorNameSerializer(serializers.ModelSerializer):
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = BerryFlavorName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-10 19:20:06 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
class BerryFlavorDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = BerryFlavorNameSerializer(
|
|
|
|
many=True, read_only=True, source="berryflavorname"
|
|
|
|
)
|
2015-11-08 21:26:02 +00:00
|
|
|
contest_type = ContestTypeSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
berries = serializers.SerializerMethodField("get_berries_with_flavor")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = BerryFlavor
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "berries", "contest_type", "names")
|
2015-11-26 01:18:35 +00:00
|
|
|
|
|
|
|
def get_berries_with_flavor(self, obj):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_map_objects = BerryFlavorMap.objects.filter(
|
2020-02-17 20:58:07 +00:00
|
|
|
berry_flavor=obj, potency__gt=0
|
|
|
|
).order_by("potency")
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_maps = BerryFlavorMapSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
flavor_map_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-26 01:18:35 +00:00
|
|
|
|
|
|
|
for map in flavor_maps:
|
2020-02-17 20:58:07 +00:00
|
|
|
del map["flavor"]
|
2015-11-26 01:18:35 +00:00
|
|
|
|
|
|
|
return flavor_maps
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class BerryDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
item = ItemSummarySerializer()
|
2015-11-26 01:18:35 +00:00
|
|
|
natural_gift_type = TypeSummarySerializer()
|
2015-10-06 17:01:32 +00:00
|
|
|
firmness = BerryFirmnessSummarySerializer(source="berry_firmness")
|
2020-02-17 20:58:07 +00:00
|
|
|
flavors = serializers.SerializerMethodField("get_berry_flavors")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Berry
|
2015-10-06 17:01:32 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"growth_time",
|
|
|
|
"max_harvest",
|
|
|
|
"natural_gift_power",
|
|
|
|
"size",
|
|
|
|
"smoothness",
|
|
|
|
"soil_dryness",
|
|
|
|
"firmness",
|
|
|
|
"flavors",
|
|
|
|
"item",
|
|
|
|
"natural_gift_type",
|
2015-10-06 17:01:32 +00:00
|
|
|
)
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
def get_berry_flavors(self, obj):
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
flavor_map_objects = BerryFlavorMap.objects.filter(berry=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_maps = BerryFlavorMapSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
flavor_map_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-10 19:20:06 +00:00
|
|
|
flavors = []
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2015-11-10 19:20:06 +00:00
|
|
|
for map in flavor_maps:
|
2020-02-17 20:58:07 +00:00
|
|
|
del map["berry"]
|
2015-11-10 19:20:06 +00:00
|
|
|
flavors.append(map)
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
return flavors
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
###########################
|
|
|
|
# EGG GROUP SERIALIZERS #
|
|
|
|
###########################
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonEggGroupSerializer(serializers.ModelSerializer):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
species = PokemonSpeciesSummarySerializer(source="pokemon_species")
|
|
|
|
egg_group = EggGroupSummarySerializer()
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-06 17:01:32 +00:00
|
|
|
model = PokemonEggGroup
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("species", "egg_group")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class EggGroupNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-06 17:01:32 +00:00
|
|
|
model = EggGroupName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EggGroupDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
names = EggGroupNameSerializer(many=True, read_only=True, source="egggroupname")
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_species = serializers.SerializerMethodField("get_species")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EggGroup
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "pokemon_species")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_species(self, obj):
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
results = PokemonEggGroup.objects.filter(egg_group=obj)
|
|
|
|
data = PokemonEggGroupSerializer(results, many=True, context=self.context).data
|
|
|
|
associated_species = []
|
|
|
|
for species in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
associated_species.append(species["species"])
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
return associated_species
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
######################
|
|
|
|
# TYPE SERIALIZERS #
|
|
|
|
######################
|
2017-10-21 13:21:23 +00:00
|
|
|
# https://stackoverflow.com/a/45987450/3482533
|
2015-09-12 04:53:46 +00:00
|
|
|
class TypeEfficacySerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = TypeEfficacy
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = "__all__"
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class TypeGameIndexSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TypeGameIndex
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("game_index", "generation")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
class TypeNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TypeName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TypeDetailSerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
Serializer for the Type resource
|
|
|
|
"""
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
names = AbilityNameSerializer(many=True, read_only=True, source="typename")
|
2020-02-17 20:58:07 +00:00
|
|
|
game_indices = TypeGameIndexSerializer(
|
|
|
|
many=True, read_only=True, source="typegameindex"
|
|
|
|
)
|
2015-10-23 04:56:01 +00:00
|
|
|
move_damage_class = MoveDamageClassSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
damage_relations = serializers.SerializerMethodField("get_type_relationships")
|
|
|
|
pokemon = serializers.SerializerMethodField("get_type_pokemon")
|
2015-11-16 19:23:41 +00:00
|
|
|
moves = MoveSummarySerializer(many=True, read_only=True, source="move")
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Type
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"damage_relations",
|
|
|
|
"game_indices",
|
|
|
|
"generation",
|
|
|
|
"move_damage_class",
|
|
|
|
"names",
|
|
|
|
"pokemon",
|
|
|
|
"moves",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
def get_type_relationships(self, obj):
|
|
|
|
|
|
|
|
relations = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
relations["no_damage_to"] = []
|
|
|
|
relations["half_damage_to"] = []
|
|
|
|
relations["double_damage_to"] = []
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
relations["no_damage_from"] = []
|
|
|
|
relations["half_damage_from"] = []
|
|
|
|
relations["double_damage_from"] = []
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
# Damage To
|
2015-09-15 12:26:47 +00:00
|
|
|
results = TypeEfficacy.objects.filter(damage_type=obj)
|
2015-09-12 04:53:46 +00:00
|
|
|
serializer = TypeEfficacySerializer(results, many=True, context=self.context)
|
|
|
|
|
|
|
|
for relation in serializer.data:
|
2020-02-17 20:58:07 +00:00
|
|
|
type = Type.objects.get(pk=relation["target_type"])
|
|
|
|
if relation["damage_factor"] == 200:
|
|
|
|
relations["double_damage_to"].append(
|
|
|
|
TypeSummarySerializer(type, context=self.context).data
|
|
|
|
)
|
|
|
|
elif relation["damage_factor"] == 50:
|
|
|
|
relations["half_damage_to"].append(
|
|
|
|
TypeSummarySerializer(type, context=self.context).data
|
|
|
|
)
|
|
|
|
elif relation["damage_factor"] == 0:
|
|
|
|
relations["no_damage_to"].append(
|
|
|
|
TypeSummarySerializer(type, context=self.context).data
|
|
|
|
)
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
# Damage From
|
2015-09-15 12:26:47 +00:00
|
|
|
results = TypeEfficacy.objects.filter(target_type=obj)
|
2015-09-12 04:53:46 +00:00
|
|
|
serializer = TypeEfficacySerializer(results, many=True, context=self.context)
|
|
|
|
|
|
|
|
for relation in serializer.data:
|
2020-02-17 20:58:07 +00:00
|
|
|
type = Type.objects.get(pk=relation["damage_type"])
|
|
|
|
if relation["damage_factor"] == 200:
|
|
|
|
relations["double_damage_from"].append(
|
|
|
|
TypeSummarySerializer(type, context=self.context).data
|
|
|
|
)
|
|
|
|
elif relation["damage_factor"] == 50:
|
|
|
|
relations["half_damage_from"].append(
|
|
|
|
TypeSummarySerializer(type, context=self.context).data
|
|
|
|
)
|
|
|
|
elif relation["damage_factor"] == 0:
|
|
|
|
relations["no_damage_from"].append(
|
|
|
|
TypeSummarySerializer(type, context=self.context).data
|
|
|
|
)
|
2015-09-12 04:53:46 +00:00
|
|
|
|
|
|
|
return relations
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_type_pokemon(self, obj):
|
|
|
|
|
|
|
|
poke_type_objects = PokemonType.objects.filter(type=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
poke_types = PokemonTypeSerializer(
|
|
|
|
poke_type_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
for poke_type in poke_types:
|
2020-02-17 20:58:07 +00:00
|
|
|
del poke_type["type"]
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
return poke_types
|
|
|
|
|
2015-09-12 04:53:46 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
#########################
|
|
|
|
# MACHINE SERIALIZERS #
|
|
|
|
#########################
|
|
|
|
class MachineDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
item = ItemSummarySerializer()
|
2016-06-25 16:45:20 +00:00
|
|
|
version_group = VersionGroupSummarySerializer()
|
2015-11-08 21:26:02 +00:00
|
|
|
move = MoveSummarySerializer()
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = Machine
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "item", "version_group", "move")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
###################################
|
|
|
|
# MOVE BATTLE STYLE SERIALIZERS #
|
|
|
|
###################################
|
|
|
|
class MoveBattleStyleNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveBattleStyleName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveBattleStyleDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = MoveBattleStyleNameSerializer(
|
|
|
|
many=True, read_only=True, source="movebattlestylename"
|
|
|
|
)
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = MoveBattleStyle
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
###################################
|
|
|
|
# MOVE DAMAGE CLASS SERIALIZERS #
|
|
|
|
###################################
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveDamageClassNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveDamageClassName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class MoveDamageClassDescriptionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveDamageClassDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveDamageClassDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = MoveDamageClassNameSerializer(
|
|
|
|
many=True, read_only=True, source="movedamageclassname"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = MoveDamageClassDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="movedamageclassdescription"
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
moves = MoveSummarySerializer(many=True, read_only=True, source="move")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveDamageClass
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = (
|
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"descriptions",
|
|
|
|
"moves",
|
|
|
|
"names",
|
|
|
|
)
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
###########################
|
|
|
|
# MOVE META SERIALIZERS #
|
|
|
|
###########################
|
|
|
|
class MoveMetaAilmentNameSerializer(serializers.ModelSerializer):
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class Meta:
|
|
|
|
model = MoveMetaAilmentName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveMetaAilmentDetailSerializer(serializers.ModelSerializer):
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = MoveMetaAilmentNameSerializer(
|
|
|
|
many=True, read_only=True, source="movemetaailmentname"
|
|
|
|
)
|
|
|
|
moves = serializers.SerializerMethodField("get_ailment_moves")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class Meta:
|
|
|
|
model = MoveMetaAilment
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "moves", "names")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_ailment_moves(self, obj):
|
|
|
|
|
|
|
|
move_meta_objects = MoveMeta.objects.filter(move_meta_ailment=obj)
|
|
|
|
moves = []
|
|
|
|
|
|
|
|
for meta in move_meta_objects:
|
|
|
|
move_obj = Move.objects.get(pk=meta.move.id)
|
|
|
|
data = MoveSummarySerializer(move_obj, context=self.context).data
|
|
|
|
moves.append(data)
|
|
|
|
|
|
|
|
return moves
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveMetaCategoryDescriptionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-27 13:36:33 +00:00
|
|
|
model = MoveMetaCategoryDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveMetaCategoryDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = MoveMetaCategoryDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="movemetacategorydescription"
|
|
|
|
)
|
|
|
|
moves = serializers.SerializerMethodField("get_category_moves")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class Meta:
|
|
|
|
model = MoveMetaCategory
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "descriptions", "moves")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_category_moves(self, obj):
|
|
|
|
|
|
|
|
move_meta_objects = MoveMeta.objects.filter(move_meta_category=obj)
|
|
|
|
moves = []
|
|
|
|
|
|
|
|
for meta in move_meta_objects:
|
|
|
|
move_obj = Move.objects.get(pk=meta.move.id)
|
|
|
|
data = MoveSummarySerializer(move_obj, context=self.context).data
|
|
|
|
moves.append(data)
|
|
|
|
|
|
|
|
return moves
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveMetaSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
ailment = MoveMetaAilmentSummarySerializer(source="move_meta_ailment")
|
2015-09-27 04:20:19 +00:00
|
|
|
category = MoveMetaCategorySummarySerializer(source="move_meta_category")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveMeta
|
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"ailment",
|
|
|
|
"category",
|
|
|
|
"min_hits",
|
|
|
|
"max_hits",
|
|
|
|
"min_turns",
|
|
|
|
"max_turns",
|
|
|
|
"drain",
|
|
|
|
"healing",
|
|
|
|
"crit_rate",
|
|
|
|
"ailment_chance",
|
|
|
|
"flinch_chance",
|
|
|
|
"stat_chance",
|
2015-09-27 04:20:19 +00:00
|
|
|
)
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
#############################
|
|
|
|
# MOVE TARGET SERIALIZERS #
|
|
|
|
#############################
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveTargetNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveTargetName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class MoveTargetDescriptionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveTargetDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveTargetDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
names = MoveTargetNameSerializer(many=True, read_only=True, source="movetargetname")
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = MoveTargetDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="movetargetdescription"
|
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
moves = MoveSummarySerializer(many=True, read_only=True, source="move")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveTarget
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "descriptions", "moves", "names")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
######################
|
|
|
|
# MOVE SERIALIZERS #
|
|
|
|
######################
|
|
|
|
class MoveNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AbilityName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class MoveChangeSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
type = TypeSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
effect_entries = serializers.SerializerMethodField("get_effects")
|
|
|
|
effect_chance = serializers.IntegerField(source="move_effect_chance")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveChange
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"accuracy",
|
|
|
|
"power",
|
|
|
|
"pp",
|
|
|
|
"effect_chance",
|
|
|
|
"effect_entries",
|
|
|
|
"type",
|
|
|
|
"version_group",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_effects(self, obj):
|
|
|
|
|
|
|
|
effect_texts = MoveEffectEffectText.objects.filter(move_effect=obj.move_effect)
|
2020-02-17 20:58:07 +00:00
|
|
|
data = MoveEffectEffectTextSerializer(
|
|
|
|
effect_texts, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
return data
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveEffectEffectTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
2016-03-05 08:26:51 +00:00
|
|
|
model = MoveEffectEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("effect", "short_effect", "language")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveEffectChangeEffectTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
2016-03-05 08:26:51 +00:00
|
|
|
model = MoveEffectChangeEffectText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("effect", "language")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MoveEffectChangeSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
2016-03-05 11:40:41 +00:00
|
|
|
effect_entries = MoveEffectChangeEffectTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="moveeffectchangeeffecttext"
|
|
|
|
)
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveEffectChange
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("version_group", "effect_entries")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2016-07-05 08:42:03 +00:00
|
|
|
class MoveFlavorTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
flavor_text = serializers.CharField()
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveFlavorText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("flavor_text", "language", "version_group")
|
2016-07-05 08:42:03 +00:00
|
|
|
|
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
class MoveDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
type = TypeSummarySerializer()
|
2015-10-27 13:36:33 +00:00
|
|
|
target = MoveTargetSummarySerializer(source="move_target")
|
2015-11-16 03:29:30 +00:00
|
|
|
contest_type = ContestTypeSummarySerializer()
|
|
|
|
contest_effect = ContestEffectSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
damage_class = MoveDamageClassSummarySerializer(source="move_damage_class")
|
|
|
|
meta = MoveMetaSerializer(read_only=True, source="movemeta")
|
2015-09-19 22:13:41 +00:00
|
|
|
names = MoveNameSerializer(many=True, read_only=True, source="movename")
|
2020-02-17 20:58:07 +00:00
|
|
|
effect_entries = serializers.SerializerMethodField("get_effect_text")
|
2015-09-27 04:20:19 +00:00
|
|
|
effect_chance = serializers.IntegerField(source="move_effect_chance")
|
2020-02-17 20:58:07 +00:00
|
|
|
contest_combos = serializers.SerializerMethodField("get_combos")
|
|
|
|
stat_changes = serializers.SerializerMethodField("get_move_stat_change")
|
2015-11-16 03:29:30 +00:00
|
|
|
super_contest_effect = SuperContestEffectSummarySerializer()
|
|
|
|
past_values = MoveChangeSerializer(many=True, read_only=True, source="movechange")
|
2020-02-17 20:58:07 +00:00
|
|
|
effect_changes = serializers.SerializerMethodField("get_effect_change_text")
|
|
|
|
machines = serializers.SerializerMethodField("get_move_machines")
|
2016-07-05 08:42:03 +00:00
|
|
|
flavor_text_entries = MoveFlavorTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="moveflavortext"
|
|
|
|
)
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Move
|
2015-09-27 04:20:19 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"accuracy",
|
|
|
|
"effect_chance",
|
|
|
|
"pp",
|
|
|
|
"priority",
|
|
|
|
"power",
|
|
|
|
"contest_combos",
|
|
|
|
"contest_type",
|
|
|
|
"contest_effect",
|
|
|
|
"damage_class",
|
|
|
|
"effect_entries",
|
|
|
|
"effect_changes",
|
|
|
|
"generation",
|
|
|
|
"meta",
|
|
|
|
"names",
|
|
|
|
"past_values",
|
|
|
|
"stat_changes",
|
|
|
|
"super_contest_effect",
|
|
|
|
"target",
|
|
|
|
"type",
|
|
|
|
"machines",
|
|
|
|
"flavor_text_entries",
|
2015-09-27 04:20:19 +00:00
|
|
|
)
|
2015-09-19 22:13:41 +00:00
|
|
|
|
2016-06-25 16:45:20 +00:00
|
|
|
def get_move_machines(self, obj):
|
|
|
|
|
|
|
|
machine_objects = Machine.objects.filter(move=obj)
|
|
|
|
|
|
|
|
machines = []
|
|
|
|
|
|
|
|
for machine_object in machine_objects:
|
|
|
|
machine_data = MachineSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
machine_object, context=self.context
|
|
|
|
).data
|
2016-06-25 16:45:20 +00:00
|
|
|
|
|
|
|
version_group_data = VersionGroupSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
machine_object.version_group, context=self.context
|
|
|
|
).data
|
2016-06-25 16:45:20 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
machines.append(
|
|
|
|
{"machine": machine_data, "version_group": version_group_data}
|
|
|
|
)
|
2016-06-25 16:45:20 +00:00
|
|
|
|
|
|
|
return machines
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_combos(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
normal_before_objects = ContestCombo.objects.filter(first_move=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
normal_before_data = ContestComboSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
normal_before_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
normal_after_objects = ContestCombo.objects.filter(second_move=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
normal_after_data = ContestComboSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
normal_after_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
super_before_objects = SuperContestCombo.objects.filter(first_move=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
super_before_data = SuperContestComboSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
super_before_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
super_after_objects = SuperContestCombo.objects.filter(second_move=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
super_after_data = SuperContestComboSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
super_after_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
details = None
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
if (
|
|
|
|
normal_before_data
|
|
|
|
or normal_after_data
|
|
|
|
or super_before_data
|
|
|
|
or super_after_data
|
|
|
|
):
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
details = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
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
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
for combo in normal_before_data:
|
2020-02-17 20:58:07 +00:00
|
|
|
if details["normal"]["use_before"] is None:
|
|
|
|
details["normal"]["use_before"] = []
|
|
|
|
details["normal"]["use_before"].append(combo["second_move"])
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
for combo in normal_after_data:
|
2020-02-17 20:58:07 +00:00
|
|
|
if details["normal"]["use_after"] is None:
|
|
|
|
details["normal"]["use_after"] = []
|
|
|
|
details["normal"]["use_after"].append(combo["first_move"])
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
for combo in super_before_data:
|
2020-02-17 20:58:07 +00:00
|
|
|
if details["super"]["use_before"] is None:
|
|
|
|
details["super"]["use_before"] = []
|
|
|
|
details["super"]["use_before"].append(combo["second_move"])
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
for combo in super_after_data:
|
2020-02-17 20:58:07 +00:00
|
|
|
if details["super"]["use_after"] is None:
|
|
|
|
details["super"]["use_after"] = []
|
|
|
|
details["super"]["use_after"].append(combo["first_move"])
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
return details
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_effect_text(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
effect_texts = MoveEffectEffectText.objects.filter(move_effect=obj.move_effect)
|
2020-02-17 20:58:07 +00:00
|
|
|
data = MoveEffectEffectTextSerializer(
|
|
|
|
effect_texts, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
return data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_effect_change_text(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
effect_changes = MoveEffectChange.objects.filter(move_effect=obj.move_effect)
|
2020-02-17 20:58:07 +00:00
|
|
|
data = MoveEffectChangeSerializer(
|
|
|
|
effect_changes, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
return data
|
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
def get_move_stat_change(self, obj):
|
|
|
|
|
|
|
|
stat_change_objects = MoveMetaStatChange.objects.filter(move=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
stat_changes = MoveMetaStatChangeSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
stat_change_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
for change in stat_changes:
|
2020-02-17 20:58:07 +00:00
|
|
|
del change["move"]
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-16 19:23:41 +00:00
|
|
|
return stat_changes
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
##########################
|
|
|
|
# PAL PARK SERIALIZERS #
|
|
|
|
##########################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
class PalParkSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
area = PalParkAreaSummarySerializer(read_only=True, source="pal_park_area")
|
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer()
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
class Meta:
|
|
|
|
model = PalPark
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("base_score", "rate", "area", "pokemon_species")
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class PalParkAreaNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PalParkAreaName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PalParkAreaDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = PalParkAreaNameSerializer(
|
|
|
|
many=True, read_only=True, source="palparkareaname"
|
|
|
|
)
|
|
|
|
pokemon_encounters = serializers.SerializerMethodField("get_encounters")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class Meta:
|
|
|
|
model = PalParkArea
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "pokemon_encounters")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_encounters(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
pal_park_objects = PalPark.objects.filter(pal_park_area=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
parks = PalParkSerializer(
|
|
|
|
pal_park_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
encounters = []
|
2015-09-19 22:13:41 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
for encounter in parks:
|
2020-02-17 20:58:07 +00:00
|
|
|
del encounter["area"]
|
2015-11-16 03:29:30 +00:00
|
|
|
encounters.append(encounter)
|
2015-09-19 22:13:41 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
return encounters
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# POKEMON COLOR SERIALIZERS #
|
|
|
|
###############################
|
2015-09-15 12:26:47 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
class PokemonColorNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonColorName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PokemonColorDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = PokemonColorNameSerializer(
|
|
|
|
many=True, read_only=True, source="pokemoncolorname"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspecies"
|
|
|
|
)
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonColor
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "pokemon_species")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
##############################
|
|
|
|
# POKEMON FORM SERIALIZERS #
|
|
|
|
##############################
|
2016-02-16 06:31:19 +00:00
|
|
|
class PokemonFormSpritesSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokemonFormSprites
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("sprites",)
|
2016-02-16 06:31:19 +00:00
|
|
|
|
|
|
|
|
2016-06-25 16:56:24 +00:00
|
|
|
class PokemonFormNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonFormName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "pokemon_name", "language")
|
2016-06-25 16:56:24 +00:00
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonFormDetailSerializer(serializers.ModelSerializer):
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
pokemon = PokemonSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
version_group = VersionGroupSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites = serializers.SerializerMethodField("get_pokemon_form_sprites")
|
|
|
|
form_names = serializers.SerializerMethodField("get_pokemon_form_names")
|
|
|
|
names = serializers.SerializerMethodField("get_pokemon_form_pokemon_names")
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonForm
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"order",
|
|
|
|
"form_order",
|
|
|
|
"is_default",
|
|
|
|
"is_battle_only",
|
|
|
|
"is_mega",
|
|
|
|
"form_name",
|
|
|
|
"pokemon",
|
|
|
|
"sprites",
|
|
|
|
"version_group",
|
|
|
|
"form_names",
|
|
|
|
"names",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2016-06-25 16:56:24 +00:00
|
|
|
def get_pokemon_form_names(self, obj):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
form_results = PokemonFormName.objects.filter(
|
|
|
|
pokemon_form=obj, name__regex=".+"
|
|
|
|
)
|
|
|
|
form_serializer = PokemonFormNameSerializer(
|
|
|
|
form_results, many=True, context=self.context
|
|
|
|
)
|
2016-06-25 16:56:24 +00:00
|
|
|
|
|
|
|
data = form_serializer.data
|
|
|
|
|
|
|
|
for name in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del name["pokemon_name"]
|
2016-06-25 16:56:24 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
def get_pokemon_form_pokemon_names(self, obj):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
form_results = PokemonFormName.objects.filter(
|
|
|
|
pokemon_form=obj, pokemon_name__regex=".+"
|
|
|
|
)
|
|
|
|
form_serializer = PokemonFormNameSerializer(
|
|
|
|
form_results, many=True, context=self.context
|
|
|
|
)
|
2016-06-25 16:56:24 +00:00
|
|
|
|
|
|
|
data = form_serializer.data
|
|
|
|
|
|
|
|
for name in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
name["name"] = name["pokemon_name"]
|
|
|
|
del name["pokemon_name"]
|
2016-06-25 16:56:24 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
2016-02-16 06:31:19 +00:00
|
|
|
def get_pokemon_form_sprites(self, obj):
|
|
|
|
|
|
|
|
sprites_object = PokemonFormSprites.objects.get(pokemon_form_id=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites_data = PokemonFormSpritesSerializer(
|
|
|
|
sprites_object, context=self.context
|
|
|
|
).data
|
|
|
|
sprites_data = json.loads(sprites_data["sprites"])
|
2016-02-16 06:31:19 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
host = "raw.githubusercontent.com/PokeAPI/sprites/master/"
|
2016-02-16 06:31:19 +00:00
|
|
|
|
2018-10-20 00:05:10 +00:00
|
|
|
for key in sprites_data:
|
2016-02-16 06:31:19 +00:00
|
|
|
if sprites_data[key]:
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites_data[key] = (
|
|
|
|
"https://" + host + sprites_data[key].replace("/media/", "")
|
|
|
|
)
|
2016-02-16 06:31:19 +00:00
|
|
|
|
|
|
|
return sprites_data
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
#################################
|
|
|
|
# POKEMON HABITAT SERIALIZERS #
|
|
|
|
#################################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class PokemonHabitatNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonHabitatName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PokemonHabitatDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = PokemonHabitatNameSerializer(
|
|
|
|
many=True, read_only=True, source="pokemonhabitatname"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspecies"
|
|
|
|
)
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonHabitat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "pokemon_species")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
##############################
|
|
|
|
# POKEMON MOVE SERIALIZERS #
|
|
|
|
##############################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveLearnMethodNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-27 13:36:33 +00:00
|
|
|
model = MoveLearnMethodName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveLearnMethodDescriptionSerializer(serializers.HyperlinkedModelSerializer):
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
language = LanguageSummarySerializer()
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class Meta:
|
|
|
|
model = MoveLearnMethodDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2015-10-27 13:36:33 +00:00
|
|
|
class MoveLearnMethodDetailSerializer(serializers.ModelSerializer):
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = MoveLearnMethodNameSerializer(
|
|
|
|
many=True, read_only=True, source="movelearnmethodname"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = MoveLearnMethodDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="movelearnmethoddescription"
|
|
|
|
)
|
|
|
|
version_groups = serializers.SerializerMethodField("get_method_version_groups")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MoveLearnMethod
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "descriptions", "version_groups")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
def get_method_version_groups(self, obj):
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
version_group_objects = VersionGroupMoveLearnMethod.objects.filter(
|
|
|
|
move_learn_method=obj
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
version_group_data = VersionGroupMoveLearnMethodSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
version_group_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-08 21:26:02 +00:00
|
|
|
groups = []
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
for vg in version_group_data:
|
2020-02-17 20:58:07 +00:00
|
|
|
groups.append(vg["version_group"])
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
return groups
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
2017-10-21 13:21:23 +00:00
|
|
|
# https://stackoverflow.com/a/45987450/3482533
|
2015-09-27 04:20:19 +00:00
|
|
|
class PokemonMoveSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokemonMove
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = "__all__"
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# POKEMON SHAPE SERIALIZERS #
|
|
|
|
###############################
|
2015-09-19 22:13:41 +00:00
|
|
|
class PokemonShapeNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonShapeName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "awesome_name", "language")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PokemonShapeDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = serializers.SerializerMethodField("get_shape_names")
|
|
|
|
awesome_names = serializers.SerializerMethodField("get_shape_awesome_names")
|
2016-03-05 11:40:41 +00:00
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspecies"
|
|
|
|
)
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonShape
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "awesome_names", "names", "pokemon_species")
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
def get_shape_names(self, obj):
|
|
|
|
|
|
|
|
results = PokemonShapeName.objects.filter(pokemon_shape_id=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
serializer = PokemonShapeNameSerializer(
|
|
|
|
results, many=True, context=self.context
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
data = serializer.data
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
for entry in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del entry["awesome_name"]
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
def get_shape_awesome_names(self, obj):
|
|
|
|
|
|
|
|
results = PokemonShapeName.objects.filter(pokemon_shape_id=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
serializer = PokemonShapeNameSerializer(
|
|
|
|
results, many=True, context=self.context
|
|
|
|
)
|
2015-09-19 22:13:41 +00:00
|
|
|
data = serializer.data
|
|
|
|
|
|
|
|
for entry in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del entry["name"]
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
##############################
|
|
|
|
# POKEMON ITEM SERIALIZERS #
|
|
|
|
##############################
|
|
|
|
class PokemonItemSerializer(serializers.ModelSerializer):
|
|
|
|
|
2015-11-05 14:55:14 +00:00
|
|
|
version = VersionSummarySerializer()
|
2015-10-06 17:01:32 +00:00
|
|
|
item = ItemSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonItem
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("rarity", "item", "version")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
##############################
|
|
|
|
# POKEMON STAT SERIALIZERS #
|
|
|
|
##############################
|
|
|
|
class PokemonStatSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
stat = StatSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonStat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("base_stat", "effort", "stat")
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
#########################
|
|
|
|
# POKEMON SERIALIZERS #
|
|
|
|
#########################
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class PokemonGameIndexSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
version = VersionSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonGameIndex
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("game_index", "version")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2016-02-16 06:31:19 +00:00
|
|
|
class PokemonSpritesSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PokemonSprites
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("sprites",)
|
2016-02-16 06:31:19 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class PokemonDetailSerializer(serializers.ModelSerializer):
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
abilities = serializers.SerializerMethodField("get_pokemon_abilities")
|
|
|
|
game_indices = PokemonGameIndexSerializer(
|
|
|
|
many=True, read_only=True, source="pokemongameindex"
|
|
|
|
)
|
|
|
|
moves = serializers.SerializerMethodField("get_pokemon_moves")
|
2015-10-06 17:01:32 +00:00
|
|
|
species = PokemonSpeciesSummarySerializer(source="pokemon_species")
|
2015-09-27 04:20:19 +00:00
|
|
|
stats = PokemonStatSerializer(many=True, read_only=True, source="pokemonstat")
|
2020-02-17 20:58:07 +00:00
|
|
|
types = serializers.SerializerMethodField("get_pokemon_types")
|
|
|
|
forms = PokemonFormSummarySerializer(
|
|
|
|
many=True, read_only=True, source="pokemonform"
|
|
|
|
)
|
|
|
|
held_items = serializers.SerializerMethodField("get_pokemon_held_items")
|
|
|
|
location_area_encounters = serializers.SerializerMethodField("get_encounters")
|
|
|
|
sprites = serializers.SerializerMethodField("get_pokemon_sprites")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
class Meta:
|
|
|
|
model = Pokemon
|
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"base_experience",
|
|
|
|
"height",
|
|
|
|
"is_default",
|
|
|
|
"order",
|
|
|
|
"weight",
|
|
|
|
"abilities",
|
|
|
|
"forms",
|
|
|
|
"game_indices",
|
|
|
|
"held_items",
|
|
|
|
"location_area_encounters",
|
|
|
|
"moves",
|
|
|
|
"species",
|
|
|
|
"sprites",
|
|
|
|
"stats",
|
|
|
|
"types",
|
2015-09-27 04:20:19 +00:00
|
|
|
)
|
|
|
|
|
2016-02-16 06:31:19 +00:00
|
|
|
def get_pokemon_sprites(self, obj):
|
|
|
|
|
|
|
|
sprites_object = PokemonSprites.objects.get(pokemon_id=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites_data = PokemonSpritesSerializer(
|
|
|
|
sprites_object, context=self.context
|
|
|
|
).data
|
|
|
|
sprites_data = json.loads(sprites_data["sprites"])
|
|
|
|
host = "raw.githubusercontent.com/PokeAPI/sprites/master/"
|
2016-02-16 06:31:19 +00:00
|
|
|
|
2018-10-20 00:05:10 +00:00
|
|
|
for key in sprites_data:
|
2016-02-16 06:31:19 +00:00
|
|
|
if sprites_data[key]:
|
2020-02-17 20:58:07 +00:00
|
|
|
sprites_data[key] = (
|
|
|
|
"https://" + host + sprites_data[key].replace("/media/", "")
|
|
|
|
)
|
2016-02-16 06:31:19 +00:00
|
|
|
|
|
|
|
return sprites_data
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-09-27 04:20:19 +00:00
|
|
|
def get_pokemon_moves(self, obj):
|
|
|
|
|
|
|
|
version_objects = VersionGroup.objects.all()
|
2016-03-05 11:40:41 +00:00
|
|
|
version_data = VersionGroupSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
version_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-09-27 04:20:19 +00:00
|
|
|
method_objects = MoveLearnMethod.objects.all()
|
2016-03-05 11:40:41 +00:00
|
|
|
method_data = MoveLearnMethodSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
method_objects, many=True, context=self.context
|
|
|
|
).data
|
2016-03-05 11:40:41 +00:00
|
|
|
|
2018-10-20 00:05:10 +00:00
|
|
|
# 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.
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_moves = PokemonMove.objects.filter(pokemon_id=obj).order_by("move_id")
|
|
|
|
move_ids = pokemon_moves.values("move_id").distinct()
|
2015-09-27 04:20:19 +00:00
|
|
|
move_list = []
|
|
|
|
|
|
|
|
for id in move_ids:
|
|
|
|
|
|
|
|
pokemon_move_details = OrderedDict()
|
|
|
|
|
|
|
|
# Get each Unique Move by ID
|
2020-02-17 20:58:07 +00:00
|
|
|
move_object = Move.objects.get(pk=id["move_id"])
|
2015-09-27 04:20:19 +00:00
|
|
|
move_data = MoveSummarySerializer(move_object, context=self.context).data
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_move_details["move"] = move_data
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
# Get Versions and Move Methods associated with each unique move
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_move_objects = pokemon_moves.filter(move_id=id["move_id"])
|
2016-03-05 11:40:41 +00:00
|
|
|
serializer = PokemonMoveSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_move_objects, many=True, context=self.context
|
|
|
|
)
|
|
|
|
pokemon_move_details["version_group_details"] = []
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
for move in serializer.data:
|
|
|
|
|
|
|
|
version_detail = OrderedDict()
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
version_detail["level_learned_at"] = move["level"]
|
|
|
|
version_detail["version_group"] = version_data[
|
|
|
|
move["version_group"] - 1
|
|
|
|
]
|
|
|
|
version_detail["move_learn_method"] = method_data[
|
|
|
|
move["move_learn_method"] - 1
|
|
|
|
]
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_move_details["version_group_details"].append(version_detail)
|
2015-09-27 04:20:19 +00:00
|
|
|
|
|
|
|
move_list.append(pokemon_move_details)
|
|
|
|
|
|
|
|
return move_list
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
def get_pokemon_held_items(self, obj):
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
# Get items related to this pokemon and pull out unique Item IDs
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_items = PokemonItem.objects.filter(pokemon_id=obj).order_by("item_id")
|
|
|
|
item_ids = pokemon_items.values("item_id").distinct()
|
2015-10-06 17:01:32 +00:00
|
|
|
item_list = []
|
|
|
|
|
|
|
|
for id in item_ids:
|
|
|
|
|
|
|
|
pokemon_item_details = OrderedDict()
|
|
|
|
|
|
|
|
# Get each Unique Item by ID
|
2020-02-17 20:58:07 +00:00
|
|
|
item_object = Item.objects.get(pk=id["item_id"])
|
2015-10-06 17:01:32 +00:00
|
|
|
item_data = ItemSummarySerializer(item_object, context=self.context).data
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_item_details["item"] = item_data
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
# Get Versions associated with each unique item
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_item_objects = pokemon_items.filter(item_id=id["item_id"])
|
2016-03-05 11:40:41 +00:00
|
|
|
serializer = PokemonItemSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_item_objects, many=True, context=self.context
|
|
|
|
)
|
|
|
|
pokemon_item_details["version_details"] = []
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
for item in serializer.data:
|
|
|
|
|
|
|
|
version_detail = OrderedDict()
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
version_detail["rarity"] = item["rarity"]
|
|
|
|
version_detail["version"] = item["version"]
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_item_details["version_details"].append(version_detail)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
item_list.append(pokemon_item_details)
|
|
|
|
|
|
|
|
return item_list
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_pokemon_abilities(self, obj):
|
|
|
|
|
|
|
|
pokemon_ability_objects = PokemonAbility.objects.filter(pokemon=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
data = PokemonAbilitySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_ability_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
abilities = []
|
|
|
|
|
|
|
|
for ability in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del ability["pokemon"]
|
2015-11-16 03:29:30 +00:00
|
|
|
abilities.append(ability)
|
|
|
|
|
|
|
|
return abilities
|
2015-09-27 04:20:19 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_pokemon_types(self, obj):
|
|
|
|
|
|
|
|
poke_type_objects = PokemonType.objects.filter(pokemon=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
poke_types = PokemonTypeSerializer(
|
|
|
|
poke_type_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
for poke_type in poke_types:
|
2020-02-17 20:58:07 +00:00
|
|
|
del poke_type["pokemon"]
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
return poke_types
|
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
def get_encounters(self, obj):
|
2015-11-05 14:55:14 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
return reverse("pokemon_encounters", kwargs={"pokemon_id": obj.pk})
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
#################################
|
|
|
|
# POKEMON SPECIES SERIALIZERS #
|
|
|
|
#################################
|
2015-10-06 17:01:32 +00:00
|
|
|
class EvolutionTriggerNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
class Meta:
|
2015-10-06 17:01:32 +00:00
|
|
|
model = EvolutionTriggerName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EvolutionTriggerDetailSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = EvolutionTriggerNameSerializer(
|
|
|
|
many=True, read_only=True, source="evolutiontriggername"
|
|
|
|
)
|
|
|
|
pokemon_species = serializers.SerializerMethodField("get_species")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EvolutionTrigger
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "pokemon_species")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
def get_species(self, obj):
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
evo_objects = PokemonEvolution.objects.filter(evolution_trigger=obj)
|
2015-11-26 01:18:35 +00:00
|
|
|
species_list = []
|
2019-05-01 02:42:24 +00:00
|
|
|
species_names = set()
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
for evo in evo_objects:
|
2016-03-05 11:40:41 +00:00
|
|
|
species = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
evo.evolved_species, context=self.context
|
|
|
|
).data
|
|
|
|
if species["name"] not in species_names:
|
2019-05-01 02:42:24 +00:00
|
|
|
species_list.append(species)
|
2020-02-17 20:58:07 +00:00
|
|
|
species_names.add(species["name"])
|
2015-11-26 01:18:35 +00:00
|
|
|
|
|
|
|
return species_list
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
class PokemonSpeciesDescriptionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonSpeciesDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2016-02-25 04:55:59 +00:00
|
|
|
class PokemonSpeciesFlavorTextSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
flavor_text = serializers.CharField()
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
version = VersionSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonSpeciesFlavorText
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("flavor_text", "language", "version")
|
2016-02-25 04:55:59 +00:00
|
|
|
|
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
class PokemonSpeciesNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonSpeciesName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "genus", "language")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
class PokemonSpeciesEvolutionSerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
This is here purely to help build pokemon evolution chains
|
|
|
|
"""
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2016-03-05 08:26:51 +00:00
|
|
|
class Meta:
|
2015-10-03 03:40:21 +00:00
|
|
|
model = PokemonSpecies
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "id", "evolves_from_species", "is_baby")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = serializers.SerializerMethodField("get_pokemon_names")
|
2016-03-05 11:40:41 +00:00
|
|
|
form_descriptions = PokemonSpeciesDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspeciesdescription"
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
pokedex_numbers = PokemonDexEntrySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemondexnumber"
|
|
|
|
)
|
|
|
|
egg_groups = serializers.SerializerMethodField("get_pokemon_egg_groups")
|
2016-03-05 11:40:41 +00:00
|
|
|
flavor_text_entries = PokemonSpeciesFlavorTextSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokemonspeciesflavortext"
|
|
|
|
)
|
|
|
|
genera = serializers.SerializerMethodField("get_pokemon_genera")
|
2015-10-03 03:40:21 +00:00
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
growth_rate = GrowthRateSummarySerializer()
|
|
|
|
color = PokemonColorSummarySerializer(source="pokemon_color")
|
|
|
|
habitat = PokemonHabitatSummarySerializer(source="pokemon_habitat")
|
|
|
|
shape = PokemonShapeSummarySerializer(source="pokemon_shape")
|
|
|
|
evolves_from_species = PokemonSpeciesSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
varieties = serializers.SerializerMethodField("get_pokemon_varieties")
|
2015-10-06 17:01:32 +00:00
|
|
|
evolution_chain = EvolutionChainSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
pal_park_encounters = serializers.SerializerMethodField("get_encounters")
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2016-03-05 08:26:51 +00:00
|
|
|
class Meta:
|
2015-10-03 03:40:21 +00:00
|
|
|
model = PokemonSpecies
|
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"order",
|
|
|
|
"gender_rate",
|
|
|
|
"capture_rate",
|
|
|
|
"base_happiness",
|
|
|
|
"is_baby",
|
|
|
|
"hatch_counter",
|
|
|
|
"has_gender_differences",
|
|
|
|
"forms_switchable",
|
|
|
|
"growth_rate",
|
|
|
|
"pokedex_numbers",
|
|
|
|
"egg_groups",
|
|
|
|
"color",
|
|
|
|
"shape",
|
|
|
|
"evolves_from_species",
|
|
|
|
"evolution_chain",
|
|
|
|
"habitat",
|
|
|
|
"generation",
|
|
|
|
"names",
|
|
|
|
"pal_park_encounters",
|
|
|
|
"form_descriptions",
|
|
|
|
"flavor_text_entries",
|
|
|
|
"genera",
|
|
|
|
"varieties",
|
2015-10-03 03:40:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_pokemon_names(self, obj):
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
species_results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
species_serializer = PokemonSpeciesNameSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
species_results, many=True, context=self.context
|
|
|
|
)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
data = species_serializer.data
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
for name in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del name["genus"]
|
2015-10-03 03:40:21 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
def get_pokemon_genera(self, obj):
|
|
|
|
|
|
|
|
results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
serializer = PokemonSpeciesNameSerializer(
|
|
|
|
results, many=True, context=self.context
|
|
|
|
)
|
2015-10-03 03:40:21 +00:00
|
|
|
data = serializer.data
|
|
|
|
genera = []
|
|
|
|
|
|
|
|
for entry in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
if entry["genus"]:
|
|
|
|
del entry["name"]
|
2015-10-03 03:40:21 +00:00
|
|
|
genera.append(entry)
|
|
|
|
|
|
|
|
return genera
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
def get_pokemon_egg_groups(self, obj):
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
results = PokemonEggGroup.objects.filter(pokemon_species=obj)
|
|
|
|
data = PokemonEggGroupSerializer(results, many=True, context=self.context).data
|
|
|
|
groups = []
|
|
|
|
for group in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
groups.append(group["egg_group"])
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
return groups
|
|
|
|
|
|
|
|
def get_pokemon_varieties(self, obj):
|
|
|
|
|
|
|
|
results = Pokemon.objects.filter(pokemon_species=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
summary_data = PokemonSummarySerializer(
|
|
|
|
results, many=True, context=self.context
|
|
|
|
).data
|
|
|
|
detail_data = PokemonDetailSerializer(
|
|
|
|
results, many=True, context=self.context
|
|
|
|
).data
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
varieties = []
|
|
|
|
|
|
|
|
for index, pokemon in enumerate(detail_data):
|
|
|
|
entry = OrderedDict()
|
2020-02-17 20:58:07 +00:00
|
|
|
entry["is_default"] = pokemon["is_default"]
|
|
|
|
entry["pokemon"] = summary_data[index]
|
2015-10-06 17:01:32 +00:00
|
|
|
varieties.append(entry)
|
|
|
|
|
|
|
|
return varieties
|
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_encounters(self, obj):
|
|
|
|
|
2015-11-26 01:18:35 +00:00
|
|
|
pal_park_objects = PalPark.objects.filter(pokemon_species=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
parks = PalParkSerializer(
|
|
|
|
pal_park_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
encounters = []
|
|
|
|
|
|
|
|
for encounter in parks:
|
2020-02-17 20:58:07 +00:00
|
|
|
del encounter["pokemon_species"]
|
2015-11-16 03:29:30 +00:00
|
|
|
encounters.append(encounter)
|
|
|
|
|
|
|
|
return encounters
|
|
|
|
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class PokemonEvolutionSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
item = ItemSummarySerializer(source="evolution_item")
|
|
|
|
held_item = ItemSummarySerializer()
|
|
|
|
known_move = MoveSummarySerializer()
|
|
|
|
known_move_type = TypeSummarySerializer()
|
|
|
|
party_species = PokemonSpeciesSummarySerializer()
|
|
|
|
party_type = TypeSummarySerializer()
|
|
|
|
trade_species = PokemonSpeciesSummarySerializer()
|
2015-10-27 13:36:33 +00:00
|
|
|
location = LocationSummarySerializer()
|
2015-10-06 17:01:32 +00:00
|
|
|
trigger = EvolutionTriggerSummarySerializer(source="evolution_trigger")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokemonEvolution
|
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"item",
|
|
|
|
"trigger",
|
|
|
|
"gender",
|
|
|
|
"held_item",
|
|
|
|
"known_move",
|
|
|
|
"known_move_type",
|
|
|
|
"location",
|
|
|
|
"min_level",
|
|
|
|
"min_happiness",
|
|
|
|
"min_beauty",
|
|
|
|
"min_affection",
|
|
|
|
"needs_overworld_rain",
|
|
|
|
"party_species",
|
|
|
|
"party_type",
|
|
|
|
"relative_physical_stats",
|
|
|
|
"time_of_day",
|
|
|
|
"trade_species",
|
|
|
|
"turn_upside_down",
|
2015-10-06 17:01:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class EvolutionChainDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
baby_trigger_item = ItemSummarySerializer()
|
2020-02-17 20:58:07 +00:00
|
|
|
chain = serializers.SerializerMethodField("build_chain")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = EvolutionChain
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "baby_trigger_item", "chain")
|
2015-10-06 17:01:32 +00:00
|
|
|
|
|
|
|
def build_chain(self, obj):
|
|
|
|
|
|
|
|
chain_id = obj.id
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
pokemon_objects = PokemonSpecies.objects.filter(
|
2020-02-17 20:58:07 +00:00
|
|
|
evolution_chain_id=chain_id
|
|
|
|
).order_by("order")
|
2016-03-05 11:40:41 +00:00
|
|
|
summary_data = PokemonSpeciesSummarySerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_objects, many=True, context=self.context
|
|
|
|
).data
|
2016-03-05 11:40:41 +00:00
|
|
|
ref_data = PokemonSpeciesEvolutionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
pokemon_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2020-04-13 13:12:19 +00:00
|
|
|
# convert evolution data list to tree
|
|
|
|
evolution_tree = self.build_evolution_tree(ref_data)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-13 13:12:19 +00:00
|
|
|
# serialize chain recursively from tree
|
2020-04-21 22:30:23 +00:00
|
|
|
chain = self.build_chain_link_entry(evolution_tree, summary_data)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-13 13:12:19 +00:00
|
|
|
return chain
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-13 13:12:19 +00:00
|
|
|
# converts a list of Pokemon species evolution data into a tree representing the evolution chain
|
|
|
|
def build_evolution_tree(self, species_evolution_data):
|
2020-04-21 22:30:23 +00:00
|
|
|
evolution_tree = OrderedDict()
|
|
|
|
evolution_tree["species"] = species_evolution_data[0]
|
|
|
|
evolution_tree["children"] = []
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2020-04-21 22:30:23 +00:00
|
|
|
for species in species_evolution_data[1:]:
|
|
|
|
chain_link = OrderedDict()
|
|
|
|
chain_link["species"] = species
|
|
|
|
chain_link["children"] = []
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-21 22:30:23 +00:00
|
|
|
evolves_from_species_id = chain_link["species"]["evolves_from_species"]
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2020-04-21 22:30:23 +00:00
|
|
|
# find parent link by DFS
|
|
|
|
parent_link = evolution_tree
|
|
|
|
search_stack = [parent_link]
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-21 22:30:23 +00:00
|
|
|
while len(search_stack) > 0:
|
|
|
|
l = search_stack.pop()
|
|
|
|
if l["species"]["id"] == evolves_from_species_id:
|
|
|
|
parent_link = l
|
|
|
|
break
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2020-04-21 22:30:23 +00:00
|
|
|
# "left" to "right" requires reversing the list of children
|
|
|
|
search_stack += reversed(l["children"])
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-21 22:30:23 +00:00
|
|
|
parent_link["children"].append(chain_link)
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2020-04-13 13:12:19 +00:00
|
|
|
return evolution_tree
|
|
|
|
|
|
|
|
# serializes an evolution chain link recursively
|
|
|
|
# chain_link is a tree representing an evolution chain
|
|
|
|
def build_chain_link_entry(self, chain_link, summary_data):
|
|
|
|
entry = OrderedDict()
|
|
|
|
evolution_data = None
|
|
|
|
|
|
|
|
species = chain_link["species"]
|
|
|
|
if species["evolves_from_species"]:
|
|
|
|
|
|
|
|
evolution_object = PokemonEvolution.objects.filter(
|
|
|
|
evolved_species=species["id"]
|
|
|
|
)
|
|
|
|
|
|
|
|
evolution_data = PokemonEvolutionSerializer(
|
|
|
|
evolution_object, many=True, context=self.context
|
|
|
|
).data
|
|
|
|
|
|
|
|
entry["is_baby"] = species["is_baby"]
|
|
|
|
|
|
|
|
species_summary = next(x for x in summary_data if x["name"] == species["name"])
|
|
|
|
entry["species"] = species_summary
|
|
|
|
|
|
|
|
entry["evolution_details"] = evolution_data or []
|
|
|
|
|
|
|
|
evolves_to = [
|
|
|
|
self.build_chain_link_entry(c, summary_data) for c in chain_link["children"]
|
|
|
|
]
|
|
|
|
entry["evolves_to"] = evolves_to
|
|
|
|
|
|
|
|
return entry
|
2015-10-06 17:01:32 +00:00
|
|
|
|
2015-10-03 03:40:21 +00:00
|
|
|
|
2015-09-15 12:26:47 +00:00
|
|
|
class PokemonDexNumberSerializer(serializers.ModelSerializer):
|
2015-09-19 22:13:41 +00:00
|
|
|
|
|
|
|
entry_number = serializers.IntegerField(source="pokedex_number")
|
2015-11-16 03:29:30 +00:00
|
|
|
pokemon_species = PokemonSpeciesSummarySerializer()
|
2016-03-05 08:26:51 +00:00
|
|
|
|
2015-09-15 12:26:47 +00:00
|
|
|
class Meta:
|
|
|
|
model = PokemonDexNumber
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("pokedex", "entry_number", "pokemon_species")
|
2015-09-15 12:26:47 +00:00
|
|
|
|
|
|
|
|
2015-11-08 21:26:02 +00:00
|
|
|
############################
|
|
|
|
# POKEATHLON SERIALIZERS #
|
|
|
|
############################
|
|
|
|
class PokeathlonStatNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokeathlonStatName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PokeathlonStatDetailSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
names = PokeathlonStatNameSerializer(
|
|
|
|
many=True, read_only=True, source="pokeathlonstatname"
|
|
|
|
)
|
|
|
|
affecting_natures = serializers.SerializerMethodField("get_natures_that_affect")
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokeathlonStat
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "affecting_natures", "names")
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
def get_natures_that_affect(self, obj):
|
|
|
|
|
|
|
|
stat_change_objects = NaturePokeathlonStat.objects.filter(pokeathlon_stat=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
stat_changes = NaturePokeathlonStatSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
stat_change_objects, many=True, context=self.context
|
|
|
|
).data
|
|
|
|
changes = OrderedDict([("increase", []), ("decrease", [])])
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
for change in stat_changes:
|
2020-02-17 20:58:07 +00:00
|
|
|
del change["pokeathlon_stat"]
|
|
|
|
if change["max_change"] > 0:
|
|
|
|
changes["increase"].append(change)
|
2015-11-16 19:23:41 +00:00
|
|
|
else:
|
2020-02-17 20:58:07 +00:00
|
|
|
changes["decrease"].append(change)
|
2015-11-16 19:23:41 +00:00
|
|
|
|
|
|
|
return changes
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
|
2015-09-10 04:03:18 +00:00
|
|
|
#########################
|
2015-09-15 12:26:47 +00:00
|
|
|
# POKEDEX SERIALIZERS #
|
|
|
|
#########################
|
2015-10-27 13:36:33 +00:00
|
|
|
class PokedexNameSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokedexName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-27 13:36:33 +00:00
|
|
|
|
|
|
|
|
2015-09-15 12:26:47 +00:00
|
|
|
class PokedexDescriptionSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = PokedexDescription
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("description", "language")
|
2015-09-15 12:26:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PokedexDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
region = RegionSummarySerializer()
|
2015-10-27 13:36:33 +00:00
|
|
|
names = PokedexNameSerializer(many=True, read_only=True, source="pokedexname")
|
2016-03-05 11:40:41 +00:00
|
|
|
descriptions = PokedexDescriptionSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
many=True, read_only=True, source="pokedexdescription"
|
|
|
|
)
|
|
|
|
pokemon_entries = serializers.SerializerMethodField("get_pokedex_entries")
|
|
|
|
version_groups = serializers.SerializerMethodField("get_pokedex_version_groups")
|
2015-09-15 12:26:47 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Pokedex
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"is_main_series",
|
|
|
|
"descriptions",
|
|
|
|
"names",
|
|
|
|
"pokemon_entries",
|
|
|
|
"region",
|
|
|
|
"version_groups",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-09-15 12:26:47 +00:00
|
|
|
|
|
|
|
def get_pokedex_entries(self, obj):
|
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
results = PokemonDexNumber.objects.filter(pokedex=obj).order_by(
|
|
|
|
"pokedex_number"
|
|
|
|
)
|
|
|
|
serializer = PokemonDexNumberSerializer(
|
|
|
|
results, many=True, context=self.context
|
|
|
|
)
|
2015-09-19 22:13:41 +00:00
|
|
|
data = serializer.data
|
|
|
|
|
|
|
|
for entry in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
del entry["pokedex"]
|
2015-09-15 12:26:47 +00:00
|
|
|
|
2015-09-19 22:13:41 +00:00
|
|
|
return data
|
2015-10-29 17:45:58 +00:00
|
|
|
|
2015-11-16 03:29:30 +00:00
|
|
|
def get_pokedex_version_groups(self, obj):
|
|
|
|
|
|
|
|
dex_group_objects = PokedexVersionGroup.objects.filter(pokedex=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
dex_groups = PokedexVersionGroupSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
dex_group_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
results = []
|
|
|
|
|
|
|
|
for dex_group in dex_groups:
|
2020-02-17 20:58:07 +00:00
|
|
|
results.append(dex_group["version_group"])
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
return results
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
#########################
|
|
|
|
# VERSION SERIALIZERS #
|
|
|
|
#########################
|
|
|
|
class VersionNameSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
language = LanguageSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = VersionName
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("name", "language")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VersionDetailSerializer(serializers.ModelSerializer):
|
|
|
|
"""
|
|
|
|
Should have a link to Version Group info but the Circular
|
|
|
|
dependency and compilation order fight eachother and I'm
|
|
|
|
not sure how to add anything other than a hyperlink
|
|
|
|
"""
|
|
|
|
|
|
|
|
names = VersionNameSerializer(many=True, read_only=True, source="versionname")
|
|
|
|
version_group = VersionGroupSummarySerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Version
|
2020-02-17 20:58:07 +00:00
|
|
|
fields = ("id", "name", "names", "version_group")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VersionGroupDetailSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
generation = GenerationSummarySerializer()
|
|
|
|
versions = VersionSummarySerializer(many=True, read_only=True, source="version")
|
2020-02-17 20:58:07 +00:00
|
|
|
regions = serializers.SerializerMethodField("get_version_group_regions")
|
|
|
|
move_learn_methods = serializers.SerializerMethodField("get_learn_methods")
|
|
|
|
pokedexes = serializers.SerializerMethodField("get_version_groups_pokedexes")
|
2015-10-29 17:45:58 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = VersionGroup
|
2016-03-05 11:40:41 +00:00
|
|
|
fields = (
|
2020-02-17 20:58:07 +00:00
|
|
|
"id",
|
|
|
|
"name",
|
|
|
|
"order",
|
|
|
|
"generation",
|
|
|
|
"move_learn_methods",
|
|
|
|
"pokedexes",
|
|
|
|
"regions",
|
|
|
|
"versions",
|
2016-03-05 11:40:41 +00:00
|
|
|
)
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
def get_version_group_regions(self, obj):
|
|
|
|
|
|
|
|
vg_regions = VersionGroupRegion.objects.filter(version_group=obj)
|
2020-02-17 20:58:07 +00:00
|
|
|
data = VersionGroupRegionSerializer(
|
|
|
|
vg_regions, many=True, context=self.context
|
|
|
|
).data
|
2015-11-05 14:55:14 +00:00
|
|
|
regions = []
|
|
|
|
|
|
|
|
for region in data:
|
2020-02-17 20:58:07 +00:00
|
|
|
regions.append(region["region"])
|
2015-11-05 14:55:14 +00:00
|
|
|
|
|
|
|
return regions
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2016-03-05 11:40:41 +00:00
|
|
|
def get_learn_methods(self, obj):
|
2015-11-08 21:26:02 +00:00
|
|
|
|
2020-02-17 20:58:07 +00:00
|
|
|
learn_method_objects = VersionGroupMoveLearnMethod.objects.filter(
|
|
|
|
version_group=obj
|
|
|
|
)
|
2016-03-05 11:40:41 +00:00
|
|
|
learn_method_data = VersionGroupMoveLearnMethodSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
learn_method_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-08 21:26:02 +00:00
|
|
|
methods = []
|
|
|
|
|
|
|
|
for method in learn_method_data:
|
2020-02-17 20:58:07 +00:00
|
|
|
methods.append(method["move_learn_method"])
|
2015-11-08 21:26:02 +00:00
|
|
|
|
|
|
|
return methods
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
def get_version_groups_pokedexes(self, obj):
|
|
|
|
|
|
|
|
dex_group_objects = PokedexVersionGroup.objects.filter(version_group=obj)
|
2016-03-05 11:40:41 +00:00
|
|
|
dex_groups = PokedexVersionGroupSerializer(
|
2020-02-17 20:58:07 +00:00
|
|
|
dex_group_objects, many=True, context=self.context
|
|
|
|
).data
|
2015-11-16 03:29:30 +00:00
|
|
|
results = []
|
|
|
|
|
|
|
|
for dex_group in dex_groups:
|
2020-02-17 20:58:07 +00:00
|
|
|
results.append(dex_group["pokedex"])
|
2015-11-16 03:29:30 +00:00
|
|
|
|
|
|
|
return results
|