Skip to content

Commit

Permalink
Update apply_pokemon_template
Browse files Browse the repository at this point in the history
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
  • Loading branch information
magical committed Apr 28, 2018
1 parent 5394be3 commit 5cc7b26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions splinext/pokedex/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,

Expand Down
12 changes: 9 additions & 3 deletions splinext/pokedex/templates/pokedex/search/pokemon.mako
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<p><a href="${url.current()}"><img src="${h.static_uri('spline', 'icons/eraser.png')}" alt=""> ${_(u"Start over")}</a></p>
</%def>
<%
# 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
Expand Down Expand Up @@ -132,7 +138,7 @@ ${getattr(self, 'col_' + column)()}
## Plain bulleted list with a Template.
<ul class="dex-pokemon-search-list classic-list">
% for result in c.results:
<li>${dexlib.pokemon_link(result, h.pokedex.apply_pokemon_template(c.display_template, result))}</li>
<li>${dexlib.pokemon_link(result, h.pokedex.apply_pokemon_template(c.display_template, result, get_icon=get_icon))}</li>
% endfor
</ul>

Expand All @@ -141,7 +147,7 @@ ${getattr(self, 'col_' + column)()}
## friendly to clipboards.
<div class="dex-pokemon-search-list">
% for result in c.results:
${dexlib.pokemon_link(result, h.pokedex.apply_pokemon_template(c.display_template, result))}<br>
${dexlib.pokemon_link(result, h.pokedex.apply_pokemon_template(c.display_template, result, get_icon=get_icon))}<br>
% endfor
</div>

Expand Down Expand Up @@ -390,7 +396,7 @@ ${h.form(url.current(), method='GET')}
<%! from string import Template %>\
<% template = Template(pattern) %>\
<dt><code>${pattern}</code></dt>
<dd>${h.pokedex.apply_pokemon_template(template, c.eevee)}</dd>
<dd>${h.pokedex.apply_pokemon_template(template, c.eevee, get_icon=get_icon)}</dd>
% endfor
</dl>
</div>
Expand Down

0 comments on commit 5cc7b26

Please sign in to comment.