Remove remaining references to request.site

pull/5837/head
Matt Westcott 2020-01-24 12:48:55 +00:00
rodzic 76cd26b099
commit 4950158e46
5 zmienionych plików z 9 dodań i 6 usunięć

Wyświetl plik

@ -112,8 +112,11 @@ If access to a setting is required in the code, the :func:`~wagtail.contrib.sett
.. code-block:: python
from wagtail.core.models import Site
def view(request):
social_media_settings = SocialMediaSettings.for_site(request.site)
site = Site.find_for_request(request)
social_media_settings = SocialMediaSettings.for_site(site)
...
Using in Django templates

Wyświetl plik

@ -78,7 +78,8 @@ Reference
.. code-block:: python
# Get all the EventPages in the current site
site_events = EventPage.objects.in_site(request.site)
site = Site.find_for_request(request)
site_events = EventPage.objects.in_site(site)
.. automethod:: page

Wyświetl plik

@ -226,7 +226,7 @@ For more information, please see :meth:`wagtail.core.models.Page.get_url_parts`.
Obtaining URLs for page instances
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``Page.get_url(request)`` method can be called whenever a page URL is needed. It defaults to returning local URLs (not including the protocol or domain) if it can detect that the page is on the current site (via ``request.site``); otherwise, a full URL including the protocol and domain is returned. Whenever possible, the optional ``request`` argument should be included to enable per-request caching of site-level URL information and facilitate the generation of local URLs.
The ``Page.get_url(request)`` method can be called whenever a page URL is needed. It defaults to returning local URLs (not including the protocol or domain) if it determines that the page is on the current site (via the hostname in ``request``); otherwise, a full URL including the protocol and domain is returned. Whenever possible, the optional ``request`` argument should be included to enable per-request caching of site-level URL information and facilitate the generation of local URLs.
A common use case for ``get_url(request)`` is in any custom template tag your project may include for generating navigation menus. When writing such a custom template tag, ensure that it includes ``takes_context=True`` and use ``context.get('request')`` to safely pass the
request or ``None`` if no request exists in the context.

Wyświetl plik

@ -18,7 +18,6 @@ def sitemap(request, sitemaps=None, **kwargs):
def prepare_sitemaps(request, sitemaps):
"""Intialize the wagtail Sitemap by passing the request.site value. """
initialised_sitemaps = {}
for name, sitemap_cls in sitemaps.items():
if inspect.isclass(sitemap_cls) and issubclass(sitemap_cls, Sitemap):

Wyświetl plik

@ -29,11 +29,11 @@ def pageurl(context, page, fallback=None):
site = Site.find_for_request(context['request'])
current_site = site
except KeyError:
# site not available in the current context; fall back on page.url
# request not available in the current context; fall back on page.url
return page.url
if current_site is None:
# request.site is set to None; fall back on page.url
# request does not correspond to a recognised site; fall back on page.url
return page.url
# Pass page.relative_url the request object, which may contain a cached copy of