mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-09 20:37:46 +00:00
fix flake8 formatting of SQLAlchemy example
This commit is contained in:
@@ -9,12 +9,14 @@ import orm
|
||||
|
||||
db_session = None
|
||||
|
||||
|
||||
def get_pets(limit, animal_type=None):
|
||||
q = db_session.query(orm.Pet)
|
||||
if animal_type:
|
||||
q = q.filter(orm.Pet.animal_type == animal_type)
|
||||
return [p.dump() for p in q][:limit]
|
||||
|
||||
|
||||
def get_pet(pet_id):
|
||||
pet = db_session.query(orm.Pet).filter(orm.Pet.id == pet_id).one_or_none()
|
||||
return pet.dump() or ('Not found', 404)
|
||||
@@ -51,6 +53,7 @@ app.add_api('swagger.yaml')
|
||||
|
||||
application = app.app
|
||||
|
||||
|
||||
@application.teardown_appcontext
|
||||
def shutdown_session(exception=None):
|
||||
db_session.remove()
|
||||
|
||||
@@ -12,8 +12,7 @@ class Pet(Base):
|
||||
animal_type = Column(String(20))
|
||||
created = Column(DateTime())
|
||||
|
||||
def update(self, id=None, name=None, animal_type=None, tags=None,
|
||||
created=None):
|
||||
def update(self, id=None, name=None, animal_type=None, tags=None, created=None):
|
||||
if name is not None:
|
||||
self.name = name
|
||||
if animal_type is not None:
|
||||
@@ -22,14 +21,12 @@ class Pet(Base):
|
||||
self.created = created
|
||||
|
||||
def dump(self):
|
||||
return dict([(k,v) for k,v in vars(self).items()
|
||||
if not k.startswith('_')])
|
||||
return dict([(k, v) for k, v in vars(self).items() if not k.startswith('_')])
|
||||
|
||||
|
||||
def init_db(uri):
|
||||
engine = create_engine(uri, convert_unicode=True)
|
||||
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False,
|
||||
bind=engine))
|
||||
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine))
|
||||
Base.query = db_session.query_property()
|
||||
Base.metadata.create_all(bind=engine)
|
||||
return db_session
|
||||
|
||||
Reference in New Issue
Block a user