wagtail 7.1.1__py3-none-any.whl → 7.1.2__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.
@@ -6,7 +6,9 @@
6
6
  {% if breadcrumbs_items %}
7
7
  <div class="nice-padding w-mt-8">
8
8
  <h2 class="w-relative w-h1" id="header-title">
9
- {% icon classname="w-absolute w-top-1 -w-left-11 w-max-w-[1em] w-max-h-[1em]" name=header_icon %}
9
+ {% if header_icon %}
10
+ {% icon classname="w-absolute w-top-1 -w-left-11 w-max-w-[1em] w-max-h-[1em]" name=header_icon %}
11
+ {% endif %}
10
12
  {{ page_subtitle|default:page_title }}
11
13
  </h2>
12
14
  </div>
@@ -5,7 +5,8 @@
5
5
  <aside {% if request.in_preview_panel %}hidden{% endif %}>
6
6
  <div class="w-userbar w-userbar--{{ position|default:'bottom-right' }} {% admin_theme_classname %}" data-wagtail-userbar data-wagtail-userbar-origin="{{ origin|default:"" }}" part="userbar">
7
7
  {% block css %}
8
- <link rel="stylesheet" href="{% absolute_static 'wagtailadmin/css/core.css' %}">
8
+ {% versioned_static 'wagtailadmin/css/core.css' as core_css_url %}
9
+ <link rel="stylesheet" href="{% build_absolute_url core_css_url %}">
9
10
  {# For headless userbar: the contents of the hook also need absolute URLs #}
10
11
  {% hook_output 'insert_global_admin_css' %}
11
12
  {% endblock %}
@@ -44,7 +45,9 @@
44
45
  </template>
45
46
  <wagtail-userbar></wagtail-userbar>
46
47
  {% block js %}
47
- <script src="{% absolute_static 'wagtailadmin/js/vendor.js' %}"></script>
48
- <script src="{% absolute_static 'wagtailadmin/js/userbar.js' %}"></script>
48
+ {% versioned_static 'wagtailadmin/js/vendor.js' as vendor_js_url %}
49
+ {% versioned_static 'wagtailadmin/js/userbar.js' as userbar_js_url %}
50
+ <script src="{% build_absolute_url vendor_js_url %}"></script>
51
+ <script src="{% build_absolute_url userbar_js_url %}"></script>
49
52
  {% endblock %}
50
53
  <!-- end Wagtail user bar embed code -->
@@ -2,8 +2,8 @@
2
2
  {% load i18n wagtailadmin_tags %}
3
3
 
4
4
  {% block item_content %}
5
- {% base_url_setting default="" as base_url %}
6
- <a href="{{ base_url }}{% url 'wagtailadmin_home' %}" target="_parent" role="menuitem">
5
+ {% url 'wagtailadmin_home' as admin_home_url %}
6
+ <a href="{% build_absolute_url admin_home_url %}" target="_parent" role="menuitem">
7
7
  {% icon name="key" classname="w-action-icon" %}
8
8
  {% trans 'Go to Wagtail admin' %}
9
9
  </a>
@@ -2,8 +2,8 @@
2
2
  {% load i18n wagtailadmin_tags %}
3
3
 
4
4
  {% block item_content %}
5
- {% base_url_setting default="" as base_url %}
6
- <a href="{{ base_url }}{% url 'wagtailadmin_pages:add_subpage' self.page.id %}" target="_parent" role="menuitem">
5
+ {% url 'wagtailadmin_pages:add_subpage' self.page.id as add_url %}
6
+ <a href="{% build_absolute_url add_url %}" target="_parent" role="menuitem">
7
7
  {% icon name="plus" classname="w-action-icon" %}
8
8
  {% trans 'Add a child page' %}
9
9
  </a>
@@ -2,8 +2,8 @@
2
2
  {% load i18n wagtailadmin_tags %}
3
3
 
4
4
  {% block item_content %}
5
- {% base_url_setting default="" as base_url %}
6
- <a href="{{ base_url }}{% url 'wagtailadmin_pages:edit' self.page.id %}" target="_parent" role="menuitem">
5
+ {% url 'wagtailadmin_pages:edit' self.page.id as edit_url %}
6
+ <a href="{% build_absolute_url edit_url %}" target="_parent" role="menuitem">
7
7
  {% icon name="edit" classname="w-action-icon" %}
8
8
  {% trans 'Edit this page' %}
9
9
  </a>
@@ -2,8 +2,8 @@
2
2
  {% load i18n wagtailadmin_tags %}
3
3
 
4
4
  {% block item_content %}
5
- {% base_url_setting default="" as base_url %}
6
- <a href="{{ base_url }}{% url 'wagtailadmin_explore' self.parent_page.id %}" target="_parent" role="menuitem">
5
+ {% url 'wagtailadmin_explore' self.parent_page.id as explore_url %}
6
+ <a href="{% build_absolute_url explore_url %}" target="_parent" role="menuitem">
7
7
  {% icon name="folder-open-inverse" classname="w-action-icon" %}
8
8
  {% trans 'Show in Explorer' %}
9
9
  </a>
@@ -206,6 +206,21 @@ def admin_url_name(obj, action):
206
206
  return obj.snippet_viewset.get_url_name(action)
207
207
 
208
208
 
209
+ @register.simple_tag(takes_context=True)
210
+ def build_absolute_url(context, url):
211
+ """
212
+ Usage: {% build_absolute_url url %}
213
+ Returns the absolute URL of the given URL based on the request's host.
214
+ If the request doesn't exist in the context, falls back to
215
+ WAGTAILADMIN_BASE_URL as the base URL.
216
+ If the given URL is already absolute, returns it unchanged.
217
+ """
218
+ request = context.get("request")
219
+ if not request:
220
+ return urljoin(get_admin_base_url(), url)
221
+ return request.build_absolute_uri(url)
222
+
223
+
209
224
  @register.simple_tag
210
225
  def latest_str(obj):
211
226
  """
@@ -1,6 +1,5 @@
1
1
  import json
2
2
 
3
- from django.conf import settings
4
3
  from django.contrib.auth.models import AnonymousUser, Permission
5
4
  from django.template import Context, Template
6
5
  from django.test import TestCase, override_settings
@@ -9,7 +8,7 @@ from django.utils import translation
9
8
  from django.utils.translation import gettext
10
9
 
11
10
  from wagtail import hooks
12
- from wagtail.admin.templatetags.wagtailadmin_tags import absolute_static
11
+ from wagtail.admin.staticfiles import versioned_static
13
12
  from wagtail.admin.userbar import AccessibilityItem, Userbar
14
13
  from wagtail.coreutils import get_dummy_request
15
14
  from wagtail.models import PAGE_TEMPLATE_VAR, Locale, Page, Site
@@ -67,7 +66,7 @@ class TestUserbarTag(WagtailTestUtils, TestCase):
67
66
  # Wagtail admin core CSS should be linked with absolute URL to
68
67
  # ensure it works when loaded from a different domain
69
68
  # (e.g. headless frontend)
70
- absolute_static("wagtailadmin/css/core.css"),
69
+ f"http://localhost{versioned_static('wagtailadmin/css/core.css')}",
71
70
  # Custom CSS must be changed appropriately if necessary
72
71
  "/path/to/my/custom.css",
73
72
  ],
@@ -80,8 +79,8 @@ class TestUserbarTag(WagtailTestUtils, TestCase):
80
79
  # Wagtail vendor and userbar JS should be linked with absolute
81
80
  # URL to ensure it works when loaded from a different domain
82
81
  # (e.g. headless frontend)
83
- absolute_static("wagtailadmin/js/vendor.js"),
84
- absolute_static("wagtailadmin/js/userbar.js"),
82
+ f"http://localhost{versioned_static('wagtailadmin/js/vendor.js')}",
83
+ f"http://localhost{versioned_static('wagtailadmin/js/userbar.js')}",
85
84
  ],
86
85
  )
87
86
 
@@ -136,9 +135,7 @@ class TestUserbarTag(WagtailTestUtils, TestCase):
136
135
  # Should render the "Go to Wagtail admin" link using an absolute URL
137
136
  soup = self.get_soup(content)
138
137
  admin_url = reverse("wagtailadmin_home")
139
- admin_link = soup.select_one(
140
- f"a[href='{settings.WAGTAILADMIN_BASE_URL}{admin_url}']"
141
- )
138
+ admin_link = soup.select_one(f"a[href='http://localhost{admin_url}']")
142
139
  self.assertIsNotNone(admin_link)
143
140
  self.assertEqual(admin_link.text.strip(), "Go to Wagtail admin")
144
141
 
@@ -156,16 +153,12 @@ class TestUserbarTag(WagtailTestUtils, TestCase):
156
153
  soup = self.get_soup(content)
157
154
 
158
155
  edit_url = reverse("wagtailadmin_pages:edit", args=(self.homepage.id,))
159
- edit_link = soup.select_one(
160
- f"a[href='{settings.WAGTAILADMIN_BASE_URL}{edit_url}']"
161
- )
156
+ edit_link = soup.select_one(f"a[href='http://localhost{edit_url}']")
162
157
  self.assertIsNotNone(edit_link)
163
158
  self.assertEqual(edit_link.text.strip(), "Edit this page")
164
159
 
165
160
  explore_url = reverse("wagtailadmin_explore", args=(self.parent_page.id,))
166
- explore_link = soup.select_one(
167
- f"a[href='{settings.WAGTAILADMIN_BASE_URL}{explore_url}']"
168
- )
161
+ explore_link = soup.select_one(f"a[href='http://localhost{explore_url}']")
169
162
  self.assertIsNotNone(explore_link)
170
163
  self.assertEqual(explore_link.text.strip(), "Show in Explorer")
171
164
 
@@ -185,16 +178,12 @@ class TestUserbarTag(WagtailTestUtils, TestCase):
185
178
  soup = self.get_soup(content)
186
179
 
187
180
  edit_url = reverse("wagtailadmin_pages:edit", args=(self.homepage.id,))
188
- edit_link = soup.select_one(
189
- f"a[href='{settings.WAGTAILADMIN_BASE_URL}{edit_url}']"
190
- )
181
+ edit_link = soup.select_one(f"a[href='http://localhost{edit_url}']")
191
182
  self.assertIsNotNone(edit_link)
192
183
  self.assertEqual(edit_link.text.strip(), "Edit this page")
193
184
 
194
185
  explore_url = reverse("wagtailadmin_explore", args=(self.parent_page.id,))
195
- explore_link = soup.select_one(
196
- f"a[href='{settings.WAGTAILADMIN_BASE_URL}{explore_url}']"
197
- )
186
+ explore_link = soup.select_one(f"a[href='http://localhost{explore_url}']")
198
187
  self.assertIsNotNone(explore_link)
199
188
  self.assertEqual(explore_link.text.strip(), "Show in Explorer")
200
189
 
@@ -221,9 +210,7 @@ class TestUserbarTag(WagtailTestUtils, TestCase):
221
210
  # The explore link should still be visible
222
211
  soup = self.get_soup(content)
223
212
  explore_url = reverse("wagtailadmin_explore", args=(self.parent_page.id,))
224
- explore_link = soup.select_one(
225
- f"a[href='{settings.WAGTAILADMIN_BASE_URL}{explore_url}']"
226
- )
213
+ explore_link = soup.select_one(f"a[href='http://localhost{explore_url}']")
227
214
  self.assertIsNotNone(explore_link)
228
215
  self.assertEqual(explore_link.text.strip(), "Show in Explorer")
229
216
 
@@ -718,7 +705,7 @@ class TestUserbarAddLink(WagtailTestUtils, TestCase):
718
705
  self.assertEqual(response.status_code, 200)
719
706
 
720
707
  # page allows subpages, so the 'add page' button should show
721
- expected_url = settings.WAGTAILADMIN_BASE_URL + (
708
+ expected_url = self.request.build_absolute_uri(
722
709
  reverse("wagtailadmin_pages:add_subpage", args=(self.event_index.id,))
723
710
  )
724
711
  needle = f"""
@@ -762,7 +749,7 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
762
749
  items = soup.select("li")
763
750
  self.assertEqual(len(items), 2)
764
751
 
765
- admin_url = f"{settings.WAGTAILADMIN_BASE_URL}{reverse('wagtailadmin_home')}"
752
+ admin_url = f"http://localhost{reverse('wagtailadmin_home')}"
766
753
  admin_item = items[0]
767
754
  admin_link = admin_item.select_one("a")
768
755
  self.assertIsNotNone(admin_link)
@@ -780,11 +767,18 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
780
767
  def test_render_no_request(self):
781
768
  rendered = Userbar().render_html({})
782
769
  soup = self.get_soup(rendered)
770
+ # Without a request provided, URLs should fall back to the
771
+ # WAGTAILADMIN_BASE_URL setting
772
+ base_url = "http://testserver"
773
+
774
+ userbar = soup.select_one("[data-wagtail-userbar]")
775
+ self.assertIsNotNone(userbar)
776
+ self.assertEqual(userbar.get("data-wagtail-userbar-origin"), base_url)
783
777
 
784
778
  items = soup.select("li")
785
779
  self.assertEqual(len(items), 2)
786
780
 
787
- admin_url = f"{settings.WAGTAILADMIN_BASE_URL}{reverse('wagtailadmin_home')}"
781
+ admin_url = f"{base_url}{reverse('wagtailadmin_home')}"
788
782
  admin_item = items[0]
789
783
  admin_link = admin_item.select_one("a")
790
784
  self.assertIsNotNone(admin_link)
@@ -799,21 +793,44 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
799
793
  "Issues found | Accessibility",
800
794
  )
