mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-23 16:14:48 +00:00
Merge branch 'business-rules' of https://github.com/lojack/wagtail into lojack-business-rules
Conflicts: wagtail/tests/models.py wagtail/wagtailadmin/tests.py
This commit is contained in:
commit
f56179f8ba
5 changed files with 57 additions and 9 deletions
|
|
@ -294,3 +294,16 @@ class ZuluSnippet(models.Model):
|
|||
|
||||
def __unicode__(self):
|
||||
return self.text
|
||||
|
||||
|
||||
class StandardIndex(Page):
|
||||
pass
|
||||
|
||||
class StandardChild(Page):
|
||||
pass
|
||||
|
||||
class BusinessIndex(Page):
|
||||
subpage_types = ['tests.BusinessChild']
|
||||
|
||||
class BusinessChild(Page):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
<div class="nice-padding">
|
||||
<p>{% trans "Choose which type of page you'd like to create." %}</p>
|
||||
|
||||
{% if all_page_types %}
|
||||
{% if page_types %}
|
||||
<ul class="listing">
|
||||
{% for content_type in all_page_types %}
|
||||
{% for content_type in page_types %}
|
||||
<li>
|
||||
<div class="row row-flush">
|
||||
<div class="col6">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from django.test import TestCase
|
||||
from wagtail.tests.models import SimplePage, EventPage
|
||||
from wagtail.tests.models import SimplePage, EventPage, StandardIndex, StandardChild, BusinessIndex, BusinessChild
|
||||
from wagtail.tests.utils import unittest, WagtailTestUtils
|
||||
from wagtail.wagtailcore.models import Page, PageRevision
|
||||
from django.core.urlresolvers import reverse
|
||||
|
|
@ -669,3 +669,36 @@ class TestContentTypeUse(TestCase, WagtailTestUtils):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'wagtailadmin/pages/content_type_use.html')
|
||||
self.assertContains(response, "Christmas")
|
||||
|
||||
|
||||
class TestSubpageBusinessRules(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
# Find root page
|
||||
self.root_page = Page.objects.get(id=2)
|
||||
|
||||
# Add standard page
|
||||
self.standard_index = StandardIndex()
|
||||
self.standard_index.title = "Standard Index"
|
||||
self.standard_index.slug = "standard-index"
|
||||
self.root_page.add_child(instance=self.standard_index)
|
||||
|
||||
# Add business page
|
||||
self.business_index = BusinessIndex()
|
||||
self.business_index.title = "Business Index"
|
||||
self.business_index.slug = "business-index"
|
||||
self.root_page.add_child(instance=self.business_index)
|
||||
|
||||
# Login
|
||||
self.login()
|
||||
|
||||
def test_standard_subpage(self):
|
||||
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.standard_index.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, 'Standard Child')
|
||||
self.assertContains(response, 'Business Child')
|
||||
|
||||
def test_business_subpage(self):
|
||||
response = self.client.get(reverse('wagtailadmin_pages_add_subpage', args=(self.business_index.id, )))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertNotContains(response, 'Standard Child')
|
||||
self.assertContains(response, 'Business Child')
|
||||
|
|
|
|||
|
|
@ -57,13 +57,11 @@ def add_subpage(request, parent_page_id):
|
|||
if not parent_page.permissions_for_user(request.user).can_add_subpage():
|
||||
raise PermissionDenied
|
||||
|
||||
page_types = sorted([ContentType.objects.get_for_model(model_class) for model_class in parent_page.clean_subpage_types()], key=lambda pagetype: pagetype.name.lower())
|
||||
all_page_types = sorted(get_page_types(), key=lambda pagetype: pagetype.name.lower())
|
||||
page_types = sorted(parent_page.clean_subpage_types(), key=lambda pagetype: pagetype.name.lower())
|
||||
|
||||
return render(request, 'wagtailadmin/pages/add_subpage.html', {
|
||||
'parent_page': parent_page,
|
||||
'page_types': page_types,
|
||||
'all_page_types': all_page_types,
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -484,7 +484,11 @@ class Page(MP_Node, ClusterableModel, Indexed):
|
|||
where required
|
||||
"""
|
||||
if cls._clean_subpage_types is None:
|
||||
res = []
|
||||
if len(cls.subpage_types) == 0:
|
||||
res = get_page_types()
|
||||
else:
|
||||
res = []
|
||||
|
||||
for page_type in cls.subpage_types:
|
||||
if isinstance(page_type, basestring):
|
||||
try:
|
||||
|
|
@ -496,13 +500,13 @@ class Page(MP_Node, ClusterableModel, Indexed):
|
|||
|
||||
model = get_model(app_label, model_name)
|
||||
if model:
|
||||
res.append(model)
|
||||
res.append(ContentType.objects.get_for_model(model))
|
||||
else:
|
||||
raise NameError(_("name '{0}' (used in subpage_types list) is not defined.").format(page_type))
|
||||
|
||||
else:
|
||||
# assume it's already a model class
|
||||
res.append(page_type)
|
||||
res.append(ContentType.objects.get_for_model(page_type))
|
||||
|
||||
cls._clean_subpage_types = res
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue