contents.py 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # -*- coding: utf-8 -*-
  2. import typing
  3. from enum import Enum
  4. from tracim.exceptions import ContentStatusNotExist, ContentTypeNotExist
  5. from tracim.models.applications import pagehtml, file, thread, pagemarkdownplus
  6. ####
  7. # Content Status
  8. class GlobalStatus(Enum):
  9. OPEN = 'open'
  10. CLOSED = 'closed'
  11. class NewContentStatus(object):
  12. """
  13. Future ContentStatus object class
  14. """
  15. def __init__(
  16. self,
  17. slug: str,
  18. global_status: str,
  19. label: str,
  20. icon: str,
  21. hexcolor: str,
  22. ):
  23. self.slug = slug
  24. self.global_status = global_status
  25. self.label = label
  26. self.icon = icon
  27. self.hexcolor = hexcolor
  28. open_status = NewContentStatus(
  29. slug='open',
  30. global_status=GlobalStatus.OPEN.value,
  31. label='Open',
  32. icon='fa-square-o',
  33. hexcolor='#000FF',
  34. )
  35. closed_validated_status = NewContentStatus(
  36. slug='closed-validated',
  37. global_status=GlobalStatus.CLOSED.value,
  38. label='Validated',
  39. icon='fa-check-square-o',
  40. hexcolor='#000FF',
  41. )
  42. closed_unvalidated_status = NewContentStatus(
  43. slug='closed-unvalidated',
  44. global_status=GlobalStatus.CLOSED.value,
  45. label='Cancelled',
  46. icon='fa-close',
  47. hexcolor='#000FF',
  48. )
  49. closed_deprecated_status = NewContentStatus(
  50. slug='closed-deprecated',
  51. global_status=GlobalStatus.CLOSED.value,
  52. label='Deprecated',
  53. icon='fa-warning',
  54. hexcolor='#000FF',
  55. )
  56. CONTENT_DEFAULT_STATUS = [
  57. open_status,
  58. closed_validated_status,
  59. closed_unvalidated_status,
  60. closed_deprecated_status,
  61. ]
  62. class ContentStatusLegacy(NewContentStatus):
  63. """
  64. Temporary remplacement object for Legacy ContentStatus Object
  65. """
  66. OPEN = open_status.slug
  67. CLOSED_VALIDATED = closed_validated_status.slug
  68. CLOSED_UNVALIDATED = closed_unvalidated_status.slug
  69. CLOSED_DEPRECATED = closed_deprecated_status.slug
  70. def __init__(self, slug: str):
  71. for status in CONTENT_DEFAULT_STATUS:
  72. if slug == status.slug:
  73. super(ContentStatusLegacy).__init__(
  74. slug=status.slug,
  75. global_status=status.global_status,
  76. label=status.label,
  77. icon=status.icon,
  78. hexcolor=status.hexcolor,
  79. )
  80. return
  81. raise ContentStatusNotExist()
  82. @classmethod
  83. def all(cls, type='') -> ['NewContentStatus']:
  84. return CONTENT_DEFAULT_STATUS
  85. @classmethod
  86. def allowed_values(cls):
  87. return [status.slug for status in CONTENT_DEFAULT_STATUS]
  88. ####
  89. # ContentType
  90. class NewContentType(object):
  91. """
  92. Future ContentType object class
  93. """
  94. def __init__(
  95. self,
  96. slug: str,
  97. icon: str,
  98. hexcolor: str,
  99. label: str,
  100. creation_label: str,
  101. available_statuses: typing.List[NewContentStatus],
  102. ):
  103. self.slug = slug
  104. self.icon = icon
  105. self.hexcolor = hexcolor
  106. self.label = label
  107. self.creation_label = creation_label
  108. self.available_statuses = available_statuses
  109. thread_type = NewContentType(
  110. slug='thread',
  111. icon=thread.icon,
  112. hexcolor=thread.hexcolor,
  113. label='Thread',
  114. creation_label='Discuss about a topic',
  115. available_statuses=CONTENT_DEFAULT_STATUS,
  116. )
  117. file_type = NewContentType(
  118. slug='file',
  119. icon=file.icon,
  120. hexcolor=file.hexcolor,
  121. label='File',
  122. creation_label='Upload a file',
  123. available_statuses=CONTENT_DEFAULT_STATUS,
  124. )
  125. pagemarkdownplus_type = NewContentType(
  126. slug='markdownpage',
  127. icon=pagemarkdownplus.icon,
  128. hexcolor=pagemarkdownplus.hexcolor,
  129. label='Rich Markdown File',
  130. creation_label='Create a Markdown document',
  131. available_statuses=CONTENT_DEFAULT_STATUS,
  132. )
  133. pagehtml_type = NewContentType(
  134. slug='page',
  135. icon=pagehtml.icon,
  136. hexcolor=pagehtml.hexcolor,
  137. label='Text Document',
  138. creation_label='Write a document',
  139. available_statuses=CONTENT_DEFAULT_STATUS,
  140. )
  141. CONTENT_DEFAULT_TYPE = [
  142. thread_type,
  143. file_type,
  144. pagemarkdownplus_type,
  145. pagehtml_type,
  146. ]
  147. class ContentTypeLegacy(NewContentType):
  148. """
  149. Temporary remplacement object for Legacy ContentType Object
  150. """
  151. # special type
  152. Any = 'any'
  153. Folder = 'folder'
  154. Event = 'event'
  155. Comment = 'comment'
  156. File = file_type.slug
  157. Thread = thread_type.slug
  158. Page = pagehtml_type.slug
  159. def __init__(self, slug: str):
  160. for content_type in CONTENT_DEFAULT_TYPE:
  161. if slug == content_type.slug:
  162. super(ContentTypeLegacy).__init__(
  163. slug=content_type.slug,
  164. icon=content_type.icon,
  165. hexcolor=content_type.hexcolor,
  166. label=content_type.label,
  167. creation_label=content_type.creation_label,
  168. available_statuses=content_type.available_statuses
  169. )
  170. return
  171. raise ContentTypeNotExist()
  172. @classmethod
  173. def all(cls) -> typing.List[str]:
  174. return cls.allowed_types()
  175. @classmethod
  176. def allowed_types(cls) -> typing.List[str]:
  177. contents_types = [status.slug for status in CONTENT_DEFAULT_TYPE]
  178. contents_types.extend([cls.Folder, cls.Event, cls.Comment])
  179. return contents_types
  180. @classmethod
  181. def allowed_types_for_folding(cls):
  182. # This method is used for showing only "main"
  183. # types in the left-side treeview
  184. contents_types = [status.slug for status in CONTENT_DEFAULT_TYPE]
  185. contents_types.extend([cls.Folder])
  186. return contents_types
  187. # TODO - G.M - 30-05-2018 - This method don't do anything.
  188. @classmethod
  189. def sorted(cls, types: ['ContentType']) -> ['ContentType']:
  190. return types
  191. @property
  192. def id(self):
  193. return self.slug
  194. def toDict(self):
  195. raise NotImplementedError()