From: Michael Fladischer <FladischerMichael@fladi.at>
Date: Fri, 12 Nov 2021 14:02:42 +0000
Subject: Make intersphinx use local copies of objects.inv files.

---
 docs/conf.py | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index 2f3f587..53d50d5 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -15,6 +15,7 @@ import os
 import sys
 
 import django
+import polymorphic
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
@@ -282,8 +283,30 @@ texinfo_documents = [
 
 
 # Example configuration for intersphinx: refer to the Python standard library.
-intersphinx_mapping = {
-    "https://docs.python.org/3/": None,
-    "https://docs.djangoproject.com/en/dev": "https://docs.djangoproject.com/en/dev/_objects/",
-    "polymorphic": ("https://django-polymorphic.readthedocs.io/en/latest/", 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/',
+        '/usr/share/doc/python' + '.'.join([str(x) for x in sys.version_info[0:2]]) + '/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'django',
+        'https://docs.djangoproject.com/en/' + django.get_version() + '/',
+        '/usr/share/doc/python-django-doc/html/objects.inv'
+    )
+)
+intersphinx_mapping.update(
+    check_object_path(
+        'polymorphic',
+        'https://django-polymorphic.readthedocs.io/en/' + polymorphic.__version__ + '/',
+        '/usr/share/doc/python-django-polymorphic-doc/html/objects.inv'
+    )
+)
