wagtail 7.2.1__py3-none-any.whl → 7.3rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. wagtail/__init__.py +1 -1
  2. wagtail/actions/copy_for_translation.py +4 -2
  3. wagtail/admin/action_menu.py +4 -1
  4. wagtail/admin/api/actions/convert_alias.py +2 -2
  5. wagtail/admin/api/actions/copy.py +2 -2
  6. wagtail/admin/api/actions/copy_for_translation.py +2 -2
  7. wagtail/admin/api/actions/create_alias.py +2 -2
  8. wagtail/admin/api/actions/delete.py +1 -1
  9. wagtail/admin/api/actions/move.py +1 -1
  10. wagtail/admin/api/actions/publish.py +2 -2
  11. wagtail/admin/api/actions/revert_to_page_revision.py +2 -2
  12. wagtail/admin/api/actions/unpublish.py +1 -1
  13. wagtail/admin/api/filters.py +2 -2
  14. wagtail/admin/compare.py +22 -0
  15. wagtail/admin/forms/account.py +52 -1
  16. wagtail/admin/forms/comments.py +53 -0
  17. wagtail/admin/forms/models.py +36 -0
  18. wagtail/admin/forms/pages.py +7 -0
  19. wagtail/admin/forms/workflows.py +5 -2
  20. wagtail/admin/icons.py +4 -3
  21. wagtail/admin/locale/ar/LC_MESSAGES/django.mo +0 -0
  22. wagtail/admin/locale/ar/LC_MESSAGES/django.po +35 -0
  23. wagtail/admin/locale/en/LC_MESSAGES/django.po +262 -234
  24. wagtail/admin/locale/en/LC_MESSAGES/djangojs.po +72 -43
  25. wagtail/admin/locale/it/LC_MESSAGES/django.mo +0 -0
  26. wagtail/admin/locale/it/LC_MESSAGES/django.po +566 -6
  27. wagtail/admin/locale/it/LC_MESSAGES/djangojs.mo +0 -0
  28. wagtail/admin/locale/it/LC_MESSAGES/djangojs.po +40 -2
  29. wagtail/admin/locale/nl/LC_MESSAGES/django.mo +0 -0
  30. wagtail/admin/locale/nl/LC_MESSAGES/django.po +2 -2
  31. wagtail/admin/locale/sv/LC_MESSAGES/django.mo +0 -0
  32. wagtail/admin/locale/sv/LC_MESSAGES/django.po +330 -15
  33. wagtail/admin/locale/sv/LC_MESSAGES/djangojs.mo +0 -0
  34. wagtail/admin/locale/sv/LC_MESSAGES/djangojs.po +3 -2
  35. wagtail/admin/panels/comment_panel.py +1 -51
  36. wagtail/admin/panels/title_field_panel.py +3 -1
  37. wagtail/admin/static/wagtailadmin/css/core.css +1 -1
  38. wagtail/admin/static/wagtailadmin/js/bulk-actions.js +1 -1
  39. wagtail/admin/static/wagtailadmin/js/comments.js +1 -1
  40. wagtail/admin/static/wagtailadmin/js/core.js +1 -1
  41. wagtail/admin/static/wagtailadmin/js/core.js.LICENSE.txt +1 -1
  42. wagtail/admin/static/wagtailadmin/js/draftail.js +1 -1
  43. wagtail/admin/static/wagtailadmin/js/privacy-switch.js +1 -1
  44. wagtail/admin/static/wagtailadmin/js/sidebar.js +1 -1
  45. wagtail/admin/static/wagtailadmin/js/telepath/blocks.js +1 -1
  46. wagtail/admin/static/wagtailadmin/js/userbar.js +1 -1
  47. wagtail/admin/static/wagtailadmin/js/userbar.js.LICENSE.txt +1 -1
  48. wagtail/admin/static/wagtailadmin/js/vendor.js +1 -1
  49. wagtail/admin/static/wagtailadmin/js/wagtailadmin.js +1 -1
  50. wagtail/admin/templates/wagtailadmin/base.html +1 -1
  51. wagtail/admin/templates/wagtailadmin/generic/edit_partials.html +100 -0
  52. wagtail/admin/templates/wagtailadmin/generic/form.html +26 -5
  53. wagtail/admin/templates/wagtailadmin/generic/includes/_loaded_revision_inputs.html +3 -0
  54. wagtail/admin/templates/wagtailadmin/generic/listing_results.html +1 -17
  55. wagtail/admin/templates/wagtailadmin/pages/create.html +14 -4
  56. wagtail/admin/templates/wagtailadmin/pages/edit.html +16 -3
  57. wagtail/admin/templates/wagtailadmin/pages/edit_partials.html +31 -0
  58. wagtail/admin/templates/wagtailadmin/pages/index_results.html +1 -9
  59. wagtail/admin/templates/wagtailadmin/shared/autosave/indicator.html +36 -0
  60. wagtail/admin/templates/wagtailadmin/shared/breadcrumbs.html +1 -1
  61. wagtail/admin/templates/wagtailadmin/shared/editing_sessions/list.html +2 -2
  62. wagtail/admin/templates/wagtailadmin/shared/editing_sessions/module.html +19 -3
  63. wagtail/admin/templates/wagtailadmin/shared/headers/_actions.html +5 -0
  64. wagtail/admin/templates/wagtailadmin/shared/headers/_history_icon_link.html +2 -2
  65. wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html +8 -9
  66. wagtail/admin/templates/wagtailadmin/shared/listing/filter_partials.html +19 -0
  67. wagtail/admin/templates/wagtailadmin/shared/side_panel_toggle.html +3 -3
  68. wagtail/admin/templates/wagtailadmin/shared/side_panels/includes/side_panel.html +3 -0
  69. wagtail/admin/templates/wagtailadmin/shared/side_panels/includes/status/privacy.html +18 -6
  70. wagtail/admin/templates/wagtailadmin/shared/side_panels/includes/status/usage.html +11 -4
  71. wagtail/admin/templates/wagtailadmin/shared/side_panels/includes/status/workflow.html +22 -1
  72. wagtail/admin/templates/wagtailadmin/shared/side_panels/preview.html +1 -0
  73. wagtail/admin/templates/wagtailadmin/shared/side_panels.html +1 -2
  74. wagtail/admin/templates/wagtailadmin/shared/unsaved_changes_warning.html +20 -20
  75. wagtail/admin/templates/wagtailadmin/userbar/base.html +2 -0
  76. wagtail/admin/templates/wagtailadmin/userbar/item_accessibility.html +1 -1
  77. wagtail/admin/templatetags/wagtailadmin_tags.py +6 -14
  78. wagtail/admin/tests/pages/test_create_page.py +298 -1
  79. wagtail/admin/tests/pages/test_custom_listing.py +48 -2
  80. wagtail/admin/tests/pages/test_edit_page.py +721 -7
  81. wagtail/admin/tests/pages/test_explorer_view.py +9 -5
  82. wagtail/admin/tests/pages/test_page_search.py +15 -0
  83. wagtail/admin/tests/pages/test_revisions.py +4 -0
  84. wagtail/admin/tests/test_account_management.py +88 -2
  85. wagtail/admin/tests/test_collections_views.py +15 -15
  86. wagtail/admin/tests/test_compare.py +34 -0
  87. wagtail/admin/tests/test_editing_sessions.py +230 -8
  88. wagtail/admin/tests/test_forms.py +192 -1
  89. wagtail/admin/tests/test_icon_sprite.py +22 -2
  90. wagtail/admin/tests/test_page_chooser.py +13 -13
  91. wagtail/admin/tests/test_reports_views.py +4 -1
  92. wagtail/admin/tests/test_userbar.py +69 -5
  93. wagtail/admin/tests/test_views_generic.py +5 -5
  94. wagtail/admin/tests/test_workflows.py +14 -12
  95. wagtail/admin/tests/viewsets/test_model_viewset.py +13 -0
  96. wagtail/admin/ui/autosave.py +5 -0
  97. wagtail/admin/ui/editing_sessions.py +3 -0
  98. wagtail/admin/ui/side_panels.py +19 -20
  99. wagtail/admin/userbar.py +48 -27
  100. wagtail/admin/views/bulk_action/dispatcher.py +2 -2
  101. wagtail/admin/views/chooser.py +6 -6
  102. wagtail/admin/views/editing_sessions.py +20 -7
  103. wagtail/admin/views/generic/__init__.py +1 -0
  104. wagtail/admin/views/generic/chooser.py +5 -5
  105. wagtail/admin/views/generic/mixins.py +143 -26
  106. wagtail/admin/views/generic/models.py +157 -27
  107. wagtail/admin/views/generic/ordering.py +1 -1
  108. wagtail/admin/views/generic/preview.py +4 -4
  109. wagtail/admin/views/home.py +3 -1
  110. wagtail/admin/views/pages/create.py +77 -29
  111. wagtail/admin/views/pages/edit.py +160 -34
  112. wagtail/admin/views/pages/preview.py +4 -4
  113. wagtail/admin/views/pages/revisions.py +3 -0
  114. wagtail/admin/views/pages/search.py +4 -4
  115. wagtail/admin/views/pages/usage.py +2 -2
  116. wagtail/admin/views/tags.py +2 -2
  117. wagtail/admin/views/workflows.py +73 -54
  118. wagtail/admin/viewsets/model.py +34 -8
  119. wagtail/admin/widgets/button.py +11 -4
  120. wagtail/admin/widgets/chooser.py +6 -4
  121. wagtail/admin/widgets/slug.py +1 -1
  122. wagtail/api/v2/filters.py +27 -21
  123. wagtail/api/v2/pagination.py +4 -4
  124. wagtail/api/v2/views.py +7 -7
  125. wagtail/blocks/list_block.py +0 -8
  126. wagtail/blocks/migrations/migrate_operation.py +8 -1
  127. wagtail/blocks/stream_block.py +2 -10
  128. wagtail/blocks/struct_block.py +192 -12
  129. wagtail/compat.py +2 -2
  130. wagtail/contrib/forms/locale/en/LC_MESSAGES/django.po +1 -1
  131. wagtail/contrib/forms/locale/it/LC_MESSAGES/django.mo +0 -0
  132. wagtail/contrib/forms/locale/it/LC_MESSAGES/django.po +40 -2
  133. wagtail/contrib/frontend_cache/backends/azure.py +6 -6
  134. wagtail/contrib/frontend_cache/backends/cloudfront.py +2 -2
  135. wagtail/contrib/frontend_cache/utils.py +1 -1
  136. wagtail/contrib/redirects/forms.py +1 -1
  137. wagtail/contrib/redirects/locale/en/LC_MESSAGES/django.po +14 -14
  138. wagtail/contrib/redirects/locale/it/LC_MESSAGES/django.mo +0 -0
  139. wagtail/contrib/redirects/locale/it/LC_MESSAGES/django.po +15 -2
  140. wagtail/contrib/redirects/locale/sv/LC_MESSAGES/django.mo +0 -0
  141. wagtail/contrib/redirects/locale/sv/LC_MESSAGES/django.po +16 -3
  142. wagtail/contrib/redirects/middleware.py +11 -7
  143. wagtail/contrib/redirects/models.py +17 -1
  144. wagtail/contrib/redirects/tests/test_import_admin_views.py +3 -3
  145. wagtail/contrib/redirects/tests/test_redirects.py +56 -8
  146. wagtail/contrib/search_promotions/locale/en/LC_MESSAGES/django.po +6 -6
  147. wagtail/contrib/search_promotions/locale/it/LC_MESSAGES/django.mo +0 -0
  148. wagtail/contrib/search_promotions/locale/it/LC_MESSAGES/django.po +43 -2
  149. wagtail/contrib/search_promotions/tests.py +1 -1
  150. wagtail/contrib/search_promotions/views/settings.py +24 -25
  151. wagtail/contrib/settings/jinja2tags.py +2 -2
  152. wagtail/contrib/settings/locale/en/LC_MESSAGES/django.po +2 -2
  153. wagtail/contrib/settings/locale/it/LC_MESSAGES/django.mo +0 -0
  154. wagtail/contrib/settings/locale/it/LC_MESSAGES/django.po +6 -2
  155. wagtail/contrib/settings/locale/sv/LC_MESSAGES/django.mo +0 -0
  156. wagtail/contrib/settings/locale/sv/LC_MESSAGES/django.po +3 -2
  157. wagtail/contrib/settings/tests/generic/test_admin.py +118 -2
  158. wagtail/contrib/settings/tests/site_specific/test_admin.py +78 -15
  159. wagtail/contrib/settings/tests/site_specific/test_model.py +2 -2
  160. wagtail/contrib/settings/views.py +7 -0
  161. wagtail/contrib/simple_translation/locale/en/LC_MESSAGES/django.po +1 -1
  162. wagtail/contrib/simple_translation/locale/it/LC_MESSAGES/django.mo +0 -0
  163. wagtail/contrib/simple_translation/locale/it/LC_MESSAGES/django.po +5 -2
  164. wagtail/contrib/styleguide/locale/en/LC_MESSAGES/django.po +7 -7
  165. wagtail/contrib/styleguide/tests.py +2 -0
  166. wagtail/contrib/styleguide/views.py +4 -5
  167. wagtail/contrib/table_block/locale/ar/LC_MESSAGES/django.mo +0 -0
  168. wagtail/contrib/table_block/locale/ar/LC_MESSAGES/django.po +5 -1
  169. wagtail/contrib/table_block/locale/en/LC_MESSAGES/django.po +1 -1
  170. wagtail/contrib/table_block/locale/it/LC_MESSAGES/django.mo +0 -0
  171. wagtail/contrib/table_block/locale/it/LC_MESSAGES/django.po +5 -2
  172. wagtail/contrib/typed_table_block/blocks.py +37 -0
  173. wagtail/contrib/typed_table_block/locale/en/LC_MESSAGES/django.po +10 -10
  174. wagtail/contrib/typed_table_block/locale/sv/LC_MESSAGES/django.mo +0 -0
  175. wagtail/contrib/typed_table_block/locale/sv/LC_MESSAGES/django.po +4 -3
  176. wagtail/contrib/typed_table_block/tests.py +108 -0
  177. wagtail/coreutils.py +4 -4
  178. wagtail/documents/__init__.py +4 -4
  179. wagtail/documents/locale/en/LC_MESSAGES/django.po +15 -15
  180. wagtail/documents/locale/it/LC_MESSAGES/django.mo +0 -0
  181. wagtail/documents/locale/it/LC_MESSAGES/django.po +32 -2
  182. wagtail/documents/locale/sv/LC_MESSAGES/django.mo +0 -0
  183. wagtail/documents/locale/sv/LC_MESSAGES/django.po +32 -4
  184. wagtail/documents/models.py +1 -1
  185. wagtail/documents/tests/test_admin_views.py +19 -4
  186. wagtail/documents/tests/test_search.py +0 -2
  187. wagtail/documents/tests/test_views.py +6 -4
  188. wagtail/documents/views/bulk_actions/add_tags.py +1 -1
  189. wagtail/embeds/finders/facebook.py +3 -3
  190. wagtail/embeds/finders/instagram.py +3 -3
  191. wagtail/embeds/finders/oembed.py +7 -2
  192. wagtail/embeds/locale/en/LC_MESSAGES/django.po +1 -1
  193. wagtail/embeds/oembed_providers.py +8 -0
  194. wagtail/embeds/tests/test_embeds.py +35 -0
  195. wagtail/images/__init__.py +4 -4
  196. wagtail/images/admin_urls.py +3 -3
  197. wagtail/images/blocks.py +1 -1
  198. wagtail/images/formats.py +2 -2
  199. wagtail/images/image_operations.py +2 -2
  200. wagtail/images/locale/en/LC_MESSAGES/django.po +44 -40
  201. wagtail/images/locale/it/LC_MESSAGES/django.mo +0 -0
  202. wagtail/images/locale/it/LC_MESSAGES/django.po +50 -4
  203. wagtail/images/locale/nl/LC_MESSAGES/django.mo +0 -0
  204. wagtail/images/locale/nl/LC_MESSAGES/django.po +3 -3
  205. wagtail/images/locale/sv/LC_MESSAGES/django.mo +0 -0
  206. wagtail/images/locale/sv/LC_MESSAGES/django.po +49 -6
  207. wagtail/images/models.py +11 -10
  208. wagtail/images/templates/wagtailimages/images/index_results.html +1 -1
  209. wagtail/images/templates/wagtailimages/images/url_generator.html +17 -38
  210. wagtail/images/templates/wagtailimages/images/url_generator_output.html +28 -0
  211. wagtail/images/templatetags/wagtailimages_tags.py +4 -4
  212. wagtail/images/tests/test_admin_views.py +432 -59
  213. wagtail/images/tests/test_image_operations.py +2 -2
  214. wagtail/images/tests/test_models.py +0 -2
  215. wagtail/images/views/bulk_actions/add_tags.py +1 -1
  216. wagtail/images/views/images.py +72 -39
  217. wagtail/locale/en/LC_MESSAGES/django.po +103 -105
  218. wagtail/locale/it/LC_MESSAGES/django.mo +0 -0
  219. wagtail/locale/it/LC_MESSAGES/django.po +105 -2
  220. wagtail/locale/sv/LC_MESSAGES/django.mo +0 -0
  221. wagtail/locale/sv/LC_MESSAGES/django.po +95 -12
  222. wagtail/locales/locale/en/LC_MESSAGES/django.po +1 -1
  223. wagtail/locales/locale/it/LC_MESSAGES/django.mo +0 -0
  224. wagtail/locales/locale/it/LC_MESSAGES/django.po +13 -2
  225. wagtail/locales/locale/sv/LC_MESSAGES/django.mo +0 -0
  226. wagtail/locales/locale/sv/LC_MESSAGES/django.po +4 -3
  227. wagtail/locales/tests.py +5 -5
  228. wagtail/models/i18n.py +4 -6
  229. wagtail/models/media.py +18 -0
  230. wagtail/models/pages.py +65 -11
  231. wagtail/models/reference_index.py +15 -0
  232. wagtail/models/revisions.py +40 -12
  233. wagtail/models/workflows.py +0 -3
  234. wagtail/permission_policies/base.py +2 -2
  235. wagtail/permission_policies/collections.py +2 -2
  236. wagtail/project_template/requirements.txt +2 -2
  237. wagtail/search/locale/en/LC_MESSAGES/django.po +1 -1
  238. wagtail/signal_handlers.py +1 -0
  239. wagtail/sites/locale/en/LC_MESSAGES/django.po +1 -1
  240. wagtail/sites/locale/sv/LC_MESSAGES/django.mo +0 -0
  241. wagtail/sites/locale/sv/LC_MESSAGES/django.po +3 -2
  242. wagtail/sites/tests.py +7 -7
  243. wagtail/snippets/action_menu.py +2 -1
  244. wagtail/snippets/locale/en/LC_MESSAGES/django.po +23 -13
  245. wagtail/snippets/locale/sv/LC_MESSAGES/django.mo +0 -0
  246. wagtail/snippets/locale/sv/LC_MESSAGES/django.po +12 -1
  247. wagtail/snippets/tests/test_chooser_block.py +197 -0
  248. wagtail/snippets/tests/test_chooser_panel.py +149 -0
  249. wagtail/snippets/tests/test_chooser_views.py +375 -0
  250. wagtail/snippets/tests/test_chooser_widget.py +22 -0
  251. wagtail/snippets/tests/test_compare_revisions_view.py +167 -0
  252. wagtail/snippets/tests/test_copy_view.py +38 -0
  253. wagtail/snippets/tests/test_create_view.py +1159 -0
  254. wagtail/snippets/tests/test_delete_view.py +225 -0
  255. wagtail/snippets/tests/test_edit_view.py +2882 -0
  256. wagtail/snippets/tests/test_history_view.py +182 -0
  257. wagtail/snippets/tests/test_index_view.py +105 -0
  258. wagtail/snippets/tests/test_list_view.py +786 -0
  259. wagtail/snippets/tests/test_locking.py +28 -0
  260. wagtail/snippets/tests/test_permissions.py +167 -0
  261. wagtail/snippets/tests/test_preview.py +3 -3
  262. wagtail/snippets/tests/test_revert_view.py +343 -0
  263. wagtail/snippets/tests/test_snippet_models.py +112 -0
  264. wagtail/snippets/tests/test_unpublish_view.py +228 -0
  265. wagtail/snippets/tests/test_unschedule_view.py +151 -0
  266. wagtail/snippets/tests/test_viewset.py +38 -5
  267. wagtail/snippets/views/snippets.py +78 -30
  268. wagtail/snippets/widgets.py +2 -2
  269. wagtail/templatetags/wagtailcore_tags.py +2 -2
  270. wagtail/test/dummy_external_storage.py +1 -1
  271. wagtail/test/testapp/fixtures/test.json +22 -0
  272. wagtail/test/testapp/fixtures/test_empty.json +2 -0
  273. wagtail/test/testapp/fixtures/test_explorable_pages.json +10 -0
  274. wagtail/test/testapp/fixtures/test_specific.json +9 -0
  275. wagtail/test/testapp/migrations/0059_nopromotepage.py +25 -0
  276. wagtail/test/testapp/models.py +7 -0
  277. wagtail/test/testapp/views.py +5 -0
  278. wagtail/test/utils/page_tests.py +7 -7
  279. wagtail/test/utils/wagtail_factories/builder.py +2 -2
  280. wagtail/tests/streamfield_migrations/test_migrations.py +35 -0
  281. wagtail/tests/test_blocks.py +321 -61
  282. wagtail/tests/test_collection_model.py +12 -0
  283. wagtail/tests/test_page_model.py +190 -1
  284. wagtail/tests/test_page_privacy.py +5 -0
  285. wagtail/tests/test_reference_index.py +42 -0
  286. wagtail/tests/test_revision_model.py +118 -1
  287. wagtail/tests/test_utils.py +2 -2
  288. wagtail/users/locale/en/LC_MESSAGES/django.po +14 -14
  289. wagtail/users/locale/id_ID/LC_MESSAGES/django.mo +0 -0
  290. wagtail/users/locale/id_ID/LC_MESSAGES/django.po +6 -2
  291. wagtail/users/locale/it/LC_MESSAGES/django.mo +0 -0
  292. wagtail/users/locale/it/LC_MESSAGES/django.po +14 -2
  293. wagtail/users/locale/sv/LC_MESSAGES/django.mo +0 -0
  294. wagtail/users/locale/sv/LC_MESSAGES/django.po +48 -17
  295. wagtail/users/tests/test_admin_views.py +39 -25
  296. wagtail/users/utils.py +4 -1
  297. wagtail/users/views/groups.py +19 -5
  298. wagtail/users/wagtail_hooks.py +1 -1
  299. wagtail/utils/loading.py +2 -2
  300. wagtail-7.3rc1.data/data/AGENTS.md +21 -0
  301. wagtail-7.3rc1.data/data/CHANGELOG.txt +4941 -0
  302. wagtail-7.3rc1.data/data/CODE_OF_CONDUCT.md +71 -0
  303. wagtail-7.3rc1.data/data/CONTRIBUTORS.md +999 -0
  304. wagtail-7.3rc1.data/data/SPONSORS.md +55 -0
  305. {wagtail-7.2.1.dist-info → wagtail-7.3rc1.dist-info}/METADATA +6 -6
  306. {wagtail-7.2.1.dist-info → wagtail-7.3rc1.dist-info}/RECORD +310 -280
  307. {wagtail-7.2.1.dist-info → wagtail-7.3rc1.dist-info}/WHEEL +1 -1
  308. wagtail/images/static/wagtailimages/js/image-url-generator.js +0 -1
  309. wagtail/snippets/tests/test_snippets.py +0 -6377
  310. {wagtail-7.2.1.dist-info → wagtail-7.3rc1.dist-info}/entry_points.txt +0 -0
  311. {wagtail-7.2.1.dist-info → wagtail-7.3rc1.dist-info}/licenses/LICENSE +0 -0
  312. {wagtail-7.2.1.dist-info → wagtail-7.3rc1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,182 @@
1
+ import datetime
2
+
3
+ from django.contrib.admin.utils import quote
4
+ from django.contrib.contenttypes.models import ContentType
5
+ from django.test import TestCase
6
+ from django.test.utils import override_settings
7
+ from django.urls import reverse
8
+ from django.utils.timezone import make_aware
9
+
10
+ from wagtail.models import ModelLogEntry
11
+ from wagtail.test.testapp.models import Advert, DraftStateModel, FullFeaturedSnippet
12
+ from wagtail.test.utils import WagtailTestUtils
13
+
14
+
15
+ class TestSnippetHistory(WagtailTestUtils, TestCase):
16
+ fixtures = ["test.json"]
17
+
18
+ def get(self, snippet, params=None):
19
+ return self.client.get(self.get_url(snippet, "history"), params)
20
+
21
+ def get_url(self, snippet, url_name, args=None):
22
+ if args is None:
23
+ args = [quote(snippet.pk)]
24
+ return reverse(snippet.snippet_viewset.get_url_name(url_name), args=args)
25
+
26
+ def setUp(self):
27
+ self.user = self.login()
28
+ self.non_revisable_snippet = Advert.objects.get(pk=1)
29
+ ModelLogEntry.objects.create(
30
+ content_type=ContentType.objects.get_for_model(Advert),
31
+ label="Test Advert",
32
+ action="wagtail.create",
33
+ timestamp=make_aware(datetime.datetime(2021, 9, 30, 10, 1, 0)),
34
+ object_id="1",
35
+ )
36
+ ModelLogEntry.objects.create(
37
+ content_type=ContentType.objects.get_for_model(Advert),
38
+ label="Test Advert Updated",
39
+ action="wagtail.edit",
40
+ timestamp=make_aware(datetime.datetime(2022, 5, 10, 12, 34, 0)),
41
+ object_id="1",
42
+ )
43
+ self.revisable_snippet = FullFeaturedSnippet.objects.create(text="Foo")
44
+ self.initial_revision = self.revisable_snippet.save_revision(user=self.user)
45
+ ModelLogEntry.objects.create(
46
+ content_type=ContentType.objects.get_for_model(FullFeaturedSnippet),
47
+ label="Foo",
48
+ action="wagtail.create",
49
+ timestamp=make_aware(datetime.datetime(2022, 5, 10, 20, 22, 0)),
50
+ object_id=self.revisable_snippet.pk,
51
+ revision=self.initial_revision,
52
+ content_changed=True,
53
+ )
54
+ self.revisable_snippet.text = "Bar"
55
+ self.edit_revision = self.revisable_snippet.save_revision(
56
+ user=self.user, log_action=True
57
+ )
58
+
59
+ def test_simple(self):
60
+ response = self.get(self.non_revisable_snippet)
61
+ self.assertEqual(response.status_code, 200)
62
+ self.assertContains(response, "<td>Created</td>", html=True)
63
+ self.assertContains(
64
+ response,
65
+ 'data-w-tooltip-content-value="Sept. 30, 2021, 10:01 a.m."',
66
+ )
67
+
68
+ def test_filters(self):
69
+ # Should work on both non-revisable and revisable snippets
70
+ snippets = [self.non_revisable_snippet, self.revisable_snippet]
71
+ for snippet in snippets:
72
+ with self.subTest(snippet=snippet):
73
+ response = self.get(snippet, {"action": "wagtail.edit"})
74
+ self.assertEqual(response.status_code, 200)
75
+ self.assertContains(response, "Edited", count=1)
76
+ self.assertNotContains(response, "Created")
77
+ soup = self.get_soup(response.content)
78
+ filter = soup.select_one(".w-active-filters .w-pill")
79
+ clear_button = filter.select_one(".w-pill__remove")
80
+ self.assertEqual(
81
+ filter.get_text(separator=" ", strip=True),
82
+ "Action: Edit",
83
+ )
84
+ self.assertIsNotNone(clear_button)
85
+ url, params = clear_button.attrs.get("data-w-swap-src-value").split("?")
86
+ self.assertEqual(url, self.get_url(snippet, "history_results"))
87
+ self.assertNotIn("action=wagtail.edit", params)
88
+
89
+ def test_should_not_show_actions_on_non_revisable_snippet(self):
90
+ response = self.get(self.non_revisable_snippet)
91
+ edit_url = self.get_url(self.non_revisable_snippet, "edit")
92
+ self.assertNotContains(
93
+ response,
94
+ f'<a href="{edit_url}">Edit</a>',
95
+ )
96
+
97
+ def test_should_show_actions_on_revisable_snippet(self):
98
+ response = self.get(self.revisable_snippet)
99
+ edit_url = self.get_url(self.revisable_snippet, "edit")
100
+ revert_url = self.get_url(
101
+ self.revisable_snippet,
102
+ "revisions_revert",
103
+ args=[self.revisable_snippet.pk, self.initial_revision.pk],
104
+ )
105
+
106
+ # Should not show the "live version" or "current draft" status tags
107
+ self.assertNotContains(
108
+ response, '<span class="w-status w-status--primary">Live version</span>'
109
+ )
110
+ self.assertNotContains(
111
+ response, '<span class="w-status w-status--primary">Current draft</span>'
112
+ )
113
+
114
+ # The latest revision should have an "Edit" action instead of "Review"
115
+ self.assertContains(
116
+ response,
117
+ f'<a href="{edit_url}">Edit</a>',
118
+ count=1,
119
+ )
120
+
121
+ # Any other revision should have a "Review" action
122
+ self.assertContains(
123
+ response,
124
+ f'<a href="{revert_url}">Review this version</a>',
125
+ count=1,
126
+ )
127
+
128
+ def test_with_live_and_draft_status(self):
129
+ snippet = DraftStateModel.objects.create(text="Draft-enabled Foo, Published")
130
+ snippet.save_revision().publish()
131
+ snippet.refresh_from_db()
132
+
133
+ snippet.text = "Draft-enabled Bar, In Draft"
134
+ snippet.save_revision(log_action=True)
135
+
136
+ response = self.get(snippet)
137
+
138
+ # Should show the "live version" status tag for the published revision
139
+ self.assertContains(
140
+ response,
141
+ '<span class="w-status w-status--primary">Live version</span>',
142
+ count=1,
143
+ html=True,
144
+ )
145
+
146
+ # Should show the "current draft" status tag for the draft revision
147
+ self.assertContains(
148
+ response,
149
+ '<span class="w-status w-status--primary">Current draft</span>',
150
+ count=1,
151
+ html=True,
152
+ )
153
+
154
+ soup = self.get_soup(response.content)
155
+ sublabel = soup.select_one(".w-breadcrumbs__sublabel")
156
+ # Should use the latest draft title in the breadcrumbs sublabel
157
+ self.assertEqual(sublabel.get_text(strip=True), "Draft-enabled Bar, In Draft")
158
+
159
+ @override_settings(WAGTAIL_I18N_ENABLED=True)
160
+ def test_get_with_i18n_enabled(self):
161
+ response = self.get(self.non_revisable_snippet)
162
+ self.assertEqual(response.status_code, 200)
163
+ response = self.get(self.revisable_snippet)
164
+ self.assertEqual(response.status_code, 200)
165
+
166
+ def test_num_queries(self):
167
+ snippet = self.revisable_snippet
168
+
169
+ # Warm up the cache
170
+ self.get(snippet)
171
+
172
+ with self.assertNumQueries(14):
173
+ self.get(snippet)
174
+
175
+ for i in range(20):
176
+ revision = snippet.save_revision(user=self.user, log_action=True)
177
+ if i % 5 == 0:
178
+ revision.publish(user=self.user, log_action=True)
179
+
180
+ # Should have the same number of queries as before (no N+1 queries)
181
+ with self.assertNumQueries(14):
182
+ self.get(snippet)
@@ -0,0 +1,105 @@
1
+ from django.contrib.auth.models import Permission
2
+ from django.test import SimpleTestCase, TestCase
3
+ from django.test.utils import override_settings
4
+ from django.urls import reverse
5
+
6
+ from wagtail.admin.menu import admin_menu
7
+ from wagtail.coreutils import get_dummy_request
8
+ from wagtail.snippets.models import SNIPPET_MODELS
9
+ from wagtail.snippets.views.snippets import get_snippet_models_for_index_view
10
+ from wagtail.test.utils import WagtailTestUtils
11
+ from wagtail.test.utils.template_tests import AdminTemplateTestUtils
12
+
13
+
14
+ class TestGetSnippetModelsForIndexView(SimpleTestCase):
15
+ def test_default_lists_all_snippets_without_menu_items(self):
16
+ self.assertEqual(
17
+ get_snippet_models_for_index_view(),
18
+ [
19
+ model
20
+ for model in SNIPPET_MODELS
21
+ if not model.snippet_viewset.get_menu_item_is_registered()
22
+ ],
23
+ )
24
+
25
+ @override_settings(WAGTAILSNIPPETS_MENU_SHOW_ALL=True)
26
+ def test_setting_allows_listing_of_all_snippet_models(self):
27
+ self.assertEqual(get_snippet_models_for_index_view(), SNIPPET_MODELS)
28
+
29
+
30
+ class TestSnippetIndexView(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
31
+ def setUp(self):
32
+ self.user = self.login()
33
+
34
+ def get(self, params=None):
35
+ return self.client.get(reverse("wagtailsnippets:index"), params)
36
+
37
+ def test_get_with_limited_permissions(self):
38
+ self.user.is_superuser = False
39
+ self.user.user_permissions.add(
40
+ Permission.objects.get(
41
+ content_type__app_label="wagtailadmin", codename="access_admin"
42
+ )
43
+ )
44
+ self.user.save()
45
+
46
+ response = self.get()
47
+ self.assertEqual(response.status_code, 302)
48
+
49
+ def test_get_with_only_view_permissions(self):
50
+ self.user.is_superuser = False
51
+ self.user.user_permissions.add(
52
+ Permission.objects.get(
53
+ content_type__app_label="wagtailadmin", codename="access_admin"
54
+ ),
55
+ Permission.objects.get(
56
+ content_type__app_label="tests", codename="view_advert"
57
+ ),
58
+ )
59
+ self.user.save()
60
+
61
+ response = self.get()
62
+ self.assertEqual(response.status_code, 200)
63
+ self.assertTemplateUsed(response, "wagtailadmin/generic/listing.html")
64
+ soup = self.get_soup(response.content)
65
+ link = soup.select_one("tr td a")
66
+ self.assertEqual(link["href"], reverse("wagtailsnippets_tests_advert:list"))
67
+ self.assertEqual(link.text.strip(), "Adverts")
68
+
69
+ def test_simple(self):
70
+ response = self.get()
71
+ self.assertEqual(response.status_code, 200)
72
+ self.assertTemplateUsed(response, "wagtailadmin/generic/listing.html")
73
+ self.assertBreadcrumbsItemsRendered(
74
+ [{"url": "", "label": "Snippets"}],
75
+ response.content,
76
+ )
77
+ # Now that it uses the generic template,
78
+ # it should not contain the locale selector
79
+ self.assertNotContains(response, "data-locale-selector")
80
+
81
+ def test_displays_snippet(self):
82
+ self.assertContains(self.get(), "Adverts")
83
+
84
+ def test_snippets_menu_item_shown_with_only_view_permission(self):
85
+ self.user.is_superuser = False
86
+ self.user.user_permissions.add(
87
+ Permission.objects.get(
88
+ content_type__app_label="wagtailadmin", codename="access_admin"
89
+ ),
90
+ Permission.objects.get(
91
+ content_type__app_label="tests", codename="view_advert"
92
+ ),
93
+ )
94
+ self.user.save()
95
+
96
+ request = get_dummy_request()
97
+ request.user = self.user
98
+ menu_items = admin_menu.menu_items_for_request(request)
99
+ snippets = [item for item in menu_items if item.name == "snippets"]
100
+ self.assertEqual(len(snippets), 1)
101
+ item = snippets[0]
102
+ self.assertEqual(item.name, "snippets")
103
+ self.assertEqual(item.label, "Snippets")
104
+ self.assertEqual(item.icon_name, "snippet")
105
+ self.assertEqual(item.url, reverse("wagtailsnippets:index"))