kopia lustrzana https://github.com/wagtail/wagtail
Add convenience method for finding root page to navigation.py. Add context variables to home renderer.
rodzic
fab11259bc
commit
47f7d79aec
|
@ -6,6 +6,7 @@ Changelog
|
|||
|
||||
* Form builder form submissions can now be bulk-deleted (Karl Hobley)
|
||||
* `get_context` methods on StreamField blocks can now access variables from the parent context (Mikael Svensson, Peter Baumgartner)
|
||||
* Updated admin dashboard welcome message for multi-tenanted installations (Jeffrey Chau)
|
||||
* Added `before_copy_page` and `after_copy_page` hooks (Matheus Bratfisch)
|
||||
* View live / draft links in the admin now consistently open in a new window (Marco Fucci)
|
||||
* `ChoiceBlock` now omits the blank option if the block is required and has a default value (Andreas Nüßlein)
|
||||
|
|
|
@ -79,6 +79,32 @@ To replace the welcome message on the dashboard, create a template file ``dashbo
|
|||
|
||||
{% block branding_welcome %}Welcome to Frank's Site{% endblock %}
|
||||
|
||||
Specifying a site or page in the branding
|
||||
=========================================
|
||||
|
||||
The admin interface has a number of variables available to the renderer context that can be used to customize the branding in the admin page. These can be useful for customizing the dashboard on a multitenanted Wagtail installation:
|
||||
|
||||
``root_page``
|
||||
-------------
|
||||
Returns the highest explorable page object for the currently logged in user. If the user has no explore rights, this will default to ``None``.
|
||||
|
||||
``root_site``
|
||||
-------------
|
||||
Returns the name on the site record for the above root page.
|
||||
|
||||
|
||||
``site_name``
|
||||
-------------
|
||||
Returns the value of ``root_site``, unless it evaluates to ``None``. In that case, it will return the value of ``settings.WAGTAIL_SITE_NAME``.
|
||||
|
||||
To use these variables, create a template file ``dashboard/templates/wagtailadmin/home.html``, just as if you were overriding one of the template blocks in the dashboard, and use them as you would any other Django template variable:
|
||||
|
||||
.. code-block:: html+django
|
||||
|
||||
{% extends "wagtailadmin/home.html" %}
|
||||
|
||||
{% block branding_welcome %}Welcome to the Admin Homepage for {{ root_site }}{% endblock %}
|
||||
|
||||
Extending the login form
|
||||
========================
|
||||
|
||||
|
|
|
@ -22,6 +22,12 @@ Accessing parent context from StreamField block ``get_context`` methods
|
|||
The ``get_context`` method on StreamField blocks now receives a ``parent_context`` keyword argument, consisting of the dict of variables passed in from the calling template. For example, this makes it possible to perform pagination logic within ``get_context``, retrieving the current page number from ``parent_context['request'].GET``. See :ref:`get_context on StreamField blocks <streamfield_get_context>`. This feature was developed by Mikael Svensson and Peter Baumgartner.
|
||||
|
||||
|
||||
Welcome message customisation for multi-tenanted installations
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The welcome message on the admin dashboard has been updated to be more suitable for multi-tenanted installations. Users whose page permissions lie within a single site will now see that site name in the welcome message, rather than the installation-wide ``WAGTAIL_SITE_NAME``. As before, this message can be customised, and additional template variables have been provided for this purpose - see :ref:`custom_branding`. This feature was developed by Jeffrey Chau.
|
||||
|
||||
|
||||
Other features
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -17,6 +17,18 @@ def get_pages_with_direct_explore_permission(user):
|
|||
)
|
||||
|
||||
|
||||
def get_explorable_root_page(user):
|
||||
# Get the highest common explorable ancestor for the given user. If the user
|
||||
# has no permissions over any pages, this method will return None.
|
||||
pages = get_pages_with_direct_explore_permission(user)
|
||||
if pages:
|
||||
return pages.first_common_ancestor(
|
||||
include_self=True,
|
||||
strict=True)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def get_navigation_menu_items(user):
|
||||
# Get all pages that the user has direct add/edit/publish/lock permission on
|
||||
pages_with_direct_permission = get_pages_with_direct_explore_permission(user)
|
||||
|
|
|
@ -13,8 +13,7 @@ from django.utils.safestring import mark_safe
|
|||
|
||||
from wagtail.utils.pagination import DEFAULT_PAGE_KEY, replace_page_in_query
|
||||
from wagtail.wagtailadmin.menu import admin_menu
|
||||
from wagtail.wagtailadmin.navigation import (
|
||||
get_navigation_menu_items, get_pages_with_direct_explore_permission)
|
||||
from wagtail.wagtailadmin.navigation import get_explorable_root_page, get_navigation_menu_items
|
||||
from wagtail.wagtailadmin.search import admin_search_areas
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import Page, PageViewRestriction, UserPagePermissionsProxy
|
||||
|
@ -61,11 +60,8 @@ def explorer_breadcrumb(context, page, include_self=False):
|
|||
|
||||
# find the closest common ancestor of the pages that this user has direct explore permission
|
||||
# (i.e. add/edit/publish/lock) over; this will be the root of the breadcrumb
|
||||
try:
|
||||
cca = get_pages_with_direct_explore_permission(user).first_common_ancestor(
|
||||
include_self=True, strict=True
|
||||
)
|
||||
except Page.DoesNotExist:
|
||||
cca = get_explorable_root_page(user)
|
||||
if not cca:
|
||||
return {'pages': Page.objects.none()}
|
||||
|
||||
return {
|
||||
|
|
|
@ -407,6 +407,21 @@ class TestExplorablePageVisibility(TestCase, WagtailTestUtils):
|
|||
# The page title shouldn't appear because it's the "home" breadcrumb.
|
||||
self.assertNotContains(response, "Welcome to example.com!")
|
||||
|
||||
def test_admin_home_page_changes_with_permissions(self):
|
||||
self.assertTrue(self.client.login(username='bob', password='password'))
|
||||
response = self.client.get(reverse('wagtailadmin_home'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# Bob should only see the welcome for example.com, not testserver
|
||||
self.assertContains(response, "Welcome to the example.com Wagtail CMS")
|
||||
self.assertNotContains(response, "testserver")
|
||||
|
||||
def test_breadcrumb_with_no_user_permissions(self):
|
||||
self.assertTrue(self.client.login(username='mary', password='password'))
|
||||
response = self.client.get(reverse('wagtailadmin_home'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# Since Mary has no page permissions, she should not see the breadcrumb
|
||||
self.assertNotContains(response, """<li class="home"><a href="/admin/pages/4/" class="icon icon-home text-replace">Home</a></li>""")
|
||||
|
||||
|
||||
class TestPageCreation(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
|
|
|
@ -26,6 +26,7 @@ class TestHome(TestCase, WagtailTestUtils):
|
|||
def test_simple(self):
|
||||
response = self.client.get(reverse('wagtailadmin_home'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Welcome to the Test Site Wagtail CMS")
|
||||
|
||||
def test_admin_menu(self):
|
||||
response = self.client.get(reverse('wagtailadmin_home'))
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.conf import settings
|
|||
from django.shortcuts import render
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from wagtail.wagtailadmin.navigation import get_explorable_root_page
|
||||
from wagtail.wagtailadmin.site_summary import SiteSummaryPanel
|
||||
from wagtail.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.models import Page, PageRevision, UserPagePermissionsProxy
|
||||
|
@ -82,8 +83,20 @@ def home(request):
|
|||
for fn in hooks.get_hooks('construct_homepage_panels'):
|
||||
fn(request, panels)
|
||||
|
||||
root_page = get_explorable_root_page(request.user)
|
||||
if root_page:
|
||||
root_site = root_page.get_site()
|
||||
else:
|
||||
root_site = None
|
||||
|
||||
real_site_name = None
|
||||
if root_site:
|
||||
real_site_name = root_site.site_name if root_site.site_name else root_site.hostname
|
||||
|
||||
return render(request, "wagtailadmin/home.html", {
|
||||
'site_name': settings.WAGTAIL_SITE_NAME,
|
||||
'root_page': root_page,
|
||||
'root_site': root_site,
|
||||
'site_name': real_site_name if real_site_name else settings.WAGTAIL_SITE_NAME,
|
||||
'panels': sorted(panels, key=lambda p: p.order),
|
||||
'user': request.user
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue