allow default for show_in_menus

pull/3615/merge
LB 2017-05-26 16:09:15 +02:00 zatwierdzone przez Matt Westcott
rodzic 0c9ad90edd
commit 18cb0245fc
7 zmienionych plików z 76 dodań i 10 usunięć

Wyświetl plik

@ -9,7 +9,8 @@ Changelog
* The current live version of a page is now tracked on the revision listing view (Matheus Bratfisch)
* Each block created in a `StreamField` is now assigned a globally unique identifier (Matt Westcott)
* Mixcloud oEmbed pattern has been updated (Alice Rose)
* Added ``last_published_at`` field to the Page model (Matt Westcott)
* Added `last_published_at` field to the Page model (Matt Westcott)
* Added `show_in_menus_default` flag on page models, to allow "show in menus" to be checked by default (LB (Ben Johnston))
* Fix: Unauthenticated AJAX requests to admin views now return 403 rather than redirecting to the login page (Karl Hobley)
* Fix: `TableBlock` options `afterChange`, `afterCreateCol`, `afterCreateRow`, `afterRemoveCol`, `afterRemoveRow` and `contextMenu` can now be overridden (Loic Teixeira)
* Fix: The lastmod field returned by wagtailsitemaps now shows the last published date rather than the date of the last draft edit (Matt Westcott)

Wyświetl plik

@ -86,6 +86,8 @@ Database fields
Toggles whether the page should be included in site-wide menus.
Defaults to ``False`` and can be overridden on the model with ``show_in_menus_default = True``.
This is used by the :meth:`~wagtail.wagtailcore.query.PageQuerySet.in_menu` QuerySet filter.
Methods and properties

Wyświetl plik

@ -49,6 +49,7 @@ Other features
* Each block created in a ``StreamField`` is now assigned a globally unique identifier (Matt Westcott)
* Mixcloud oEmbed pattern has been updated (Alice Rose)
* Added ``last_published_at`` field to the Page model (Matt Westcott)
* Added ``show_in_menus_default`` flag on page models, to allow "show in menus" to be checked by default (LB (Ben Johnston))
Bug fixes

Wyświetl plik

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-05-26 13:38
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wagtailcore', '0032_add_bulk_delete_page_permission'),
('tests', '0016_auto_20170303_2340'),
]
operations = [
migrations.CreateModel(
name='AlwaysShowInMenusPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
]

Wyświetl plik

@ -961,3 +961,7 @@ class TabbedSettings(TestSetting):
FieldPanel('email')
], heading='Second tab'),
])
class AlwaysShowInMenusPage(Page):
show_in_menus_default = True

Wyświetl plik

@ -295,6 +295,8 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
blank=True,
help_text=_("Optional. 'Search Engine Friendly' title. This will appear at the top of the browser window.")
)
show_in_menus_default = False
show_in_menus = models.BooleanField(
verbose_name=_('show in menus'),
default=False,
@ -367,11 +369,16 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable
def __init__(self, *args, **kwargs):
super(Page, self).__init__(*args, **kwargs)
if not self.id and not self.content_type_id:
# this model is being newly created rather than retrieved from the db;
# set content type to correctly represent the model class that this was
# created as
self.content_type = ContentType.objects.get_for_model(self)
if not self.id:
# this model is being newly created
# rather than retrieved from the db;
if not self.content_type_id:
# set content type to correctly represent the model class
# that this was created as
self.content_type = ContentType.objects.get_for_model(self)
if 'show_in_menus' not in kwargs:
# if the value is not set on submit refer to the model setting
self.show_in_menus = self.show_in_menus_default
def __str__(self):
return self.title

Wyświetl plik

@ -16,10 +16,11 @@ from django.test.utils import override_settings
from freezegun import freeze_time
from wagtail.tests.testapp.models import (
AbstractPage, Advert, BlogCategory, BlogCategoryBlogPage, BusinessChild, BusinessIndex,
BusinessNowherePage, BusinessSubIndex, CustomManager, CustomManagerPage, EventIndex, EventPage,
GenericSnippetPage, ManyToManyBlogPage, MTIBasePage, MTIChildPage, MyCustomPage, OneToOnePage,
SimplePage, SingleEventPage, SingletonPage, StandardIndex, TaggedPage)
AbstractPage, Advert, AlwaysShowInMenusPage, BlogCategory, BlogCategoryBlogPage, BusinessChild,
BusinessIndex, BusinessNowherePage, BusinessSubIndex, CustomManager, CustomManagerPage,
EventIndex, EventPage, GenericSnippetPage, ManyToManyBlogPage, MTIBasePage, MTIChildPage,
MyCustomPage, OneToOnePage, SimplePage, SingleEventPage, SingletonPage, StandardIndex,
TaggedPage)
from wagtail.tests.utils import WagtailTestUtils
from wagtail.wagtailcore.models import Page, PageManager, Site, get_page_models
@ -1349,3 +1350,26 @@ class TestDummyRequest(TestCase):
# '*' is not a valid hostname, so ensure that we replace it with something sensible
self.assertNotEqual(request.META['HTTP_HOST'], '*')
class TestShowInMenusDefaultOption(TestCase):
"""
This tests that a page model can define the default for 'show_in_menus'
"""
fixtures = ['test.json']
def test_show_in_menus_default(self):
# Create a page that does not have the default init
page = Page(
title='My Awesome Page', slug='my-awesome-page')
# Check that the page instance creates with show_in_menu as False
self.assertFalse(page.show_in_menus)
def test_show_in_menus_default_override(self):
# Create a page that does have the default init
page = AlwaysShowInMenusPage(
title='My Awesome Page', slug='my-awesome-page')
# Check that the page instance creates with show_in_menu as True
self.assertTrue(page.show_in_menus)