Upgrade to Pylons 1.0. #283
[zzz-spline-gts.git] / splinext / gts / controllers / gts.py
index a9262f0..c4bed33 100644 (file)
@@ -12,20 +12,19 @@ import struct
 import pokedex.db
 import pokedex.db.tables as tables
 import pokedex.formulae
-from pokedex.savefile import PokemonSave
+from pokedex.struct import SaveFilePokemon
 from pylons import config, request, response, session, tmpl_context as c, url
-from pylons.controllers.util import abort, redirect_to
+from pylons.controllers.util import abort, redirect
 from sqlalchemy import and_, or_, not_
 from sqlalchemy.orm import aliased, contains_eager, eagerload, eagerload_all, join
 from sqlalchemy.orm.exc import NoResultFound
 from sqlalchemy.sql import func
+from sqlalchemy.exc import IntegrityError
 
-from spline import model
 from spline.model import meta
 from spline.lib.base import BaseController, render
 from spline.lib import helpers as h
-
-from splinext.gts.model import GTSPokemon
+from splinext.gts import model as gts_model
 
 log = logging.getLogger(__name__)
 
@@ -153,12 +152,12 @@ class GTSController(BaseController):
         # Check for an existing Pokémon
         # TODO support multiple!
         try:
-            stored_pokemon = meta.Session.query(model.GTSPokemon) \
+            stored_pokemon = meta.Session.query(gts_model.GTSPokemon) \
                 .filter_by(pid=pid) \
                 .one()
             # We've got one!  Cool, send it back.  The game will ask us to
             # delete it after receiving successfully
-            pokemon_save = PokemonSave(stored_pokemon.pokemon_blob)
+            pokemon_save = SaveFilePokemon(stored_pokemon.pokemon_blob)
             return pokemon_save.as_encrypted
 
         except:
@@ -174,7 +173,7 @@ class GTSController(BaseController):
         Returns 0x0001.
         """
 
-        meta.Session.query(model.GTSPokemon).filter_by(pid=pid).delete()
+        meta.Session.query(gts_model.GTSPokemon).filter_by(pid=pid).delete()
         meta.Session.commit()
 
         return '\x01\x00'
@@ -188,19 +187,19 @@ class GTSController(BaseController):
 
         try:
             # The uploaded Pokémon is encrypted, which is not very useful
-            pokemon_save = PokemonSave(data, encrypted=True)
+            pokemon_save = SaveFilePokemon(data, encrypted=True)
 
             # Create a record...
-            stored_pokemon = model.GTSPokemon(
+            stored_pokemon = gts_model.GTSPokemon(
                 pid=pid,
                 pokemon_blob=pokemon_save.as_struct,
             )
             meta.Session.add(stored_pokemon)
             meta.Session.commit()
             return '\x01\x00'
-        except:
-            # If that failed (presumably due to unique key collision), we're
-            # already storing something.  Reject!
+        except IntegrityError:
+            # If that failed due to unique key collision, we're already storing
+            # something.  Reject!
             return '\x0c\x00'
 
     def page_post_finish(self, pid, data):