contents.py 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 htmlpage, _file, thread, markdownpluspage
  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. fa_icon: str,
  21. hexcolor: str,
  22. ):
  23. self.slug = slug
  24. self.global_status = global_status
  25. self.label = label
  26. self.fa_icon = fa_icon
  27. self.hexcolor = hexcolor
  28. open_status = NewContentStatus(
  29. slug='open',
  30. global_status=GlobalStatus.OPEN.value,
  31. label='Open',
  32. fa_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. fa_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. fa_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. fa_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, self).__init__(
  74. slug=status.slug,
  75. global_status=status.global_status,
  76. label=status.label,
  77. fa_icon=status.fa_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. fa_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.fa_icon = fa_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. fa_icon=thread.fa_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. fa_icon=_file.fa_icon,
  120. hexcolor=_file.hexcolor,
  121. label='File',
  122. creation_label='Upload a file',
  123. available_statuses=CONTENT_DEFAULT_STATUS,
  124. )
  125. markdownpluspage_type = NewContentType(
  126. slug='markdownpage',
  127. fa_icon=markdownpluspage.fa_icon,
  128. hexcolor=markdownpluspage.hexcolor,
  129. label='Rich Markdown File',
  130. creation_label='Create a Markdown document',
  131. available_statuses=CONTENT_DEFAULT_STATUS,
  132. )
  133. htmlpage_type = NewContentType(
  134. slug='page',
  135. fa_icon=htmlpage.fa_icon,
  136. hexcolor=htmlpage.hexcolor,
  137. label='Text Document',
  138. creation_label='Write a document',
  139. available_statuses=CONTENT_DEFAULT_STATUS,
  140. )
  141. # TODO - G.M - 31-05-2018 - Set Better folder params
  142. folder_type = NewContentType(
  143. slug='folder',
  144. fa_icon=thread.fa_icon,
  145. hexcolor=thread.hexcolor,
  146. label='Folder',
  147. creation_label='Create collection of any documents',
  148. available_statuses=CONTENT_DEFAULT_STATUS,
  149. )
  150. CONTENT_DEFAULT_TYPE = [
  151. thread_type,
  152. file_type,
  153. markdownpluspage_type,
  154. htmlpage_type,
  155. folder_type,
  156. ]
  157. # TODO - G.M - 31-05-2018 - Set Better Event params
  158. event_type = NewContentType(
  159. slug='event',
  160. fa_icon=thread.fa_icon,
  161. hexcolor=thread.hexcolor,
  162. label='Event',
  163. creation_label='Event',
  164. available_statuses=CONTENT_DEFAULT_STATUS,
  165. )
  166. # TODO - G.M - 31-05-2018 - Set Better Event params
  167. comment_type = NewContentType(
  168. slug='comment',
  169. fa_icon=thread.fa_icon,
  170. hexcolor=thread.hexcolor,
  171. label='Comment',
  172. creation_label='Comment',
  173. available_statuses=CONTENT_DEFAULT_STATUS,
  174. )
  175. CONTENT_DEFAULT_TYPE_SPECIAL = [
  176. event_type,
  177. comment_type,
  178. ]
  179. ALL_CONTENTS_DEFAULT_TYPES = CONTENT_DEFAULT_TYPE + CONTENT_DEFAULT_TYPE_SPECIAL
  180. class ContentTypeLegacy(NewContentType):
  181. """
  182. Temporary remplacement object for Legacy ContentType Object
  183. """
  184. # special type
  185. Any = 'any'
  186. Folder = 'folder'
  187. Event = 'event'
  188. Comment = 'comment'
  189. File = file_type.slug
  190. Thread = thread_type.slug
  191. Page = htmlpage_type.slug
  192. MarkdownPage = markdownpluspage_type.slug
  193. def __init__(self, slug: str):
  194. for content_type in ALL_CONTENTS_DEFAULT_TYPES:
  195. if slug == content_type.slug:
  196. super(ContentTypeLegacy, self).__init__(
  197. slug=content_type.slug,
  198. fa_icon=content_type.fa_icon,
  199. hexcolor=content_type.hexcolor,
  200. label=content_type.label,
  201. creation_label=content_type.creation_label,
  202. available_statuses=content_type.available_statuses
  203. )
  204. return
  205. raise ContentTypeNotExist()
  206. @classmethod
  207. def all(cls) -> typing.List[str]:
  208. return cls.allowed_types()
  209. @classmethod
  210. def allowed_types(cls) -> typing.List[str]:
  211. contents_types = [status.slug for status in ALL_CONTENTS_DEFAULT_TYPES]
  212. return contents_types
  213. @classmethod
  214. def allowed_types_for_folding(cls):
  215. # This method is used for showing only "main"
  216. # types in the left-side treeview
  217. contents_types = [status.slug for status in CONTENT_DEFAULT_TYPE]
  218. return contents_types
  219. # TODO - G.M - 30-05-2018 - This method don't do anything.
  220. @classmethod
  221. def sorted(cls, types: ['ContentType']) -> ['ContentType']:
  222. return types
  223. @property
  224. def id(self):
  225. return self.slug
  226. def toDict(self):
  227. raise NotImplementedError()