801
795
 
796
+ css_links = soup.select("link[rel='stylesheet']")
797
+ self.assertEqual(
798
+ [link.get("href") for link in css_links],
799
+ [
800
+ # Wagtail admin core CSS should be linked with absolute URL to
801
+ # ensure it works when loaded from a different domain
802
+ # (e.g. headless frontend)
803
+ f"{base_url}{versioned_static('wagtailadmin/css/core.css')}",
804
+ # Custom CSS must be changed appropriately if necessary
805
+ "/path/to/my/custom.css",
806
+ ],
807
+ )
808
+
809
+ scripts = soup.select("script[src]")
810
+ self.assertEqual(
811
+ [script.get("src") for script in scripts],
812
+ [
813
+ # Wagtail vendor and userbar JS should be linked with absolute
814
+ # URL to ensure it works when loaded from a different domain
815
+ # (e.g. headless frontend)
816
+ f"{base_url}{versioned_static('wagtailadmin/js/vendor.js')}",
817
+ f"{base_url}{versioned_static('wagtailadmin/js/userbar.js')}",
818
+ ],
819
+ )
820
+
802
821
  def test_render_minimal(self):
803
822
  rendered = Userbar().render_html({"request": self.request})
804
823
  soup = self.get_soup(rendered)
805
824
 
