Skip to content

Commit

Permalink
Move pokemon_has_media back to helpers, with an explicit config param
Browse files Browse the repository at this point in the history
It is needed by the flavor page controller.

Updates #117
  • Loading branch information
magical committed Apr 28, 2018
1 parent 5cc7b26 commit a8b8fba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion splinext/pokedex/controllers/pokedex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ def sprite_exists(directory):
# n.b. calling dict.setdefault always evaluates the default
if directory not in c.sprites:
c.sprites[directory] = pokedex_helpers.pokemon_has_media(
c.form, directory, extension)
c.form, directory, extension, config)
return c.sprites[directory]
c.sprite_exists = sprite_exists

Expand Down
22 changes: 22 additions & 0 deletions splinext/pokedex/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import re
from itertools import groupby, chain, repeat
from operator import attrgetter
import os
import os.path
import warnings

from pylons import url

Expand Down Expand Up @@ -181,6 +183,26 @@ def filename_from_name(name):
name = re.sub(u'[\'.()]', u'', name)
return name

def pokemon_has_media(pokemon_form, prefix, ext, config, use_form=True):
"""Determine whether a file exists in the specified directory for the
specified Pokémon form.
"""
# TODO share this somewhere
media_dir = config.get('spline-pokedex.media_directory', None)
if not media_dir:
warnings.warn(
"No media_directory found; "
"you may want to clone pokedex-media.git")
return False

if use_form:
kwargs = dict(form=pokemon_form)
else:
kwargs = dict()

return os.path.exists(os.path.join(media_dir,
pokemon_media_path(pokemon_form.species, prefix, ext, **kwargs)))

def pokemon_media_path(pokemon_species, prefix, ext, form=None):
"""Returns a path to a Pokémon media file.
Expand Down
20 changes: 1 addition & 19 deletions splinext/pokedex/templates/pokedex/lib.mako
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<%! from splinext.pokedex import i18n, db %>\
<%! import os, warnings %>\
#### Images and links
Expand Down Expand Up @@ -64,24 +63,7 @@


<%def name="pokemon_has_media(pokemon_form, prefix, ext, use_form=True)"><%
"""Determine whether a file exists in the specified directory for the
specified Pokémon form.
"""
# TODO share this somewhere
media_dir = config.get('spline-pokedex.media_directory', None)
if not media_dir:
warnings.warn(
"No media_directory found; "
"you may want to clone pokedex-media.git")
return False
if use_form:
kwargs = dict(form=pokemon_form)
else:
kwargs = dict()
return os.path.exists(os.path.join(media_dir,
h.pokedex.pokemon_media_path(pokemon_form.species, prefix, ext, **kwargs)))
return h.pokedex.pokemon_has_media(pokemon_form, prefix, ext, config, use_form=use_form)
%></%def>

<%def name="species_image(pokemon_species, prefix='main-sprites/black-white', **attr)"><%
Expand Down

0 comments on commit a8b8fba

Please sign in to comment.