mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Fix non-model form fields being compared. Fixes #3737
This commit is contained in:
parent
b743b87d2f
commit
443503d145
@ -508,7 +508,10 @@ class FieldPanel(EditHandler):
|
|||||||
comparator_class = self.get_comparison_class()
|
comparator_class = self.get_comparison_class()
|
||||||
|
|
||||||
if comparator_class:
|
if comparator_class:
|
||||||
return [curry(comparator_class, self.db_field)]
|
try:
|
||||||
|
return [curry(comparator_class, self.db_field)]
|
||||||
|
except FieldDoesNotExist:
|
||||||
|
return []
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
|
@ -27,8 +27,8 @@ from wagtail.search.index import SearchField
|
|||||||
from wagtail.tests.testapp.models import (
|
from wagtail.tests.testapp.models import (
|
||||||
EVENT_AUDIENCE_CHOICES, Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex,
|
EVENT_AUDIENCE_CHOICES, Advert, AdvertPlacement, BusinessChild, BusinessIndex, BusinessSubIndex,
|
||||||
DefaultStreamPage, EventCategory, EventPage, EventPageCarouselItem, FilePage,
|
DefaultStreamPage, EventCategory, EventPage, EventPageCarouselItem, FilePage,
|
||||||
ManyToManyBlogPage, SimplePage, SingleEventPage, SingletonPage, StandardChild, StandardIndex,
|
FormClassAdditionalFieldPage, ManyToManyBlogPage, SimplePage, SingleEventPage, SingletonPage,
|
||||||
TaggedPage)
|
StandardChild, StandardIndex, TaggedPage)
|
||||||
from wagtail.tests.utils import WagtailTestUtils
|
from wagtail.tests.utils import WagtailTestUtils
|
||||||
from wagtail.users.models import UserProfile
|
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'll just feed it to the dog</span>')
|
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'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):
|
class TestRevisionsUnschedule(TestCase, WagtailTestUtils):
|
||||||
fixtures = ['test.json']
|
fixtures = ['test.json']
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user