aboutsummaryrefslogtreecommitdiffstats
path: root/famille.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2013-12-01 19:05:00 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2013-12-01 19:05:00 -0500
commit85eada5021e197da4fe6fb3df18a324435c7fac7 (patch)
tree31eafe3e734027c4e5dc31ae041dc41f94072eb9 /famille.py
parent29fd9243954966d4a1c86e2ab3bc4ebf4c16bef2 (diff)
downloadfamille-flask-85eada5021e197da4fe6fb3df18a324435c7fac7.tar.gz
one more try
Diffstat (limited to 'famille.py')
-rw-r--r--famille.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/famille.py b/famille.py
index d7a0e5f..207d3ac 100644
--- a/famille.py
+++ b/famille.py
@@ -81,15 +81,17 @@ def connect_db():
return conn
def get_db():
- if not hasattr(g, 'sqlite_db'):
- g.sqlite_db = connect_db()
- return g.sqlite_db
+ db = getattr(g, 'sqlite_db', None)
+ if db is None:
+ db = g.sqlite_db = connect_db()
+ return db
@app.teardown_appcontext
def close_db(error):
"""Closes the database again at the end of the request."""
- if hasattr(g, 'sqlite_db'):
- g.sqlite_db.close()
+ db = getattr(g, 'sqlite_db', None)
+ if db:
+ db.close()
def login_required(f):
@wraps(f)