Merge pull request #508 from C-Garza/staging

This commit is contained in:
Alessandro Pezzè 2020-07-10 12:30:01 +02:00 committed by GitHub
commit dd9680ecf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 16 deletions

View file

@ -31,7 +31,7 @@ DB_VENDOR = connection.vendor
MEDIA_DIR = "/media/sprites/{0}"
IMAGE_DIR = os.getcwd() + "/data/v2/sprites/"
IMAGE_DIR = os.getcwd() + "/data/v2/sprites/sprites/"
RESOURCE_IMAGES = []
for root, dirs, files in os.walk(IMAGE_DIR):
@ -1347,27 +1347,45 @@ def _build_pokemons():
build_generic((Pokemon,), "pokemon.csv", csv_record_to_objects)
def csv_record_to_objects(info):
file_name = "%s.png" % info[0]
file_name_png = "%s.png" % info[0]
file_name_svg = "%s.svg" % info[0]
poke_sprites = "pokemon/{0}"
dream_world = "other/dream-world/{0}"
sprites = {
"front_default": file_path_or_none(poke_sprites.format(file_name)),
"front_default": file_path_or_none(poke_sprites.format(file_name_png)),
"front_female": file_path_or_none(
poke_sprites.format("female/" + file_name)
poke_sprites.format("female/" + file_name_png)
),
"front_shiny": file_path_or_none(
poke_sprites.format("shiny/" + file_name_png)
),
"front_shiny": file_path_or_none(poke_sprites.format("shiny/" + file_name)),
"front_shiny_female": file_path_or_none(
poke_sprites.format("shiny/female/" + file_name)
poke_sprites.format("shiny/female/" + file_name_png)
),
"back_default": file_path_or_none(
poke_sprites.format("back/" + file_name_png)
),
"back_default": file_path_or_none(poke_sprites.format("back/" + file_name)),
"back_female": file_path_or_none(
poke_sprites.format("back/female/" + file_name)
poke_sprites.format("back/female/" + file_name_png)
),
"back_shiny": file_path_or_none(
poke_sprites.format("back/shiny/" + file_name)
poke_sprites.format("back/shiny/" + file_name_png)
),
"back_shiny_female": file_path_or_none(
poke_sprites.format("back/shiny/female/" + file_name)
poke_sprites.format("back/shiny/female/" + file_name_png)
),
"other": {
"dream_world": {
"front_default": file_path_or_none(
poke_sprites.format(dream_world.format(file_name_svg))
),
"front_female": file_path_or_none(
poke_sprites.format(
dream_world.format("female/" + file_name_svg)
)
),
}
},
}
yield PokemonSprites(
id=int(info[0]),

View file

@ -0,0 +1,16 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("pokemon_v2", "0004_iso639length_20191217"),
]
operations = [
migrations.AlterField(
model_name="pokemonsprites",
name="sprites",
field=models.CharField(max_length=20000),
),
]

View file

@ -1870,4 +1870,4 @@ class PokemonType(HasPokemon, HasType):
class PokemonSprites(HasPokemon):
sprites = models.CharField(max_length=500)
sprites = models.CharField(max_length=20000)

View file

@ -2738,11 +2738,15 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
sprites_data = json.loads(sprites_data["sprites"])
host = "raw.githubusercontent.com/PokeAPI/sprites/master/"
for key in sprites_data:
if sprites_data[key]:
sprites_data[key] = (
"https://" + host + sprites_data[key].replace("/media/", "")
)
def replace_sprite_url(d):
for key, value in d.items():
if isinstance(value, dict):
replace_sprite_url(value)
else:
if d[key]:
d[key] = "https://" + host + d[key].replace("/media/", "")
replace_sprite_url(sprites_data)
return sprites_data