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