diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index 1014cb31f5..4eced802f5 100644 --- a/django/contrib/gis/admin/options.py +++ b/django/contrib/gis/admin/options.py @@ -39,13 +39,13 @@ class GeoModelAdmin(ModelAdmin): debug = False widget = OpenLayersWidget - def _media(self): + @property + def media(self): "Injects OpenLayers JavaScript into the admin." - media = super(GeoModelAdmin, self)._media() + media = super(GeoModelAdmin, self).media media.add_js([self.openlayers_url]) media.add_js(self.extra_js) return media - media = property(_media) def formfield_for_dbfield(self, db_field, **kwargs): """ diff --git a/django/contrib/gis/tests/__init__.py b/django/contrib/gis/tests/__init__.py index 3d04242fa8..f27ce7a40b 100644 --- a/django/contrib/gis/tests/__init__.py +++ b/django/contrib/gis/tests/__init__.py @@ -29,6 +29,9 @@ def geo_apps(namespace=True, runtests=False): # The following GeoDjango test apps depend on GDAL support. if HAS_GDAL: + # Geographic admin requires GDAL + apps.append('geoadmin') + # 3D apps use LayerMapping, which uses GDAL. if connection.ops.postgis and GEOS_PREPARE: apps.append('geo3d') diff --git a/django/contrib/gis/tests/geoadmin/__init__.py b/django/contrib/gis/tests/geoadmin/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/contrib/gis/tests/geoadmin/models.py b/django/contrib/gis/tests/geoadmin/models.py new file mode 100644 index 0000000000..51a76d1a0e --- /dev/null +++ b/django/contrib/gis/tests/geoadmin/models.py @@ -0,0 +1,10 @@ +from django.contrib.gis.db import models +from django.contrib.gis import admin + +class City(models.Model): + name = models.CharField(max_length=30) + point = models.PointField() + objects = models.GeoManager() + def __unicode__(self): return self.name + +admin.site.register(City, admin.OSMGeoAdmin) diff --git a/django/contrib/gis/tests/geoadmin/tests.py b/django/contrib/gis/tests/geoadmin/tests.py new file mode 100644 index 0000000000..419e30cd02 --- /dev/null +++ b/django/contrib/gis/tests/geoadmin/tests.py @@ -0,0 +1,14 @@ +from django.test import TestCase +from django.contrib.gis import admin +from models import City + +class GeoAdminTest(TestCase): + urls = 'django.contrib.gis.tests.geoadmin.urls' + + def test01_ensure_geographic_media(self): + geoadmin = admin.site._registry[City] + admin_js = geoadmin.media.render_js() + osm_url = geoadmin.extra_js[0] + self.assertTrue(any([geoadmin.openlayers_url in js for js in admin_js])) + self.assertTrue(any([osm_url in js for js in admin_js])) + diff --git a/django/contrib/gis/tests/geoadmin/urls.py b/django/contrib/gis/tests/geoadmin/urls.py new file mode 100644 index 0000000000..c3e8af8fe1 --- /dev/null +++ b/django/contrib/gis/tests/geoadmin/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls.defaults import * +from django.contrib import admin + +urlpatterns = patterns('', + (r'^admin/', include(admin.site.urls)), +)