Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions django/contrib/auth/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,27 @@ def _redirect_to_login(request):
return redirect_to_login(path, resolved_login_url, redirect_field_name)

if iscoroutinefunction(view_func):
if iscoroutinefunction(test_func):
_async_test_func = test_func
else:
_async_test_func = sync_to_async(test_func)

async def _view_wrapper(request, *args, **kwargs):
auser = await request.auser()
if iscoroutinefunction(test_func):
test_pass = await test_func(auser)
else:
test_pass = await sync_to_async(test_func)(auser)
test_pass = await _async_test_func(auser)

if test_pass:
return await view_func(request, *args, **kwargs)
return _redirect_to_login(request)

else:
if iscoroutinefunction(test_func):
_sync_test_func = async_to_sync(test_func)
else:
_sync_test_func = test_func

def _view_wrapper(request, *args, **kwargs):
if iscoroutinefunction(test_func):
test_pass = async_to_sync(test_func)(request.user)
else:
test_pass = test_func(request.user)
test_pass = _sync_test_func(request.user)

if test_pass:
return view_func(request, *args, **kwargs)
Expand Down
45 changes: 45 additions & 0 deletions docs/internals/contributing/writing-documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,51 @@ will be themed differently than the documentation at
`docs.djangoproject.com <https://docs.djangoproject.com/>`_. This is OK! If
your changes look good on your local machine, they'll look good on the website.

Automating documentation rebuilds
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:pypi:`sphinx-autobuild` can be used to automatically rebuild the documentation
and reload the documentation page in the browser whenever a file changes. To
enable auto-reloading:

1. Install the package:

.. console::

$ python -m pip install sphinx-autobuild

2. From the ``docs`` directory, run one of the following commands:

* On Linux and macOS:

.. code-block:: shell

$ SPHINXBUILD=sphinx-autobuild SPHINXOPTS="--open-browser --delay 0" make html

* On Windows (Command Prompt):

.. code-block:: doscon

...\> set SPHINXBUILD=sphinx-autobuild
...\> set SPHINXOPTS=--open-browser --delay 0
...\> make html

* On Windows (PowerShell):

.. code-block:: powershell

PS> $env:SPHINXBUILD="sphinx-autobuild"
PS> $env:SPHINXOPTS="--open-browser --delay 0"
PS> make html

Alternatively, ``sphinx-autobuild`` can be invoked directly:

.. console::

$ sphinx-autobuild . _build/html --open-browser --delay 0

The auto-reloader can be stopped with ``Ctrl+C``.

Making edits to the documentation
---------------------------------

Expand Down
28 changes: 0 additions & 28 deletions docs/ref/utils.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1187,31 +1187,3 @@ For a complete discussion on the usage of the following see the
Turns a Django template into something that is understood by ``xgettext``.
It does so by translating the Django translation tags into standard
``gettext`` function invocations.

``django.utils.warnings``
=========================

.. module:: django.utils.warnings
:synopsis: Helpers for issuing warnings.

.. function:: django_file_prefixes()

.. versionadded:: 6.2

Returns a tuple of file path prefixes for the Django package directory.
This is used as the ``skip_file_prefixes`` argument to
:func:`warnings.warn` so that warnings are attributed to the *caller*
(your project or third-party library) rather than to Django internals.

The result is cached after the first call.

Usage example::

import warnings
from django.utils.warnings import django_file_prefixes

warnings.warn(
"Your custom warning message.",
category=RuntimeWarning,
skip_file_prefixes=django_file_prefixes(),
)
5 changes: 1 addition & 4 deletions docs/releases/6.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ URLs
Utilities
~~~~~~~~~

* The new ``django.utils.warnings`` module provides
:func:`~django.utils.warnings.django_file_prefixes`, which returns the file
path prefix of the Django package for use as the ``skip_file_prefixes``
argument of :func:`warnings.warn`.
* ...

Validators
~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ is printed to the console as a development aid (for projects created with
:djadmin:`startproject`) or results in a ``MailerDoesNotExist`` error (when the
:setting:`MAILERS` setting isn't defined).

Define edit the :setting:`MAILERS` setting to tell Django how to send email.
For example, to send through an SMTP server running on the local machine::
Use the :setting:`MAILERS` setting to tell Django how to send email. For
example, to send through an SMTP server running on the local machine::

MAILERS = {
"default": {
Expand Down
4 changes: 3 additions & 1 deletion tests/admin_views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7489,7 +7489,9 @@ def test_messages(self):
Select(self.selenium.find_element(By.NAME, "action")).select_by_value(
f"message_{level}"
)
self.selenium.find_element(By.XPATH, '//button[text()="Run"]').click()
self.selenium.find_element(
By.CSS_SELECTOR, 'button[name="index"]'
).click()
message = self.selenium.find_element(
By.CSS_SELECTOR, "ul.messagelist li"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/py3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pymemcache >= 3.4.0
pywatchman; sys_platform != 'win32'
PyYAML >= 6.0.2
redis >= 5.1.0
selenium >= 4.23.0,<4.44.0
selenium >= 4.23.0
sqlparse >= 0.5.0
tblib >= 3.0.0
tzdata
Expand Down
Loading