From 5cc7b269c14b4e6811f7fa7aa814d8e5f83bb330 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Fri, 27 Apr 2018 22:46:48 -0700 Subject: [PATCH] Update apply_pokemon_template Needs access to dexlib.pokemon_form_image to generate pokemon icons. Rather than moving it to dexlib, introduce a callback for getting the icon. Updates #115 --- splinext/pokedex/helpers.py | 7 +++++-- .../pokedex/templates/pokedex/search/pokemon.mako | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/splinext/pokedex/helpers.py b/splinext/pokedex/helpers.py index d1067131..b6329b9a 100644 --- a/splinext/pokedex/helpers.py +++ b/splinext/pokedex/helpers.py @@ -308,7 +308,10 @@ def scale_sizes(size_dict, dimensions=1): return scaled_sizes -def apply_pokemon_template(template, pokemon, _=_): +def _no_icon(pokemon): + return u"" + +def apply_pokemon_template(template, pokemon, get_icon=_no_icon, _=_): u"""`template` should be a string.Template object. Uses safe_substitute to inject some fields from the Pokémon into the @@ -319,7 +322,7 @@ def apply_pokemon_template(template, pokemon, _=_): """ d = dict( - icon=pokemon_form_image(pokemon.default_form, prefix=u'icons'), + icon=get_icon(pokemon), id=pokemon.species.id, name=pokemon.default_form.name, diff --git a/splinext/pokedex/templates/pokedex/search/pokemon.mako b/splinext/pokedex/templates/pokedex/search/pokemon.mako index 5fadc509..5802443d 100644 --- a/splinext/pokedex/templates/pokedex/search/pokemon.mako +++ b/splinext/pokedex/templates/pokedex/search/pokemon.mako @@ -17,6 +17,12 @@

${_(u"Start over")}

+<% +# Callback for apply_pokemon_template +def get_icon(pokemon): + return dexlib.pokemon_form_image(pokemon.default_form, prefix=u'icons') +%> + ### RESULTS ### ## Four possibilities here: the form wasn't submitted, the form was submitted ## but was bogus, the form was submitted and there are no results, or the form @@ -132,7 +138,7 @@ ${getattr(self, 'col_' + column)()} ## Plain bulleted list with a Template. @@ -141,7 +147,7 @@ ${getattr(self, 'col_' + column)()} ## friendly to clipboards.
% for result in c.results: -${dexlib.pokemon_link(result, h.pokedex.apply_pokemon_template(c.display_template, result))}
+${dexlib.pokemon_link(result, h.pokedex.apply_pokemon_template(c.display_template, result, get_icon=get_icon))}
% endfor
@@ -390,7 +396,7 @@ ${h.form(url.current(), method='GET')} <%! from string import Template %>\ <% template = Template(pattern) %>\
${pattern}
-
${h.pokedex.apply_pokemon_template(template, c.eevee)}
+
${h.pokedex.apply_pokemon_template(template, c.eevee, get_icon=get_icon)}
% endfor