8000 Delayed GDAL check for OSMGeoAdmin · ddriddle/django@a37dcfd · GitHub
[go: up one dir, main page]

Skip to content

Commit a37dcfd

Browse files
committed
Delayed GDAL check for OSMGeoAdmin
1 parent b695153 commit a37dcfd

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

django/contrib/gis/admin/__init__.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,5 @@
44
HORIZONTAL, VERTICAL,
55
)
66
# Geographic admin options classes and widgets.
7-
from django.contrib.gis.admin.options import GeoModelAdmin # NOQA
7+
from django.contrib.gis.admin.options import GeoModelAdmin, OSMGeoAdmin # NOQA
88
from django.contrib.gis.admin.widgets import OpenLayersWidget # NOQA
9-
10-
__all__ = [
11-
"autodiscover", "site", "AdminSite", "ModelAdmin", "StackedInline",
12-
"TabularInline", "HORIZONTAL", "VERTICAL",
13-
"GeoModelAdmin", "OpenLayersWidget", "HAS_OSM",
14-
]
15-
16-
try:
17-
from django.contrib.gis.admin.options import OSMGeoAdmin
18-
HAS_OSM = True
19-
__all__ += ['OSMGeoAdmin']
20-
except ImportError:
21-
HAS_OSM = False

django/contrib/gis/admin/options.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from django.contrib.gis.admin.widgets import OpenLayersWidget
33
from django.contrib.gis.db import models
44
from django.contrib.gis.gdal import HAS_GDAL, OGRGeomType
5+
from django.core.exceptions import ImproperlyConfigured
6+
7+
spherical_mercator_srid = 3857
58

69

710
class GeoModelAdmin(ModelAdmin):
@@ -123,14 +126,17 @@ class OLMap(self.widget):
123126
}
124127
return OLMap
125128

126-
if HAS_GDAL:
127-
spherical_mercator_srid = 3857
128129

129-
class OSMGeoAdmin(GeoModelAdmin):
130-
map_template = 'gis/admin/osm.html'
131-
num_zoom = 20
132-
map_srid = spherical_mercator_srid
133-
max_extent = '-20037508,-20037508,20037508,20037508'
134-
max_resolution = '156543.0339'
135-
point_zoom = num_zoom - 6
136-
units = 'm'
130+
class OSMGeoAdmin(GeoModelAdmin):
131+
map_template = 'gis/admin/osm.html'
132+
num_zoom = 20
133+
map_srid = spherical_mercator_srid
134+
max_extent = '-20037508,-20037508,20037508,20037508'
135+
max_resolution = '156543.0339'
136+
point_zoom = num_zoom - 6
137+
units = 'm'
138+
139+
def __init__(self, *args):
140+
if not HAS_GDAL:
141+
raise ImproperlyConfigured("OSMGeoAdmin is not usable without GDAL libs installed")
142+
super(OSMGeoAdmin, self).__init__(*args)

tests/gis_tests/geoadmin/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.contrib.gis.gdal import HAS_GDAL
12
from django.utils.encoding import python_2_unicode_compatible
23

34
from ..admin import admin
@@ -19,4 +20,5 @@ def __str__(self):
1920
return self.name
2021

2122
site = admin.AdminSite(name='admin_gis')
22-
site.register(City, admin.OSMGeoAdmin)
23+
if HAS_GDAL:
24+
site.register(City, admin.OSMGeoAdmin)

0 commit comments

Comments
 (0)
0