wagtail 6.0.2__py3-none-any.whl → 6.1rc1__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 (355) hide show
  1. wagtail/__init__.py +1 -1
  2. wagtail/admin/checks.py +51 -0
  3. wagtail/admin/compare.py +1 -1
  4. wagtail/admin/filters.py +70 -1
  5. wagtail/admin/forms/account.py +1 -1
  6. wagtail/admin/forms/collections.py +15 -0
  7. wagtail/admin/forms/pages.py +49 -0
  8. wagtail/admin/locale/de/LC_MESSAGES/django.mo +0 -0
  9. wagtail/admin/locale/de/LC_MESSAGES/django.po +5 -5
  10. wagtail/admin/locale/en/LC_MESSAGES/django.po +474 -385
  11. wagtail/admin/locale/en/LC_MESSAGES/djangojs.po +3 -3
  12. wagtail/admin/locale/pt_PT/LC_MESSAGES/django.mo +0 -0
  13. wagtail/admin/locale/pt_PT/LC_MESSAGES/django.po +73 -2
  14. wagtail/admin/locale/ro/LC_MESSAGES/django.mo +0 -0
  15. wagtail/admin/locale/ro/LC_MESSAGES/django.po +3 -3
  16. wagtail/admin/panels/comment_panel.py +1 -1
  17. wagtail/admin/panels/field_panel.py +1 -1
  18. wagtail/admin/rich_text/converters/editor_html.py +3 -1
  19. wagtail/admin/rich_text/editors/draftail/__init__.py +28 -2
  20. wagtail/admin/static/wagtailadmin/css/core.css +1 -1
  21. wagtail/admin/static/wagtailadmin/css/panels/draftail.css +1 -1
  22. wagtail/admin/static/wagtailadmin/images/favicon.ico +0 -0
  23. wagtail/admin/static/wagtailadmin/js/bulk-actions.js +1 -1
  24. wagtail/admin/static/wagtailadmin/js/chooser-modal.js +1 -1
  25. wagtail/admin/static/wagtailadmin/js/chooser-widget-telepath.js +1 -1
  26. wagtail/admin/static/wagtailadmin/js/chooser-widget.js +1 -1
  27. wagtail/admin/static/wagtailadmin/js/comments.js +1 -1
  28. wagtail/admin/static/wagtailadmin/js/core.js +1 -1
  29. wagtail/admin/static/wagtailadmin/js/core.js.LICENSE.txt +1 -1
  30. wagtail/admin/static/wagtailadmin/js/date-time-chooser.js +1 -1
  31. wagtail/admin/static/wagtailadmin/js/draftail.js +1 -1
  32. wagtail/admin/static/wagtailadmin/js/expanding-formset.js +1 -1
  33. wagtail/admin/static/wagtailadmin/js/filtered-select.js +1 -1
  34. wagtail/admin/static/wagtailadmin/js/modal-workflow.js +1 -1
  35. wagtail/admin/static/wagtailadmin/js/page-chooser-modal.js +1 -1
  36. wagtail/admin/static/wagtailadmin/js/page-chooser-telepath.js +1 -1
  37. wagtail/admin/static/wagtailadmin/js/page-chooser.js +1 -1
  38. wagtail/admin/static/wagtailadmin/js/preview-panel.js +1 -1
  39. wagtail/admin/static/wagtailadmin/js/privacy-switch.js +1 -1
  40. wagtail/admin/static/wagtailadmin/js/sidebar.js +1 -1
  41. wagtail/admin/static/wagtailadmin/js/task-chooser-modal.js +1 -1
  42. wagtail/admin/static/wagtailadmin/js/task-chooser.js +1 -1
  43. wagtail/admin/static/wagtailadmin/js/telepath/blocks.js +1 -1
  44. wagtail/admin/static/wagtailadmin/js/telepath/telepath.js +1 -1
  45. wagtail/admin/static/wagtailadmin/js/telepath/widgets.js +1 -1
  46. wagtail/admin/static/wagtailadmin/js/userbar.js +1 -1
  47. wagtail/admin/static/wagtailadmin/js/vendor.js +1 -1
  48. wagtail/admin/static/wagtailadmin/js/vendor.js.LICENSE.txt +4 -4
  49. wagtail/admin/static/wagtailadmin/js/wagtailadmin.js +1 -1
  50. wagtail/admin/static/wagtailadmin/js/workflow-action.js +1 -1
  51. wagtail/admin/staticfiles.py +1 -0
  52. wagtail/admin/templates/wagtailadmin/base.html +1 -0
  53. wagtail/admin/templates/wagtailadmin/collection_privacy/set_privacy.html +3 -1
  54. wagtail/admin/templates/wagtailadmin/collections/index_results.html +10 -0
  55. wagtail/admin/templates/wagtailadmin/generic/base.html +1 -9
  56. wagtail/admin/templates/wagtailadmin/generic/form.html +3 -2
  57. wagtail/admin/templates/wagtailadmin/generic/history/action_cell.html +27 -0
  58. wagtail/admin/templates/wagtailadmin/home/workflow_objects_to_moderate.html +3 -3
  59. wagtail/admin/templates/wagtailadmin/icons/keyboard.svg +1 -0
  60. wagtail/admin/templates/wagtailadmin/page_privacy/set_privacy.html +3 -1
  61. wagtail/admin/templates/wagtailadmin/pages/_editor_js.html +0 -14
  62. wagtail/admin/templates/wagtailadmin/pages/action_menu/save_draft.html +3 -1
  63. wagtail/admin/templates/wagtailadmin/pages/choose_parent.html +17 -0
  64. wagtail/admin/templates/wagtailadmin/pages/explorable_index.html +8 -0
  65. wagtail/admin/templates/wagtailadmin/pages/history.html +1 -61
  66. wagtail/admin/templates/wagtailadmin/pages/index.html +1 -3
  67. wagtail/admin/templates/wagtailadmin/pages/listing/_locked_indicator.html +2 -2
  68. wagtail/admin/templates/wagtailadmin/pages/listing/_page_title_column_header.html +25 -27
  69. wagtail/admin/templates/wagtailadmin/pages/page_listing_header.html +2 -1
  70. wagtail/admin/templates/wagtailadmin/panels/multi_field_panel_child.html +1 -1
  71. wagtail/admin/templates/wagtailadmin/panels/publishing/schedule_publishing_panel.html +3 -1
  72. wagtail/admin/templates/wagtailadmin/panels/tabbed_interface.html +1 -1
  73. wagtail/admin/templates/wagtailadmin/shared/active_filters.html +2 -1
  74. wagtail/admin/templates/wagtailadmin/shared/breadcrumbs.html +8 -0
  75. wagtail/admin/templates/wagtailadmin/shared/forms/single_checkbox.html +1 -1
  76. wagtail/admin/templates/wagtailadmin/shared/headers/page_edit_header.html +1 -1
  77. wagtail/admin/templates/wagtailadmin/shared/headers/slim_header.html +21 -9
  78. wagtail/admin/templates/wagtailadmin/shared/human_readable_date.html +1 -1
  79. wagtail/admin/templates/wagtailadmin/shared/keyboard_shortcuts_dialog.html +29 -0
  80. wagtail/admin/templates/wagtailadmin/shared/side_panel_toggle.html +2 -1
  81. wagtail/admin/templates/wagtailadmin/skeleton.html +2 -1
  82. wagtail/admin/templates/wagtailadmin/tables/related_objects_cell.html +9 -0
  83. wagtail/admin/templates/wagtailadmin/tables/title_cell.html +9 -7
  84. wagtail/admin/templates/wagtailadmin/widgets/draftail_rich_text_area.html +1 -1
  85. wagtail/admin/templates/wagtailadmin/workflows/create.html +6 -23
  86. wagtail/admin/templates/wagtailadmin/workflows/create_task.html +6 -15
  87. wagtail/admin/templates/wagtailadmin/workflows/edit.html +6 -23
  88. wagtail/admin/templates/wagtailadmin/workflows/edit_task.html +6 -13
  89. wagtail/admin/templates/wagtailadmin/workflows/includes/task_usage_cell.html +4 -4
  90. wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_tasks_cell.html +18 -0
  91. wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_title_cell.html +7 -0
  92. wagtail/admin/templates/wagtailadmin/workflows/includes/workflow_used_by_cell.html +25 -0
  93. wagtail/admin/templates/wagtailadmin/workflows/index.html +0 -99
  94. wagtail/admin/templates/wagtailadmin/workflows/index_results.html +10 -0
  95. wagtail/admin/templates/wagtailadmin/workflows/task_index.html +0 -30
  96. wagtail/admin/templates/wagtailadmin/workflows/task_index_results.html +10 -0
  97. wagtail/admin/templates/wagtailadmin/workflows/usage.html +1 -1
  98. wagtail/admin/templatetags/wagtailadmin_tags.py +116 -39
  99. wagtail/admin/tests/pages/test_create_page.py +10 -4
  100. wagtail/admin/tests/pages/test_custom_listing.py +37 -0
  101. wagtail/admin/tests/pages/test_edit_page.py +6 -6
  102. wagtail/admin/tests/pages/test_explorer_view.py +19 -18
  103. wagtail/admin/tests/pages/test_move_page.py +1 -1
  104. wagtail/admin/tests/pages/test_page_usage.py +50 -2
  105. wagtail/admin/tests/pages/test_parent_page_chooser_view.py +119 -0
  106. wagtail/admin/tests/pages/test_preview.py +18 -4
  107. wagtail/admin/tests/test_account_management.py +20 -1
  108. wagtail/admin/tests/test_audit_log.py +172 -5
  109. wagtail/admin/tests/test_checks.py +92 -0
  110. wagtail/admin/tests/test_collections_views.py +19 -5
  111. wagtail/admin/tests/test_compare.py +6 -6
  112. wagtail/admin/tests/test_dashboard.py +404 -0
  113. wagtail/admin/tests/test_dbwhitelister.py +4 -5
  114. wagtail/admin/tests/test_edit_handlers.py +2 -2
  115. wagtail/admin/tests/test_keyboard_shortcuts.py +84 -0
  116. wagtail/admin/tests/test_page_chooser.py +31 -18
  117. wagtail/admin/tests/test_privacy.py +36 -2
  118. wagtail/admin/tests/test_rich_text.py +168 -23
  119. wagtail/admin/tests/test_templatetags.py +411 -43
  120. wagtail/admin/tests/test_views.py +4 -2
  121. wagtail/admin/tests/test_workflows.py +531 -9
  122. wagtail/admin/tests/tests.py +3 -1
  123. wagtail/admin/tests/ui/test_tables.py +48 -1
  124. wagtail/admin/tests/viewsets/test_model_viewset.py +126 -29
  125. wagtail/admin/ui/side_panels.py +3 -1
  126. wagtail/admin/ui/tables/__init__.py +13 -1
  127. wagtail/admin/ui/tables/pages.py +17 -6
  128. wagtail/admin/urls/__init__.py +8 -3
  129. wagtail/admin/urls/pages.py +5 -0
  130. wagtail/admin/urls/workflows.py +10 -0
  131. wagtail/admin/views/chooser.py +20 -24
  132. wagtail/admin/views/collections.py +17 -1
  133. wagtail/admin/views/generic/base.py +31 -4
  134. wagtail/admin/views/generic/history.py +220 -51
  135. wagtail/admin/views/generic/mixins.py +7 -4
  136. wagtail/admin/views/generic/models.py +54 -38
  137. wagtail/admin/views/generic/multiple_upload.py +17 -8
  138. wagtail/admin/views/generic/usage.py +17 -11
  139. wagtail/admin/views/home.py +15 -12
  140. wagtail/admin/views/mixins.py +30 -0
  141. wagtail/admin/views/pages/choose_parent.py +73 -0
  142. wagtail/admin/views/pages/history.py +54 -66
  143. wagtail/admin/views/pages/listing.py +187 -106
  144. wagtail/admin/views/pages/usage.py +6 -1
  145. wagtail/admin/views/pages/utils.py +70 -1
  146. wagtail/admin/views/workflows.py +150 -21
  147. wagtail/admin/viewsets/model.py +2 -2
  148. wagtail/admin/viewsets/pages.py +77 -0
  149. wagtail/admin/wagtail_hooks.py +40 -2
  150. wagtail/admin/widgets/button.py +10 -9
  151. wagtail/api/v2/filters.py +1 -1
  152. wagtail/api/v2/tests/test_pages.py +1 -1
  153. wagtail/blocks/base.py +18 -9
  154. wagtail/blocks/field_block.py +9 -7
  155. wagtail/blocks/list_block.py +16 -6
  156. wagtail/blocks/static_block.py +3 -0
  157. wagtail/blocks/stream_block.py +58 -23
  158. wagtail/blocks/struct_block.py +15 -9
  159. wagtail/contrib/forms/locale/en/LC_MESSAGES/django.po +39 -47
  160. wagtail/contrib/forms/models.py +5 -5
  161. wagtail/contrib/forms/templates/wagtailforms/list_submissions.html +44 -33
  162. wagtail/contrib/forms/templates/wagtailforms/submissions_index.html +2 -63
  163. wagtail/contrib/forms/tests/test_models.py +26 -0
  164. wagtail/contrib/forms/urls.py +6 -0
  165. wagtail/contrib/forms/views.py +52 -49
  166. wagtail/contrib/redirects/locale/ca/LC_MESSAGES/django.mo +0 -0
  167. wagtail/contrib/redirects/locale/ca/LC_MESSAGES/django.po +3 -3
  168. wagtail/contrib/redirects/locale/en/LC_MESSAGES/django.po +34 -42
  169. wagtail/contrib/redirects/signal_handlers.py +1 -1
  170. wagtail/contrib/redirects/templates/wagtailredirects/index.html +1 -36
  171. wagtail/contrib/redirects/templates/wagtailredirects/index_results.html +18 -0
  172. wagtail/contrib/redirects/templates/wagtailredirects/redirect_target_cell.html +8 -0
  173. wagtail/contrib/redirects/tests/test_import_command.py +1 -1
  174. wagtail/contrib/redirects/tests/test_redirects.py +79 -8
  175. wagtail/contrib/redirects/urls.py +2 -1
  176. wagtail/contrib/redirects/views.py +85 -55
  177. wagtail/contrib/search_promotions/admin_urls.py +2 -1
  178. wagtail/contrib/search_promotions/locale/en/LC_MESSAGES/django.po +41 -64
  179. wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/index.html +1 -16
  180. wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/index_results.html +11 -0
  181. wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/list.html +0 -51
  182. wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/results.html +3 -16
  183. wagtail/contrib/search_promotions/templates/wagtailsearchpromotions/search_promotion_column.html +15 -0
  184. wagtail/contrib/search_promotions/tests.py +122 -9
  185. wagtail/contrib/search_promotions/views.py +66 -65
  186. wagtail/contrib/settings/locale/en/LC_MESSAGES/django.po +3 -3
  187. wagtail/contrib/settings/registry.py +10 -5
  188. wagtail/contrib/settings/tests/generic/test_admin.py +9 -0
  189. wagtail/contrib/settings/tests/site_specific/test_admin.py +10 -1
  190. wagtail/contrib/settings/tests/site_specific/test_model.py +3 -3
  191. wagtail/contrib/settings/tests/site_specific/test_templates.py +1 -1
  192. wagtail/contrib/settings/views.py +3 -1
  193. wagtail/contrib/simple_translation/locale/en/LC_MESSAGES/django.po +1 -1
  194. wagtail/contrib/simple_translation/tests/test_wagtail_hooks.py +2 -2
  195. wagtail/contrib/styleguide/locale/en/LC_MESSAGES/django.po +7 -7
  196. wagtail/contrib/table_block/blocks.py +1 -1
  197. wagtail/contrib/table_block/locale/en/LC_MESSAGES/django.po +1 -1
  198. wagtail/contrib/table_block/static/table_block/js/table.js +1 -1
  199. wagtail/contrib/typed_table_block/locale/en/LC_MESSAGES/django.po +1 -1
  200. wagtail/contrib/typed_table_block/static/typed_table_block/js/typed_table_block.js +1 -1
  201. wagtail/coreutils.py +3 -2
  202. wagtail/documents/admin_urls.py +2 -2
  203. wagtail/documents/locale/en/LC_MESSAGES/django.po +22 -22
  204. wagtail/documents/migrations/0013_delete_uploadeddocument.py +16 -0
  205. wagtail/documents/models.py +1 -20
  206. wagtail/documents/rich_text/__init__.py +11 -7
  207. wagtail/documents/static/wagtaildocs/js/document-chooser-modal.js +1 -1
  208. wagtail/documents/static/wagtaildocs/js/document-chooser-telepath.js +1 -1
  209. wagtail/documents/static/wagtaildocs/js/document-chooser.js +1 -1
  210. wagtail/documents/templates/wagtaildocs/documents/index.html +0 -16
  211. wagtail/documents/tests/test_admin_views.py +155 -23
  212. wagtail/documents/tests/test_collection_privacy.py +55 -1
  213. wagtail/documents/tests/test_rich_text.py +14 -0
  214. wagtail/documents/views/documents.py +25 -22
  215. wagtail/documents/views/multiple.py +6 -7
  216. wagtail/documents/views/serve.py +16 -1
  217. wagtail/documents/wagtail_hooks.py +20 -15
  218. wagtail/embeds/blocks.py +5 -0
  219. wagtail/embeds/locale/en/LC_MESSAGES/django.po +2 -2
  220. wagtail/embeds/rich_text/__init__.py +1 -1
  221. wagtail/embeds/tests/test_rich_text.py +14 -0
  222. wagtail/embeds/wagtail_hooks.py +4 -14
  223. wagtail/fields.py +3 -48
  224. wagtail/images/admin_urls.py +2 -2
  225. wagtail/images/check_files/wagtail.jpg +0 -0
  226. wagtail/images/check_files/wagtail.png +0 -0
  227. wagtail/images/fields.py +2 -0
  228. wagtail/images/image_operations.py +1 -1
  229. wagtail/images/locale/en/LC_MESSAGES/django.po +33 -45
  230. wagtail/images/locale/pt_PT/LC_MESSAGES/django.mo +0 -0
  231. wagtail/images/locale/pt_PT/LC_MESSAGES/django.po +4 -0
  232. wagtail/images/migrations/0026_delete_uploadedimage.py +16 -0
  233. wagtail/images/models.py +49 -43
  234. wagtail/images/rich_text/__init__.py +18 -8
  235. wagtail/images/static/wagtailimages/js/image-chooser-modal.js +1 -1
  236. wagtail/images/static/wagtailimages/js/image-chooser-telepath.js +1 -1
  237. wagtail/images/static/wagtailimages/js/image-chooser.js +1 -1
  238. wagtail/images/templates/wagtailimages/images/image_listing_header.html +6 -0
  239. wagtail/images/templates/wagtailimages/images/index.html +11 -51
  240. wagtail/images/tests/test_admin_views.py +119 -62
  241. wagtail/images/tests/test_image_operations.py +10 -0
  242. wagtail/images/tests/test_models.py +35 -33
  243. wagtail/images/tests/test_rich_text.py +14 -0
  244. wagtail/images/tests/utils.py +1 -1
  245. wagtail/images/views/images.py +35 -64
  246. wagtail/images/views/multiple.py +6 -7
  247. wagtail/images/wagtail_hooks.py +4 -14
  248. wagtail/locale/en/LC_MESSAGES/django.po +150 -136
  249. wagtail/locales/locale/en/LC_MESSAGES/django.po +1 -1
  250. wagtail/locales/tests.py +18 -3
  251. wagtail/locales/views.py +0 -1
  252. wagtail/management/commands/rebuild_references_index.py +3 -1
  253. wagtail/migrations/0092_alter_collectionviewrestriction_password_and_more.py +33 -0
  254. wagtail/migrations/0093_uploadedfile.py +53 -0
  255. wagtail/models/__init__.py +147 -32
  256. wagtail/models/i18n.py +1 -1
  257. wagtail/models/{collections.py → media.py} +33 -2
  258. wagtail/models/reference_index.py +1 -1
  259. wagtail/models/view_restrictions.py +10 -3
  260. wagtail/project_template/project_name/settings/base.py +6 -0
  261. wagtail/project_template/requirements.txt +1 -1
  262. wagtail/rich_text/__init__.py +25 -8
  263. wagtail/rich_text/pages.py +19 -8
  264. wagtail/rich_text/rewriters.py +140 -68
  265. wagtail/search/backends/database/mysql/mysql.py +3 -3
  266. wagtail/search/backends/database/postgres/postgres.py +3 -3
  267. wagtail/search/backends/database/sqlite/sqlite.py +2 -2
  268. wagtail/search/backends/elasticsearch7.py +4 -0
  269. wagtail/search/locale/en/LC_MESSAGES/django.po +3 -3
  270. wagtail/search/tests/test_postgres_backend.py +50 -0
  271. wagtail/sites/locale/en/LC_MESSAGES/django.po +8 -8
  272. wagtail/sites/tests.py +35 -9
  273. wagtail/sites/views.py +3 -1
  274. wagtail/snippets/locale/de/LC_MESSAGES/django.mo +0 -0
  275. wagtail/snippets/locale/de/LC_MESSAGES/django.po +5 -6
  276. wagtail/snippets/locale/en/LC_MESSAGES/django.po +16 -56
  277. wagtail/snippets/static/wagtailsnippets/js/snippet-chooser-telepath.js +1 -1
  278. wagtail/snippets/static/wagtailsnippets/js/snippet-chooser.js +1 -1
  279. wagtail/snippets/templates/wagtailsnippets/snippets/action_menu/publish.html +3 -1
  280. wagtail/snippets/templates/wagtailsnippets/snippets/action_menu/save.html +3 -1
  281. wagtail/snippets/templates/wagtailsnippets/snippets/create.html +1 -1
  282. wagtail/snippets/templates/wagtailsnippets/snippets/edit.html +1 -1
  283. wagtail/snippets/tests/test_preview.py +13 -2
  284. wagtail/snippets/tests/test_snippets.py +41 -16
  285. wagtail/snippets/tests/test_viewset.py +63 -18
  286. wagtail/snippets/tests/test_workflows.py +12 -0
  287. wagtail/snippets/views/snippets.py +1 -40
  288. wagtail/templatetags/wagtailcore_tags.py +1 -1
  289. wagtail/test/demosite/models.py +1 -1
  290. wagtail/test/middleware.py +14 -1
  291. wagtail/test/testapp/fixtures/test.json +20 -0
  292. wagtail/test/testapp/migrations/0001_squashed_0073_revisablechildmodel_secret_text.py +8 -8
  293. wagtail/test/testapp/migrations/0023_snippetchoosermodel_full_featured.py +1 -0
  294. wagtail/test/testapp/migrations/0034_custompermissionmodel.py +44 -0
  295. wagtail/test/testapp/migrations/0035_modelwithcustommanager.py +30 -0
  296. wagtail/test/testapp/migrations/0036_complexdefaultstreampage.py +28 -0
  297. wagtail/test/testapp/models.py +79 -2
  298. wagtail/test/testapp/templates/tests/custom_docs_password_required.html +10 -0
  299. wagtail/test/testapp/templates/tests/custom_page_password_required.html +10 -0
  300. wagtail/test/testapp/views.py +24 -2
  301. wagtail/test/testapp/wagtail_hooks.py +19 -0
  302. wagtail/test/utils/wagtail_tests.py +2 -2
  303. wagtail/tests/test_blocks.py +262 -1
  304. wagtail/tests/test_migrations.py +1 -1
  305. wagtail/tests/test_page_model.py +77 -0
  306. wagtail/tests/test_page_privacy.py +18 -1
  307. wagtail/tests/test_rich_text.py +95 -5
  308. wagtail/tests/test_streamfield.py +43 -0
  309. wagtail/tests/test_utils.py +8 -2
  310. wagtail/tests/test_views.py +52 -1
  311. wagtail/tests/test_whitelist.py +7 -7
  312. wagtail/users/forms.py +3 -1
  313. wagtail/users/locale/en/LC_MESSAGES/django.po +124 -96
  314. wagtail/users/migrations/0013_userprofile_density.py +23 -0
  315. wagtail/users/models.py +14 -3
  316. wagtail/users/templates/wagtailusers/groups/create.html +1 -7
  317. wagtail/users/templates/wagtailusers/groups/edit.html +1 -13
  318. wagtail/users/templates/wagtailusers/groups/includes/formatted_permissions.html +46 -2
  319. wagtail/users/templates/wagtailusers/groups/includes/group_form_js.html +0 -2
  320. wagtail/users/templates/wagtailusers/users/create.html +1 -9
  321. wagtail/users/templates/wagtailusers/users/edit.html +1 -9
  322. wagtail/users/templates/wagtailusers/users/index.html +2 -5
  323. wagtail/users/templates/wagtailusers/users/index_results.html +3 -13
  324. wagtail/users/templates/wagtailusers/users/user_cell.html +9 -0
  325. wagtail/users/templatetags/wagtailusers_tags.py +107 -20
  326. wagtail/users/tests/test_admin_views.py +669 -90
  327. wagtail/users/views/groups.py +58 -61
  328. wagtail/users/views/users.py +211 -92
  329. wagtail/users/wagtail_hooks.py +6 -38
  330. wagtail/users/widgets.py +3 -5
  331. wagtail/utils/text.py +1 -1
  332. wagtail/views.py +5 -9
  333. wagtail/whitelist.py +1 -1
  334. {wagtail-6.0.2.dist-info → wagtail-6.1rc1.dist-info}/METADATA +4 -5
  335. {wagtail-6.0.2.dist-info → wagtail-6.1rc1.dist-info}/RECORD +339 -320
  336. wagtail/admin/static/wagtailadmin/js/page-editor.js +0 -1
  337. wagtail/admin/static/wagtailadmin/js/vendor/mousetrap.min.js +0 -1
  338. wagtail/admin/static/wagtailadmin/js/vendor/urlify.js +0 -1
  339. wagtail/admin/static/wagtailadmin/js/vendor/xregexp.min.js +0 -1
  340. wagtail/admin/templates/wagtailadmin/collections/index.html +0 -34
  341. wagtail/admin/templates/wagtailadmin/pages/revisions/_actions.html +0 -22
  342. wagtail/admin/templates/wagtailadmin/shared/page_breadcrumbs.html +0 -55
  343. wagtail/admin/tests/pages/test_dashboard.py +0 -172
  344. wagtail/contrib/redirects/templates/wagtailredirects/results.html +0 -23
  345. wagtail/documents/templates/wagtaildocs/documents/list.html +0 -2
  346. wagtail/search/tests/test_postgres_stemming.py +0 -40
  347. wagtail/sites/templates/wagtailsites/create.html +0 -6
  348. wagtail/sites/templates/wagtailsites/edit.html +0 -6
  349. wagtail/snippets/templates/wagtailsnippets/snippets/revisions/_actions.html +0 -36
  350. wagtail/users/templates/wagtailusers/users/list.html +0 -62
  351. wagtail/users/urls/users.py +0 -12
  352. {wagtail-6.0.2.dist-info → wagtail-6.1rc1.dist-info}/LICENSE +0 -0
  353. {wagtail-6.0.2.dist-info → wagtail-6.1rc1.dist-info}/WHEEL +0 -0
  354. {wagtail-6.0.2.dist-info → wagtail-6.1rc1.dist-info}/entry_points.txt +0 -0
  355. {wagtail-6.0.2.dist-info → wagtail-6.1rc1.dist-info}/top_level.txt +0 -0