806
825
  userbar = soup.select_one("[data-wagtail-userbar]")
807
826
  self.assertIsNotNone(userbar)
808
- self.assertEqual(
809
- userbar.get("data-wagtail-userbar-origin"),
810
- settings.WAGTAILADMIN_BASE_URL,
811
- )
827
+ # The origin should be based on the request's scheme and host information
828
+ self.assertEqual(userbar.get("data-wagtail-userbar-origin"), "http://localhost")
812
829
 
813
830
  items = soup.select("li")
814
831
  self.assertEqual(len(items), 2)
815
832
 
816
- admin_url = f"{settings.WAGTAILADMIN_BASE_URL}{reverse('wagtailadmin_home')}"
833
+ admin_url = f"http://localhost{reverse('wagtailadmin_home')}"
817
834
  admin_item = items[0]
818
835
  admin_link = admin_item.select_one("a")
819
836
  self.assertIsNotNone(admin_link)
@@ -844,7 +861,7 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
844
861
  self.assertEqual(len(links), 4)
845
862
  self.assertEqual(
846
863
  [link.get("href") for link in links],
847
- [f"{settings.WAGTAILADMIN_BASE_URL}{url}" for url in expected_urls],
864
+ [f"http://localhost{url}" for url in expected_urls],
848
865
  )
