From eaea9deca849262a677fec0f0d74495bb146f691 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Sat, 10 Sep 2011 03:04:30 +0000 Subject: [PATCH] Fixed #16790 -- Modified the geographic admin to work after r16594. Thanks, jdiego, for the bug report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16775 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/admin/options.py | 6 +++--- django/contrib/gis/tests/__init__.py | 3 +++ django/contrib/gis/tests/geoadmin/__init__.py | 0 django/contrib/gis/tests/geoadmin/models.py | 10 ++++++++++ django/contrib/gis/tests/geoadmin/tests.py | 14 ++++++++++++++ django/contrib/gis/tests/geoadmin/urls.py | 6 ++++++ 6 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 django/contrib/gis/tests/geoadmin/__init__.py create mode 100644 django/contrib/gis/tests/geoadmin/models.py create mode 100644 django/contrib/gis/tests/geoadmin/tests.py create mode 100644 django/contrib/gis/tests/geoadmin/urls.py diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index 1014cb31f5d..4eced802f51 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 3d04242fa8d..f27ce7a40b2 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 00000000000..e69de29bb2d diff --git a/django/contrib/gis/tests/geoadmin/models.py b/django/contrib/gis/tests/geoadmin/models.py new file mode 100644 index 00000000000..51a76d1a0e5 --- /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 00000000000..419e30cd02e --- /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 00000000000..c3e8af8fe13 --- /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)), +)