@@ -50,6 +50,13 @@ class ContextCharBlock(blocks.CharBlock):
50
50
  return super(blocks.CharBlock, self).get_context(value, parent_context)
51
51
 
52
52
 
53
+ class TestBlock(SimpleTestCase):
54
+ def test_normalize(self):
55
+ """The base normalize implementation should return its argument unchanged"""
56
+ obj = object()
57
+ self.assertIs(blocks.Block().normalize(obj), obj)
58
+
59
+
53
60
  class TestFieldBlock(WagtailTestUtils, SimpleTestCase):
54
61
  def test_charfield_render(self):
55
62
  block = blocks.CharBlock()
@@ -206,7 +213,8 @@ class TestFieldBlock(WagtailTestUtils, SimpleTestCase):
206
213
  def test_form_handling_is_independent_of_serialisation(self):
207
214
  class Base64EncodingCharBlock(blocks.CharBlock):
208
215
  """A CharBlock with a deliberately perverse JSON (de)serialisation format
209
- so that it visibly blows up if we call to_python / get_prep_value where we shouldn't"""
216
+ so that it visibly blows up if we call to_python / get_prep_value where we shouldn't
217
+ """
210
218
 
211
219
  def to_python(self, jsonish_value):
212
220
  # decode as base64 on the way out of the JSON serialisation
@@ -718,6 +726,14 @@ class TestRichTextBlock(TestCase):
718
726
 
719
727
  self.assertEqual(list(block.extract_references(value)), [(Page, "1", "", "")])
720
728
 
729
+ def test_normalize(self):
730
+ block = blocks.RichTextBlock()
731
+ for value in ("Hello, world", RichText("Hello, world")):
732
+ with self.subTest(value=value):
733
+ normalized = block.normalize(value)
734
+ self.assertIsInstance(normalized, RichText)
735
+ self.assertEqual(normalized.source, "Hello, world")
736
+
721
737
 
722
738
  class TestChoiceBlock(WagtailTestUtils, SimpleTestCase):
723
739
  def setUp(self):
@@ -2256,6 +2272,53 @@ class TestStructBlock(SimpleTestCase):
2256
2272
  self.assertIs(value.block, copied.block)
2257
2273
  self.assertEqual(value, copied)
2258
2274
 
2275
+ def test_normalize_base_cases(self):
2276
+ """Test the trivially recursive and already normalized cases"""
2277
+ block = blocks.StructBlock([("title", blocks.CharBlock())])
2278
+ self.assertEqual(
2279
+ block.normalize({"title": "Foo"}), block._to_struct_value({"title": "Foo"})
2280
+ )
2281
+ self.assertEqual(
2282
+ block.normalize(block._to_struct_value({"title": "Foo"})),
2283
+ block._to_struct_value({"title": "Foo"}),
2284
+ )
2285
+
2286
+ def test_recursive_normalize(self):
2287
+ """StructBlock.normalize should recursively normalize all children"""
2288
+
2289
+ block = blocks.StructBlock(
2290
+ [
2291
+ (
2292
+ "inner_stream",
2293
+ blocks.StreamBlock(
2294
+ [
2295
+ ("inner_char", blocks.CharBlock()),
2296
+ ("inner_int", blocks.IntegerBlock()),
2297
+ ]
2298
+ ),
2299
+ ),
2300
+ ("list_of_ints", blocks.ListBlock(blocks.IntegerBlock())),
2301
+ ]
2302
+ )
2303
+
2304
+ # A value in the human friendly format
2305
+ value = {
2306
+ "inner_stream": [("inner_char", "Hello, world"), ("inner_int", 42)],
2307
+ "list_of_ints": [5, 6, 7, 8],
2308
+ }
2309
+
2310
+ normalized = block.normalize(value)
2311
+ self.assertIsInstance(normalized, blocks.StructValue)
2312
+ self.assertIsInstance(normalized["inner_stream"], blocks.StreamValue)
2313
+ self.assertIsInstance(
2314
+ normalized["inner_stream"][0], blocks.StreamValue.StreamChild
2315
+ )
2316
+ self.assertIsInstance(
2317
+ normalized["inner_stream"][1], blocks.StreamValue.StreamChild
2318
+ )
2319
+ self.assertIsInstance(normalized["list_of_ints"], blocks.list_block.ListValue)
2320
+ self.assertIsInstance(normalized["list_of_ints"][0], int)
2321
+
2259
2322
 
2260
2323
  class TestStructBlockWithCustomStructValue(SimpleTestCase):
2261
2324
  def test_initialisation(self):
@@ -2433,8 +2496,50 @@ class TestStructBlockWithCustomStructValue(SimpleTestCase):
2433
2496
  html = block.render(struct_value)
2434
2497
  self.assertEqual(html, "<div>EMPTY TITLE</div>\n")
2435
2498
 
2499
+ def test_normalize(self):
2500
+ """A normalized StructBlock value should be an instance of the StructBlock's value_class"""
2501
+
2502
+ class CustomStructValue(blocks.StructValue):
2503
+ pass
2504
+
2505
+ class CustomStructBlock(blocks.StructBlock):
2506
+ text = blocks.TextBlock()
2507
+
2508
+ class Meta:
2509
+ value_class = CustomStructValue
2510
+
2511
+ self.assertIsInstance(
2512
+ CustomStructBlock().normalize({"text": "She sells sea shells"}),
2513
+ CustomStructValue,
2514
+ )
2515
+
2516
+ def test_normalize_incorrect_value_class(self):
2517
+ """
2518
+ If StructBlock.normalize is passed a StructValue instance that doesn't
2519
+ match the StructBlock's `value_class', it should convert the value
2520
+ to the correct class.
2521
+ """
2522
+
2523
+ class CustomStructValue(blocks.StructValue):
2524
+ pass
2525
+
2526
+ class CustomStructBlock(blocks.StructBlock):
2527
+ text = blocks.TextBlock()
2528
+
2529
+ class Meta:
2530
+ value_class = CustomStructValue
2531
+
2532
+ block = CustomStructBlock()
2533
+ # Not an instance of CustomStructValue, which CustomStructBlock uses.
2534
+ value = blocks.StructValue(block, {"text": "The quick brown fox"})
2535
+ self.assertIsInstance(block.normalize(value), CustomStructValue)
2536
+
2436
2537
 
