From 2837af4fbff47a930432f182f2f9c6e211c14f51 Mon Sep 17 00:00:00 2001 From: Eric Drechsel Date: Fri, 21 Nov 2014 11:57:32 -0800 Subject: [PATCH 1/7] Use a common base template for test pages --- wagtail/tests/templates/tests/base.html | 10 ++++++++ .../testapp/templates/tests/event_index.html | 15 ++++------- .../testapp/templates/tests/event_page.html | 25 ++++++++----------- .../tests/event_page_password_required.html | 25 ++++++++----------- .../testapp/templates/tests/form_page.html | 22 ++++++---------- .../templates/tests/form_page_landing.html | 15 +++-------- .../testapp/templates/tests/simple_page.html | 15 +++-------- 7 files changed, 51 insertions(+), 76 deletions(-) create mode 100644 wagtail/tests/templates/tests/base.html diff --git a/wagtail/tests/templates/tests/base.html b/wagtail/tests/templates/tests/base.html new file mode 100644 index 000000000..875d13d9c --- /dev/null +++ b/wagtail/tests/templates/tests/base.html @@ -0,0 +1,10 @@ + + + + {% block html_title %}{{ self.title }}{% endblock %} + + +

{{ self.title }}

+ {% block content %}{% endblock %} + + diff --git a/wagtail/tests/testapp/templates/tests/event_index.html b/wagtail/tests/testapp/templates/tests/event_index.html index dc07020b2..345aac9e0 100644 --- a/wagtail/tests/testapp/templates/tests/event_index.html +++ b/wagtail/tests/testapp/templates/tests/event_index.html @@ -1,10 +1,5 @@ - - - - {{ self.title }} - - -

{{ self.title }}

- {% include "tests/includes/event_listing.html" %} - - +{% extends "tests/base.html" %} + +{% block content %} + {% include "tests/includes/event_listing.html" %} +{% endblock %} diff --git a/wagtail/tests/testapp/templates/tests/event_page.html b/wagtail/tests/testapp/templates/tests/event_page.html index a3ccaa718..f2f486962 100644 --- a/wagtail/tests/testapp/templates/tests/event_page.html +++ b/wagtail/tests/testapp/templates/tests/event_page.html @@ -1,17 +1,12 @@ +{% extends "tests/base.html" %} {% load wagtailcore_tags wagtailimages_tags %} - - - - Event: {{ self.title }} - - -

{{ self.title }}

-

Event

- {% if self.feed_image %} - {% image self.feed_image width-200 class="feed-image" %} - {% endif %} - {{ self.body|richtext }} -

Back to events index

- - +{% block html_title %}Event: {{ self.title }}{% endblock %} +{% block content %} +

Event

+ {% if self.feed_image %} + {% image self.feed_image width-200 class="feed-image" %} + {% endif %} + {{ self.body|richtext }} +

Back to events index

+{% endblock %} diff --git a/wagtail/tests/testapp/templates/tests/event_page_password_required.html b/wagtail/tests/testapp/templates/tests/event_page_password_required.html index e58d740ad..7311c7940 100644 --- a/wagtail/tests/testapp/templates/tests/event_page_password_required.html +++ b/wagtail/tests/testapp/templates/tests/event_page_password_required.html @@ -1,15 +1,10 @@ - - - - {{ self.title }} - - -

{{ self.title }}

-

This event is invitation only. Please enter your password to see the details.

-
- {% csrf_token %} - {{ form.as_p }} - -
- - +{% extends "tests/base.html" %} + +{% block content %} +

This event is invitation only. Please enter your password to see the details.

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/wagtail/tests/testapp/templates/tests/form_page.html b/wagtail/tests/testapp/templates/tests/form_page.html index d908c60a2..f275ec80f 100644 --- a/wagtail/tests/testapp/templates/tests/form_page.html +++ b/wagtail/tests/testapp/templates/tests/form_page.html @@ -1,16 +1,10 @@ +{% extends "tests/base.html" %} {% load wagtailcore_tags %} - - - - {{ self.title }} - - -

{{ self.title }}

-
- {% csrf_token %} - {{ form.as_p }} - -
- - +{% block content %} +
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/wagtail/tests/testapp/templates/tests/form_page_landing.html b/wagtail/tests/testapp/templates/tests/form_page_landing.html index d9a6369d4..9615c79d3 100644 --- a/wagtail/tests/testapp/templates/tests/form_page_landing.html +++ b/wagtail/tests/testapp/templates/tests/form_page_landing.html @@ -1,12 +1,5 @@ -{% load wagtailcore_tags %} +{% extends "tests/base.html" %} - - - - {{ self.title }} - - -

{{ self.title }}

