diff --git a/django/contrib/auth/decorators.py b/django/contrib/auth/decorators.py index 3407555852e1..d2e6845abede 100644 --- a/django/contrib/auth/decorators.py +++ b/django/contrib/auth/decorators.py @@ -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) diff --git a/docs/internals/contributing/writing-documentation.txt b/docs/internals/contributing/writing-documentation.txt index a9fa1a0267f0..cbbe611d7c35 100644 --- a/docs/internals/contributing/writing-documentation.txt +++ b/docs/internals/contributing/writing-documentation.txt @@ -142,6 +142,51 @@ will be themed differently than the documentation at `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 --------------------------------- diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index 0f38105713c3..1c42784d1394 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -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(), - ) diff --git a/docs/releases/6.2.txt b/docs/releases/6.2.txt index b949b0aa24ae..f1bde4805ca3 100644 --- a/docs/releases/6.2.txt +++ b/docs/releases/6.2.txt @@ -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 ~~~~~~~~~~ diff --git a/docs/topics/email.txt b/docs/topics/email.txt index 3aa52843796e..d52ffd12ed9d 100644 --- a/docs/topics/email.txt +++ b/docs/topics/email.txt @@ -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": { diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index b6c4e88a43ef..3a7dde7f2dc9 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -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" ) diff --git a/tests/requirements/py3.txt b/tests/requirements/py3.txt index 6603e94a2c63..e8056bd46f26 100644 --- a/tests/requirements/py3.txt +++ b/tests/requirements/py3.txt @@ -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