2437
2538
  class TestListBlock(WagtailTestUtils, SimpleTestCase):
2539
+ def assert_eq_list_values(self, p, q):
2540
+ # We can't directly compare ListValue instances yet
2541
+ self.assertEqual(list(p), list(q))
2542
+
2438
2543
  def test_initialise_with_class(self):
2439
2544
  block = blocks.ListBlock(blocks.CharBlock)
2440
2545
 
@@ -2961,6 +3066,42 @@ class TestListBlock(WagtailTestUtils, SimpleTestCase):
2961
3066
  self.assertEqual(len(result[0]["value"]), 2)
2962
3067
  self.assertEqual(result[0]["value"][0]["value"], "foo")
2963
3068
 
3069
+ def test_normalize_base_case(self):
3070
+ """Test normalize when trivially recursive, or already a ListValue"""
3071
+ block = blocks.ListBlock(blocks.IntegerBlock)
3072
+ normalized = block.normalize([0, 1, 1, 2, 3])
3073
+ self.assertIsInstance(normalized, blocks.list_block.ListValue)
3074
+ self.assert_eq_list_values(normalized, [0, 1, 1, 2, 3])
3075
+
3076
+ normalized = block.normalize(
3077
+ blocks.list_block.ListValue(block, [0, 1, 1, 2, 3])
3078
+ )
3079
+ self.assertIsInstance(normalized, blocks.list_block.ListValue)
3080
+ self.assert_eq_list_values(normalized, [0, 1, 1, 2, 3])
3081
+
3082
+ def test_normalize_empty(self):
3083
+ block = blocks.ListBlock(blocks.IntegerBlock())
3084
+ normalized = block.normalize([])
3085
+ self.assertIsInstance(normalized, blocks.list_block.ListValue)
3086
+ self.assert_eq_list_values(normalized, [])
3087
+
3088
+ def test_recursive_normalize(self):
3089
+ """
3090
+ ListBlock.normalize should recursively normalize all values passed to
3091
+ it, and return a ListValue.
3092
+ """
3093
+ inner_list_block = blocks.ListBlock(blocks.IntegerBlock())
3094
+ block = blocks.ListBlock(inner_list_block)
3095
+ values = [
3096
+ [[1, 2, 3]],
3097
+ [blocks.list_block.ListValue(block, [1, 2, 3])],
3098
+ ]
3099
+
3100
+ for value in values:
3101
+ normalized = block.normalize(value)
3102
+ self.assertIsInstance(normalized, blocks.list_block.ListValue)
3103
+ self.assert_eq_list_values(normalized[0], [1, 2, 3])
3104
+
2964
3105
 
