Skip to content
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

Merged
merged 3 commits into from Apr 15, 2023

Conversation

edisonwang03
Copy link
Contributor

Added documentation for django.contrib.admin.sites.all_sites

@edisonwang03
Copy link
Contributor Author

I'm unsure about the formatting, but the content should be good. Please check so I can revise if needed

Comment on lines 3211 to 3237
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

Copy link
Member

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?

Copy link
Sponsor Member

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...)

Copy link
Sponsor Member

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..."

@felixxm
Copy link
Member

felixxm commented Apr 14, 2023

@edisonwang03 Do you have time to keep working on this?

@felixxm felixxm changed the title Fixed #34419 -- Added doc for all_sites Fixed #34419 -- Doc'd django.contrib.admin.sites.all_sites. Apr 14, 2023
@edisonwang03
Copy link
Contributor Author

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 all_sites can be used

@felixxm
Copy link
Member

felixxm commented Apr 15, 2023

@edisonwang03 Thanks 👍

@felixxm felixxm merged commit 255f534 into django:main Apr 15, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants