123456789101112131415161718192021 |
- from functools import wraps
- from pycs import db
- def commit_on_return(method):
- """
- Decorator for model's methods. It provides an extra argument to the method: commit.
- On return if commit is True, then the database session is commited.
- """
- @wraps(method)
- def inner(self, *args, commit: bool = True, **kwargs):
- res = method(self, *args, **kwargs)
- if commit:
- db.session.commit()
- return res
- return inner
|