Skip to content

Commit

Permalink
add ability view
Browse files Browse the repository at this point in the history
  • Loading branch information
magical committed Apr 27, 2018
1 parent b2eaa02 commit 5e9d014
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 7 deletions.
1 change: 1 addition & 0 deletions splinext/pokedex/pyramidapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def main(global_config, **settings):

# lookup
config.add_view(route_name='dex/lookup', view='splinext.pokedex.views.lookup:lookup', renderer='pokedex/lookup_results.mako')
config.add_view(route_name='dex/abilities', view='splinext.pokedex.views.abilities:ability_view', renderer='pokedex/ability.mako')

# error pages
#config.add_view(context='pyramid.httpexceptions.HTTPForbidden', view=error_view)
Expand Down
14 changes: 7 additions & 7 deletions splinext/pokedex/templates/pokedex/ability.mako
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
</%def>
<div id="dex-header">
<a href="${url.current(name=c.prev_ability.name.lower())}" id="dex-header-prev" class="dex-box-link">
<a href="${url(controller='dex', action='abilities', name=c.prev_ability.name.lower())}" id="dex-header-prev" class="dex-box-link">
<img src="${h.static_uri('spline', 'icons/control-180.png')}" alt="«">
${c.prev_ability.name}
</a>
<a href="${url.current(name=c.next_ability.name.lower())}" id="dex-header-next" class="dex-box-link">
<a href="${url(controller='dex', action='abilities', name=c.next_ability.name.lower())}" id="dex-header-next" class="dex-box-link">
${c.next_ability.name}
<img src="${h.static_uri('spline', 'icons/control.png')}" alt="»">
</a>
Expand All @@ -33,11 +33,11 @@
</div>
<%lib:cache_content>
## <%lib:cache_content>
${h.h1(_('Essentials'))}
<div class="dex-page-portrait">
<p id="dex-page-name">${c.ability.name}</p>
<p>${h.pokedex.generation_icon(c.ability.generation)}</p>
<p>${dexlib.generation_icon(c.ability.generation)}</p>
</div>
<div class="dex-page-beside-portrait">
Expand Down Expand Up @@ -78,7 +78,7 @@ ${h.h2(_('Moves affected'), id=_('moves', context='anchor'))}
${h.h1(_('History'))}
<dl>
% for change in c.ability.changelog:
<dt>${_('Before %s') % h.pokedex.version_icons(*change.changed_in.versions) | n}</dt>
<dt>${_('Before %s') % dexlib.version_icons(*change.changed_in.versions) | n}</dt>
<dd class="markdown">${change.effect}</dd>
% endfor
</dl>
Expand Down Expand Up @@ -128,9 +128,9 @@ ${h.h1(_('External Links'), id='links')}
<ul class="classic-list">
<li><a href="http://bulbapedia.bulbagarden.net/wiki/${c.ability.name.replace(' ', '_')}_%28ability%29">${_("Bulbapedia")}</a></li>
% if c.ability.generation_id <= 4:
<li>${h.pokedex.generation_icon(4)} <a href="http://legendarypokemon.net/dp/abilities#${c.ability.name.lower().replace(' ', '+')}">${_(u"Legendary Pokémon")}</a></li>
<li>${dexlib.generation_icon(4)} <a href="http://legendarypokemon.net/dp/abilities#${c.ability.name.lower().replace(' ', '+')}">${_(u"Legendary Pokémon")}</a></li>
% endif
<li><a href="http://serebii.net/abilitydex/${c.ability.name.lower().replace(' ', '')}.shtml">${_("Serebii.net")}</a></li>
<li><a href="http://smogon.com/dex/sm/abilities/${c.ability.name.lower().replace(' ', '_')}">${_("Smogon")}</a></li>
</ul>
</%lib:cache_content>
## </%lib:cache_content>
93 changes: 93 additions & 0 deletions splinext/pokedex/views/abilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# encoding: utf-8

import re

from sqlalchemy.orm import (joinedload, joinedload_all, subqueryload, subqueryload_all)
from sqlalchemy.orm.exc import NoResultFound
import pyramid.httpexceptions as exc

import pokedex.db.tables as t

from .. import db

def ability_view(request):
name = request.matchdict.get('name')
c = request.tmpl_context

try:
# Make sure that any ability we get is from the main series
c.ability = (db.get_by_name_query(t.Ability, name)
.filter(t.Ability.is_main_series)
.one())
except NoResultFound:
raise exc.NotFound()

### Prev/next for header
# XXX pyramid
c.prev_ability = c.ability
c.next_ability = c.ability
#c.prev_ability, c.next_ability = self._prev_next(
# table=t.Ability,
# current=c.ability,
# filters=[t.Ability.is_main_series],
#)


# Eagerload
db.pokedex_session.query(t.Ability) \
.filter_by(id=c.ability.id) \
.options(
joinedload(t.Ability.names_local),

subqueryload(t.Ability.flavor_text),
joinedload(t.Ability.flavor_text, t.AbilityFlavorText.version_group),
joinedload(t.Ability.flavor_text, t.AbilityFlavorText.version_group, t.VersionGroup.versions),

# Pokémon stuff
subqueryload(t.Ability.pokemon),
subqueryload(t.Ability.hidden_pokemon),
subqueryload(t.Ability.all_pokemon),
subqueryload(t.Ability.all_pokemon, t.Pokemon.abilities),
subqueryload(t.Ability.all_pokemon, t.Pokemon.species, t.PokemonSpecies.egg_groups),
subqueryload(t.Ability.all_pokemon, t.Pokemon.types),
subqueryload(t.Ability.all_pokemon, t.Pokemon.stats),
joinedload(t.Ability.all_pokemon, t.Pokemon.stats, t.PokemonStat.stat),
) \
.one()

c.method_labels = {
'Normal': u'May be found normally on Pokémon.',
'Hidden': u'Found on Pokémon from the Dream World and Dream Radar, '
u'as well as a few Pokémon from specific in-game encounters.',
}

hidden_pokemon = [pokemon for pokemon in c.ability.hidden_pokemon if
pokemon not in c.ability.pokemon]

c.pokemon = []
if c.ability.pokemon:
c.pokemon.append(('Normal', c.ability.pokemon))
if hidden_pokemon:
c.pokemon.append(('Hidden', hidden_pokemon))

move_flag = None
if c.ability.identifier == u'soundproof':
move_flag = 'sound'
elif c.ability.identifier == u'iron-fist':
move_flag = 'punch'

c.moves = []
if move_flag:
c.moves = db.pokedex_session.query(t.Move) \
.join(t.MoveFlagMap, t.MoveFlag) \
.filter(t.MoveFlag.identifier == move_flag) \
.join(t.Move.names_local) \
.order_by(t.Move.names_table.name) \
.options(
subqueryload('move_effect'),
subqueryload('type'),
subqueryload('damage_class')
) \
.all()

return {}

0 comments on commit 5e9d014

Please sign in to comment.