849
866
 
850
867
  accessibility_button = soup.select_one("li button")
@@ -855,8 +872,8 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
855
872
  )
856
873
 
857
874
  @override_settings(WAGTAILADMIN_BASE_URL=None)
858
- def test_render_without_admin_base_url_setting(self):
859
- rendered = Userbar().render_html({"request": self.request})
875
+ def test_render_without_request_and_admin_base_url_setting(self):
876
+ rendered = Userbar().render_html({})
860
877
  soup = self.get_soup(rendered)
861
878
 
862
879
  userbar = soup.select_one("[data-wagtail-userbar]")
@@ -868,7 +885,8 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
868
885
  items = soup.select("li")
869
886
  self.assertEqual(len(items), 2)
870
887
 
871
- # Becomes the root-relative URL since WAGTAILADMIN_BASE_URL is None
888
+ # Becomes the root-relative URL since no request is provided
889
+ # and WAGTAILADMIN_BASE_URL is None
872
890
  admin_url = reverse("wagtailadmin_home")
873
891
  admin_item = items[0]
874
892
  admin_link = admin_item.select_one("a")
@@ -883,3 +901,25 @@ class TestUserbarComponent(WagtailTestUtils, TestCase):
883
901
  button.get_text(separator=" | ", strip=True).strip(),