2965
3106
  class TestListBlockWithFixtures(TestCase):
2966
3107
  fixtures = ["test.json"]
@@ -4228,6 +4369,120 @@ class TestStreamBlock(WagtailTestUtils, SimpleTestCase):
4228
4369
  )
4229
4370
 
4230
4371
 
4372
+ class TestNormalizeStreamBlock(SimpleTestCase):
4373
+ @classmethod
4374
+ def setUpClass(cls):
4375
+ super().setUpClass()
4376
+ cls.simple_block = blocks.StreamBlock(
4377
+ [("number", blocks.IntegerBlock()), ("text", blocks.TextBlock())]
4378
+ )
4379
+ cls.recursive_block = blocks.StreamBlock(
4380
+ [
4381
+ (
4382
+ "inner_stream",
4383
+ blocks.StreamBlock(
4384
+ [
4385
+ ("number", blocks.IntegerBlock()),
4386
+ ("text", blocks.TextBlock()),
4387
+ ("inner_list", blocks.ListBlock(blocks.IntegerBlock)),
4388
+ ]
4389
+ ),
4390
+ ),
4391
+ ("struct", blocks.StructBlock([("bool", blocks.BooleanBlock())])),
4392
+ ("list", blocks.ListBlock(blocks.IntegerBlock)),
4393
+ ]
4394
+ )
4395
+
4396
+ def test_normalize_empty_stream(self):
4397
+ values = [[], "", None]
4398
+ for value in values:
4399
+ with self.subTest(value=value):
4400
+ self.assertEqual(
4401
+ self.simple_block.normalize(value),
4402
+ blocks.StreamValue(self.simple_block, []),
4403
+ )
4404
+
4405
+ def test_normalize_base_case(self):
4406
+ """
4407
+ Test normalize when trivially recursive, or already a StreamValue
4408
+ """
4409
+ value = [("number", 1), ("text", "ichiban")]
4410
+ stream_value = blocks.StreamValue(self.simple_block, value)
4411
+ self.assertEqual(stream_value, self.simple_block.normalize(value))
4412
+ self.assertEqual(stream_value, self.simple_block.normalize(stream_value))
4413
+
4414
+ def test_normalize_recursive(self):
4415
+ """
4416
+ A stream block is normalized iff all of its sub-blocks are normalized.
4417
+ """
4418
+ values = (
4419
+ # A smart, "list of tuples" representation
4420
+ [
4421
+ ("struct", {"bool": True}),
4422
+ (
4423
+ "inner_stream",
4424
+ [
4425
+ ("number", 1),
4426
+ ("text", "one"),
4427
+ ("inner_list", [0, 1, 1, 2, 3, 5]),
4428
+ ],
4429
+ ),
4430
+ ("list", [0, 1, 1, 2, 3, 5]),
4431
+ ],
4432
+ # A json-ish representation - the serialized format
4433
+ [
4434
+ {"type": "struct", "value": {"bool": True}},
4435
+ {
4436
+ "type": "inner_stream",
4437
+ "value": [
4438
+ {"type": "number", "value": 1},
4439
+ {"type": "text", "value": "one"},
4440
+ {
4441
+ "type": "inner_list",
4442
+ "value": [
4443
+ # Unlike StreamBlock, ListBlock requires that its items
4444
+ # have IDs, to distinguish the new serialization format
4445
+ # from the old.
4446
+ {"type": "item", "value": 0, "id": 1},
4447
+ {"type": "item", "value": 1, "id": 2},
4448
+ {"type": "item", "value": 2, "id": 3},
4449
+ ],
4450
+ },
4451
+ ],
4452
+ },
4453
+ {
4454
+ "type": "list",
4455
+ "value": [
4456
+ {"type": "item", "value": 0, "id": 1},
4457
+ {"type": "item", "value": 1, "id": 2},
4458
+ {"type": "item", "value": 2, "id": 3},
4459
+ ],
4460
+ },
4461
+ ],
4462
+ )
4463
+
4464
+ for value in values:
4465
+ with self.subTest(value=value):
4466
+ # Normalize the value.
4467
+ normalized = self.recursive_block.normalize(value)
4468
+ # Then check all of the sub-blocks have been normalized:
4469
+ # the StructBlock child
4470
+ self.assertIsInstance(normalized[0].value, blocks.StructValue)
4471
+ self.assertIsInstance(normalized[0].value["bool"], bool)
4472
+ # the nested StreamBlock child
4473
+ self.assertIsInstance(normalized[1].value, blocks.StreamValue)
4474
+ self.assertIsInstance(normalized[1].value[0].value, int)
4475
+ self.assertIsInstance(normalized[1].value[1].value, str)
4476
+ # the ListBlock child
4477
+ self.assertIsInstance(normalized[2].value[0], int)
4478
+ self.assertIsInstance(normalized[2].value, blocks.list_block.ListValue)
4479
+ # the inner ListBlock nested in the nested streamblock
4480
+ self.assertIsInstance(normalized[1].value[2].value[0], int)
4481
+ self.assertIsInstance(
4482
+ normalized[1].value[2].value, blocks.list_block.ListValue
4483
+ )
4484
+
4485
+
4231
4486
  class TestStructBlockWithFixtures(TestCase):
