applications.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. ):
  50. content_type = ContentType(
  51. slug=slug,
  52. fa_icon=self.fa_icon,
  53. label=label,
  54. hexcolor=self.hexcolor,
  55. creation_label=creation_label,
  56. available_statuses=available_statuses,
  57. slug_alias=slug_alias,
  58. )
  59. self.content_types.append(content_type)
  60. def _get_hexcolor_or_default(self, slug: str, app_config: 'CFG') -> str:
  61. assert app_config.APPS_COLORS
  62. assert 'primary' in app_config.APPS_COLORS
  63. if slug in app_config.APPS_COLORS:
  64. return app_config.APPS_COLORS[slug]
  65. return app_config.APPS_COLORS['primary']