-

Thank you for your feedback.

- - +{% block content %} +

Thank you for your feedback.

+{% endblock %} diff --git a/wagtail/tests/testapp/templates/tests/simple_page.html b/wagtail/tests/testapp/templates/tests/simple_page.html index 1f3593514..7a173c096 100644 --- a/wagtail/tests/testapp/templates/tests/simple_page.html +++ b/wagtail/tests/testapp/templates/tests/simple_page.html @@ -1,12 +1,5 @@ -{% load wagtailcore_tags %} +{% extends "tests/base.html" %} - - - - {{ self.title }} - - -

{{ self.title }}

-

Simple page

- - +{% block content %} +

Simple page

+{% endblock %} From 8dfa5942da20436233a34aa9a063f855afd410d7 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 24 Oct 2014 12:20:02 +0100 Subject: [PATCH 2/7] Add wagtailuserbar tag to base test template --- wagtail/tests/templates/tests/base.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wagtail/tests/templates/tests/base.html b/wagtail/tests/templates/tests/base.html index 875d13d9c..636b5c588 100644 --- a/wagtail/tests/templates/tests/base.html +++ b/wagtail/tests/templates/tests/base.html @@ -1,9 +1,12 @@ +{% load wagtailuserbar %} + {% block html_title %}{{ self.title }}{% endblock %} + {% wagtailuserbar %}

{{ self.title }}

{% block content %}{% endblock %} From a5940bef98be498a5c45fa9a383cb440a7ac0ed2 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 24 Oct 2014 12:41:28 +0100 Subject: [PATCH 3/7] add (partly failing) unit tests for add button on wagtailuserbar --- .../tests/templates/tests/business_child.html | 5 +++ wagtail/wagtailadmin/tests/test_userbar.py | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 wagtail/tests/templates/tests/business_child.html diff --git a/wagtail/tests/templates/tests/business_child.html b/wagtail/tests/templates/tests/business_child.html new file mode 100644 index 000000000..33e29f1c2 --- /dev/null +++ b/wagtail/tests/templates/tests/business_child.html @@ -0,0 +1,5 @@ +{% extends "tests/base.html" %} + +{% block content %} +

Business Child

