summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-05-15 09:10:54 -0400
committerTim Graham <timograham@gmail.com>2015-05-15 09:20:04 -0400
commit30e57038440d7785072088c10fef3ed6e71faba5 (patch)
tree81afa722ac1551242570b40a3a7d4bce59d4c752 /django
parentf19932591b91c519545e4a53854f6289e35fa239 (diff)
[1.8.x] Fixed #24802 -- Delayed GDAL check for OSMGeoAdmin
Backport of a37dcfd0a38cff24eb4fb5e3858791aa5428c853 from master
Diffstat (limited to 'django')
-rw-r--r--django/contrib/gis/admin/__init__.py19
-rw-r--r--django/contrib/gis/admin/options.py26
2 files changed, 22 insertions, 23 deletions
diff --git a/django/contrib/gis/admin/__init__.py b/django/contrib/gis/admin/__init__.py
index fdf7166306..79e51e4303 100644
--- a/django/contrib/gis/admin/__init__.py
+++ b/django/contrib/gis/admin/__init__.py
@@ -1,21 +1,14 @@
# Getting the normal admin routines, classes, and `site` instance.
-from django.contrib.admin import ( # NOQA: flake8 detects only the last __all__
+from django.contrib.admin import (
autodiscover, site, AdminSite, ModelAdmin, StackedInline, TabularInline,
HORIZONTAL, VERTICAL,
)
# Geographic admin options classes and widgets.
-from django.contrib.gis.admin.options import GeoModelAdmin # NOQA
-from django.contrib.gis.admin.widgets import OpenLayersWidget # NOQA
+from django.contrib.gis.admin.options import GeoModelAdmin, OSMGeoAdmin
+from django.contrib.gis.admin.widgets import OpenLayersWidget
__all__ = [
- "autodiscover", "site", "AdminSite", "ModelAdmin", "StackedInline",
- "TabularInline", "HORIZONTAL", "VERTICAL",
- "GeoModelAdmin", "OpenLayersWidget", "HAS_OSM",
+ 'autodiscover', 'site', 'AdminSite', 'ModelAdmin', 'StackedInline',
+ 'TabularInline', 'HORIZONTAL', 'VERTICAL', 'GeoModelAdmin', 'OSMGeoAdmin',
+ 'OpenLayersWidget',
]
-
-try:
- from django.contrib.gis.admin.options import OSMGeoAdmin
- HAS_OSM = True
- __all__ += ['OSMGeoAdmin']
-except ImportError:
- HAS_OSM = False
diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py
index f9412336e3..dca46829fd 100644
--- a/django/contrib/gis/admin/options.py
+++ b/django/contrib/gis/admin/options.py
@@ -2,6 +2,9 @@ from django.contrib.admin import ModelAdmin
from django.contrib.gis.admin.widgets import OpenLayersWidget
from django.contrib.gis.db import models
from django.contrib.gis.gdal import HAS_GDAL, OGRGeomType
+from django.core.exceptions import ImproperlyConfigured
+
+spherical_mercator_srid = 3857
class GeoModelAdmin(ModelAdmin):
@@ -123,14 +126,17 @@ class GeoModelAdmin(ModelAdmin):
}
return OLMap
-if HAS_GDAL:
- spherical_mercator_srid = 3857
- class OSMGeoAdmin(GeoModelAdmin):
- map_template = 'gis/admin/osm.html'
- num_zoom = 20
- map_srid = spherical_mercator_srid
- max_extent = '-20037508,-20037508,20037508,20037508'
- max_resolution = '156543.0339'
- point_zoom = num_zoom - 6
- units = 'm'
+class OSMGeoAdmin(GeoModelAdmin):
+ map_template = 'gis/admin/osm.html'
+ num_zoom = 20
+ map_srid = spherical_mercator_srid
+ max_extent = '-20037508,-20037508,20037508,20037508'
+ max_resolution = '156543.0339'
+ point_zoom = num_zoom - 6
+ units = 'm'
+
+ def __init__(self, *args):
+ if not HAS_GDAL:
+ raise ImproperlyConfigured("OSMGeoAdmin is not usable without GDAL libs installed")
+ super(OSMGeoAdmin, self).__init__(*args)