[frontend] new 'db_session_scope' idiom
This commit adds a new convenient context manager used to handle
database transaction so we don't have to be afraid of missing
session.commit() or session.rollback() calls.
Typical use-case is:
with db_session_scope() as session:
session.add(object)
Or even:
with db_session_scope():
CoprLogicClass.do_something()
If there occur no exceptions within 'with' block, the transaction
is automatically committed; in the other case the session
is rolled back. In any way, we may be sure that the db session is
in consistent state after stepping out from the 'with' context.
This is implemented per sqlalchemy suggestions upstream (search
for the @contextmanager keyword), but note that we are using
flask's wrapper on top of sqlchemy - so it's slightly different:
https://docs.sqlalchemy.org/en/latest/orm/session_basics.html