+{% endblock %} diff --git a/wagtail/wagtailadmin/tests/test_userbar.py b/wagtail/wagtailadmin/tests/test_userbar.py index c43a1bbc0..04056f87a 100644 --- a/wagtail/wagtailadmin/tests/test_userbar.py +++ b/wagtail/wagtailadmin/tests/test_userbar.py @@ -7,6 +7,7 @@ from django.contrib.auth.models import AnonymousUser from wagtail.tests.utils import WagtailTestUtils from wagtail.wagtailcore.models import Page +from wagtail.tests.models import BusinessIndex, BusinessChild class TestUserbarTag(TestCase): @@ -60,6 +61,37 @@ class TestUserbarFrontend(TestCase, WagtailTestUtils): self.assertEqual(response.status_code, 403) +class TestUserbarAddLink(TestCase, WagtailTestUtils): + fixtures = ['test.json'] + + def setUp(self): + self.login() + self.homepage = Page.objects.get(url_path='/home/') + self.event_index = Page.objects.get(url_path='/home/events/') + + self.business_index = BusinessIndex(title='Business', slug='business', live=True) + self.homepage.add_child(instance=self.business_index) + + self.business_child = BusinessChild(title='Business Child', slug='child', live=True) + self.business_index.add_child(instance=self.business_child) + + def test_page_allowing_subpages(self): + response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.event_index.id, ))) + + # page allows subpages, so the 'add page' button should add a subpage + expected_url = reverse('wagtailadmin_pages_add_subpage', args=(self.event_index.id, )) + expected_link = 'Add' % expected_url + self.assertContains(response, expected_link) + + def test_page_disallowing_subpages(self): + response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.business_child.id, ))) + print response + # page disallows subpages, so the 'add page' button should add a page at the same level + expected_url = reverse('wagtailadmin_pages_add_subpage', args=(self.business_index.id, )) + expected_link = 'Add' % expected_url + self.assertContains(response, expected_link) + + class TestUserbarModeration(TestCase, WagtailTestUtils): def setUp(self): self.login() From 805e0785562d7080c8c6f828c639432cac18e4a2 Mon Sep 17 00:00:00 2001 From: Eric Drechsel Date: Fri, 21 Nov 2014 13:24:29 -0800 Subject: [PATCH 4/7] test that add button is present only if page allows subpages --- wagtail/wagtailadmin/tests/test_userbar.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wagtail/wagtailadmin/tests/test_userbar.py b/wagtail/wagtailadmin/tests/test_userbar.py index 04056f87a..4daf9370a 100644 --- a/wagtail/wagtailadmin/tests/test_userbar.py +++ b/wagtail/wagtailadmin/tests/test_userbar.py @@ -78,18 +78,18 @@ class TestUserbarAddLink(TestCase, WagtailTestUtils): def test_page_allowing_subpages(self): response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.event_index.id, ))) - # page allows subpages, so the 'add page' button should add a subpage + # page allows subpages, so the 'add page' button should show expected_url = reverse('wagtailadmin_pages_add_subpage', args=(self.event_index.id, )) expected_link = 'Add' % expected_url self.assertContains(response, expected_link) def test_page_disallowing_subpages(self): response = self.client.get(reverse('wagtailadmin_userbar_frontend', args=(self.business_child.id, ))) - print response - # page disallows subpages, so the 'add page' button should add a page at the same level + + # page disallows subpages, so the 'add page' button shouldn't show expected_url = reverse('wagtailadmin_pages_add_subpage', args=(self.business_index.id, )) - expected_link = 'Add' % expected_url - self.assertContains(response, expected_link) + expected_link = 'Add' % expected_url + self.assertNotContains(response, expected_link) class TestUserbarModeration(TestCase, WagtailTestUtils): From e28051e3f35bcb066c313a1839d9462490bfb478 Mon Sep 17 00:00:00 2001 From: Eric Drechsel Date: Fri, 21 Nov 2014 13:24:57 -0800 Subject: [PATCH 5/7] only include add button in userbar if page allows subpages --- .../templates/wagtailadmin/userbar/item_page_add.html | 4 ++-- wagtail/wagtailadmin/userbar.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/userbar/item_page_add.html b/wagtail/wagtailadmin/templates/wagtailadmin/userbar/item_page_add.html index 45f0002e9..1a4d0a7f4 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/userbar/item_page_add.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/userbar/item_page_add.html @@ -2,5 +2,5 @@ {% load i18n %} {% block item_content %} - {% trans 'Add' %} -{% endblock %} \ No newline at end of file + {% trans 'Add' %} +{% endblock %} diff --git a/wagtail/wagtailadmin/userbar.py b/wagtail/wagtailadmin/userbar.py index 195e936b3..6ee8cda72 100644 --- a/wagtail/wagtailadmin/userbar.py +++ b/wagtail/wagtailadmin/userbar.py @@ -24,7 +24,7 @@ class AddPageItem(BaseItem): return "" # Don't render if user doesn't have ability to add siblings - permission_checker = self.page.get_parent().permissions_for_user(request.user) + permission_checker = self.page.permissions_for_user(request.user) if not permission_checker.can_add_subpage(): return "" From f7ab4048872e61bcbd2c0eefa11bf869901790ec Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 31 Mar 2015 15:25:43 +0100 Subject: [PATCH 6/7] Comment tweak --- wagtail/wagtailadmin/userbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wagtail/wagtailadmin/userbar.py b/wagtail/wagtailadmin/userbar.py index 6ee8cda72..8416255ff 100644 --- a/wagtail/wagtailadmin/userbar.py +++ b/wagtail/wagtailadmin/userbar.py @@ -23,7 +23,7 @@ class AddPageItem(BaseItem): if not request.user.has_perm('wagtailadmin.access_admin'): return "" - # Don't render if user doesn't have ability to add siblings + # Don't render if user doesn't have ability to add children here permission_checker = self.page.permissions_for_user(request.user) if not permission_checker.can_add_subpage(): return "" From addb57c0cdd9268c088771a17584328e508cfa54 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 31 Mar 2015 15:29:08 +0100 Subject: [PATCH 7/7] Changelog and release notes for #728 --- CHANGELOG.txt | 1 + docs/releases/1.0.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cbc86355d..8f9c1ca87 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -40,6 +40,7 @@ Changelog * Added hooks `register_rich_text_embed_handler` and `register_rich_text_link_handler` for customising link / embed handling within rich text fields * Added hook `construct_homepage_summary_items` for customising the site summary panel on the admin homepage * No longer automatically tries to use Celery for sending notification emails + * Added "Add child page" button to admin userbar (Eric Drechsel) 0.8.6 (10.03.2015) diff --git a/docs/releases/1.0.rst b/docs/releases/1.0.rst index 3f6c69685..ccd642f18 100644 --- a/docs/releases/1.0.rst +++ b/docs/releases/1.0.rst @@ -51,6 +51,7 @@ Admin * Added pagination to the snippets listing and chooser * Page / document / image / snippet choosers now include a link to edit the chosen item * Plain text fields in the page editor now use auto-expanding text areas + * Added "Add child page" button to admin userbar **Page editor**