We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Filter archived and draft projects from the wagtail frontpage selection element


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/cms/models.py`
Content:
```
1 from django.db import models
2 from django.forms import widgets
3 from modelcluster.fields import ParentalKey
4 from modelcluster.models import ClusterableModel
5 from wagtail.wagtailadmin import edit_handlers
6 from wagtail.wagtailcore import blocks
7 from wagtail.wagtailcore import fields
8 from wagtail.wagtailcore.models import Orderable
9 from wagtail.wagtailcore.models import Page
10 from wagtail.wagtailforms.models import AbstractEmailForm
11 from wagtail.wagtailforms.models import AbstractFormField
12 from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
13 from wagtail.wagtailsnippets.models import register_snippet
14 
15 from adhocracy4.projects.models import Project
16 
17 from . import emails
18 
19 
20 class SimplePage(Page):
21     body = fields.RichTextField(blank=True)
22 
23     content_panels = [
24         edit_handlers.FieldPanel('title'),
25         edit_handlers.FieldPanel('body'),
26     ]
27 
28     subpage_types = []
29 
30 
31 class ProjectSelectionBlock(blocks.ChooserBlock):
32     target_model = Project
33     widget = widgets.Select
34 
35     def value_for_form(self, value):
36         if isinstance(value, Project):
37             return value.pk
38         return value
39 
40 
41 class ProjectsWrapperBlock(blocks.StructBlock):
42     title = blocks.CharBlock(max_length=80)
43     projects = blocks.ListBlock(
44         ProjectSelectionBlock(label='Project'),
45     )
46 
47     class Meta:
48         template = 'meinberlin_cms/blocks/projects_block.html'
49 
50 
51 class CallToActionBlock(blocks.StructBlock):
52     body = blocks.RichTextBlock()
53     link = blocks.CharBlock()
54     link_text = blocks.CharBlock(max_length=50, label='Link Text')
55 
56     class Meta:
57         template = 'meinberlin_cms/blocks/cta_block.html'
58 
59 
60 class ColumnsBlock(blocks.StructBlock):
61     columns_count = blocks.ChoiceBlock(choices=[
62         (2, 'Two columns'),
63         (3, 'Three columns'),
64         (4, 'Four columns'),
65     ], default=2)
66 
67     columns = blocks.ListBlock(
68         blocks.RichTextBlock(label='Column body'),
69     )
70 
71     class Meta:
72         template = 'meinberlin_cms/blocks/columns_block.html'
73 
74 
75 class HomePage(Page):
76     body = fields.StreamField([
77         ('paragraph', blocks.RichTextBlock(
78             template='meinberlin_cms/blocks/richtext_block.html'
79         )),
80         ('call_to_action', CallToActionBlock()),
81         ('columns_text', ColumnsBlock()),
82         ('projects', ProjectsWrapperBlock()),
83     ])
84 
85     subtitle = models.CharField(max_length=120)
86 
87     header_image = models.ForeignKey(
88         'wagtailimages.Image',
89         null=True,
90         blank=False,
91         on_delete=models.SET_NULL,
92         related_name='+'
93     )
94 
95     content_panels = Page.content_panels + [
96         edit_handlers.FieldPanel('subtitle'),
97         ImageChooserPanel('header_image'),
98         edit_handlers.StreamFieldPanel('body'),
99     ]
100 
101 
102 class MenuItem(models.Model):
103     title = models.CharField(max_length=255)
104     link_page = models.ForeignKey('wagtailcore.Page')
105 
106     @property
107     def url(self):
108         return self.link_page.url
109 
110     def __str__(self):
111         return self.title
112 
113     panels = [
114         edit_handlers.FieldPanel('title'),
115         edit_handlers.PageChooserPanel('link_page')
116     ]
117 
118 
119 @register_snippet
120 class NavigationMenu(ClusterableModel):
121     title = models.CharField(max_length=255, null=False, blank=False)
122 
123     def __str__(self):
124         return self.title
125 
126     panels = [
127         edit_handlers.FieldPanel('title'),
128         edit_handlers.InlinePanel('items')
129     ]
130 
131 
132 class NavigationMenuItem(Orderable, MenuItem):
133     parent = ParentalKey('meinberlin_cms.NavigationMenu', related_name='items')
134 
135 
136 class EmailFormField(AbstractFormField):
137     page = ParentalKey('EmailFormPage', related_name='form_fields')
138 
139 
140 class EmailFormPage(AbstractEmailForm):
141     intro = fields.RichTextField(
142         help_text='Introduction text shown above the form'
143     )
144     thank_you = fields.RichTextField(
145         help_text='Text shown after form submission',
146     )
147     email_content = models.CharField(
148         max_length=200,
149         help_text='Email content message',
150     )
151     attach_as = models.CharField(
152         max_length=3,
153         choices=(
154             ('csv', 'CSV Document'),
155             ('txt', 'Text'),
156         ),
157         default='csv',
158         help_text='Form results are send in this document format',
159     )
160 
161     content_panels = AbstractEmailForm.content_panels + [
162         edit_handlers.MultiFieldPanel([
163             edit_handlers.FieldPanel('intro', classname='full'),
164             edit_handlers.FieldPanel('thank_you', classname='full'),
165         ], 'Page'),
166         edit_handlers.MultiFieldPanel([
167             edit_handlers.FieldPanel('to_address'),
168             edit_handlers.FieldPanel('subject'),
169             edit_handlers.FieldPanel('email_content', classname='full'),
170             edit_handlers.FieldPanel('attach_as'),
171         ], 'Email'),
172         edit_handlers.InlinePanel('form_fields', label='Form fields'),
173     ]
174 
175     def send_mail(self, form):
176         self.form = form
177         if self.attach_as == 'csv':
178             emails.CsvFormEmail.send(self)
179         elif self.attach_as == 'txt':
180             emails.TextFormEmail.send(self)
181 
182     @property
183     def field_values(self):
184         fields = {}
185         for field in self.form:
186             value = field.value()
187             if isinstance(value, list):
188                 value = ', '.join(value)
189             fields[field.label] = value
190         return fields
191
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/cms/models.py b/apps/cms/models.py
--- a/apps/cms/models.py
+++ b/apps/cms/models.py
@@ -1,5 +1,6 @@
+from django import forms
 from django.db import models