4232
4487
  fixtures = ["test.json"]
4233
4488
 
@@ -4742,6 +4997,12 @@ class TestStaticBlock(unittest.TestCase):
4742
4997
  result = block.to_python(None)
4743
4998
  self.assertIsNone(result)
4744
4999
 
5000
+ def test_normalize(self):
5001
+ """
5002
+ StaticBlock.normalize always returns None, as a StaticBlock has no value
5003
+ """
5004
+ self.assertIsNone(blocks.StaticBlock().normalize(11))
5005
+
4745
5006
 
4746
5007
  class TestDateBlock(TestCase):
4747
5008
  def test_adapt(self):
@@ -16,7 +16,7 @@ class TestForMigrations(TestCase):
16
16
  app_labels = {
17
17
  app.label
18
18
  for app in apps.get_app_configs()
19
- if app.name.startswith("wagtail.")
19
+ if app.name.split(".")[0] == "wagtail"
20
20
  }
21
21
  for app_label in app_labels:
22
22
  apps.get_app_config(app_label.split(".")[-1])
@@ -68,6 +68,7 @@ from wagtail.test.testapp.models import (
68
68
  TaggedPage,
69
69
  )
70
70
  from wagtail.test.utils import WagtailTestUtils
71
+ from wagtail.url_routing import RouteResult
71
72
 
