Fix non-model form fields being compared. Fixes #3737

pull/4436/merge
Matt Westcott 2018-04-12 17:23:13 +01:00
rodzic b743b87d2f
commit 443503d145
2 zmienionych plików z 71 dodań i 3 usunięć

Wyświetl plik

@ -508,7 +508,10 @@ class FieldPanel(EditHandler):
comparator_class = self.get_comparison_class()
if comparator_class:
return [curry(comparator_class, self.db_field)]
try:
return [curry(comparator_class, self.db_field)]
except FieldDoesNotExist:
return []
return []
@cached_property

Wyświetl plik

@ -27,8 +27,8 @@ from wagtail.search.index import SearchField
from wagtail.tests.testapp.models import (
EVENT_AUDIENCE_CHOICES, Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex,
DefaultStreamPage, EventCategory, EventPage, EventPageCarouselItem, FilePage,
ManyToManyBlogPage, SimplePage, SingleEventPage, SingletonPage, StandardChild, StandardIndex,
TaggedPage)
FormClassAdditionalFieldPage, ManyToManyBlogPage, SimplePage, SingleEventPage, SingletonPage,
StandardChild, StandardIndex, TaggedPage)
from wagtail.tests.utils import WagtailTestUtils
from wagtail.users.models import UserProfile
@ -4052,6 +4052,71 @@ class TestCompareRevisions(TestCase, WagtailTestUtils):
self.assertContains(response, '<span class="deletion">Last Christmas I gave you my heart, but the very next day you gave it away</span><span class="addition">This year, to save me from tears, I&#39;ll just feed it to the dog</span>')
class TestCompareRevisionsWithNonModelField(TestCase, WagtailTestUtils):
"""
Tests if form fields defined in the base_form_class will not be included.
in revisions view as they are not actually on the model.
Flagged in issue #3737
Note: Actual tests for comparison classes can be found in test_compare.py
"""
fixtures = ['test.json']
# FormClassAdditionalFieldPage
def setUp(self):
# Find root page
self.root_page = Page.objects.get(id=2)
# Add child page of class with base_form_class override
# non model field is 'code'
self.test_page = FormClassAdditionalFieldPage(
title='A Statement',
slug='a-statement',
location='Early Morning Cafe, Mainland, NZ',
body="<p>hello</p>"
)
self.root_page.add_child(instance=self.test_page)
# add new revision
self.test_page.title = 'Statement'
self.test_page.location = 'Victory Monument, Bangkok'
self.test_page.body = (
"<p>I would like very much to go into the forrest.</p>"
)
self.test_page_revision = self.test_page.save_revision()
self.test_page_revision.created_at = local_datetime(2017, 10, 15)
self.test_page_revision.save()
# add another new revision
self.test_page.title = 'True Statement'
self.test_page.location = 'Victory Monument, Bangkok'
self.test_page.body = (
"<p>I would like very much to go into the forest.</p>"
)
self.test_page_revision_new = self.test_page.save_revision()
self.test_page_revision_new.created_at = local_datetime(2017, 10, 16)
self.test_page_revision_new.save()
self.login()
def test_base_form_class_used(self):
"""First ensure that the non-model field is appearing in edit."""
edit_url = reverse('wagtailadmin_pages:add', args=('tests', 'formclassadditionalfieldpage', self.test_page.id))
response = self.client.get(edit_url)
self.assertContains(response, '<input type="text" name="code" required id="id_code" maxlength="5" />', html=True)
def test_compare_revisions(self):
"""Confirm that the non-model field is not shown in revision."""
compare_url = reverse(
'wagtailadmin_pages:revisions_compare',
args=(self.test_page.id, self.test_page_revision.id, self.test_page_revision_new.id)
)
response = self.client.get(compare_url)
self.assertContains(response, '<span class="deletion">forrest.</span><span class="addition">forest.</span>')
# should not contain the field defined in the formclass used
self.assertNotContains(response, '<h2>Code:</h2>')
class TestRevisionsUnschedule(TestCase, WagtailTestUtils):
fixtures = ['test.json']