context_models.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 LoginCredentials(object):
  9. """
  10. Login credentials model for login
  11. """
  12. def __init__(self, email: str, password: str):
  13. self.email = email
  14. self.password = password
  15. class UserInContext(object):
  16. """
  17. Interface to get User data and User data related to context.
  18. """
  19. def __init__(self, user: User, dbsession: Session, config: CFG):
  20. self.user = user
  21. self.dbsession = dbsession
  22. self.config = config
  23. # Default
  24. @property
  25. def email(self) -> str:
  26. return self.user.email
  27. @property
  28. def user_id(self) -> int:
  29. return self.user.user_id
  30. @property
  31. def display_name(self) -> str:
  32. return self.user.display_name
  33. @property
  34. def created(self) -> datetime:
  35. return self.user.created
  36. @property
  37. def is_active(self) -> bool:
  38. return self.user.is_active
  39. @property
  40. def timezone(self) -> str:
  41. return self.user.timezone
  42. @property
  43. def profile(self) -> Profile:
  44. return self.user.profile
  45. # Context related
  46. @property
  47. def calendar_url(self) -> typing.Optional[str]:
  48. # TODO - G-M - 20-04-2018 - [Calendar] Replace calendar code to get
  49. # url calendar url.
  50. #
  51. # from tracim.lib.calendar import CalendarManager
  52. # calendar_manager = CalendarManager(None)
  53. # return calendar_manager.get_workspace_calendar_url(self.workspace_id)
  54. return None
  55. @property
  56. def avatar_url(self) -> typing.Optional[str]:
  57. # TODO - G-M - 20-04-2018 - [Avatar] Add user avatar feature
  58. return None