mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-22 05:51:53 +00:00
FormSubmissionsPanel to use get_submission_class
This commit is contained in:
parent
9610c2d3af
commit
a42893f497
4 changed files with 51 additions and 3 deletions
|
|
@ -32,6 +32,7 @@ Changelog
|
|||
* Fix: Fixed incorrect z-index on userbar causing it to appear behind page content (Stein Strindhaug)
|
||||
* Fix: Form submissions pagination no longer looses date filter when changing page (Bertrand Bordage)
|
||||
* Fix: PostgreSQL search backend now removes duplicate page instances from the database (Bertrand Bordage)
|
||||
* Fix: `FormSubmissionsPanel` now recognises custom form submission classes (LB (Ben Johnston))
|
||||
|
||||
|
||||
1.13.1 (17.11.2017)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ Bug fixes
|
|||
* Fixed incorrect z-index on userbar causing it to appear behind page content (Stein Strindhaug)
|
||||
* Form submissions pagination no longer looses date filter when changing page (Bertrand Bordage)
|
||||
* PostgreSQL search backend now removes duplicate page instances from the database (Bertrand Bordage)
|
||||
* ``FormSubmissionsPanel`` now recognises custom form submission classes (LB (Ben Johnston))
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ class BaseFormSubmissionsPanel(EditHandler):
|
|||
template = "wagtailforms/edit_handlers/form_responses_panel.html"
|
||||
|
||||
def render(self):
|
||||
from .models import FormSubmission
|
||||
submissions = FormSubmission.objects.filter(page=self.instance)
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ from django.test import TestCase
|
|||
from django.urls import reverse
|
||||
|
||||
from wagtail.tests.testapp.models import (
|
||||
CustomFormPageSubmission, FormField, FormFieldWithCustomSubmission, FormPage)
|
||||
CustomFormPageSubmission, FormField, FormFieldWithCustomSubmission,
|
||||
FormPage, FormPageWithCustomSubmission)
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
from wagtail.admin.edit_handlers import get_form_for_model
|
||||
from wagtail.admin.forms import WagtailAdminPageForm
|
||||
|
|
@ -50,6 +51,50 @@ class TestFormResponsesPanel(TestCase):
|
|||
self.assertEqual('', result)
|
||||
|
||||
|
||||
class TestFormResponsesPanelWithCustomSubmissionClass(TestCase):
|
||||
def setUp(self):
|
||||
# Create a form page
|
||||
self.form_page = make_form_page_with_custom_submission()
|
||||
|
||||
self.FormPageForm = get_form_for_model(
|
||||
FormPageWithCustomSubmission, form_class=WagtailAdminPageForm
|
||||
)
|
||||
|
||||
self.test_user = get_user_model().objects.create_user(
|
||||
username='user-n1kola', password='123')
|
||||
|
||||
submissions_panel = FormSubmissionsPanel().bind_to_model(FormPageWithCustomSubmission)
|
||||
|
||||
self.panel = submissions_panel(self.form_page, self.FormPageForm())
|
||||
|
||||
def test_render_with_submissions(self):
|
||||
"""Show the panel with the count of submission and a link to the list_submissions view."""
|
||||
new_form_submission = CustomFormPageSubmission.objects.create(
|
||||
user=self.test_user,
|
||||
page=self.form_page,
|
||||
form_data=json.dumps({
|
||||
'your-email': 'email@domain.com',
|
||||
'your-message': 'hi joe',
|
||||
'your-choices': {'foo': '', 'bar': '', 'baz': ''}
|
||||
}),
|
||||
)
|
||||
new_form_submission.submit_time = '2017-08-29T12:00:00.000Z'
|
||||
new_form_submission.save()
|
||||
|
||||
result = self.panel.render()
|
||||
|
||||
url = reverse('wagtailforms:list_submissions', args=(self.form_page.id,))
|
||||
link = '<a href="{}">1</a>'.format(url)
|
||||
|
||||
self.assertIn(link, result)
|
||||
|
||||
def test_render_without_submissions(self):
|
||||
"""The panel should not be shown if the number of submission is zero."""
|
||||
result = self.panel.render()
|
||||
|
||||
self.assertEqual('', result)
|
||||
|
||||
|
||||
class TestFormsIndex(TestCase, WagtailTestUtils):
|
||||
fixtures = ['test.json']
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue