From af506a30917dc502e9625a32012ee355f0a1c131 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Thu, 11 Jun 2015 23:27:55 +0200 Subject: [PATCH] Add decorator for session management. --- accountant/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/accountant/__init__.py b/accountant/__init__.py index 8224fc0..c2d1872 100644 --- a/accountant/__init__.py +++ b/accountant/__init__.py @@ -46,6 +46,16 @@ def session_scope(): finally: session.close() + +def session_aware(f): + def wrapper(*args, **kwargs): + with session_scope() as session: + kwargs['session'] = session + + return f(*args, **kwargs) + return wrapper + + # Must be after db declaration because the blueprints may need it. from .api import api from .frontend import frontend