content.py 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # -*- coding: utf-8 -*-
  2. from depot.io.utils import FileIntent
  3. from tracim import models
  4. from tracim.fixtures import Fixture
  5. from tracim.fixtures.users_and_groups import Test
  6. from tracim.lib.core.content import ContentApi
  7. from tracim.lib.core.userworkspace import RoleApi
  8. from tracim.lib.core.workspace import WorkspaceApi
  9. from tracim.models.data import ContentType
  10. from tracim.models.data import UserRoleInWorkspace
  11. class Content(Fixture):
  12. require = [Test]
  13. def insert(self):
  14. admin = self._session.query(models.User) \
  15. .filter(models.User.email == 'admin@admin.admin') \
  16. .one()
  17. bob = self._session.query(models.User) \
  18. .filter(models.User.email == 'bob@fsf.local') \
  19. .one()
  20. admin_workspace_api = WorkspaceApi(
  21. current_user=admin,
  22. session=self._session,
  23. config=self._config,
  24. )
  25. bob_workspace_api = WorkspaceApi(
  26. current_user=bob,
  27. session=self._session,
  28. config=self._config
  29. )
  30. content_api = ContentApi(
  31. current_user=admin,
  32. session=self._session,
  33. config=self._config
  34. )
  35. role_api = RoleApi(
  36. current_user=admin,
  37. session=self._session,
  38. config=self._config,
  39. )
  40. # Workspaces
  41. w1 = admin_workspace_api.create_workspace(
  42. 'w1',
  43. description='This is a workspace',
  44. save_now=True
  45. )
  46. w2 = bob_workspace_api.create_workspace(
  47. 'w2',
  48. description='A great workspace',
  49. save_now=True
  50. )
  51. w3 = admin_workspace_api.create_workspace(
  52. 'w3',
  53. description='Just another workspace',
  54. save_now=True
  55. )
  56. # Workspaces roles
  57. role_api.create_one(
  58. user=bob,
  59. workspace=w1,
  60. role_level=UserRoleInWorkspace.CONTENT_MANAGER,
  61. with_notif=False,
  62. )
  63. # Folders
  64. w1f1 = content_api.create(
  65. content_type=ContentType.Folder,
  66. workspace=w1,
  67. label='w1f1',
  68. do_save=True,
  69. do_notify=False,
  70. )
  71. w1f2 = content_api.create(
  72. content_type=ContentType.Folder,
  73. workspace=w1,
  74. label='w1f2',
  75. do_save=True,
  76. do_notify=False,
  77. )
  78. w2f1 = content_api.create(
  79. content_type=ContentType.Folder,
  80. workspace=w2,
  81. label='w2f1',
  82. do_save=True,
  83. do_notify=False,
  84. )
  85. w2f2 = content_api.create(
  86. content_type=ContentType.Folder,
  87. workspace=w2,
  88. label='w2f2',
  89. do_save=True,
  90. do_notify=False,
  91. )
  92. w3f1 = content_api.create(
  93. content_type=ContentType.Folder,
  94. workspace=w3,
  95. label='w3f3',
  96. do_save=True,
  97. do_notify=False,
  98. )
  99. # Pages, threads, ..
  100. w1f1p1 = content_api.create(
  101. content_type=ContentType.Page,
  102. workspace=w1,
  103. parent=w1f1,
  104. label='w1f1p1',
  105. do_save=True,
  106. do_notify=False,
  107. )
  108. w1f1t1 = content_api.create(
  109. content_type=ContentType.Thread,
  110. workspace=w1,
  111. parent=w1f1,
  112. label='w1f1t1',
  113. do_save=False,
  114. do_notify=False,
  115. )
  116. w1f1t1.description = 'w1f1t1 description'
  117. self._session.add(w1f1t1)
  118. w1f1d1_txt = content_api.create(
  119. content_type=ContentType.File,
  120. workspace=w1,
  121. parent=w1f1,
  122. label='w1f1d1',
  123. do_save=False,
  124. do_notify=False,
  125. )
  126. w1f1d1_txt.file_extension = '.txt'
  127. w1f1d1_txt.depot_file = FileIntent(
  128. b'w1f1d1 content',
  129. 'w1f1d1.txt',
  130. 'text/plain',
  131. )
  132. self._session.add(w1f1d1_txt)
  133. w1f1d2_html = content_api.create(
  134. content_type=ContentType.File,
  135. workspace=w1,
  136. parent=w1f1,
  137. label='w1f1d2',
  138. do_save=False,
  139. do_notify=False,
  140. )
  141. w1f1d2_html.file_extension = '.html'
  142. w1f1d2_html.depot_file = FileIntent(
  143. b'<p>w1f1d2 content</p>',
  144. 'w1f1d2.html',
  145. 'text/html',
  146. )
  147. self._session.add(w1f1d2_html)
  148. w1f1f1 = content_api.create(
  149. content_type=ContentType.Folder,
  150. workspace=w1,
  151. label='w1f1f1',
  152. parent=w1f1,
  153. do_save=True,
  154. do_notify=False,
  155. )
  156. w2f1p1 = content_api.create(
  157. content_type=ContentType.Page,
  158. workspace=w2,
  159. parent=w2f1,
  160. label='w2f1p1',
  161. do_save=True,
  162. do_notify=False,
  163. )
  164. self._session.flush()