884
902
  "Issues found | Accessibility",
885
903
  )
904
+
905
+ css_links = soup.select("link[rel='stylesheet']")
906
+ self.assertEqual(
907
+ [link.get("href") for link in css_links],
908
+ [
909
+ # Cannot build absolute URL without a request and
910
+ # WAGTAILADMIN_BASE_URL, so should be root-relative
911
+ versioned_static("wagtailadmin/css/core.css"),
912
+ "/path/to/my/custom.css",
913
+ ],
914
+ )
915
+
916
+ scripts = soup.select("script[src]")
917
+ self.assertEqual(
918
+ [script.get("src") for script in scripts],
919
+ [
920
+ # Cannot build absolute URL without a request and
921
+ # WAGTAILADMIN_BASE_URL, so should be root-relative
922
+ versioned_static("wagtailadmin/js/vendor.js"),
923
+ versioned_static("wagtailadmin/js/userbar.js"),
924
+ ],
925
+ )
@@ -2,6 +2,7 @@ from django.contrib.admin.utils import quote
2
2
  from django.test import TestCase
3
3
  from django.urls import reverse
4
4
 
5
+ from wagtail.test.testapp.models import ModelWithStringTypePrimaryKey
5
6
  from wagtail.test.utils import WagtailTestUtils
6
7
 
7
8
 
@@ -37,6 +38,39 @@ class TestGenericIndexViewWithoutModel(WagtailTestUtils, TestCase):
37
38
  self.assertEqual(response_object_count, 4)
38
39
 
39
40
 
