mirror of
https://github.com/django/django.git
synced 2025-03-30 19:20:44 +00:00
Delayed GDAL check for OSMGeoAdmin
This commit is contained in:
parent
b695153852
commit
a37dcfd0a3
@ -4,18 +4,5 @@ from django.contrib.admin import ( # NOQA: flake8 detects only the last __all__
|
|||||||
HORIZONTAL, VERTICAL,
|
HORIZONTAL, VERTICAL,
|
||||||
)
|
)
|
||||||
# Geographic admin options classes and widgets.
|
# Geographic admin options classes and widgets.
|
||||||
from django.contrib.gis.admin.options import GeoModelAdmin # NOQA
|
from django.contrib.gis.admin.options import GeoModelAdmin, OSMGeoAdmin # NOQA
|
||||||
from django.contrib.gis.admin.widgets import OpenLayersWidget # NOQA
|
from django.contrib.gis.admin.widgets import OpenLayersWidget # NOQA
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"autodiscover", "site", "AdminSite", "ModelAdmin", "StackedInline",
|
|
||||||
"TabularInline", "HORIZONTAL", "VERTICAL",
|
|
||||||
"GeoModelAdmin", "OpenLayersWidget", "HAS_OSM",
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
|
||||||
from django.contrib.gis.admin.options import OSMGeoAdmin
|
|
||||||
HAS_OSM = True
|
|
||||||
__all__ += ['OSMGeoAdmin']
|
|
||||||
except ImportError:
|
|
||||||
HAS_OSM = False
|
|
||||||
|
@ -2,6 +2,9 @@ from django.contrib.admin import ModelAdmin
|
|||||||
from django.contrib.gis.admin.widgets import OpenLayersWidget
|
from django.contrib.gis.admin.widgets import OpenLayersWidget
|
||||||
from django.contrib.gis.db import models
|
from django.contrib.gis.db import models
|
||||||
from django.contrib.gis.gdal import HAS_GDAL, OGRGeomType
|
from django.contrib.gis.gdal import HAS_GDAL, OGRGeomType
|
||||||
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
|
spherical_mercator_srid = 3857
|
||||||
|
|
||||||
|
|
||||||
class GeoModelAdmin(ModelAdmin):
|
class GeoModelAdmin(ModelAdmin):
|
||||||
@ -123,14 +126,17 @@ class GeoModelAdmin(ModelAdmin):
|
|||||||
}
|
}
|
||||||
return OLMap
|
return OLMap
|
||||||
|
|
||||||
if HAS_GDAL:
|
|
||||||
spherical_mercator_srid = 3857
|
|
||||||
|
|
||||||
class OSMGeoAdmin(GeoModelAdmin):
|
class OSMGeoAdmin(GeoModelAdmin):
|
||||||
map_template = 'gis/admin/osm.html'
|
map_template = 'gis/admin/osm.html'
|
||||||
num_zoom = 20
|
num_zoom = 20
|
||||||
map_srid = spherical_mercator_srid
|
map_srid = spherical_mercator_srid
|
||||||
max_extent = '-20037508,-20037508,20037508,20037508'
|
max_extent = '-20037508,-20037508,20037508,20037508'
|
||||||
max_resolution = '156543.0339'
|
max_resolution = '156543.0339'
|
||||||
point_zoom = num_zoom - 6
|
point_zoom = num_zoom - 6
|
||||||
units = 'm'
|
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)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.contrib.gis.gdal import HAS_GDAL
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
|
||||||
from ..admin import admin
|
from ..admin import admin
|
||||||
@ -19,4 +20,5 @@ class City(models.Model):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
site = admin.AdminSite(name='admin_gis')
|
site = admin.AdminSite(name='admin_gis')
|
||||||
site.register(City, admin.OSMGeoAdmin)
|
if HAS_GDAL:
|
||||||
|
site.register(City, admin.OSMGeoAdmin)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user