72
73
 
73
74
  def get_ct(model):
@@ -211,6 +212,50 @@ class TestSiteRouting(TestCase):
211
212
  self.unrecognised_port = "8000"
212
213
  self.unrecognised_hostname = "unknown.site.com"
213
214
 
215
+ def test_route_for_request_query_count(self):
216
+ request = get_dummy_request(site=self.events_site)
217
+ with self.assertNumQueries(2):
218
+ # expect queries for site & page
219
+ Page.route_for_request(request, request.path)
220
+ with self.assertNumQueries(0):
221
+ # subsequent lookups should be cached on the request
222
+ Page.route_for_request(request, request.path)
223
+
224
+ def test_route_for_request_value(self):
225
+ request = get_dummy_request(site=self.events_site)
226
+ self.assertFalse(hasattr(request, "_wagtail_route_for_request"))
227
+ result = Page.route_for_request(request, request.path)
228
+ self.assertTrue(isinstance(result, RouteResult))
229
+ self.assertEqual(
230
+ (result[0], result[1], result[2]),
231
+ (self.events_site.root_page.specific, [], {}),
232
+ )
233
+ self.assertTrue(hasattr(request, "_wagtail_route_for_request"))
234
+ self.assertIs(request._wagtail_route_for_request, result)
235
+
236
+ def test_route_for_request_cached(self):
237
+ request = get_dummy_request(site=self.events_site)
238
+ m = Mock()
239
+ request._wagtail_route_for_request = m
240
+ with self.assertNumQueries(0):
241
+ self.assertEqual(Page.route_for_request(request, request.path), m)
242
+
243
+ def test_route_for_request_suppresses_404(self):
244
+ request = get_dummy_request(path="does-not-exist", site=self.events_site)
245
+ self.assertIsNone(Page.route_for_request(request, request.path))
246
+
247
+ def test_find_for_request(self):
248
+ request_200 = get_dummy_request(site=self.events_site)
249
+ self.assertEqual(
250
+ Page.find_for_request(request_200, request_200.path),
251
+ self.events_site.root_page.specific,
252
+ )
253
+ request_404 = get_dummy_request(path="does-not-exist", site=self.events_site)
254
+ self.assertEqual(
255
+ Page.find_for_request(request_404, request_404.path),
256
+ None,
257
+ )
258
+
214
259
  def test_valid_headers_route_to_specific_site(self):
