Skip to content

Commit

Permalink
Enable sessions and make obdurate work
Browse files Browse the repository at this point in the history
Gonna have to pull beaker in for caching anyway, so might as well use it
for sessions. I'd rather do without sessions, but i don't want to go
through the trouble of figuring out something different right now.

While we're at it, set the minimum version for pyramid_beaker to 0.8 (the
latest release, from 2013).

Updates veekun#115
  • Loading branch information
magical committed Jul 14, 2019
1 parent adb8a04 commit ddcc2df
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

install_requires = [
"pyramid>=1.5",
"pyramid_beaker",
"pyramid_beaker>=0.8",
"pyramid_debugtoolbar>=0.15.1",
"pyramid_mako>=1.0.2",
"pyramid_tm",
Expand Down
1 change: 1 addition & 0 deletions splinext/pokedex/pyramidapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def main(global_config, **settings):
config = Configurator(settings=settings)
config.include('pyramid_tm')
config.include('pyramid_mako')
config.include('pyramid_beaker')
config.include('pyramid_debugtoolbar')

config.add_renderer('jsonp', JSONP(param_name='callback'))
Expand Down
2 changes: 1 addition & 1 deletion splinext/pokedex/templates/pokedex/lib.mako
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
<%def name="flavor_text_list(flavor_text, classes='')">
<%
flavor_text = (text for text in flavor_text if text.language == c.game_language)
obdurate = False # session.get('cheat_obdurate', False)
obdurate = request.session.get('cheat_obdurate', False)
collapse_key = h.pokedex.collapse_flavor_text_key(literal=obdurate)
%>
<dl class="dex-flavor-text${' ' if classes else ''}${classes}">
Expand Down
11 changes: 7 additions & 4 deletions splinext/pokedex/views/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

import pyramid.httpexceptions as exc
from pyramid.renderers import render_to_response

import pokedex.db.tables as t

Expand All @@ -27,13 +28,15 @@

redirect = exc.HTTPFound

def _egg_unlock_cheat(cheat):
def _egg_unlock_cheat(request, cheat):
"""Easter egg that writes Pokédex data in the Pokémon font."""
session = request.session
c = request.tmpl_context
cheat_key = "cheat_%s" % cheat
session[cheat_key] = not session.get(cheat_key, False)
session.save()
c.this_cheat_key = cheat_key
return render('/pokedex/cheat_unlocked.mako')
return render_to_response('/pokedex/cheat_unlocked.mako', {'session': session}, request=request)


def lookup(request):
Expand All @@ -48,15 +51,15 @@ def lookup(request):
# Nothing entered. What? Where did you come from?
# There's nothing sensible to do here. Let's use an obscure status
# code, like 204 No Content.
abort(204)
return exc.HTTPNoContent()

name = name.strip()
lookup = name.lower()

### Special stuff that bypasses lookup
if lookup == 'obdurate':
# Pokémon flavor text in the D/P font
return _egg_unlock_cheat('obdurate')
return _egg_unlock_cheat(request, 'obdurate')


### Regular lookup
Expand Down

0 comments on commit ddcc2df

Please sign in to comment.