applications.py 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # coding=utf-8
  2. import typing
  3. from tracim_backend.app_models.contents import ContentType
  4. class Application(object):
  5. """
  6. Application class with data needed for frontend
  7. """
  8. def __init__(
  9. self,
  10. label: str,
  11. slug: str,
  12. fa_icon: str,
  13. is_active: bool,
  14. config: typing.Dict[str, str],
  15. main_route: str,
  16. app_config: 'CFG',
  17. ) -> None:
  18. """
  19. @param label: public label of application
  20. @param slug: identifier of application
  21. @param fa_icon: font awesome icon class
  22. @param is_active: True if application enable, False if inactive
  23. @param config: a dict with eventual application config
  24. @param main_route: the route of the frontend "home" screen of
  25. the application. For exemple, if you have an application
  26. called "calendar", the main route will be something
  27. like /#/workspace/{wid}/calendar.
  28. """
  29. self.label = label
  30. self.slug = slug
  31. self.fa_icon = fa_icon
  32. self.hexcolor = self._get_hexcolor_or_default(slug, app_config)
  33. self.is_active = is_active
  34. self.config = config
  35. self.main_route = main_route
  36. self.content_types = []
  37. # TODO - G.M - 2018-08-07 - Refactor slug coherence issue like this one.
  38. # we probably should not have 2 kind of slug
  39. @property
  40. def minislug(self):
  41. return self.slug.replace('contents/', '')
  42. def add_content_type(
  43. self,
  44. label: str,
  45. slug: str,
  46. creation_label: str,
  47. available_statuses: typing.List['ContentStatus'],
  48. slug_alias: typing.List[str] = None,
  49. allow_sub_content: bool = False,
  50. ):
  51. content_type = ContentType(
  52. slug=slug,
  53. fa_icon=self.fa_icon,
  54. label=label,
  55. hexcolor=self.hexcolor,
  56. creation_label=creation_label,
  57. available_statuses=available_statuses,
  58. slug_alias=slug_alias,
  59. allow_sub_content=allow_sub_content,
  60. )
  61. self.content_types.append(content_type)
  62. def _get_hexcolor_or_default(self, slug: str, app_config: 'CFG') -> str:
  63. assert app_config.APPS_COLORS
  64. assert 'primary' in app_config.APPS_COLORS
  65. if slug in app_config.APPS_COLORS:
  66. return app_config.APPS_COLORS[slug]
  67. return app_config.APPS_COLORS['primary']