group.py 719B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. import typing
  3. __author__ = 'damien'
  4. from tracim.models.auth import Group, User
  5. from sqlalchemy.orm import Query
  6. from sqlalchemy.orm import Session
  7. class GroupApi(object):
  8. def __init__(
  9. self,
  10. session: Session,
  11. current_user: typing.Optional[User],
  12. ):
  13. self._user = current_user
  14. self._session = session
  15. def _base_query(self) -> Query:
  16. return self._session.query(Group)
  17. def get_one(self, group_id) -> Group:
  18. return self._base_query().filter(Group.group_id == group_id).one()
  19. def get_one_with_name(self, group_name) -> Group:
  20. return self._base_query().filter(Group.group_name == group_name).one()