Link to homepage from dashboard page link if single site

If the Wagtail install has only one site, link to the homepage of that
site from the dashboard page summary instead of the root page of the
hierarchy.

Hopefully this will prevent some of the confusion causing people to
create pages under the root page, where they are inaccessible. See #1612
for more information around this issue.

Wagtail installs with multiple (or zero) sites retain the old behaviour
of linking to the root page.
pull/2041/merge
Tim Heap 2015-10-30 10:32:09 +11:00 zatwierdzone przez Matt Westcott
rodzic 2dd3f42e25
commit 44564ea76a
5 zmienionych plików z 55 dodań i 7 usunięć

Wyświetl plik

@ -25,6 +25,7 @@ Changelog
* Added success message after updating image from the image upload view (Christian Peters)
* Added a `request.is_preview` variable for templates to distinguish between previewing and live (Denis Voskvitsov)
* New translations for Arabic and Latvian
* 'Pages' link on site stats dashboard now links to the site homepage when only one site exists, rather than the root level
* Fix: Images and page revisions created by a user are no longer deleted when the user is deleted (Rich Atkinson)
* Fix: HTTP cache purge now works again on Python 2 (Mitchel Cabuloy)
* Fix: Locked pages can no longer be unpublished (Alex Bridge)

Wyświetl plik

@ -69,6 +69,7 @@ Minor features
* Added an optional human-friendly ``site_name`` field to sites (Timo Rieber)
* Added success message after updating image from the image upload view (Christian Peters)
* Added a ``request.is_preview`` variable for templates to distinguish between previewing and live (Denis Voskvitsov)
* 'Pages' link on site stats dashboard now links to the site homepage when only one site exists, rather than the root level
* New translations for Arabic and Latvian

Wyświetl plik

@ -1,5 +1,5 @@
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.models import Page, Site
from wagtail.utils.compat import render_to_string
@ -21,7 +21,19 @@ class PagesSummaryItem(SummaryItem):
template = 'wagtailadmin/home/site_summary_pages.html'
def get_context(self):
# If there is a single site, link to the homepage of that site
# Otherwise, if there are multiple sites, link to the root page
try:
site = Site.objects.get()
root = site.root_page
single_site = True
except (Site.DoesNotExist, Site.MultipleObjectsReturned):
root = None
single_site = False
return {
'single_site': single_site,
'root_page': root,
'total_pages': Page.objects.count() - 1, # subtract 1 because the root node is not a real page
}

Wyświetl plik

@ -1,7 +1,7 @@
{% load i18n wagtailadmin_tags %}
<li class="icon icon-doc-empty-inverse">
<a href="{% url 'wagtailadmin_explore_root' %}">
<a href="{% if single_site %}{% url 'wagtailadmin_explore' root_page.pk %}{% else %}{% url 'wagtailadmin_explore_root' %}{% endif %}">
{% blocktrans count counter=total_pages with total_pages|intcomma as total %}
<span>{{ total }}</span> Page
{% plural %}

Wyświetl plik

@ -4,16 +4,16 @@ from __future__ import unicode_literals
import json
from django.test import TestCase, override_settings
from django.core.urlresolvers import reverse
from django.core import mail
from django.contrib.auth import get_user_model
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase, override_settings
from taggit.models import Tag
from wagtail.tests.utils import WagtailTestUtils
from wagtail.wagtailcore.models import Page
from wagtail.wagtailadmin.site_summary import PagesSummaryItem
from wagtail.wagtailadmin.utils import send_mail
from wagtail.wagtailcore.models import Page, Site
from django.core.urlresolvers import reverse_lazy
from wagtail.wagtailadmin.menu import MenuItem
@ -69,6 +69,40 @@ class TestHome(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 200)
class TestPagesSummary(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def get_request(self):
"""
Get a Django WSGI request that has been passed through middleware etc.
"""
return self.client.get('/admin/').wsgi_request
def test_page_summary_single_site(self):
request = self.get_request()
root_page = request.site.root_page
link = '<a href="{}">'.format(reverse('wagtailadmin_explore', args=[root_page.pk]))
page_summary = PagesSummaryItem(request)
self.assertIn(link, page_summary.render())
def test_page_summary_multiple_sites(self):
Site.objects.create(
hostname='example.com',
root_page=Page.objects.get(pk=1))
request = self.get_request()
link = '<a href="{}">'.format(reverse('wagtailadmin_explore_root'))
page_summary = PagesSummaryItem(request)
self.assertIn(link, page_summary.render())
def test_page_summary_zero_sites(self):
Site.objects.all().delete()
request = self.get_request()
link = '<a href="{}">'.format(reverse('wagtailadmin_explore_root'))
page_summary = PagesSummaryItem(request)
self.assertIn(link, page_summary.render())
class TestEditorHooks(TestCase, WagtailTestUtils):
def setUp(self):
self.homepage = Page.objects.get(id=2)