diff --git a/ckanext/spatial/model.py b/ckanext/spatial/model.py index 5144602..908dcd8 100644 --- a/ckanext/spatial/model.py +++ b/ckanext/spatial/model.py @@ -1,12 +1,16 @@ from logging import getLogger +from sqlalchemy import types, Column, Table + +from geoalchemy import Geometry, GeometryColumn, GeometryDDL, GeometryExtensionColumn +from geoalchemy.postgis import PGComparator + + from ckan.lib.base import config from ckan import model from ckan.model import Session -from ckan.model.meta import * +from ckan.model import meta from ckan.model.domain_object import DomainObject -from geoalchemy import * -from geoalchemy.postgis import PGComparator log = getLogger(__name__) @@ -20,9 +24,9 @@ def setup(srid=None): define_spatial_tables(srid) log.debug('Spatial tables defined in memory') - if model.repo.are_tables_created(): - if not Table('geometry_columns',metadata).exists() or \ - not Table('spatial_ref_sys',metadata).exists(): + if model.package_table.exists(): + if not Table('geometry_columns',meta.metadata).exists() or \ + not Table('spatial_ref_sys',meta.metadata).exists(): raise Exception('The spatial extension is enabled, but PostGIS ' + \ 'has not been set up in the database. ' + \ 'Please refer to the "Setting up PostGIS" section in the README.') @@ -63,12 +67,12 @@ def define_spatial_tables(db_srid=None): else: db_srid = int(db_srid) - package_extent_table = Table('package_extent', metadata, + package_extent_table = Table('package_extent', meta.metadata, Column('package_id', types.UnicodeText, primary_key=True), GeometryExtensionColumn('the_geom', Geometry(2,srid=db_srid))) - mapper(PackageExtent, package_extent_table, properties={ + meta.mapper(PackageExtent, package_extent_table, properties={ 'the_geom': GeometryColumn(package_extent_table.c.the_geom, comparator=PGComparator)}) diff --git a/ckanext/spatial/public/ckanext/spatial/css/spatial_search_form.css b/ckanext/spatial/public/ckanext/spatial/css/spatial_search_form.css index 2f8a9f3..f89afba 100644 --- a/ckanext/spatial/public/ckanext/spatial/css/spatial_search_form.css +++ b/ckanext/spatial/public/ckanext/spatial/css/spatial_search_form.css @@ -1,5 +1,5 @@ #spatial-search-show{ - margin-top: 10px; + margin-top: 40px; } #spatial-search-show a.more:after { diff --git a/ckanext/spatial/tests/test_dataset_map.py b/ckanext/spatial/tests/test_dataset_map.py index 4e77109..8815563 100644 --- a/ckanext/spatial/tests/test_dataset_map.py +++ b/ckanext/spatial/tests/test_dataset_map.py @@ -16,18 +16,19 @@ class TestDatasetMap(FunctionalTestCase,SpatialTestBase): def test_map_shown(self): CreateTestData.create() - + + extra_environ = {'REMOTE_USER': 'annafan'} name = 'annakarenina' offset = url_for(controller='package', action='edit',id=name) - res = self.app.get(offset) + res = self.app.get(offset, extra_environ=extra_environ) assert 'Edit - Datasets' in res fv = res.forms['dataset-edit'] prefix = '' fv[prefix+'extras__1__key'] = u'spatial' fv[prefix+'extras__1__value'] = self.geojson_examples['point'] - res = fv.submit('save') + res = fv.submit('save', extra_environ=extra_environ) assert not 'Error' in res, res # Load the dataset page and check if the libraries have been loaded diff --git a/ckanext/spatial/tests/test_functional.py b/ckanext/spatial/tests/test_functional.py index 5c3de81..2e29aa9 100644 --- a/ckanext/spatial/tests/test_functional.py +++ b/ckanext/spatial/tests/test_functional.py @@ -14,6 +14,11 @@ log = logging.getLogger(__name__) class TestPackageController(FunctionalTestCase,SpatialTestBase): + + @classmethod + def setup_class(cls): + cls.extra_environ = {'REMOTE_USER': 'annafan'} + def setup(self): CreateTestData.create() @@ -24,7 +29,7 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): name = 'test-spatial-dataset-1' offset = url_for(controller='package', action='new') - res = self.app.get(offset) + res = self.app.get(offset, extra_environ=self.extra_environ) assert 'Add - Datasets' in res fv = res.forms['dataset-edit'] prefix = '' @@ -32,7 +37,7 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): fv[prefix+'extras__0__key'] = u'spatial' fv[prefix+'extras__0__value'] = self.geojson_examples['point'] - res = fv.submit('save') + res = fv.submit('save', extra_environ=self.extra_environ) assert not 'Error' in res, res package = Package.get(name) @@ -52,7 +57,7 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): name = 'test-spatial-dataset-2' offset = url_for(controller='package', action='new') - res = self.app.get(offset) + res = self.app.get(offset, extra_environ=self.extra_environ) assert 'Add - Datasets' in res fv = res.forms['dataset-edit'] prefix = '' @@ -60,7 +65,7 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): fv[prefix+'extras__0__key'] = u'spatial' fv[prefix+'extras__0__value'] = u'{"Type":Bad Json]' - res = fv.submit('save') + res = fv.submit('save', extra_environ=self.extra_environ) assert 'Error' in res, res assert 'Spatial' in res assert 'Error decoding JSON object' in res @@ -72,7 +77,7 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): name = 'test-spatial-dataset-3' offset = url_for(controller='package', action='new') - res = self.app.get(offset) + res = self.app.get(offset, extra_environ=self.extra_environ) assert 'Add - Datasets' in res fv = res.forms['dataset-edit'] prefix = '' @@ -80,7 +85,7 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): fv[prefix+'extras__0__key'] = u'spatial' fv[prefix+'extras__0__value'] = u'{"Type":"Bad_GeoJSON","a":2}' - res = fv.submit('save') + res = fv.submit('save', extra_environ=self.extra_environ) assert 'Error' in res, res assert 'Spatial' in res assert 'Error creating geometry' in res @@ -93,14 +98,14 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): name = 'annakarenina' offset = url_for(controller='package', action='edit',id=name) - res = self.app.get(offset) + res = self.app.get(offset, extra_environ=self.extra_environ) assert 'Edit - Datasets' in res fv = res.forms['dataset-edit'] prefix = '' fv[prefix+'extras__1__key'] = u'spatial' fv[prefix+'extras__1__value'] = self.geojson_examples['point'] - res = fv.submit('save') + res = fv.submit('save', extra_environ=self.extra_environ) assert not 'Error' in res, res package = Package.get(name) @@ -117,13 +122,13 @@ class TestPackageController(FunctionalTestCase,SpatialTestBase): # Update the spatial extra offset = url_for(controller='package', action='edit',id=name) - res = self.app.get(offset) + res = self.app.get(offset, extra_environ=self.extra_environ) assert 'Edit - Datasets' in res fv = res.forms['dataset-edit'] prefix = '' fv[prefix+'extras__1__value'] = self.geojson_examples['polygon'] - res = fv.submit('save') + res = fv.submit('save', extra_environ=self.extra_environ) assert not 'Error' in res, res # Check that the PackageExtent object has been updated