41
+ class TestGenericCreateView(WagtailTestUtils, TestCase):
42
+ fixtures = ["test.json"]
43
+
44
+ def get(self, params={}):
45
+ return self.client.get(reverse("testapp_generic_create"), params)
46
+
47
+ def test_get_create_view(self):
48
+ response = self.get()
49
+ self.assertEqual(response.status_code, 200)
50
+ soup = self.get_soup(response.content)
51
+ h2 = soup.select_one("main h2")
52
+ self.assertIsNotNone(h2)
53
+ self.assertEqual(h2.text.strip(), "Model with string type primary key")
54
+ form = soup.select_one("main form")
55
+ self.assertIsNotNone(form)
56
+ id_input = form.select_one("input[name='custom_id']")
57
+ self.assertIsNotNone(id_input)
58
+ self.assertEqual(id_input.get("type"), "text")
59
+ content_input = form.select_one("input[name='content']")
60
+ self.assertIsNotNone(content_input)
61
+
62
+ def test_post_create_view(self):
63
+ post_data = {
64
+ "custom_id": "string-pk-3",
65
+ "content": "third modelwithstringtypeprimarykey model",
66
+ }
67
+ response = self.client.post(reverse("testapp_generic_create"), post_data)
68
+ self.assertEqual(response.status_code, 302) # Redirect to index view
69
+ self.assertTrue(
70
+ ModelWithStringTypePrimaryKey.objects.filter(pk="string-pk-3").exists()
71
+ )
72
+
73
+
40
74
  class TestGenericEditView(WagtailTestUtils, TestCase):
41
75
  fixtures = ["test.json"]
42
76
 
wagtail/admin/userbar.py CHANGED
@@ -364,10 +364,15 @@ class Userbar(Component):
364
364
  # Remove any unrendered items
365
365
  rendered_items = [item for item in rendered_items if item]
366
366
 
367
+ if request:
368
+ origin = f"{request.scheme}://{request.get_host()}"
369
+ else:
370
+ origin = get_admin_base_url() or ""
371
+
367
372
  # Render the userbar items
