New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #34419 -- Doc'd django.contrib.admin.sites.all_sites. #16712
Conversation
I'm unsure about the formatting, but the content should be good. Please check so I can revise if needed |
docs/ref/contrib/admin/index.txt
Outdated
Creating custom checks and tests | ||
------------------------------- | ||
|
||
The global variable ``all_sites`` is a weak set of all ``AdminSite`` instances. | ||
You can iterate through ``all_sites`` to perform custom checks and tests. | ||
|
||
In this example, the ``test_all_sites_config`` function iterates over the | ||
``all_sites`` set and performs tests on each ``AdminSite`` instance to ensure | ||
that its configuration properties are not ``None``. If any of the tests fail, | ||
an ``AssertionError`` is raised, indicating that the ``AdminSite`` instance | ||
is not properly configured: | ||
|
||
.. code-block:: python | ||
from django.contrib.admin.sites import AdminSite, all_sites | ||
|
||
|
||
def test_all_sites_config(): | ||
""" | ||
A custom function that tests the configuration of all `AdminSite` instances | ||
""" | ||
|
||
for site in all_sites: | ||
# Test that the `AdminSite` is properly configured | ||
assert site.site_title is not None | ||
assert site.site_header is not None | ||
assert site.index_title is not None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the extensive paragraph is not needed. I'd add a small reference to the AdminSite
docs, e.g.
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 3fd13b28e8..2eb5565fcb 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -2831,6 +2831,10 @@ linked to the document in ``{% block dark-mode-vars %}``.
See :ref:`customizing-adminsite` for an example of customizing the
:class:`AdminSite` class.
+.. data:: django.contrib.admin.sites.all_sites
+
+ A weak set contains all admin site instances.
+
``AdminSite`` attributes
------------------------
@adamchainz What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes something like that, but with a link to WeakSet
in the python docs, since it's a rare data type.
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 3fd13b28e8..2eb5565fcb 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -2831,6 +2831,10 @@ linked to the document in ``{% block dark-mode-vars %}``.
See :ref:`customizing-adminsite` for an example of customizing the
:class:`AdminSite` class.
+.. data:: django.contrib.admin.sites.all_sites
+
+ A :class:`~weakref.WeakSet` contains all admin site instances.
+
``AdminSite`` attributes
------------------------
(untested, :class:
should work though...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, the content you have written, @edisonwang03 , is perfect blog post material. "Here's how I tested all my admin sites were well configured..."
@edisonwang03 Do you have time to keep working on this? |
Sorry for delay. I made the changes according to adamchainz. In the future, I may write a blog post on what I initially wrote to better explain how |
@edisonwang03 Thanks 👍 |
Added documentation for django.contrib.admin.sites.all_sites