-from django.forms import widgets
+from django.utils.functional import cached_property
 from modelcluster.fields import ParentalKey
 from modelcluster.models import ClusterableModel
 from wagtail.wagtailadmin import edit_handlers
@@ -30,13 +31,30 @@
 
 class ProjectSelectionBlock(blocks.ChooserBlock):
     target_model = Project
-    widget = widgets.Select
+    widget = forms.widgets.Select
+
+    @cached_property
+    def field(self):
+        return forms.ModelChoiceField(
+            queryset=self.target_model.objects.filter(
+                is_draft=False,
+                is_archived=False,
+                is_public=True),
+            widget=self.widget,
+            required=self._required,
+            help_text=self._help_text)
 
     def value_for_form(self, value):
         if isinstance(value, Project):
             return value.pk
         return value
 
+    def value_from_form(self, value):
+        # if project became unavailable (unpublished), selection will become an
+        # empty string and cause a server error on save, so we give a fallback
+        value = value or None
+        return super().value_from_form(value)
+
 
 class ProjectsWrapperBlock(blocks.StructBlock):
     title = blocks.CharBlock(max_length=80)

{"golden_diff": "diff --git a/apps/cms/models.py b/apps/cms/models.py\n--- a/apps/cms/models.py\n+++ b/apps/cms/models.py\n@@ -1,5 +1,6 @@\n+from django import forms\n from django.db import models\n-from django.forms import widgets\n+from django.utils.functional import cached_property\n from modelcluster.fields import ParentalKey\n from modelcluster.models import ClusterableModel\n from wagtail.wagtailadmin import edit_handlers\n@@ -30,13 +31,30 @@\n \n class ProjectSelectionBlock(blocks.ChooserBlock):\n     target_model = Project\n-    widget = widgets.Select\n+    widget = forms.widgets.Select\n+\n+    @cached_property\n+    def field(self):\n+        return forms.ModelChoiceField(\n+            queryset=self.target_model.objects.filter(\n+                is_draft=False,\n+                is_archived=False,\n+                is_public=True),\n+            widget=self.widget,\n+            required=self._required,\n+            help_text=self._help_text)\n \n     def value_for_form(self, value):\n         if isinstance(value, Project):\n             return value.pk\n         return value\n \n+    def value_from_form(self, value):\n+        # if project became unavailable (unpublished), selection will become an\n+        # empty string and cause a server error on save, so we give a fallback\n+        value = value or None\n+        return super().value_from_form(value)\n+\n \n class ProjectsWrapperBlock(blocks.StructBlock):\n     title = blocks.CharBlock(max_length=80)\n", "issue": "Filter archived and draft projects from the wagtail frontpage selection element\n\n", "before_files": [{"content": "from django.db import models\nfrom django.forms import widgets\nfrom modelcluster.fields import ParentalKey\nfrom modelcluster.models import ClusterableModel\nfrom wagtail.wagtailadmin import edit_handlers\nfrom wagtail.wagtailcore import blocks\nfrom wagtail.wagtailcore import fields\nfrom wagtail.wagtailcore.models import Orderable\nfrom wagtail.wagtailcore.models import Page\nfrom wagtail.wagtailforms.models import AbstractEmailForm\nfrom wagtail.wagtailforms.models import AbstractFormField\nfrom wagtail.wagtailimages.edit_handlers import ImageChooserPanel\nfrom wagtail.wagtailsnippets.models import register_snippet\n\nfrom adhocracy4.projects.models import Project\n\nfrom . import emails\n\n\nclass SimplePage(Page):\n    body = fields.RichTextField(blank=True)\n\n    content_panels = [\n        edit_handlers.FieldPanel('title'),\n        edit_handlers.FieldPanel('body'),\n    ]\n\n    subpage_types = []\n\n\nclass ProjectSelectionBlock(blocks.ChooserBlock):\n    target_model = Project\n    widget = widgets.Select\n\n    def value_for_form(self, value):\n        if isinstance(value, Project):\n            return value.pk\n        return value\n\n\nclass ProjectsWrapperBlock(blocks.StructBlock):\n    title = blocks.CharBlock(max_length=80)\n    projects = blocks.ListBlock(\n        ProjectSelectionBlock(label='Project'),\n    )\n\n    class Meta:\n        template = 'meinberlin_cms/blocks/projects_block.html'\n\n\nclass CallToActionBlock(blocks.StructBlock):\n    body = blocks.RichTextBlock()\n    link = blocks.CharBlock()\n    link_text = blocks.CharBlock(max_length=50, label='Link Text')\n\n    class Meta:\n        template = 'meinberlin_cms/blocks/cta_block.html'\n\n\nclass ColumnsBlock(blocks.StructBlock):\n    columns_count = blocks.ChoiceBlock(choices=[\n        (2, 'Two columns'),\n        (3, 'Three columns'),\n        (4, 'Four columns'),\n    ], default=2)\n\n    columns = blocks.ListBlock(\n        blocks.RichTextBlock(label='Column body'),\n    )\n\n    class Meta:\n        template = 'meinberlin_cms/blocks/columns_block.html'\n\n\nclass HomePage(Page):\n    body = fields.StreamField([\n        ('paragraph', blocks.RichTextBlock(\n            template='meinberlin_cms/blocks/richtext_block.html'\n        )),\n        ('call_to_action', CallToActionBlock()),\n        ('columns_text', ColumnsBlock()),\n        ('projects', ProjectsWrapperBlock()),\n    ])\n\n    subtitle = models.CharField(max_length=120)\n\n    header_image = models.ForeignKey(\n        'wagtailimages.Image',\n        null=True,\n        blank=False,\n        on_delete=models.SET_NULL,\n        related_name='+'\n    )\n\n    content_panels = Page.content_panels + [\n        edit_handlers.FieldPanel('subtitle'),\n        ImageChooserPanel('header_image'),\n        edit_handlers.StreamFieldPanel('body'),\n    ]\n\n\nclass MenuItem(models.Model):\n    title = models.CharField(max_length=255)\n    link_page = models.ForeignKey('wagtailcore.Page')\n\n    @property\n    def url(self):\n        return self.link_page.url\n\n    def __str__(self):\n        return self.title\n\n    panels = [\n        edit_handlers.FieldPanel('title'),\n        edit_handlers.PageChooserPanel('link_page')\n    ]\n\n\n@register_snippet\nclass NavigationMenu(ClusterableModel):\n    title = models.CharField(max_length=255, null=False, blank=False)\n\n    def __str__(self):\n        return self.title\n\n    panels = [\n        edit_handlers.FieldPanel('title'),\n        edit_handlers.InlinePanel('items')\n    ]\n\n\nclass NavigationMenuItem(Orderable, MenuItem):\n    parent = ParentalKey('meinberlin_cms.NavigationMenu', related_name='items')\n\n\nclass EmailFormField(AbstractFormField):\n    page = ParentalKey('EmailFormPage', related_name='form_fields')\n\n\nclass EmailFormPage(AbstractEmailForm):\n    intro = fields.RichTextField(\n        help_text='Introduction text shown above the form'\n    )\n    thank_you = fields.RichTextField(\n        help_text='Text shown after form submission',\n    )\n    email_content = models.CharField(\n        max_length=200,\n        help_text='Email content message',\n    )\n    attach_as = models.CharField(\n        max_length=3,\n        choices=(\n            ('csv', 'CSV Document'),\n            ('txt', 'Text'),\n        ),\n        default='csv',\n        help_text='Form results are send in this document format',\n    )\n\n    content_panels = AbstractEmailForm.content_panels + [\n        edit_handlers.MultiFieldPanel([\n            edit_handlers.FieldPanel('intro', classname='full'),\n            edit_handlers.FieldPanel('thank_you', classname='full'),\n        ], 'Page'),\n        edit_handlers.MultiFieldPanel([\n            edit_handlers.FieldPanel('to_address'),\n            edit_handlers.FieldPanel('subject'),\n            edit_handlers.FieldPanel('email_content', classname='full'),\n            edit_handlers.FieldPanel('attach_as'),\n        ], 'Email'),\n        edit_handlers.InlinePanel('form_fields', label='Form fields'),\n    ]\n\n    def send_mail(self, form):\n        self.form = form\n        if self.attach_as == 'csv':\n            emails.CsvFormEmail.send(self)\n        elif self.attach_as == 'txt':\n            emails.TextFormEmail.send(self)\n\n    @property\n    def field_values(self):\n        fields = {}\n        for field in self.form:\n            value = field.value()\n            if isinstance(value, list):\n                value = ', '.join(value)\n            fields[field.label] = value\n        return fields\n", "path": "apps/cms/models.py"}], "after_files": [{"content": "from django import forms\nfrom django.db import models\nfrom django.utils.functional import cached_property\nfrom modelcluster.fields import ParentalKey\nfrom modelcluster.models import ClusterableModel\nfrom wagtail.wagtailadmin import edit_handlers\nfrom wagtail.wagtailcore import blocks\nfrom wagtail.wagtailcore import fields\nfrom wagtail.wagtailcore.models import Orderable\nfrom wagtail.wagtailcore.models import Page\nfrom wagtail.wagtailforms.models import AbstractEmailForm\nfrom wagtail.wagtailforms.models import AbstractFormField\nfrom wagtail.wagtailimages.edit_handlers import ImageChooserPanel\nfrom wagtail.wagtailsnippets.models import register_snippet\n\nfrom adhocracy4.projects.models import Project\n\nfrom . import emails\n\n\nclass SimplePage(Page):\n    body = fields.RichTextField(blank=True)\n\n    content_panels = [\n        edit_handlers.FieldPanel('title'),\n        edit_handlers.FieldPanel('body'),\n    ]\n\n    subpage_types = []\n\n\nclass ProjectSelectionBlock(blocks.ChooserBlock):\n    target_model = Project\n    widget = forms.widgets.Select\n\n    @cached_property\n    def field(self):\n        return forms.ModelChoiceField(\n            queryset=self.target_model.objects.filter(\n                is_draft=False,\n                is_archived=False,\n                is_public=True),\n            widget=self.widget,\n            required=self._required,\n            help_text=self._help_text)\n\n    def value_for_form(self, value):\n        if isinstance(value, Project):\n            return value.pk\n        return value\n\n    def value_from_form(self, value):\n        # if project became unavailable (unpublished), selection will become an\n        # empty string and cause a server error on save, so we give a fallback\n        value = value or None\n        return super().value_from_form(value)\n\n\nclass ProjectsWrapperBlock(blocks.StructBlock):\n    title = blocks.CharBlock(max_length=80)\n    projects = blocks.ListBlock(\n        ProjectSelectionBlock(label='Project'),\n    )\n\n    class Meta:\n        template = 'meinberlin_cms/blocks/projects_block.html'\n\n\nclass CallToActionBlock(blocks.StructBlock):\n    body = blocks.RichTextBlock()\n    link = blocks.CharBlock()\n    link_text = blocks.CharBlock(max_length=50, label='Link Text')\n\n    class Meta:\n        template = 'meinberlin_cms/blocks/cta_block.html'\n\n\nclass ColumnsBlock(blocks.StructBlock):\n    columns_count = blocks.ChoiceBlock(choices=[\n        (2, 'Two columns'),\n        (3, 'Three columns'),\n        (4, 'Four columns'),\n    ], default=2)\n\n    columns = blocks.ListBlock(\n        blocks.RichTextBlock(label='Column body'),\n    )\n\n    class Meta:\n        template = 'meinberlin_cms/blocks/columns_block.html'\n\n\nclass HomePage(Page):\n    body = fields.StreamField([\n        ('paragraph', blocks.RichTextBlock(\n            template='meinberlin_cms/blocks/richtext_block.html'\n        )),\n        ('call_to_action', CallToActionBlock()),\n        ('columns_text', ColumnsBlock()),\n        ('projects', ProjectsWrapperBlock()),\n    ])\n\n    subtitle = models.CharField(max_length=120)\n\n    header_image = models.ForeignKey(\n        'wagtailimages.Image',\n        null=True,\n        blank=False,\n        on_delete=models.SET_NULL,\n        related_name='+'\n    )\n\n    content_panels = Page.content_panels + [\n        edit_handlers.FieldPanel('subtitle'),\n        ImageChooserPanel('header_image'),\n        edit_handlers.StreamFieldPanel('body'),\n    ]\n\n\nclass MenuItem(models.Model):\n    title = models.CharField(max_length=255)\n    link_page = models.ForeignKey('wagtailcore.Page')\n\n    @property\n    def url(self):\n        return self.link_page.url\n\n    def __str__(self):\n        return self.title\n\n    panels = [\n        edit_handlers.FieldPanel('title'),\n        edit_handlers.PageChooserPanel('link_page')\n    ]\n\n\n@register_snippet\nclass NavigationMenu(ClusterableModel):\n    title = models.CharField(max_length=255, null=False, blank=False)\n\n    def __str__(self):\n        return self.title\n\n    panels = [\n        edit_handlers.FieldPanel('title'),\n        edit_handlers.InlinePanel('items')\n    ]\n\n\nclass NavigationMenuItem(Orderable, MenuItem):\n    parent = ParentalKey('meinberlin_cms.NavigationMenu', related_name='items')\n\n\nclass EmailFormField(AbstractFormField):\n    page = ParentalKey('EmailFormPage', related_name='form_fields')\n\n\nclass EmailFormPage(AbstractEmailForm):\n    intro = fields.RichTextField(\n        help_text='Introduction text shown above the form'\n    )\n    thank_you = fields.RichTextField(\n        help_text='Text shown after form submission',\n    )\n    email_content = models.CharField(\n        max_length=200,\n        help_text='Email content message',\n    )\n    attach_as = models.CharField(\n        max_length=3,\n        choices=(\n            ('csv', 'CSV Document'),\n            ('txt', 'Text'),\n        ),\n        default='csv',\n        help_text='Form results are send in this document format',\n    )\n\n    content_panels = AbstractEmailForm.content_panels + [\n        edit_handlers.MultiFieldPanel([\n            edit_handlers.FieldPanel('intro', classname='full'),\n            edit_handlers.FieldPanel('thank_you', classname='full'),\n        ], 'Page'),\n        edit_handlers.MultiFieldPanel([\n            edit_handlers.FieldPanel('to_address'),\n            edit_handlers.FieldPanel('subject'),\n            edit_handlers.FieldPanel('email_content', classname='full'),\n            edit_handlers.FieldPanel('attach_as'),\n        ], 'Email'),\n        edit_handlers.InlinePanel('form_fields', label='Form fields'),\n    ]\n\n    def send_mail(self, form):\n        self.form = form\n        if self.attach_as == 'csv':\n            emails.CsvFormEmail.send(self)\n        elif self.attach_as == 'txt':\n            emails.TextFormEmail.send(self)\n\n    @property\n    def field_values(self):\n        fields = {}\n        for field in self.form:\n            value = field.value()\n            if isinstance(value, list):\n                value = ', '.join(value)\n            fields[field.label] = value\n        return fields\n", "path": "apps/cms/models.py"}]}