__init__.py 478 B

123456789101112131415161718192021
  1. from functools import wraps
  2. from pycs import db
  3. def commit_on_return(method):
  4. """
  5. Decorator for model's methods. It provides an extra argument to the method: commit.
  6. On return if commit is True, then the database session is commited.
  7. """
  8. @wraps(method)
  9. def inner(self, *args, commit: bool = True, **kwargs):
  10. res = method(self, *args, **kwargs)
  11. if commit:
  12. db.session.commit()
  13. return res
  14. return inner