368
373
  return {
369
374
  "request": request,
370
- "origin": get_admin_base_url(),
375
+ "origin": origin,
371
376
  "items": rendered_items,
372
377
  "position": self.position,
373
378
  "page": self.object,
@@ -427,7 +427,8 @@ class StructBlockAdapter(Adapter):
427
427
  if block.meta.form_template:
428
428
  meta["formTemplate"] = block.render_form_template()
429
429
 
430
- if block.meta.label_format:
430
+ # Check specifically for None to allow for empty string
431
+ if block.meta.label_format is not None:
431
432
  meta["labelFormat"] = block.meta.label_format
432
433
 
433
434
  return [
@@ -6,7 +6,6 @@ from django.utils import timezone
6
6
  from freezegun import freeze_time
7
7
 
8
8
  from wagtail.admin.staticfiles import versioned_static
9
- from wagtail.admin.templatetags.wagtailadmin_tags import absolute_static
10
9
  from wagtail.admin.views.generic.preview import PreviewOnEdit
11
10
  from wagtail.test.testapp.models import (
12
11
  EventCategory,
@@ -325,10 +324,10 @@ class TestPreview(WagtailTestUtils, TestCase):
325
324
  )
326
325
  self.assertNotContains(response, versioned_static("wagtailadmin/js/icons.js"))
327
326
 
328
- @override_settings(WAGTAILADMIN_BASE_URL="http://other.example.com:8000")
329
327
  def test_userbar_in_preview(self):
330
328
  self.client.post(self.preview_on_edit_url, self.post_data)
331
- response = self.client.get(self.preview_on_edit_url)
329
+ host = "other.example.com:8000"
330
+ response = self.client.get(self.preview_on_edit_url, headers={"host": host})
332
331
 
333
332
  # Check the HTML response
334
333
  self.assertEqual(response.status_code, 200)
@@ -345,7 +344,7 @@ class TestPreview(WagtailTestUtils, TestCase):
345
344
  self.assertEqual(
346
345
  [link.get("href") for link in css_links],
347
346
  [
348
- absolute_static("wagtailadmin/css/core.css"),
347
+ f"http://{host}{versioned_static('wagtailadmin/css/core.css')}",
349
348
  "/path/to/my/custom.css",
350
349
  ],
351
350
  )
@@ -353,8 +352,8 @@ class TestPreview(WagtailTestUtils, TestCase):
353
352
  self.assertEqual(
354
353
  [script.get("src") for script in scripts],
355
354
  [
356
- absolute_static("wagtailadmin/js/vendor.js"),
357
- absolute_static("wagtailadmin/js/userbar.js"),
355
+ f"http://{host}{versioned_static('wagtailadmin/js/vendor.js')}",
356
+ f"http://{host}{versioned_static('wagtailadmin/js/userbar.js')}",
358
357
  ],
359
358
  )
360
359
 
@@ -6,6 +6,7 @@ urlpatterns = [
6
6
  path("bob-only-zone", views.bob_only_zone, name="testapp_bob_only_zone"),
7
7
  path("messages/", views.message_test, name="testapp_message_test"),
8
8
  path("test-index/", views.TestIndexView.as_view(), name="testapp_generic_index"),
9
+ path("test-create/", views.TestCreateView.as_view(), name="testapp_generic_create"),
9
10
  path(
10
11
  "test-edit/<str:pk>/", views.TestEditView.as_view(), name="testapp_generic_edit"
11
12
  ),
@@ -14,7 +14,13 @@ from wagtail.admin.auth import user_passes_test
14
14
  from wagtail.admin.filters import WagtailFilterSet
15
15
  from wagtail.admin.panels import FieldPanel
16
16
  from wagtail.admin.ui.tables import BooleanColumn, Column, UpdatedAtColumn
17
- from wagtail.admin.views.generic import DeleteView, EditView, IndexView, InspectView
17
+ from wagtail.admin.views.generic import (
18
+ CreateView,
19
+ DeleteView,
20
+ EditView,
21
+ IndexView,
22
+ InspectView,
23
+ )
18
24
  from wagtail.admin.viewsets.base import ViewSet, ViewSetGroup
19
25
  from wagtail.admin.viewsets.chooser import ChooserViewSet
20
26
  from wagtail.admin.viewsets.model import ModelViewSet, ModelViewSetGroup
@@ -80,6 +86,14 @@ class CustomModelEditForm(forms.ModelForm):
80
86
  fields = ("content",)
81
87
 
82
88
 
89
+ class TestCreateView(CreateView):
90
+ model = ModelWithStringTypePrimaryKey
91
+ fields = ["custom_id", "content"]
92
+ add_url_name = "testapp_generic_create"
93
+ edit_url_name = "testapp_generic_edit"
94
+ index_url_name = "testapp_generic_index"
95
+
96
+
83
97
  class TestEditView(EditView):
84
98
  model = ModelWithStringTypePrimaryKey
85
99
  context_object_name = "test_object"
@@ -2366,6 +2366,21 @@ class TestStructBlock(SimpleTestCase):
2366
2366
 
2367
2367
  self.assertIs(js_args[2]["collapsed"], case)
2368
2368
 
2369
+ def test_adapt_label_format(self):
2370
+ class LinkBlock(blocks.StructBlock):
2371
+ title = blocks.CharBlock()
2372
+ link = blocks.URLBlock()
2373
+
2374
+ cases = [None, "", "{title} ({link})"]
2375
+ for case in cases:
2376
+ with self.subTest(label_format=case):
2377
+ block = LinkBlock(label_format=case)
2378
+
2379
+ block.set_name("test_structblock")
2380
+ js_args = StructBlockAdapter().js_args(block)
2381
+
2382
+ self.assertEqual(js_args[2].get("labelFormat"), case)
2383
+
2369
2384
  def test_searchable_content(self):
2370
2385
  class LinkBlock(blocks.StructBlock):
2371
2386
  title = blocks.CharBlock()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wagtail
3
- Version: 7.1.1
3
+ Version: 7.1.2
4
4
  Summary: A Django content management system.
5
5
  Author-email: Wagtail core team + contributors <hello@wagtail.org>
6
6
  License-Expression: BSD-3-Clause