context_models.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # coding=utf-8
  2. import typing
  3. from datetime import datetime
  4. from sqlalchemy.orm import Session
  5. from tracim import CFG
  6. from tracim.models import User
  7. from tracim.models.auth import Profile
  8. class UserInContext(object):
  9. """
  10. Interface to get User data and User data related to context.
  11. """
  12. def __init__(self, user: User, dbsession: Session, config: CFG):
  13. self.user = user
  14. self.dbsession = dbsession
  15. self.config = config
  16. # Default
  17. @property
  18. def email(self) -> str:
  19. return self.user.email
  20. @property
  21. def user_id(self) -> int:
  22. return self.user.user_id
  23. @property
  24. def display_name(self) -> str:
  25. return self.user.display_name
  26. @property
  27. def created(self) -> datetime:
  28. return self.user.created
  29. @property
  30. def is_active(self) -> bool:
  31. return self.user.is_active
  32. @property
  33. def timezone(self) -> str:
  34. return self.user.timezone
  35. @property
  36. def profile(self) -> Profile:
  37. return self.user.profile
  38. # Context related
  39. @property
  40. def calendar_url(self) -> typing.Optional[str]:
  41. # TODO - G-M - 20-04-2018 - [Calendar] Replace calendar code to get
  42. # url calendar url.
  43. #
  44. # from tracim.lib.calendar import CalendarManager
  45. # calendar_manager = CalendarManager(None)
  46. # return calendar_manager.get_workspace_calendar_url(self.workspace_id)
  47. return None
  48. @property
  49. def avatar_url(self) -> typing.Optional[str]:
  50. # TODO - G-M - 20-04-2018 - [Avatar] Add user avatar feature
  51. return None