215
260
  # requests with a known Host: header should be directed to the specific site
216
261
  request = get_dummy_request(site=self.events_site)
@@ -502,6 +547,20 @@ class TestRouting(TestCase):
502
547
  christmas_page.get_url(request=request), "/events/christmas/"
503
548
  )
504
549
 
550
+ def test_cached_parent_obj_set(self):
551
+ homepage = Page.objects.get(url_path="/home/")
552
+ christmas_page = EventPage.objects.get(url_path="/home/events/christmas/")
553
+
554
+ request = get_dummy_request(path="/events/christmas/")
555
+ (found_page, args, kwargs) = homepage.route(request, ["events", "christmas"])
556
+ self.assertEqual(found_page, christmas_page)
557
+
558
+ # parent cache should be set
559
+ events_page = Page.objects.get(url_path="/home/events/").specific
560
+ with self.assertNumQueries(0):
561
+ parent = found_page.get_parent(update=False)
562
+ self.assertEqual(parent, events_page)
563
+
505
564
 
506
565
  @override_settings(
507
566
  ROOT_URLCONF="wagtail.test.urls_multilang",
@@ -3917,3 +3976,21 @@ class TestPageCacheKey(TestCase):
3917
3976
  self.page.slug = "something-else"
3918
3977
  self.page.save()
3919
3978
  self.assertNotEqual(self.page.cache_key, original_cache_key)
3979
+
3980
+
3981
+ class TestPageCachedParentObjExists(TestCase):
3982
+ fixtures = ["test.json"]
3983
+
3984
+ def test_cached_parent_obj_exists(self):
3985
+ # https://github.com/wagtail/wagtail/pull/11737
3986
+
3987
+ # Test if _cached_parent_obj is set after using page.get_parent()
3988
+ # This is treebeard specific, we don't know if their API will change.
3989
+ homepage = Page.objects.get(url_path="/home/")
3990
+ homepage._cached_parent_obj = "_cached_parent_obj_exists"
3991
+ parent = homepage.get_parent(update=False)
3992
+ self.assertEqual(
3993
+ parent,
3994
+ "_cached_parent_obj_exists",
3995
+ "Page.get_parent() (treebeard) no longer uses _cached_parent_obj to cache the parent object",
3996
+ )
@@ -1,5 +1,5 @@
1
1
  from django.contrib.auth.models import Group
2
- from django.test import TestCase
2
+ from django.test import TestCase, override_settings
3
3
 
4
4
  from wagtail.models import Page, PageViewRestriction
5
5
  from wagtail.test.utils import WagtailTestUtils
@@ -79,6 +79,23 @@ class TestPagePrivacy(WagtailTestUtils, TestCase):
79
79
  )
80
80
  self.assertRedirects(response, "/")
81
81
 
82
+ @override_settings(
83
+ WAGTAIL_PASSWORD_REQUIRED_TEMPLATE="tests/custom_page_password_required.html"
84
+ )
85
+ def test_anonymous_user_must_authenticate_with_custom_password_required_template(
86
+ self
87
+ ):
88
+ response = self.client.get("/secret-plans/")
89
+
90
+ self.assertNotEqual(
91
+ "wagtailcore/password_required.html",
92
+ response.templates[0].name,
93
+ )
94
+ self.assertEqual(
95
+ "tests/custom_page_password_required.html",
96
+ response.templates[0].name,
97
+ )
98
+
82
99
  def test_view_restrictions_apply_to_subpages(self):
