Skip to content

Commit b4a0c62

Browse files
committed
Cleanup code for older versions of Wagtail (< 4.1)
1 parent 3ca2980 commit b4a0c62

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

tests/testapp/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from django.db import models
22
from wagtail.admin.panels import FieldPanel
3-
from wagtail.admin.panels import FieldPanel as StreamFieldPanel
43
from wagtail.fields import StreamField
54
from wagtail.models import Page
65

@@ -42,5 +41,5 @@ class PageWithStreamfield(Page):
4241
)
4342

4443
content_panels = Page.content_panels + [
45-
StreamFieldPanel("body"),
44+
FieldPanel("body"),
4645
]

wagtail_color_panel/edit_handlers.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@
44

55

66
class NativeColorPanel(FieldPanel):
7-
def widget_overrides(self):
8-
# For Wagtail<3.0 we use widget_overrides
9-
return {
10-
self.field_name: ColorInputWidget(),
11-
}
12-
137
def get_form_options(self):
14-
# For Wagtail 3.0 we use get_form_options
15-
# So we can mix them to provide supports to Wagtail 2,3
168
opts = super().get_form_options()
17-
opts["widgets"] = self.widget_overrides()
9+
opts["widgets"] = {
10+
self.field_name: ColorInputWidget(),
11+
}
1812
return opts
1913

2014

2115
class PolyfillColorPanel(FieldPanel):
22-
def widget_overrides(self):
23-
return {
24-
self.field_name: PolyfillColorInputWidget(),
25-
}
26-
2716
def get_form_options(self):
2817
opts = super().get_form_options()
29-
opts["widgets"] = self.widget_overrides()
18+
opts["widgets"] = {
19+
self.field_name: PolyfillColorInputWidget(),
20+
}
3021
return opts

0 commit comments

Comments
 (0)