Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geomfields Reorg for Issue #28 #29

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ install:
before_script:
- bash ./travis_postgis_setup.sh

script: python example/manage.py test conduit
script:
- python example/manage.py test conduit
- python example/manage.py test --settings='geoexample.settings'

matrix:
exclude:
Expand Down
8 changes: 8 additions & 0 deletions conduit/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db.models.fields import FieldDoesNotExist
from django.db import models
from django.contrib.gis.db import models as geomodels
from django.contrib.gis.geos import fromstr
from django.conf.urls import url
from decimal import Decimal
from dateutil import parser
Expand Down Expand Up @@ -465,6 +467,9 @@ def _from_basic_type(self, field, data):
if isinstance(field, models.DecimalField):
return Decimal(data)

if isinstance(field, geomodels.GeometryField):
return fromstr(data)

if isinstance(field, models.ForeignKey):
return data

Expand Down Expand Up @@ -836,6 +841,9 @@ def _to_basic_type(self, obj, field):
if isinstance(field, models.DecimalField):
return field.value_to_string(obj)

if isinstance(field, geomodels.GeometryField):
return field.value_to_string(obj)

if isinstance(field, models.ForeignKey):
return field.value_from_object(obj)

Expand Down
103 changes: 0 additions & 103 deletions conduit/test/non_geo_testrunner.py

This file was deleted.

34 changes: 34 additions & 0 deletions conduit/test/testrunners.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
try:
from django.test.runner import DiscoverRunner as BaseRunner
except ImportError:
# Django < 1.6 fallback
from django.test.simple import DjangoTestSuiteRunner as BaseRunner
from django.utils.unittest import TestSuite

class GeoTestRunner( BaseRunner ):
"""
only run geo related tests. To run then use the --settings flags:
`python example/manage.py test --settings='geoexample.settings'`
"""

def build_suite(self, *args, **kwargs):
suite = super(GeoTestRunner, self).build_suite(*args, **kwargs)
filtered_suite = TestSuite()
filtered_suite.addTests( [ test for test in suite if test.__class__.__name__ == 'GeoMethodTestCase' ] )
return filtered_suite


class StandardTestRunner( BaseRunner ):
"""
for local development and quick "spot-checks" with the unit tests
the installation, dependencies, permissions, and time required to set up Postgresql/PostGIS might be annoying.
this test runner excludes geo related tests. it is the default TestRunner.
"""

def build_suite(self, *args, **kwargs):
suite = super(StandardTestRunner, self).build_suite(*args, **kwargs)
filtered_suite = TestSuite()
filtered_suite.addTests( [ test for test in suite if test.__class__.__name__ != 'GeoMethodTestCase' ] )
return filtered_suite


26 changes: 0 additions & 26 deletions example/example/geo_db_router.py

This file was deleted.

2 changes: 2 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
'example',
)

TEST_RUNNER = 'conduit.test.testrunners.StandardTestRunner'

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
## api/views.py
from conduit.api import ModelResource
from conduit.api.fields import ForeignKeyField, ManyToManyField
from geoexample.models import GeoBar, GeoBaz, GeoFoo


#
#
# resources based on GeoManager(s)
#
#
class GeoBarResource(ModelResource):
class Meta(ModelResource.Meta):
model = GeoBar
Expand Down
75 changes: 32 additions & 43 deletions example/geoexample/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,35 @@

MANAGERS = ADMINS

#
# NOTE: USER and PASSWORD below are defaulted to what Travis CI expects.
# To run local tests you will need to:
#
# 0. create a spatially enabled database called 'geoexample'
# ( see django-conduit/travis_postgis_setup.sh for examples )
#
# 1. set your pg_hba.conf postgres user METHOD to 'trust' ( which some people might not like ):
# local all postgres trust
#
# 2. set your pg_hba.conf postgres user METHOD to 'md5' and change the PASSWORD below to match your postgres user
# local all postgres md5
#
# 3. remember to restart postgresql server with new configs
# sudo /etc/init.d/postgresql restart
#
#
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3' , # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'example.db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}

'default' : {
'ENGINE': 'django.contrib.gis.db.backends.postgis' ,
'NAME': 'geoexample',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
} ,

}

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
Expand Down Expand Up @@ -109,10 +126,10 @@
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'example.urls'
ROOT_URLCONF = 'geoexample.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'example.wsgi.application'
WSGI_APPLICATION = 'geoexample.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
Expand All @@ -130,42 +147,14 @@
'django.contrib.admin',
'conduit',
# 'api',
'geoexample',
)

## GEO Specific Settings
DATABASES['geodefault'] = {
'ENGINE': 'django.contrib.gis.db.backends.postgis' ,
'NAME': 'geoexample',
#
# NOTE: USER and PASSWORD below are defaulted to what Travis CI expects.
# You can skip setting up this database and running these tests by using the --testrunner flag:
# `python example/manage.py test --testrunner='conduit.test.non_geo_testrunner.NonGeoTestRunner'`
#
# To run local tests you will need to:
#
# 0. create a spatially enabled database called 'geoexample'
# ( see django-conduit/travis_postgis_setup.sh for examples )
#
# 1. set your pg_hba.conf postgres user METHOD to 'trust' ( which some people might not like ):
# local all postgres trust
#
# 2. set your pg_hba.conf postgres user METHOD to 'md5' and change the PASSWORD below to match your postgres user
# local all postgres md5
#
# 3. remember to restart postgresql server with new configs
# sudo /etc/init.d/postgresql restart
#
#
'USER': 'postgres',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}

INSTALLED_APPS += 'geoexample'
DATABASE_ROUTERS = ['example.geo_db_router.GeoDbRouter']
POSTGIS_VERSION = (2, 1)

TEST_RUNNER = 'conduit.test.testrunners.GeoTestRunner'

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
Expand Down
4 changes: 2 additions & 2 deletions example/geoexample/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## api/urls.py
from django.conf.urls import patterns, include, url
from conduit.api import Api
from api.views import (
from geoexample.api.views import (
GeoBarResource,
GeoBazResource,
GeoFooResource
Expand All @@ -16,5 +16,5 @@
api.register(GeoFooResource())

urlpatterns = patterns('',
url(r'^', include(api.urls))
url(r'^api/', include(api.urls))
)
32 changes: 32 additions & 0 deletions example/geoexample/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
WSGI config for example project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "example.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "geoexample.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)