From 2a84d7ef1dbbc1bb7b93c0bc49b214598c2d8f1d Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 3 Jun 2014 11:57:48 +0100 Subject: [PATCH 01/11] A few improvements to the wagtailforms submission tests --- wagtail/tests/fixtures/test.json | 3 +++ wagtail/wagtailforms/tests.py | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/wagtail/tests/fixtures/test.json b/wagtail/tests/fixtures/test.json index 11b82d9f16..541450211c 100644 --- a/wagtail/tests/fixtures/test.json +++ b/wagtail/tests/fixtures/test.json @@ -183,6 +183,9 @@ "pk": 8, "model": "tests.formpage", "fields": { + "to_address": "to@email.com", + "from_address": "from@email.com", + "subject": "The subject" } }, diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index 8ec2ee5c38..459dbbea4a 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -1,32 +1,50 @@ from django.test import TestCase +from django.core import mail from wagtail.wagtailcore.models import Page from wagtail.wagtailforms.models import FormSubmission + class TestFormSubmission(TestCase): fixtures = ['test.json'] def test_get_form(self): response = self.client.get('/contact-us/') + + # Check response self.assertContains(response, """""") - self.assertNotContains(response, "Thank you for your feedback") + self.assertTemplateUsed(response, 'tests/form_page.html') + self.assertTemplateNotUsed(response, 'tests/form_page_landing.html') def test_post_invalid_form(self): response = self.client.post('/contact-us/', { 'your-email': 'bob', 'your-message': 'hello world' }) - self.assertNotContains(response, "Thank you for your feedback") + + # Check response self.assertContains(response, "Enter a valid email address.") + self.assertTemplateUsed(response, 'tests/form_page.html') + self.assertTemplateNotUsed(response, 'tests/form_page_landing.html') def test_post_valid_form(self): response = self.client.post('/contact-us/', { 'your-email': 'bob@example.com', 'your-message': 'hello world' }) - self.assertNotContains(response, "Your email") - self.assertContains(response, "Thank you for your feedback") + # Check response + self.assertContains(response, "Thank you for your feedback.") + self.assertTemplateNotUsed(response, 'tests/form_page.html') + self.assertTemplateUsed(response, 'tests/form_page_landing.html') + + # Check that an email was sent + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, "The subject") + self.assertTrue("Your message: hello world" in mail.outbox[0].body) + self.assertEqual(mail.outbox[0].to, ['to@email.com']) + self.assertEqual(mail.outbox[0].from_email, 'from@email.com') + + # Check that form submission was saved correctly form_page = Page.objects.get(url_path='/home/contact-us/') - self.assertTrue(FormSubmission.objects.filter(page=form_page, form_data__contains='hello world').exists()) From 7cf899bdbc8835a05a7896fd4eaaa2452d0ddbd8 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 3 Jun 2014 17:03:33 +0100 Subject: [PATCH 02/11] Added test for FormBuilder class --- wagtail/wagtailforms/tests.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index 459dbbea4a..ac18c7fa71 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -1,8 +1,10 @@ from django.test import TestCase from django.core import mail +from django import forms from wagtail.wagtailcore.models import Page from wagtail.wagtailforms.models import FormSubmission +from wagtail.wagtailforms.forms import FormBuilder class TestFormSubmission(TestCase): @@ -48,6 +50,26 @@ class TestFormSubmission(TestCase): self.assertTrue(FormSubmission.objects.filter(page=form_page, form_data__contains='hello world').exists()) +class TestFormBuilder(TestCase): + fixtures = ['test.json'] + + def setUp(self): + self.form_page = Page.objects.get(url_path='/home/contact-us/').specific + self.fb = FormBuilder(self.form_page.form_fields.all()) + + def test_fields(self): + """ + This tests that all fields were added to the form with the correct types + """ + form_class = self.fb.get_form_class() + + self.assertTrue('your-email' in form_class.base_fields.keys()) + self.assertTrue('your-message' in form_class.base_fields.keys()) + + self.assertIsInstance(form_class.base_fields['your-email'], forms.EmailField) + self.assertIsInstance(form_class.base_fields['your-message'], forms.CharField) + + class TestFormsBackend(TestCase): fixtures = ['test.json'] From 97a981a7660154027df1da4f8a2cc314e701d037 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 3 Jun 2014 17:12:08 +0100 Subject: [PATCH 03/11] Cleaned up FormBuilder class --- wagtail/wagtailforms/forms.py | 53 +++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/wagtail/wagtailforms/forms.py b/wagtail/wagtailforms/forms.py index f17023a773..aaf16eb792 100644 --- a/wagtail/wagtailforms/forms.py +++ b/wagtail/wagtailforms/forms.py @@ -8,22 +8,9 @@ class BaseForm(django.forms.Form): return super(BaseForm, self).__init__(*args, **kwargs) -class FormBuilder(): - formfields = SortedDict() - +class FormBuilder(object): def __init__(self, fields): - for field in fields: - options = self.get_options(field) - f = getattr(self, "create_"+field.field_type+"_field")(field, options) - self.formfields[field.clean_name] = f - - def get_options(self, field): - options = {} - options['label'] = field.label - options['help_text'] = field.help_text - options['required'] = field.required - options['initial'] = field.default_value - return options + self.fields = fields def create_singleline_field(self, field, options): # TODO: This is a default value - it may need to be changed @@ -72,6 +59,42 @@ class FormBuilder(): def create_checkbox_field(self, field, options): return django.forms.BooleanField(**options) + FIELD_TYPES = { + 'singleline': create_singleline_field, + 'multiline': create_multiline_field, + 'date': create_date_field, + 'datetime': create_datetime_field, + 'email': create_email_field, + 'url': create_url_field, + 'number': create_number_field, + 'dropdown': create_dropdown_field, + 'radio': create_radio_field, + 'checkboxes': create_checkboxes_field, + 'checkbox': create_checkbox_field, + } + + @property + def formfields(self): + formfields = SortedDict() + + for field in self.fields: + options = self.get_field_options(field) + + if field.field_type in self.FIELD_TYPES: + formfields[field.clean_name] = self.FIELD_TYPES[field.field_type](self, field, options) + else: + raise Exception("Unrecognised field type: " + form.field_type) + + return formfields + + def get_field_options(self, field): + options = {} + options['label'] = field.label + options['help_text'] = field.help_text + options['required'] = field.required + options['initial'] = field.default_value + return options + def get_form_class(self): return type('WagtailForm', (BaseForm,), self.formfields) From 21ac2e3ab8bb3c52b45b7ae005a5c87a83785def Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 3 Jun 2014 17:27:48 +0100 Subject: [PATCH 04/11] Split wagtailforms landing page into separate view --- wagtail/wagtailforms/models.py | 26 +++++++++++++++++--------- wagtail/wagtailforms/tests.py | 12 +++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/wagtail/wagtailforms/models.py b/wagtail/wagtailforms/models.py index 75f0eceee0..59941c6abd 100644 --- a/wagtail/wagtailforms/models.py +++ b/wagtail/wagtailforms/models.py @@ -1,5 +1,5 @@ from django.db import models -from django.shortcuts import render +from django.shortcuts import render, redirect from django.utils.translation import ugettext_lazy as _ from django.utils.text import slugify @@ -111,6 +111,7 @@ class AbstractForm(Page): """A Form Page. Pages implementing a form should inhert from it""" form_builder = FormBuilder + landing_page_path = 'done' is_abstract = True # Don't display me in "Add" def __init__(self, *args, **kwargs): @@ -152,11 +153,8 @@ class AbstractForm(Page): form_processor = self.form_processing_backend() form_processor.process(self, form) - # render the landing_page - # TODO: It is much better to redirect to it - return render(request, self.landing_page_template, { - 'self': self, - }) + # Redirect to the landing page + return redirect(self.url + self.landing_page_path + '/') else: form = form_class(**form_params) @@ -165,6 +163,18 @@ class AbstractForm(Page): 'form': form, }) + def serve_landing(self, request): + return render(request, self.landing_page_template, { + 'self': self, + }) + + def route(self, request, path_components): + # Check if this request is for the landing page + if self.live and path_components == [self.landing_page_path]: + return self.serve_landing(request) + + return super(AbstractForm, self).route(request, path_components) + def get_page_modes(self): return [ ('form', 'Form'), @@ -173,9 +183,7 @@ class AbstractForm(Page): def show_as_mode(self, mode): if mode == 'landing': - return render(self.dummy_request(), self.landing_page_template, { - 'self': self, - }) + return self.serve_landing(self.dummy_request()) else: return super(AbstractForm, self).show_as_mode(mode) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index ac18c7fa71..2276d10d97 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -34,9 +34,7 @@ class TestFormSubmission(TestCase): }) # Check response - self.assertContains(response, "Thank you for your feedback.") - self.assertTemplateNotUsed(response, 'tests/form_page.html') - self.assertTemplateUsed(response, 'tests/form_page_landing.html') + self.assertEqual(response.status_code, 302) # Check that an email was sent self.assertEqual(len(mail.outbox), 1) @@ -49,6 +47,14 @@ class TestFormSubmission(TestCase): form_page = Page.objects.get(url_path='/home/contact-us/') self.assertTrue(FormSubmission.objects.filter(page=form_page, form_data__contains='hello world').exists()) + def test_get_landing_page(self): + response = self.client.get('/contact-us/done/') + + # Check response + self.assertContains(response, "Thank you for your feedback.") + self.assertTemplateNotUsed(response, 'tests/form_page.html') + self.assertTemplateUsed(response, 'tests/form_page_landing.html') + class TestFormBuilder(TestCase): fixtures = ['test.json'] From 6d67749f5a084b22a8ac9eac5894bfdf2e9dbd66 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 4 Jun 2014 15:48:48 +0100 Subject: [PATCH 05/11] Cleanup of TestFormsBackend TestcAse --- wagtail/wagtailforms/tests.py | 38 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index 2276d10d97..019f992d86 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -79,31 +79,43 @@ class TestFormBuilder(TestCase): class TestFormsBackend(TestCase): fixtures = ['test.json'] - def test_cannot_see_forms_without_permission(self): - form_page = Page.objects.get(url_path='/home/contact-us/') + def setUp(self): + self.client.login(username='siteeditor', password='password') + self.form_page = Page.objects.get(url_path='/home/contact-us/') + def test_cannot_see_forms_without_permission(self): + # Login with as a user without permission to see forms self.client.login(username='eventeditor', password='password') + response = self.client.get('/admin/forms/') - self.assertFalse(form_page in response.context['form_pages']) + + # Check that the user cannot see the form page + self.assertFalse(self.form_page in response.context['form_pages']) def test_can_see_forms_with_permission(self): - form_page = Page.objects.get(url_path='/home/contact-us/') - - self.client.login(username='siteeditor', password='password') response = self.client.get('/admin/forms/') - self.assertTrue(form_page in response.context['form_pages']) - def test_can_get_submissions(self): - form_page = Page.objects.get(url_path='/home/contact-us/') + # Check that the user can see the form page + self.assertTrue(self.form_page in response.context['form_pages']) - self.client.login(username='siteeditor', password='password') + def test_list_submissions(self): + response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id) - response = self.client.get('/admin/forms/submissions/%d/' % form_page.id) + # Check response + self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['data_rows']), 2) - response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014' % form_page.id) + def test_list_submissions_filtered(self): + response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014' % self.form_page.id) + + # Check response + self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['data_rows']), 1) - response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014&action=CSV' % form_page.id) + def test_list_submissions_csv_export(self): + response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014&action=CSV' % self.form_page.id) + + # Check response + self.assertEqual(response.status_code, 200) data_line = response.content.split("\n")[1] self.assertTrue('new@example.com' in data_line) From 7e7885b2b514856de0b53c513f2450201be573a6 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 4 Jun 2014 15:55:25 +0100 Subject: [PATCH 06/11] Added tests for wagtailforms page modes --- wagtail/wagtailforms/tests.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index 019f992d86..ab65f909b6 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -56,6 +56,29 @@ class TestFormSubmission(TestCase): self.assertTemplateUsed(response, 'tests/form_page_landing.html') +class TestPageModes(TestCase): + fixtures = ['test.json'] + + def setUp(self): + self.form_page = Page.objects.get(url_path='/home/contact-us/').specific + + def test_form(self): + response = self.form_page.show_as_mode('form') + + # Check response + self.assertContains(response, """""") + self.assertTemplateUsed(response, 'tests/form_page.html') + self.assertTemplateNotUsed(response, 'tests/form_page_landing.html') + + def test_landing(self): + response = self.form_page.show_as_mode('landing') + + # Check response + self.assertContains(response, "Thank you for your feedback.") + self.assertTemplateNotUsed(response, 'tests/form_page.html') + self.assertTemplateUsed(response, 'tests/form_page_landing.html') + + class TestFormBuilder(TestCase): fixtures = ['test.json'] From 24df26c8c338562e64dad8440709175d99f488fe Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 4 Jun 2014 16:25:05 +0100 Subject: [PATCH 07/11] More wagtailforms tests --- wagtail/wagtailforms/tests.py | 127 +++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index ab65f909b6..5145eae3f8 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -1,3 +1,5 @@ +import json + from django.test import TestCase from django.core import mail from django import forms @@ -5,6 +7,7 @@ from django import forms from wagtail.wagtailcore.models import Page from wagtail.wagtailforms.models import FormSubmission from wagtail.wagtailforms.forms import FormBuilder +from wagtail.tests.models import FormPage class TestFormSubmission(TestCase): @@ -99,13 +102,74 @@ class TestFormBuilder(TestCase): self.assertIsInstance(form_class.base_fields['your-message'], forms.CharField) -class TestFormsBackend(TestCase): +class TestFormsIndex(TestCase): fixtures = ['test.json'] def setUp(self): self.client.login(username='siteeditor', password='password') self.form_page = Page.objects.get(url_path='/home/contact-us/') + def make_form_pages(self): + """ + This makes 100 form pages and adds them as children to 'contact-us' + This is used to test pagination on the forms index + """ + for i in range(100): + self.form_page.add_child(instance=FormPage( + title="Form " + str(i), + slug='form-' + str(i), + live=True + )) + + def test_forms_index(self): + response = self.client.get('/admin/forms/') + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index.html') + + def test_forms_index_pagination(self): + # Create some more form pages to make pagination kick in + self.make_form_pages() + + # Get page two + response = self.client.get('/admin/forms/', {'p': 2}) + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index.html') + + # Check that we got the correct page + self.assertEqual(response.context['form_pages'].number, 2) + + def test_forms_index_pagination_invalid(self): + # Create some more form pages to make pagination kick in + self.make_form_pages() + + # Get page two + response = self.client.get('/admin/forms/', {'p': 'Hello world!'}) + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index.html') + + # Check that it got page one + self.assertEqual(response.context['form_pages'].number, 1) + + def test_forms_index_pagination_out_of_range(self): + # Create some more form pages to make pagination kick in + self.make_form_pages() + + # Get page two + response = self.client.get('/admin/forms/', {'p': 99999}) + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index.html') + + # Check that it got the last page + self.assertEqual(response.context['form_pages'].number, response.context['form_pages'].paginator.num_pages) + def test_cannot_see_forms_without_permission(self): # Login with as a user without permission to see forms self.client.login(username='eventeditor', password='password') @@ -121,20 +185,79 @@ class TestFormsBackend(TestCase): # Check that the user can see the form page self.assertTrue(self.form_page in response.context['form_pages']) + +class TestFormsSubmissions(TestCase): + fixtures = ['test.json'] + + def setUp(self): + self.client.login(username='siteeditor', password='password') + self.form_page = Page.objects.get(url_path='/home/contact-us/') + + def make_list_submissions(self): + """ + This makes 100 submissions to test pagination on the forms submissions page + """ + for i in range(100): + submission = FormSubmission( + page=self.form_page, + form_data=json.dumps({ + 'hello': 'world' + }) + ) + submission.save() + def test_list_submissions(self): response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id) # Check response self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index_submissions.html') self.assertEqual(len(response.context['data_rows']), 2) - def test_list_submissions_filtered(self): + def test_list_submissions_filtering(self): response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014' % self.form_page.id) # Check response self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index_submissions.html') self.assertEqual(len(response.context['data_rows']), 1) + def test_list_submissions_pagination(self): + self.make_list_submissions() + + response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id, {'p': 2}) + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index_submissions.html') + + # Check that we got the correct page + self.assertEqual(response.context['submissions'].number, 2) + + def test_list_submissions_pagination_invalid(self): + self.make_list_submissions() + + response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id, {'p': 'Hello World!'}) + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index_submissions.html') + + # Check that we got page one + self.assertEqual(response.context['submissions'].number, 1) + + def test_list_submissions_pagination_out_of_range(self): + self.make_list_submissions() + + response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id, {'p': 99999}) + + # Check response + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'wagtailforms/index_submissions.html') + + # Check that we got the last page + self.assertEqual(response.context['submissions'].number, response.context['submissions'].paginator.num_pages) + def test_list_submissions_csv_export(self): response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014&action=CSV' % self.form_page.id) From 2b4b19a6414d2a20654baf540fb89df907622de0 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Wed, 4 Jun 2014 16:38:44 +0100 Subject: [PATCH 08/11] Use reversed URLs in wagtailforms tests --- wagtail/wagtailforms/tests.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index 5145eae3f8..24bace8c52 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -3,6 +3,7 @@ import json from django.test import TestCase from django.core import mail from django import forms +from django.core.urlresolvers import reverse from wagtail.wagtailcore.models import Page from wagtail.wagtailforms.models import FormSubmission @@ -122,7 +123,7 @@ class TestFormsIndex(TestCase): )) def test_forms_index(self): - response = self.client.get('/admin/forms/') + response = self.client.get(reverse('wagtailforms_index')) # Check response self.assertEqual(response.status_code, 200) @@ -133,7 +134,7 @@ class TestFormsIndex(TestCase): self.make_form_pages() # Get page two - response = self.client.get('/admin/forms/', {'p': 2}) + response = self.client.get(reverse('wagtailforms_index'), {'p': 2}) # Check response self.assertEqual(response.status_code, 200) @@ -147,7 +148,7 @@ class TestFormsIndex(TestCase): self.make_form_pages() # Get page two - response = self.client.get('/admin/forms/', {'p': 'Hello world!'}) + response = self.client.get(reverse('wagtailforms_index'), {'p': 'Hello world!'}) # Check response self.assertEqual(response.status_code, 200) @@ -161,7 +162,7 @@ class TestFormsIndex(TestCase): self.make_form_pages() # Get page two - response = self.client.get('/admin/forms/', {'p': 99999}) + response = self.client.get(reverse('wagtailforms_index'), {'p': 99999}) # Check response self.assertEqual(response.status_code, 200) @@ -174,13 +175,13 @@ class TestFormsIndex(TestCase): # Login with as a user without permission to see forms self.client.login(username='eventeditor', password='password') - response = self.client.get('/admin/forms/') + response = self.client.get(reverse('wagtailforms_index')) # Check that the user cannot see the form page self.assertFalse(self.form_page in response.context['form_pages']) def test_can_see_forms_with_permission(self): - response = self.client.get('/admin/forms/') + response = self.client.get(reverse('wagtailforms_index')) # Check that the user can see the form page self.assertTrue(self.form_page in response.context['form_pages']) @@ -207,7 +208,7 @@ class TestFormsSubmissions(TestCase): submission.save() def test_list_submissions(self): - response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id) + response = self.client.get(reverse('wagtailforms_list_submissions', args=(self.form_page.id, ))) # Check response self.assertEqual(response.status_code, 200) @@ -215,7 +216,7 @@ class TestFormsSubmissions(TestCase): self.assertEqual(len(response.context['data_rows']), 2) def test_list_submissions_filtering(self): - response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014' % self.form_page.id) + response = self.client.get(reverse('wagtailforms_list_submissions', args=(self.form_page.id, )), {'date_from': '01/01/2014'}) # Check response self.assertEqual(response.status_code, 200) @@ -225,7 +226,7 @@ class TestFormsSubmissions(TestCase): def test_list_submissions_pagination(self): self.make_list_submissions() - response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id, {'p': 2}) + response = self.client.get(reverse('wagtailforms_list_submissions', args=(self.form_page.id, )), {'p': 2}) # Check response self.assertEqual(response.status_code, 200) @@ -237,7 +238,7 @@ class TestFormsSubmissions(TestCase): def test_list_submissions_pagination_invalid(self): self.make_list_submissions() - response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id, {'p': 'Hello World!'}) + response = self.client.get(reverse('wagtailforms_list_submissions', args=(self.form_page.id, )), {'p': 'Hello World!'}) # Check response self.assertEqual(response.status_code, 200) @@ -249,7 +250,7 @@ class TestFormsSubmissions(TestCase): def test_list_submissions_pagination_out_of_range(self): self.make_list_submissions() - response = self.client.get('/admin/forms/submissions/%d/' % self.form_page.id, {'p': 99999}) + response = self.client.get(reverse('wagtailforms_list_submissions', args=(self.form_page.id, )), {'p': 99999}) # Check response self.assertEqual(response.status_code, 200) @@ -259,7 +260,7 @@ class TestFormsSubmissions(TestCase): self.assertEqual(response.context['submissions'].number, response.context['submissions'].paginator.num_pages) def test_list_submissions_csv_export(self): - response = self.client.get('/admin/forms/submissions/%d/?date_from=01%%2F01%%2F2014&action=CSV' % self.form_page.id) + response = self.client.get(reverse('wagtailforms_list_submissions', args=(self.form_page.id, )), {'date_from': '01/01/2014', 'action': 'CSV'}) # Check response self.assertEqual(response.status_code, 200) From 1683287ee7b5c0780024ecb055513762f8828c34 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 3 Jun 2014 11:15:12 +0100 Subject: [PATCH 09/11] Change wagtailforms SelectDateForm to use DateTimeFields This is because DateFields are not timezone aware which causes warnings to be raised by django. The widgets are still set to "DateInput" so the look and behaviour should not change --- wagtail/wagtailforms/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailforms/forms.py b/wagtail/wagtailforms/forms.py index aaf16eb792..4f874133a3 100644 --- a/wagtail/wagtailforms/forms.py +++ b/wagtail/wagtailforms/forms.py @@ -100,11 +100,11 @@ class FormBuilder(object): class SelectDateForm(django.forms.Form): - date_from = django.forms.DateField( + date_from = django.forms.DateTimeField( required=False, widget=django.forms.DateInput(attrs={'placeholder': 'Date from'}) ) - date_to = django.forms.DateField( + date_to = django.forms.DateTimeField( required=False, widget=django.forms.DateInput(attrs={'placeholder': 'Date to'}) ) From 749df44e06b28368749e1cebec08f88292ba99ba Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 27 Jun 2014 12:17:57 +0100 Subject: [PATCH 10/11] Revert "Split wagtailforms landing page into separate view" This reverts commit 21ac2e3ab8bb3c52b45b7ae005a5c87a83785def. --- wagtail/wagtailforms/models.py | 26 +++++++++----------------- wagtail/wagtailforms/tests.py | 12 +++--------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/wagtail/wagtailforms/models.py b/wagtail/wagtailforms/models.py index 59941c6abd..75f0eceee0 100644 --- a/wagtail/wagtailforms/models.py +++ b/wagtail/wagtailforms/models.py @@ -1,5 +1,5 @@ from django.db import models -from django.shortcuts import render, redirect +from django.shortcuts import render from django.utils.translation import ugettext_lazy as _ from django.utils.text import slugify @@ -111,7 +111,6 @@ class AbstractForm(Page): """A Form Page. Pages implementing a form should inhert from it""" form_builder = FormBuilder - landing_page_path = 'done' is_abstract = True # Don't display me in "Add" def __init__(self, *args, **kwargs): @@ -153,8 +152,11 @@ class AbstractForm(Page): form_processor = self.form_processing_backend() form_processor.process(self, form) - # Redirect to the landing page - return redirect(self.url + self.landing_page_path + '/') + # render the landing_page + # TODO: It is much better to redirect to it + return render(request, self.landing_page_template, { + 'self': self, + }) else: form = form_class(**form_params) @@ -163,18 +165,6 @@ class AbstractForm(Page): 'form': form, }) - def serve_landing(self, request): - return render(request, self.landing_page_template, { - 'self': self, - }) - - def route(self, request, path_components): - # Check if this request is for the landing page - if self.live and path_components == [self.landing_page_path]: - return self.serve_landing(request) - - return super(AbstractForm, self).route(request, path_components) - def get_page_modes(self): return [ ('form', 'Form'), @@ -183,7 +173,9 @@ class AbstractForm(Page): def show_as_mode(self, mode): if mode == 'landing': - return self.serve_landing(self.dummy_request()) + return render(self.dummy_request(), self.landing_page_template, { + 'self': self, + }) else: return super(AbstractForm, self).show_as_mode(mode) diff --git a/wagtail/wagtailforms/tests.py b/wagtail/wagtailforms/tests.py index 24bace8c52..0e162e16a6 100644 --- a/wagtail/wagtailforms/tests.py +++ b/wagtail/wagtailforms/tests.py @@ -38,7 +38,9 @@ class TestFormSubmission(TestCase): }) # Check response - self.assertEqual(response.status_code, 302) + self.assertContains(response, "Thank you for your feedback.") + self.assertTemplateNotUsed(response, 'tests/form_page.html') + self.assertTemplateUsed(response, 'tests/form_page_landing.html') # Check that an email was sent self.assertEqual(len(mail.outbox), 1) @@ -51,14 +53,6 @@ class TestFormSubmission(TestCase): form_page = Page.objects.get(url_path='/home/contact-us/') self.assertTrue(FormSubmission.objects.filter(page=form_page, form_data__contains='hello world').exists()) - def test_get_landing_page(self): - response = self.client.get('/contact-us/done/') - - # Check response - self.assertContains(response, "Thank you for your feedback.") - self.assertTemplateNotUsed(response, 'tests/form_page.html') - self.assertTemplateUsed(response, 'tests/form_page_landing.html') - class TestPageModes(TestCase): fixtures = ['test.json'] From 77def962a701ae17f9a2e9f58f44c0bab36c9759 Mon Sep 17 00:00:00 2001 From: Dave Cranwell Date: Fri, 27 Jun 2014 12:40:36 +0100 Subject: [PATCH 11/11] hallo toolbar buttons reduced in height --- .../wagtailadmin/static/wagtailadmin/scss/panels/rich-text.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/wagtail/wagtailadmin/static/wagtailadmin/scss/panels/rich-text.scss b/wagtail/wagtailadmin/static/wagtailadmin/scss/panels/rich-text.scss index 36db5559a3..8870849606 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/scss/panels/rich-text.scss +++ b/wagtail/wagtailadmin/static/wagtailadmin/scss/panels/rich-text.scss @@ -14,6 +14,7 @@ } .hallotoolbar button{ @include border-radius(0); + height:2.4em; } .richtext {