浏览代码

Move wagtail.contrib.forms.edit_handlers to wagtail.contrib.forms.panels

Matt Westcott 3 年之前
父节点
当前提交
c7774ba0be

+ 1 - 1
docs/reference/contrib/forms/index.md

@@ -91,7 +91,7 @@ You now need to create two templates named `form_page.html` and `form_page_landi
 `FormSubmissionsPanel` can be added to your page's panel definitions to display the number of form submissions and the time of the most recent submission, along with a quick link to access the full submission data:
 
 ```python
-from wagtail.contrib.forms.edit_handlers import FormSubmissionsPanel
+from wagtail.contrib.forms.panels import FormSubmissionsPanel
 
 class FormPage(AbstractEmailForm):
     # ...

+ 2 - 2
docs/reference/pages/panels.rst

@@ -188,7 +188,7 @@ ImageChooserPanel
 FormSubmissionsPanel
 ~~~~~~~~~~~~~~~~~~~~
 
-.. module:: wagtail.contrib.forms.edit_handlers
+.. module:: wagtail.contrib.forms.panels
 
 .. class:: FormSubmissionsPanel
 
@@ -198,7 +198,7 @@ FormSubmissionsPanel
     .. code-block:: python
 
         from wagtail.contrib.forms.models import AbstractForm
-        from wagtail.contrib.forms.edit_handlers import FormSubmissionsPanel
+        from wagtail.contrib.forms.panels import FormSubmissionsPanel
 
         class ContactFormPage(AbstractForm):
             content_panels = [

+ 4 - 0
wagtail/bin/wagtail.py

@@ -154,6 +154,10 @@ class UpdateModulePaths(Command):
         (re.compile(r"\bwagtail\.tests\b"), "wagtail.test"),
         (re.compile(r"\bwagtail\.core\b"), "wagtail"),
         (re.compile(r"\bwagtail\.admin\.edit_handlers\b"), "wagtail.admin.panels"),
+        (
+            re.compile(r"\bwagtail\.contrib\.forms\.edit_handlers\b"),
+            "wagtail.contrib.forms.panels",
+        ),
     ]
 
     def add_arguments(self, parser):

+ 1 - 35
wagtail/contrib/forms/edit_handlers.py

@@ -1,35 +1 @@
-from django.template.loader import render_to_string
-from django.utils.safestring import mark_safe
-from django.utils.translation import gettext as _
-
-from wagtail.admin.panels import EditHandler
-
-
-class FormSubmissionsPanel(EditHandler):
-    template = "wagtailforms/edit_handlers/form_responses_panel.html"
-
-    def render(self):
-        form_page_model = self.model
-        form_submissions_model = form_page_model().get_submission_class()
-        submissions = form_submissions_model.objects.filter(page=self.instance)
-        submission_count = submissions.count()
-
-        if not submission_count:
-            return ""
-
-        return mark_safe(
-            render_to_string(
-                self.template,
-                {
-                    "self": self,
-                    "submission_count": submission_count,
-                    "last_submit_time": submissions.order_by("submit_time")
-                    .last()
-                    .submit_time,
-                },
-            )
-        )
-
-    def on_model_bound(self):
-        if not self.heading:
-            self.heading = _("%s submissions") % self.model.get_verbose_name()
+from wagtail.contrib.forms.panels import *  # noqa

+ 35 - 0
wagtail/contrib/forms/panels.py

@@ -0,0 +1,35 @@
+from django.template.loader import render_to_string
+from django.utils.safestring import mark_safe
+from django.utils.translation import gettext as _
+
+from wagtail.admin.panels import EditHandler
+
+
+class FormSubmissionsPanel(EditHandler):
+    template = "wagtailforms/edit_handlers/form_responses_panel.html"
+
+    def render(self):
+        form_page_model = self.model
+        form_submissions_model = form_page_model().get_submission_class()
+        submissions = form_submissions_model.objects.filter(page=self.instance)
+        submission_count = submissions.count()
+
+        if not submission_count:
+            return ""
+
+        return mark_safe(
+            render_to_string(
+                self.template,
+                {
+                    "self": self,
+                    "submission_count": submission_count,
+                    "last_submit_time": submissions.order_by("submit_time")
+                    .last()
+                    .submit_time,
+                },
+            )
+        )
+
+    def on_model_bound(self):
+        if not self.heading:
+            self.heading = _("%s submissions") % self.model.get_verbose_name()

+ 1 - 1
wagtail/contrib/forms/tests/test_views.py

@@ -12,8 +12,8 @@ from openpyxl import load_workbook
 
 from wagtail.admin.forms import WagtailAdminPageForm
 from wagtail.admin.panels import get_form_for_model
-from wagtail.contrib.forms.edit_handlers import FormSubmissionsPanel
 from wagtail.contrib.forms.models import FormSubmission
+from wagtail.contrib.forms.panels import FormSubmissionsPanel
 from wagtail.contrib.forms.tests.utils import (
     make_form_page,
     make_form_page_with_custom_submission,