From: Michael Fladischer <fladi@debian.org>
Date: Sun, 1 Oct 2023 21:23:57 +0000
Subject: Use local objects.inv in intersphinx mapping.

Forwarded: not-needed
---
 docs/conf.py | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index eb59b36..9acd3bc 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -13,6 +13,7 @@
 import os
 import sys
 
+import django
 from django.conf import settings
 
 settings.configure(USE_I18N=False, USE_L10N=False)
@@ -76,11 +77,26 @@ nitpick_ignore_regex = [
     ('py:class', r'drf_spectacular\.utils\.F'),
 ]
 
-intersphinx_mapping = {
-    'python': ('https://docs.python.org/3/', None),
-    'django': ('https://docs.djangoproject.com/en/stable/', 'https://docs.djangoproject.com/en/stable/_objects/'),
-    'drf-yasg': ('https://drf-yasg.readthedocs.io/en/stable/', None),
-}
+def check_object_path(key, url, path):
+    if os.path.isfile(path):
+        return {key: (url, path)}
+    return {}
+
+intersphinx_mapping = {}
+intersphinx_mapping.update(
+    check_object_path(
+        'python',
+        'https://docs.python.org/{}/'.format('.'.join((str(x) for x in sys.version_info[:2]))),
+        '/usr/share/doc/python{}/html/objects.inv'.format('.'.join((str(x) for x in sys.version_info[:2])))
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'django',
+        'https://docs.djangoproject.com/en/' + '.'.join((str(c) for c in django.VERSION[:2])) + '/_objects/',
+        '/usr/share/doc/python-django-doc/html/objects.inv'
+    )
+)
 
 # -- Options for HTML output -------------------------------------------------
 