83
100
  underpants_page = Page.objects.get(
84
101
  url_path="/home/secret-plans/steal-underpants/"
@@ -5,7 +5,7 @@ from django.test import TestCase, override_settings
5
5
  from django.utils import translation
6
6
 
7
7
  from wagtail.fields import RichTextField
8
- from wagtail.models import Locale, Page
8
+ from wagtail.models import Locale, Page, Site
9
9
  from wagtail.rich_text import RichText, RichTextMaxLengthValidator, expand_db_html
10
10
  from wagtail.rich_text.feature_registry import FeatureRegistry
11
11
  from wagtail.rich_text.pages import PageLinkHandler
@@ -82,16 +82,34 @@ class TestExtractAttrs(TestCase):
82
82
 
83
83
 
84
84
  class TestExpandDbHtml(TestCase):
85
- def test_expand_db_html_with_linktype(self):
86
- html = '<a id="1" linktype="document">foo</a>'
87
- result = expand_db_html(html)
88
- self.assertEqual(result, "<a>foo</a>")
85
+ fixtures = ["test.json"]
89
86
 
90
87
  def test_expand_db_html_no_linktype(self):
91
88
  html = '<a id="1">foo</a>'
92
89
  result = expand_db_html(html)
93
90
  self.assertEqual(result, '<a id="1">foo</a>')
94
91
 
92
+ def test_invalid_linktype_set_to_empty_link(self):
93
+ html = '<a id="1" linktype="invalid">foo</a>'
94
+ result = expand_db_html(html)
95
+ self.assertEqual(result, "<a>foo</a>")
96
+
97
+ def test_valid_linktype_and_reference(self):
98
+ html = '<a id="1" linktype="document">foo</a>'
99
+ result = expand_db_html(html)
100
+ self.assertEqual(result, '<a href="/documents/1/test.pdf">foo</a>')
101
+
102
+ def test_valid_linktype_invalid_reference_set_to_empty_link(self):
103
+ html = '<a id="9999" linktype="document">foo</a>'
104
+ result = expand_db_html(html)
105
+ self.assertEqual(result, "<a>foo</a>")
106
+
107
+ def test_no_embedtype_remove_tag(self):
108
+ self.assertEqual(expand_db_html('<embed id="1" />'), "")
109
+
110
+ def test_invalid_embedtype_remove_tag(self):
111
+ self.assertEqual(expand_db_html('<embed id="1" embedtype="invalid" />'), "")
112
+
95
113
  @patch("wagtail.embeds.embeds.get_embed")
96
114
  def test_expand_db_html_with_embed(self, get_embed):
97
115
  from wagtail.embeds.models import Embed
@@ -101,6 +119,78 @@ class TestExpandDbHtml(TestCase):
101
119
  result = expand_db_html(html)
102
120
  self.assertIn("test html", result)
103
121
 
122
+ # Override CACHES so we don't generate any cache-related SQL queries
123
+ # for page site root paths (tests use DatabaseCache otherwise).
124
+ @override_settings(
125
+ CACHES={
126
+ "default": {
127
+ "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
128
+ },
129
+ }
130
+ )
131
+ def test_expand_db_html_database_queries_pages(self):
132
+ Site.clear_site_root_paths_cache()
133
+
134
+ with self.assertNumQueries(5):
135
+ expand_db_html(
136
+ """
137
+ This rich text has 8 page links, and this test verifies that the code uses the
138
+ minimal number of database queries (5) to expand them.
139
+
140
+ All of these pages should be retrieved with 4 queries, one to do the base
141
+ Page table lookup and then 1 each for the EventIndex, EventPage, and
142
+ SimplePage tables.
143
+
144
+ <a linktype="page" id="3">This links to an EventIndex page.</a>
145
+ <a linktype="page" id="4">This links to an EventPage page.</a>
146
+ <a linktype="page" id="5">This links to an EventPage page.</a>
147
+ <a linktype="page" id="6">This links to an EventPage page.</a>
148
+ <a linktype="page" id="9">This links to an EventPage page.</a>
149
+ <a linktype="page" id="12">This links to an EventPage page.</a>
150
+ <a linktype="page" id="7">This links to a SimplePage page.</a>
151
+ <a linktype="page" id="11">This links to a SimplePage page.</a>
152
+
153
+ Finally there's one additional query needed to do the Site root paths lookup.
154
+ """
155
+ )
156
+
157
+ def test_expand_db_html_database_queries_documents(self):
158
+ with self.assertNumQueries(1):
159
+ expand_db_html(
160
+ html="""
161
+ This rich text has 2 document links, and this test verifies that the code uses
162
+ the minimal number of database queries (1) to expand them.
163
+
164
+ Both of these documents should be retrieved with 1 query:
165
+
166
+ <a linktype="document" id="1">This links to a document.</a>
167
+ <a linktype="document" id="2">This links to another document.</a>
168
+ """
169
+ )
170
+
171
+ # Disable rendition cache that might be populated by other tests.
172
+ @override_settings(
173
+ CACHES={
174
+ "renditions": {
175
+ "BACKEND": "django.core.cache.backends.dummy.DummyCache",
176
+ },
177
+ }
178
+ )
179
+ def test_expand_db_html_database_queries_images(self):
180
+ with self.assertNumQueries(3):
181
+ expand_db_html(
182
+ """
183
+ This rich text has 2 image links, and this test verifies that the code uses the
184
+ minimal number of database queries (3) to expand them.
185
+
186
+ Both of these images should be retrieved with 3 queries, one to fetch the
187
+ image objects in bulk and then one per image to fetch their renditions:
188
+
189
+ This is an image: <embed embedtype="image" id="1" format="left" />
190
+ This is another image: <embed embedtype="image" id="2" format="left" />
191
+ """
192
+ )
193
+
104
194
 
105
195
  class TestRichTextValue(TestCase):
106
196
  fixtures = ["test.json"]
@@ -16,6 +16,7 @@ from wagtail.models import Page
16
16
  from wagtail.rich_text import RichText
17
17
  from wagtail.signal_handlers import disable_reference_index_auto_update
18
18
  from wagtail.test.testapp.models import (
19
+ ComplexDefaultStreamPage,
19
20
  JSONBlockCountsStreamModel,
20
21
  JSONMinMaxCountStreamModel,
21
22
  JSONStreamModel,
@@ -236,6 +237,48 @@ class TestStreamValueAccess(TestCase):
236
237
  self.assertEqual(fetched_body[1].block_type, "text")
237
238
  self.assertEqual(fetched_body[1].value, "bar")
238
239
 
240
+ def test_complex_assignment(self):
241
+ page = StreamPage(title="Test page", body=[])
242
+ page.body = [
243
+ ("rich_text", "<h2>hello world</h2>"),
244
+ (
245
+ "books",
246
+ [
247
+ ("title", "Great Expectations"),
248
+ ("author", "Charles Dickens"),
249
+ ],
250
+ ),
251
+ ]
252
+ self.assertEqual(page.body[0].block_type, "rich_text")
253
+ self.assertIsInstance(page.body[0].value, RichText)
254
+ self.assertEqual(page.body[0].value.source, "<h2>hello world</h2>")
255
+ self.assertEqual(page.body[1].block_type, "books")
256
+ self.assertIsInstance(page.body[1].value, StreamValue)
257
+ self.assertEqual(len(page.body[1].value), 2)
258
+ self.assertEqual(page.body[1].value[0].block_type, "title")
259
+ self.assertEqual(page.body[1].value[0].value, "Great Expectations")
260
+ self.assertEqual(page.body[1].value[1].block_type, "author")
261
+ self.assertEqual(page.body[1].value[1].value, "Charles Dickens")
262
+
263
+
264
+ class TestComplexDefault(TestCase):
265
+ def setUp(self):
266
+ self.page = ComplexDefaultStreamPage(title="Test page")
267
+
268
+ def test_default_value(self):
269
+ self.assertEqual(self.page.body[0].block_type, "rich_text")
270
+ self.assertIsInstance(self.page.body[0].value, RichText)
271
+ self.assertEqual(
272
+ self.page.body[0].value.source, "<p>My <i>lovely</i> books</p>"
273
+ )
274
+ self.assertEqual(self.page.body[1].block_type, "books")
275
+ self.assertIsInstance(self.page.body[1].value, StreamValue)
276
+ self.assertEqual(len(self.page.body[1].value), 2)
277
+ self.assertEqual(self.page.body[1].value[0].block_type, "title")
278
+ self.assertEqual(self.page.body[1].value[0].value, "The Great Gatsby")
279
+ self.assertEqual(self.page.body[1].value[1].block_type, "author")
280
+ self.assertEqual(self.page.body[1].value[1].value, "F. Scott Fitzgerald")
281
+
239
282
 
240
283
  class TestStreamFieldRenderingBase(TestCase):
241
284
  model = JSONStreamModel
@@ -178,14 +178,14 @@ class TestInvokeViaAttributeShortcut(SimpleTestCase):
178
178
  pickled = pickle.dumps(self.test_object, -1)
179
179
  except Exception as e: # noqa: BLE001
180
180
  raise AssertionError(
181
- "An error occured when attempting to pickle %r: %s"
181
+ "An error occurred when attempting to pickle %r: %s"
182
182
  % (self.test_object, e)
183
183
  )
184
184
  try:
185
185
  self.test_object = pickle.loads(pickled)
186
186
  except Exception as e: # noqa: BLE001
187
187
  raise AssertionError(
188
- "An error occured when attempting to unpickle %r: %s"
188
+ "An error occurred when attempting to unpickle %r: %s"
189
189
  % (self.test_object, e)
190
190
  )
191
191
 
@@ -479,6 +479,12 @@ class TestGetDummyRequest(TestCase):
479
479
  request = get_dummy_request(site=site)
480
480
  self.assertEqual(request.get_host(), "other.example.com:8888")
481
481
 
482
+ def test_server_name_for_wildcard_allowed_hosts(self):
483
+ # Django's test runner adds "testserver" at the end of ALLOWED_HOSTS.
484
+ with self.settings(ALLOWED_HOSTS=["*", "testserver"]):
485
+ request = get_dummy_request()
486
+ self.assertEqual(request.get_host(), "example.com")
487
+
482
488
 
483
489
  class TestDeepUpdate(TestCase):
484
490
  def test_deep_update(self):