From d51fe5544dab8a41907e32f3f73a4a0dc3951c04 Mon Sep 17 00:00:00 2001
From: Michael Fladischer <FladischerMichael@fladi.at>
Date: Fri, 27 Jan 2017 09:50:38 +0100
Subject: Use local objects.inv where possible

Upstream uses intersphinx mappings that fetch the objects.inv for python by
HTTP from a remote host. Using the local objects.inv from python enables the
package to build without network connection.
---
 docs/conf.py | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/docs/conf.py b/docs/conf.py
index 7a3cef7..7b44b46 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -4,6 +4,7 @@ import os
 import pkginfo
 import sys
 import time
+import django
 
 on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
 pkg_info = pkginfo.Develop(os.path.join(os.path.dirname(__file__), '..'))
@@ -14,10 +15,28 @@ extensions = [
     'sphinx.ext.intersphinx'
     ]
 
-intersphinx_mapping = {
-    'http://docs.python.org': None,
-    'http://django.readthedocs.org/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/{v}/'.format(
+        v='.'.join(map(str, sys.version_info[0:2]))
+    ),
+    '/usr/share/doc/python{v}/html/objects.inv'.format(
+        v='.'.join(map(str, sys.version_info[0:2]))
+    )
+))
+intersphinx_mapping.update(check_object_path(
+    'django',
+    'https://docs.djangoproject.com/en/{v}/'.format(
+        v='.'.join(map(str, django.VERSION[:2]))
+    ),
+    '/usr/share/doc/python-django-doc/html/objects.inv'
+))
 
 # General
 source_suffix = '.txt'
