Continue to attack E302 violations

This commit is contained in:
Alex Gaynor 2013-11-02 10:18:46 -07:00
parent 8b3d9d96ed
commit 19256f300e
67 changed files with 171 additions and 2 deletions

View File

@ -14,21 +14,25 @@ from django.contrib.formtools.wizard.views import NamedUrlWizardView
temp_storage_location = tempfile.mkdtemp(dir=os.environ.get('DJANGO_TEST_TEMP_DIR')) temp_storage_location = tempfile.mkdtemp(dir=os.environ.get('DJANGO_TEST_TEMP_DIR'))
temp_storage = FileSystemStorage(location=temp_storage_location) temp_storage = FileSystemStorage(location=temp_storage_location)
class Page1(forms.Form): class Page1(forms.Form):
name = forms.CharField(max_length=100) name = forms.CharField(max_length=100)
user = forms.ModelChoiceField(queryset=User.objects.all()) user = forms.ModelChoiceField(queryset=User.objects.all())
thirsty = forms.NullBooleanField() thirsty = forms.NullBooleanField()
class Page2(forms.Form): class Page2(forms.Form):
address1 = forms.CharField(max_length=100) address1 = forms.CharField(max_length=100)
address2 = forms.CharField(max_length=100) address2 = forms.CharField(max_length=100)
file1 = forms.FileField() file1 = forms.FileField()
class Page3(forms.Form): class Page3(forms.Form):
random_crap = forms.CharField(max_length=100) random_crap = forms.CharField(max_length=100)
Page4 = formset_factory(Page3, extra=2) Page4 = formset_factory(Page3, extra=2)
class ContactWizard(NamedUrlWizardView): class ContactWizard(NamedUrlWizardView):
file_storage = temp_storage file_storage = temp_storage
@ -44,8 +48,10 @@ class ContactWizard(NamedUrlWizardView):
c['this_will_fail'] = self.get_cleaned_data_for_step('this_will_fail') c['this_will_fail'] = self.get_cleaned_data_for_step('this_will_fail')
return HttpResponse(Template('').render(c)) return HttpResponse(Template('').render(c))
class SessionContactWizard(ContactWizard): class SessionContactWizard(ContactWizard):
storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage' storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'
class CookieContactWizard(ContactWizard): class CookieContactWizard(ContactWizard):
storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage' storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'

View File

@ -2,6 +2,7 @@ from django.conf.urls import patterns, url
from django.contrib.formtools.tests.wizard.namedwizardtests.forms import ( from django.contrib.formtools.tests.wizard.namedwizardtests.forms import (
SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4) SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
def get_named_session_wizard(): def get_named_session_wizard():
return SessionContactWizard.as_view( return SessionContactWizard.as_view(
[('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)], [('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)],
@ -9,6 +10,7 @@ def get_named_session_wizard():
done_step_name='nwiz_session_done' done_step_name='nwiz_session_done'
) )
def get_named_cookie_wizard(): def get_named_cookie_wizard():
return CookieContactWizard.as_view( return CookieContactWizard.as_view(
[('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)], [('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)],

View File

@ -81,12 +81,14 @@ class TestWizard(WizardView):
kwargs['test'] = True kwargs['test'] = True
return kwargs return kwargs
class TestWizardWithInitAttrs(TestWizard): class TestWizardWithInitAttrs(TestWizard):
form_list = [Step1, Step2] form_list = [Step1, Step2]
condition_dict = {'step2': True} condition_dict = {'step2': True}
initial_dict = {'start': {'name': 'value1'}} initial_dict = {'start': {'name': 'value1'}}
instance_dict = {'start': User()} instance_dict = {'start': User()}
class FormTests(TestCase): class FormTests(TestCase):
def test_form_init(self): def test_form_init(self):
testform = TestWizard.get_initkwargs([Step1, Step2]) testform = TestWizard.get_initkwargs([Step1, Step2])

View File

@ -15,21 +15,25 @@ from django.contrib.formtools.wizard.views import WizardView
temp_storage_location = tempfile.mkdtemp(dir=os.environ.get('DJANGO_TEST_TEMP_DIR')) temp_storage_location = tempfile.mkdtemp(dir=os.environ.get('DJANGO_TEST_TEMP_DIR'))
temp_storage = FileSystemStorage(location=temp_storage_location) temp_storage = FileSystemStorage(location=temp_storage_location)
class Page1(forms.Form): class Page1(forms.Form):
name = forms.CharField(max_length=100) name = forms.CharField(max_length=100)
user = forms.ModelChoiceField(queryset=User.objects.all()) user = forms.ModelChoiceField(queryset=User.objects.all())
thirsty = forms.NullBooleanField() thirsty = forms.NullBooleanField()
class Page2(forms.Form): class Page2(forms.Form):
address1 = forms.CharField(max_length=100) address1 = forms.CharField(max_length=100)
address2 = forms.CharField(max_length=100) address2 = forms.CharField(max_length=100)
file1 = forms.FileField() file1 = forms.FileField()
class Page3(forms.Form): class Page3(forms.Form):
random_crap = forms.CharField(max_length=100) random_crap = forms.CharField(max_length=100)
Page4 = formset_factory(Page3, extra=2) Page4 = formset_factory(Page3, extra=2)
class ContactWizard(WizardView): class ContactWizard(WizardView):
file_storage = temp_storage file_storage = temp_storage
@ -51,6 +55,7 @@ class ContactWizard(WizardView):
context.update({'another_var': True}) context.update({'another_var': True})
return context return context
class UserForm(forms.ModelForm): class UserForm(forms.ModelForm):
class Meta: class Meta:
model = User model = User
@ -58,8 +63,10 @@ class UserForm(forms.ModelForm):
UserFormSet = modelformset_factory(User, form=UserForm) UserFormSet = modelformset_factory(User, form=UserForm)
class SessionContactWizard(ContactWizard): class SessionContactWizard(ContactWizard):
storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage' storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'
class CookieContactWizard(ContactWizard): class CookieContactWizard(ContactWizard):
storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage' storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'

View File

@ -1,5 +1,6 @@
from django import forms from django import forms
class ManagementForm(forms.Form): class ManagementForm(forms.Form):
""" """
``ManagementForm`` is used to keep track of the current wizard step. ``ManagementForm`` is used to keep track of the current wizard step.

View File

@ -1,7 +1,9 @@
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
class MissingStorage(ImproperlyConfigured): class MissingStorage(ImproperlyConfigured):
pass pass
class NoFileStorageConfigured(ImproperlyConfigured): class NoFileStorageConfigured(ImproperlyConfigured):
pass pass

View File

@ -28,6 +28,7 @@ def normalize_name(name):
new = re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', name) new = re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', name)
return new.lower().strip('_') return new.lower().strip('_')
class StepsHelper(object): class StepsHelper(object):
def __init__(self, wizard): def __init__(self, wizard):

View File

@ -3,6 +3,7 @@ from django.contrib.gis.admin.widgets import OpenLayersWidget
from django.contrib.gis.gdal import OGRGeomType from django.contrib.gis.gdal import OGRGeomType
from django.contrib.gis.db import models from django.contrib.gis.db import models
class GeoModelAdmin(ModelAdmin): class GeoModelAdmin(ModelAdmin):
""" """
The administration options class for Geographic models. Map settings The administration options class for Geographic models. Map settings

View File

@ -143,6 +143,7 @@ class BaseSpatialOperations(object):
def spatial_ref_sys(self): def spatial_ref_sys(self):
raise NotImplementedError('subclasses of BaseSpatialOperations must a provide spatial_ref_sys() method') raise NotImplementedError('subclasses of BaseSpatialOperations must a provide spatial_ref_sys() method')
@python_2_unicode_compatible @python_2_unicode_compatible
class SpatialRefSysMixin(object): class SpatialRefSysMixin(object):
""" """

View File

@ -3,6 +3,7 @@ from django.db.backends.mysql import compiler
SQLCompiler = compiler.SQLCompiler SQLCompiler = compiler.SQLCompiler
class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler): class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
def resolve_columns(self, row, fields=()): def resolve_columns(self, row, fields=()):
""" """
@ -19,17 +20,22 @@ class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler): class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
pass pass
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler): class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
pass pass
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler): class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
pass pass
class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler): class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
pass pass
class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler): class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
pass pass
class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, GeoSQLCompiler): class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, GeoSQLCompiler):
pass pass

View File

@ -1,7 +1,7 @@
from django.db.backends.mysql.creation import DatabaseCreation from django.db.backends.mysql.creation import DatabaseCreation
class MySQLCreation(DatabaseCreation):
class MySQLCreation(DatabaseCreation):
def sql_indexes_for_field(self, model, f, style): def sql_indexes_for_field(self, model, f, style):
from django.contrib.gis.db.models.fields import GeometryField from django.contrib.gis.db.models.fields import GeometryField
output = super(MySQLCreation, self).sql_indexes_for_field(model, f, style) output = super(MySQLCreation, self).sql_indexes_for_field(model, f, style)

View File

@ -3,6 +3,7 @@ from MySQLdb.constants import FIELD_TYPE
from django.contrib.gis.gdal import OGRGeomType from django.contrib.gis.gdal import OGRGeomType
from django.db.backends.mysql.introspection import DatabaseIntrospection from django.db.backends.mysql.introspection import DatabaseIntrospection
class MySQLIntrospection(DatabaseIntrospection): class MySQLIntrospection(DatabaseIntrospection):
# Updating the data_types_reverse dictionary with the appropriate # Updating the data_types_reverse dictionary with the appropriate
# type for Geometry fields. # type for Geometry fields.

View File

@ -1,5 +1,6 @@
from cx_Oracle import CLOB from cx_Oracle import CLOB
from django.contrib.gis.db.backends.adapter import WKTAdapter from django.contrib.gis.db.backends.adapter import WKTAdapter
class OracleSpatialAdapter(WKTAdapter): class OracleSpatialAdapter(WKTAdapter):
input_size = CLOB input_size = CLOB

View File

@ -3,23 +3,30 @@ from django.db.backends.oracle import compiler
SQLCompiler = compiler.SQLCompiler SQLCompiler = compiler.SQLCompiler
class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler): class GeoSQLCompiler(BaseGeoSQLCompiler, SQLCompiler):
pass pass
class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler): class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
pass pass
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler): class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
pass pass
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler): class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
pass pass
class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler): class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
pass pass
class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler): class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
pass pass
class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, GeoSQLCompiler): class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, GeoSQLCompiler):
pass pass

View File

@ -1,6 +1,7 @@
from django.db.backends.oracle.creation import DatabaseCreation from django.db.backends.oracle.creation import DatabaseCreation
from django.db.backends.utils import truncate_name from django.db.backends.utils import truncate_name
class OracleCreation(DatabaseCreation): class OracleCreation(DatabaseCreation):
def sql_indexes_for_field(self, model, f, style): def sql_indexes_for_field(self, model, f, style):

View File

@ -3,6 +3,7 @@ import sys
from django.db.backends.oracle.introspection import DatabaseIntrospection from django.db.backends.oracle.introspection import DatabaseIntrospection
from django.utils import six from django.utils import six
class OracleIntrospection(DatabaseIntrospection): class OracleIntrospection(DatabaseIntrospection):
# Associating any OBJECTVAR instances with GeometryField. Of course, # Associating any OBJECTVAR instances with GeometryField. Of course,
# this won't work right on Oracle objects that aren't MDSYS.SDO_GEOMETRY, # this won't work right on Oracle objects that aren't MDSYS.SDO_GEOMETRY,

View File

@ -11,6 +11,7 @@ from django.contrib.gis.db import models
from django.contrib.gis.db.backends.base import SpatialRefSysMixin from django.contrib.gis.db.backends.base import SpatialRefSysMixin
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible @python_2_unicode_compatible
class GeometryColumns(models.Model): class GeometryColumns(models.Model):
"Maps to the Oracle USER_SDO_GEOM_METADATA table." "Maps to the Oracle USER_SDO_GEOM_METADATA table."
@ -42,6 +43,7 @@ class GeometryColumns(models.Model):
def __str__(self): def __str__(self):
return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid) return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin): class SpatialRefSys(models.Model, SpatialRefSysMixin):
"Maps to the Oracle MDSYS.CS_SRS table." "Maps to the Oracle MDSYS.CS_SRS table."
cs_name = models.CharField(max_length=68) cs_name = models.CharField(max_length=68)

View File

@ -28,6 +28,7 @@ class SDOOperation(SpatialFunction):
kwargs.setdefault('result', 'TRUE') kwargs.setdefault('result', 'TRUE')
super(SDOOperation, self).__init__(func, **kwargs) super(SDOOperation, self).__init__(func, **kwargs)
class SDODistance(SpatialFunction): class SDODistance(SpatialFunction):
"Class for Distance queries." "Class for Distance queries."
sql_template = ('%(function)s(%(geo_col)s, %(geometry)s, %(tolerance)s) ' sql_template = ('%(function)s(%(geo_col)s, %(geometry)s, %(tolerance)s) '
@ -39,6 +40,7 @@ class SDODistance(SpatialFunction):
tolerance=tolerance, tolerance=tolerance,
operator=op, result='%s') operator=op, result='%s')
class SDODWithin(SpatialFunction): class SDODWithin(SpatialFunction):
dwithin_func = 'SDO_WITHIN_DISTANCE' dwithin_func = 'SDO_WITHIN_DISTANCE'
sql_template = "%(function)s(%(geo_col)s, %(geometry)s, %%s) = 'TRUE'" sql_template = "%(function)s(%(geo_col)s, %(geometry)s, %%s) = 'TRUE'"
@ -46,6 +48,7 @@ class SDODWithin(SpatialFunction):
def __init__(self): def __init__(self):
super(SDODWithin, self).__init__(self.dwithin_func) super(SDODWithin, self).__init__(self.dwithin_func)
class SDOGeomRelate(SpatialFunction): class SDOGeomRelate(SpatialFunction):
"Class for using SDO_GEOM.RELATE." "Class for using SDO_GEOM.RELATE."
relate_func = 'SDO_GEOM.RELATE' relate_func = 'SDO_GEOM.RELATE'
@ -58,6 +61,7 @@ class SDOGeomRelate(SpatialFunction):
super(SDOGeomRelate, self).__init__(self.relate_func, operator='=', super(SDOGeomRelate, self).__init__(self.relate_func, operator='=',
mask=mask, tolerance=tolerance) mask=mask, tolerance=tolerance)
class SDORelate(SpatialFunction): class SDORelate(SpatialFunction):
"Class for using SDO_RELATE." "Class for using SDO_RELATE."
masks = 'TOUCH|OVERLAPBDYDISJOINT|OVERLAPBDYINTERSECT|EQUAL|INSIDE|COVEREDBY|CONTAINS|COVERS|ANYINTERACT|ON' masks = 'TOUCH|OVERLAPBDYDISJOINT|OVERLAPBDYINTERSECT|EQUAL|INSIDE|COVEREDBY|CONTAINS|COVERS|ANYINTERACT|ON'
@ -73,6 +77,7 @@ class SDORelate(SpatialFunction):
# Valid distance types and substitutions # Valid distance types and substitutions
dtypes = (Decimal, Distance, float) + six.integer_types dtypes = (Decimal, Distance, float) + six.integer_types
class OracleOperations(DatabaseOperations, BaseSpatialOperations): class OracleOperations(DatabaseOperations, BaseSpatialOperations):
compiler_module = "django.contrib.gis.db.backends.oracle.compiler" compiler_module = "django.contrib.gis.db.backends.oracle.compiler"

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
from psycopg2 import Binary from psycopg2 import Binary
from psycopg2.extensions import ISQLQuote from psycopg2.extensions import ISQLQuote
class PostGISAdapter(object): class PostGISAdapter(object):
def __init__(self, geom): def __init__(self, geom):
"Initializes on the geometry." "Initializes on the geometry."

View File

@ -1,9 +1,11 @@
from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection from django.db.backends.postgresql_psycopg2.introspection import DatabaseIntrospection
from django.contrib.gis.gdal import OGRGeomType from django.contrib.gis.gdal import OGRGeomType
class GeoIntrospectionError(Exception): class GeoIntrospectionError(Exception):
pass pass
class PostGISIntrospection(DatabaseIntrospection): class PostGISIntrospection(DatabaseIntrospection):
# Reverse dictionary for PostGIS geometry types not populated until # Reverse dictionary for PostGIS geometry types not populated until
# introspection is actually performed. # introspection is actually performed.

View File

@ -5,6 +5,7 @@ from django.db import models
from django.contrib.gis.db.backends.base import SpatialRefSysMixin from django.contrib.gis.db.backends.base import SpatialRefSysMixin
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible @python_2_unicode_compatible
class GeometryColumns(models.Model): class GeometryColumns(models.Model):
""" """
@ -44,6 +45,7 @@ class GeometryColumns(models.Model):
(self.f_table_name, self.f_geometry_column, (self.f_table_name, self.f_geometry_column,
self.coord_dimension, self.type, self.srid) self.coord_dimension, self.type, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin): class SpatialRefSys(models.Model, SpatialRefSysMixin):
""" """
The 'spatial_ref_sys' table from PostGIS. See the PostGIS The 'spatial_ref_sys' table from PostGIS. See the PostGIS

View File

@ -22,15 +22,18 @@ class PostGISOperator(SpatialOperation):
def __init__(self, operator): def __init__(self, operator):
super(PostGISOperator, self).__init__(operator=operator) super(PostGISOperator, self).__init__(operator=operator)
class PostGISFunction(SpatialFunction): class PostGISFunction(SpatialFunction):
"For PostGIS function calls (e.g., `ST_Contains(table, geom)`)." "For PostGIS function calls (e.g., `ST_Contains(table, geom)`)."
def __init__(self, prefix, function, **kwargs): def __init__(self, prefix, function, **kwargs):
super(PostGISFunction, self).__init__(prefix + function, **kwargs) super(PostGISFunction, self).__init__(prefix + function, **kwargs)
class PostGISFunctionParam(PostGISFunction): class PostGISFunctionParam(PostGISFunction):
"For PostGIS functions that take another parameter (e.g. DWithin, Relate)." "For PostGIS functions that take another parameter (e.g. DWithin, Relate)."
sql_template = '%(function)s(%(geo_col)s, %(geometry)s, %%s)' sql_template = '%(function)s(%(geo_col)s, %(geometry)s, %%s)'
class PostGISDistance(PostGISFunction): class PostGISDistance(PostGISFunction):
"For PostGIS distance operations." "For PostGIS distance operations."
dist_func = 'Distance' dist_func = 'Distance'
@ -40,6 +43,7 @@ class PostGISDistance(PostGISFunction):
super(PostGISDistance, self).__init__(prefix, self.dist_func, super(PostGISDistance, self).__init__(prefix, self.dist_func,
operator=operator) operator=operator)
class PostGISSpheroidDistance(PostGISFunction): class PostGISSpheroidDistance(PostGISFunction):
"For PostGIS spherical distance operations (using the spheroid)." "For PostGIS spherical distance operations (using the spheroid)."
dist_func = 'distance_spheroid' dist_func = 'distance_spheroid'
@ -50,10 +54,12 @@ class PostGISSpheroidDistance(PostGISFunction):
super(PostGISSpheroidDistance, self).__init__(prefix, self.dist_func, super(PostGISSpheroidDistance, self).__init__(prefix, self.dist_func,
operator=operator) operator=operator)
class PostGISSphereDistance(PostGISDistance): class PostGISSphereDistance(PostGISDistance):
"For PostGIS spherical distance operations." "For PostGIS spherical distance operations."
dist_func = 'distance_sphere' dist_func = 'distance_sphere'
class PostGISRelate(PostGISFunctionParam): class PostGISRelate(PostGISFunctionParam):
"For PostGIS Relate(<geom>, <pattern>) calls." "For PostGIS Relate(<geom>, <pattern>) calls."
pattern_regex = re.compile(r'^[012TF\*]{9}$') pattern_regex = re.compile(r'^[012TF\*]{9}$')

View File

@ -1,6 +1,7 @@
from django.db.backends.sqlite3.base import Database from django.db.backends.sqlite3.base import Database
from django.contrib.gis.db.backends.adapter import WKTAdapter from django.contrib.gis.db.backends.adapter import WKTAdapter
class SpatiaLiteAdapter(WKTAdapter): class SpatiaLiteAdapter(WKTAdapter):
"SQLite adaptor for geometry objects." "SQLite adaptor for geometry objects."
def __conform__(self, protocol): def __conform__(self, protocol):

View File

@ -11,6 +11,7 @@ from django.contrib.gis.db.backends.spatialite.introspection import SpatiaLiteIn
from django.contrib.gis.db.backends.spatialite.operations import SpatiaLiteOperations from django.contrib.gis.db.backends.spatialite.operations import SpatiaLiteOperations
from django.utils import six from django.utils import six
class DatabaseWrapper(SQLiteDatabaseWrapper): class DatabaseWrapper(SQLiteDatabaseWrapper):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# Before we get too far, make sure pysqlite 2.5+ is installed. # Before we get too far, make sure pysqlite 2.5+ is installed.

View File

@ -1,4 +1,5 @@
from django.db.backends.sqlite3.client import DatabaseClient from django.db.backends.sqlite3.client import DatabaseClient
class SpatiaLiteClient(DatabaseClient): class SpatiaLiteClient(DatabaseClient):
executable_name = 'spatialite' executable_name = 'spatialite'

View File

@ -2,6 +2,7 @@ from django.contrib.gis.gdal import OGRGeomType
from django.db.backends.sqlite3.introspection import DatabaseIntrospection, FlexibleFieldLookupDict from django.db.backends.sqlite3.introspection import DatabaseIntrospection, FlexibleFieldLookupDict
from django.utils import six from django.utils import six
class GeoFlexibleFieldLookupDict(FlexibleFieldLookupDict): class GeoFlexibleFieldLookupDict(FlexibleFieldLookupDict):
""" """
Sublcass that includes updates the `base_data_types_reverse` dict Sublcass that includes updates the `base_data_types_reverse` dict
@ -18,6 +19,7 @@ class GeoFlexibleFieldLookupDict(FlexibleFieldLookupDict):
'geometrycollection': 'GeometryField', 'geometrycollection': 'GeometryField',
}) })
class SpatiaLiteIntrospection(DatabaseIntrospection): class SpatiaLiteIntrospection(DatabaseIntrospection):
data_types_reverse = GeoFlexibleFieldLookupDict() data_types_reverse = GeoFlexibleFieldLookupDict()

View File

@ -5,6 +5,7 @@ from django.db import models
from django.contrib.gis.db.backends.base import SpatialRefSysMixin from django.contrib.gis.db.backends.base import SpatialRefSysMixin
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible @python_2_unicode_compatible
class GeometryColumns(models.Model): class GeometryColumns(models.Model):
""" """
@ -42,6 +43,7 @@ class GeometryColumns(models.Model):
(self.f_table_name, self.f_geometry_column, (self.f_table_name, self.f_geometry_column,
self.coord_dimension, self.type, self.srid) self.coord_dimension, self.type, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin): class SpatialRefSys(models.Model, SpatialRefSysMixin):
""" """
The 'spatial_ref_sys' table from SpatiaLite. The 'spatial_ref_sys' table from SpatiaLite.

View File

@ -19,15 +19,18 @@ class SpatiaLiteOperator(SpatialOperation):
def __init__(self, operator): def __init__(self, operator):
super(SpatiaLiteOperator, self).__init__(operator=operator) super(SpatiaLiteOperator, self).__init__(operator=operator)
class SpatiaLiteFunction(SpatialFunction): class SpatiaLiteFunction(SpatialFunction):
"For SpatiaLite function calls." "For SpatiaLite function calls."
def __init__(self, function, **kwargs): def __init__(self, function, **kwargs):
super(SpatiaLiteFunction, self).__init__(function, **kwargs) super(SpatiaLiteFunction, self).__init__(function, **kwargs)
class SpatiaLiteFunctionParam(SpatiaLiteFunction): class SpatiaLiteFunctionParam(SpatiaLiteFunction):
"For SpatiaLite functions that take another parameter." "For SpatiaLite functions that take another parameter."
sql_template = '%(function)s(%(geo_col)s, %(geometry)s, %%s)' sql_template = '%(function)s(%(geo_col)s, %(geometry)s, %%s)'
class SpatiaLiteDistance(SpatiaLiteFunction): class SpatiaLiteDistance(SpatiaLiteFunction):
"For SpatiaLite distance operations." "For SpatiaLite distance operations."
dist_func = 'Distance' dist_func = 'Distance'
@ -37,6 +40,7 @@ class SpatiaLiteDistance(SpatiaLiteFunction):
super(SpatiaLiteDistance, self).__init__(self.dist_func, super(SpatiaLiteDistance, self).__init__(self.dist_func,
operator=operator) operator=operator)
class SpatiaLiteRelate(SpatiaLiteFunctionParam): class SpatiaLiteRelate(SpatiaLiteFunctionParam):
"For SpatiaLite Relate(<geom>, <pattern>) calls." "For SpatiaLite Relate(<geom>, <pattern>) calls."
pattern_regex = re.compile(r'^[012TF\*]{9}$') pattern_regex = re.compile(r'^[012TF\*]{9}$')
@ -46,12 +50,14 @@ class SpatiaLiteRelate(SpatiaLiteFunctionParam):
raise ValueError('Invalid intersection matrix pattern "%s".' % pattern) raise ValueError('Invalid intersection matrix pattern "%s".' % pattern)
super(SpatiaLiteRelate, self).__init__('Relate') super(SpatiaLiteRelate, self).__init__('Relate')
# Valid distance types and substitutions # Valid distance types and substitutions
dtypes = (Decimal, Distance, float) + six.integer_types dtypes = (Decimal, Distance, float) + six.integer_types
def get_dist_ops(operator): def get_dist_ops(operator):
"Returns operations for regular distances; spherical distances are not currently supported." "Returns operations for regular distances; spherical distances are not currently supported."
return (SpatiaLiteDistance(operator),) return (SpatiaLiteDistance(operator),)
class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations): class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
compiler_module = 'django.contrib.gis.db.models.sql.compiler' compiler_module = 'django.contrib.gis.db.models.sql.compiler'
name = 'spatialite' name = 'spatialite'

View File

@ -3,6 +3,7 @@ A collection of utility routines and classes used by the spatial
backends. backends.
""" """
class SpatialOperation(object): class SpatialOperation(object):
""" """
Base class for generating spatial SQL. Base class for generating spatial SQL.
@ -28,6 +29,7 @@ class SpatialOperation(object):
params.update(self.extra) params.update(self.extra)
return params return params
class SpatialFunction(SpatialOperation): class SpatialFunction(SpatialOperation):
""" """
Base class for generating spatial SQL related to a function. Base class for generating spatial SQL related to a function.

View File

@ -1,16 +1,21 @@
from django.db.models import Aggregate from django.db.models import Aggregate
class Collect(Aggregate): class Collect(Aggregate):
name = 'Collect' name = 'Collect'
class Extent(Aggregate): class Extent(Aggregate):
name = 'Extent' name = 'Extent'
class Extent3D(Aggregate): class Extent3D(Aggregate):
name = 'Extent3D' name = 'Extent3D'
class MakeLine(Aggregate): class MakeLine(Aggregate):
name = 'MakeLine' name = 'MakeLine'
class Union(Aggregate): class Union(Aggregate):
name = 'Union' name = 'Union'

View File

@ -11,6 +11,7 @@ from django.utils import six
# for SRID info each time a distance query is constructed. # for SRID info each time a distance query is constructed.
_srid_cache = {} _srid_cache = {}
def get_srid_info(srid, connection): def get_srid_info(srid, connection):
""" """
Returns the units, unit name, and spheroid WKT associated with the Returns the units, unit name, and spheroid WKT associated with the
@ -39,6 +40,7 @@ def get_srid_info(srid, connection):
return _srid_cache[connection.alias][srid] return _srid_cache[connection.alias][srid]
class GeometryField(Field): class GeometryField(Field):
"The base GIS field -- maps to the OpenGIS Specification Geometry type." "The base GIS field -- maps to the OpenGIS Specification Geometry type."
@ -269,37 +271,44 @@ class GeometryField(Field):
""" """
return connection.ops.get_geom_placeholder(self, value) return connection.ops.get_geom_placeholder(self, value)
# The OpenGIS Geometry Type Fields # The OpenGIS Geometry Type Fields
class PointField(GeometryField): class PointField(GeometryField):
geom_type = 'POINT' geom_type = 'POINT'
form_class = forms.PointField form_class = forms.PointField
description = _("Point") description = _("Point")
class LineStringField(GeometryField): class LineStringField(GeometryField):
geom_type = 'LINESTRING' geom_type = 'LINESTRING'
form_class = forms.LineStringField form_class = forms.LineStringField
description = _("Line string") description = _("Line string")
class PolygonField(GeometryField): class PolygonField(GeometryField):
geom_type = 'POLYGON' geom_type = 'POLYGON'
form_class = forms.PolygonField form_class = forms.PolygonField
description = _("Polygon") description = _("Polygon")
class MultiPointField(GeometryField): class MultiPointField(GeometryField):
geom_type = 'MULTIPOINT' geom_type = 'MULTIPOINT'
form_class = forms.MultiPointField form_class = forms.MultiPointField
description = _("Multi-point") description = _("Multi-point")
class MultiLineStringField(GeometryField): class MultiLineStringField(GeometryField):
geom_type = 'MULTILINESTRING' geom_type = 'MULTILINESTRING'
form_class = forms.MultiLineStringField form_class = forms.MultiLineStringField
description = _("Multi-line string") description = _("Multi-line string")
class MultiPolygonField(GeometryField): class MultiPolygonField(GeometryField):
geom_type = 'MULTIPOLYGON' geom_type = 'MULTIPOLYGON'
form_class = forms.MultiPolygonField form_class = forms.MultiPolygonField
description = _("Multi polygon") description = _("Multi polygon")
class GeometryCollectionField(GeometryField): class GeometryCollectionField(GeometryField):
geom_type = 'GEOMETRYCOLLECTION' geom_type = 'GEOMETRYCOLLECTION'
form_class = forms.GeometryCollectionField form_class = forms.GeometryCollectionField

View File

@ -1,6 +1,7 @@
from django.db.models.manager import Manager from django.db.models.manager import Manager
from django.contrib.gis.db.models.query import GeoQuerySet from django.contrib.gis.db.models.query import GeoQuerySet
class GeoManager(Manager): class GeoManager(Manager):
"Overrides Manager to return Geographic QuerySets." "Overrides Manager to return Geographic QuerySets."

View File

@ -8,6 +8,7 @@ Thanks to Robert Coup for providing this functionality (see #4322).
from django.contrib.gis import memoryview from django.contrib.gis import memoryview
from django.utils import six from django.utils import six
class GeometryProxy(object): class GeometryProxy(object):
def __init__(self, klass, field): def __init__(self, klass, field):
""" """

View File

@ -782,6 +782,7 @@ class GeoQuerySet(QuerySet):
else: else:
return self.query.get_compiler(self.db)._field_column(geo_field) return self.query.get_compiler(self.db)._field_column(geo_field)
class GeoValuesQuerySet(ValuesQuerySet): class GeoValuesQuerySet(ValuesQuerySet):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(GeoValuesQuerySet, self).__init__(*args, **kwargs) super(GeoValuesQuerySet, self).__init__(*args, **kwargs)
@ -790,5 +791,6 @@ class GeoValuesQuerySet(ValuesQuerySet):
# of string values are returned with `values()` or `values_list()`. # of string values are returned with `values()` or `values_list()`.
self.query.geo_values = True self.query.geo_values = True
class GeoValuesListQuerySet(GeoValuesQuerySet, ValuesListQuerySet): class GeoValuesListQuerySet(GeoValuesQuerySet, ValuesListQuerySet):
pass pass

View File

@ -1,6 +1,7 @@
from django.db.models.sql.aggregates import * from django.db.models.sql.aggregates import *
from django.contrib.gis.db.models.fields import GeometryField from django.contrib.gis.db.models.fields import GeometryField
class GeoAggregate(Aggregate): class GeoAggregate(Aggregate):
# Default SQL template for spatial aggregates. # Default SQL template for spatial aggregates.
sql_template = '%(function)s(%(field)s)' sql_template = '%(function)s(%(field)s)'
@ -46,17 +47,22 @@ class GeoAggregate(Aggregate):
return sql_template % substitutions, params return sql_template % substitutions, params
class Collect(GeoAggregate): class Collect(GeoAggregate):
pass pass
class Extent(GeoAggregate): class Extent(GeoAggregate):
is_extent = '2D' is_extent = '2D'
class Extent3D(GeoAggregate): class Extent3D(GeoAggregate):
is_extent = '3D' is_extent = '3D'
class MakeLine(GeoAggregate): class MakeLine(GeoAggregate):
pass pass
class Union(GeoAggregate): class Union(GeoAggregate):
pass pass

View File

@ -10,6 +10,7 @@ from django.utils import timezone
SQLCompiler = compiler.SQLCompiler SQLCompiler = compiler.SQLCompiler
class GeoSQLCompiler(compiler.SQLCompiler): class GeoSQLCompiler(compiler.SQLCompiler):
def get_columns(self, with_aliases=False): def get_columns(self, with_aliases=False):
@ -249,18 +250,23 @@ class GeoSQLCompiler(compiler.SQLCompiler):
return "%s.%s" % (self.quote_name_unless_alias(table_alias), return "%s.%s" % (self.quote_name_unless_alias(table_alias),
self.connection.ops.quote_name(column or field.column)) self.connection.ops.quote_name(column or field.column))
class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler): class SQLInsertCompiler(compiler.SQLInsertCompiler, GeoSQLCompiler):
pass pass
class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler): class SQLDeleteCompiler(compiler.SQLDeleteCompiler, GeoSQLCompiler):
pass pass
class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler): class SQLUpdateCompiler(compiler.SQLUpdateCompiler, GeoSQLCompiler):
pass pass
class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler): class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
pass pass
class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler): class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
""" """
This is overridden for GeoDjango to properly cast date columns, since This is overridden for GeoDjango to properly cast date columns, since
@ -286,6 +292,7 @@ class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
date = date.date() date = date.date()
yield date yield date
class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, GeoSQLCompiler): class SQLDateTimeCompiler(compiler.SQLDateTimeCompiler, GeoSQLCompiler):
""" """
This is overridden for GeoDjango to properly cast date columns, since This is overridden for GeoDjango to properly cast date columns, since

View File

@ -3,6 +3,7 @@ This module holds simple classes used by GeoQuery.convert_values
to convert geospatial values from the database. to convert geospatial values from the database.
""" """
class BaseField(object): class BaseField(object):
empty_strings_allowed = True empty_strings_allowed = True
@ -10,16 +11,19 @@ class BaseField(object):
"Overloaded method so OracleQuery.convert_values doesn't balk." "Overloaded method so OracleQuery.convert_values doesn't balk."
return None return None
class AreaField(BaseField): class AreaField(BaseField):
"Wrapper for Area values." "Wrapper for Area values."
def __init__(self, area_att): def __init__(self, area_att):
self.area_att = area_att self.area_att = area_att
class DistanceField(BaseField): class DistanceField(BaseField):
"Wrapper for Distance values." "Wrapper for Distance values."
def __init__(self, distance_att): def __init__(self, distance_att):
self.distance_att = distance_att self.distance_att = distance_att
class GeomField(BaseField): class GeomField(BaseField):
""" """
Wrapper for Geometry values. It is a lightweight alternative to Wrapper for Geometry values. It is a lightweight alternative to

View File

@ -21,6 +21,7 @@ ALL_TERMS = set([
]) ])
ALL_TERMS.update(sql.constants.QUERY_TERMS) ALL_TERMS.update(sql.constants.QUERY_TERMS)
class GeoQuery(sql.Query): class GeoQuery(sql.Query):
""" """
A single spatial SQL query. A single spatial SQL query.

View File

@ -4,6 +4,7 @@ from django.db.models.sql.expressions import SQLEvaluator
from django.db.models.sql.where import Constraint, WhereNode from django.db.models.sql.where import Constraint, WhereNode
from django.contrib.gis.db.models.fields import GeometryField from django.contrib.gis.db.models.fields import GeometryField
class GeoConstraint(Constraint): class GeoConstraint(Constraint):
""" """
This subclass overrides `process` to better handle geographic SQL This subclass overrides `process` to better handle geographic SQL
@ -27,6 +28,7 @@ class GeoConstraint(Constraint):
params = self.field.get_db_prep_lookup(lookup_type, value, connection=connection) params = self.field.get_db_prep_lookup(lookup_type, value, connection=connection)
return (self.alias, self.col, db_type), params return (self.alias, self.col, db_type), params
class GeoWhereNode(WhereNode): class GeoWhereNode(WhereNode):
""" """
Used to represent the SQL where-clause for spatial databases -- Used to represent the SQL where-clause for spatial databases --

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.contrib.syndication.views import Feed as BaseFeed from django.contrib.syndication.views import Feed as BaseFeed
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed
class GeoFeedMixin(object): class GeoFeedMixin(object):
""" """
This mixin provides the necessary routines for SyndicationFeed subclasses This mixin provides the necessary routines for SyndicationFeed subclasses
@ -79,6 +80,7 @@ class GeoFeedMixin(object):
else: else:
raise ValueError('Geometry type "%s" not supported.' % geom.geom_type) raise ValueError('Geometry type "%s" not supported.' % geom.geom_type)
### SyndicationFeed subclasses ### ### SyndicationFeed subclasses ###
class GeoRSSFeed(Rss201rev2Feed, GeoFeedMixin): class GeoRSSFeed(Rss201rev2Feed, GeoFeedMixin):
def rss_attributes(self): def rss_attributes(self):
@ -94,6 +96,7 @@ class GeoRSSFeed(Rss201rev2Feed, GeoFeedMixin):
super(GeoRSSFeed, self).add_root_elements(handler) super(GeoRSSFeed, self).add_root_elements(handler)
self.add_georss_element(handler, self.feed) self.add_georss_element(handler, self.feed)
class GeoAtom1Feed(Atom1Feed, GeoFeedMixin): class GeoAtom1Feed(Atom1Feed, GeoFeedMixin):
def root_attributes(self): def root_attributes(self):
attrs = super(GeoAtom1Feed, self).root_attributes() attrs = super(GeoAtom1Feed, self).root_attributes()
@ -108,6 +111,7 @@ class GeoAtom1Feed(Atom1Feed, GeoFeedMixin):
super(GeoAtom1Feed, self).add_root_elements(handler) super(GeoAtom1Feed, self).add_root_elements(handler)
self.add_georss_element(handler, self.feed) self.add_georss_element(handler, self.feed)
class W3CGeoFeed(Rss201rev2Feed, GeoFeedMixin): class W3CGeoFeed(Rss201rev2Feed, GeoFeedMixin):
def rss_attributes(self): def rss_attributes(self):
attrs = super(W3CGeoFeed, self).rss_attributes() attrs = super(W3CGeoFeed, self).rss_attributes()
@ -122,6 +126,7 @@ class W3CGeoFeed(Rss201rev2Feed, GeoFeedMixin):
super(W3CGeoFeed, self).add_root_elements(handler) super(W3CGeoFeed, self).add_root_elements(handler)
self.add_georss_element(handler, self.feed, w3c_geo=True) self.add_georss_element(handler, self.feed, w3c_geo=True)
### Feed subclass ### ### Feed subclass ###
class Feed(BaseFeed): class Feed(BaseFeed):
""" """

View File

@ -3,6 +3,7 @@ from ctypes import c_void_p
from django.contrib.gis.gdal.error import GDALException from django.contrib.gis.gdal.error import GDALException
from django.utils import six from django.utils import six
class GDALBase(object): class GDALBase(object):
""" """
Base object for GDAL objects that has a pointer access property Base object for GDAL objects that has a pointer access property

View File

@ -49,6 +49,7 @@ from django.utils.encoding import force_bytes, force_text
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import xrange
# For more information, see the OGR C API source code: # For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html # http://www.gdal.org/ogr/ogr__api_8h.html
# #

View File

@ -7,6 +7,7 @@ from django.contrib.gis.gdal.prototypes import ds as capi
from django.utils import six from django.utils import six
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
# For more information, see the OGR C API source code: # For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html # http://www.gdal.org/ogr/ogr__api_8h.html
# #

View File

@ -13,6 +13,7 @@
from ctypes import Structure, c_double from ctypes import Structure, c_double
from django.contrib.gis.gdal.error import OGRException from django.contrib.gis.gdal.error import OGRException
# The OGR definition of an Envelope is a C structure containing four doubles. # The OGR definition of an Envelope is a C structure containing four doubles.
# See the 'ogr_core.h' source file for more information: # See the 'ogr_core.h' source file for more information:
# http://www.gdal.org/ogr/ogr__core_8h-source.html # http://www.gdal.org/ogr/ogr__core_8h-source.html
@ -24,6 +25,7 @@ class OGREnvelope(Structure):
("MaxY", c_double), ("MaxY", c_double),
] ]
class Envelope(object): class Envelope(object):
""" """
The Envelope object is a C structure that contains the minimum and The Envelope object is a C structure that contains the minimum and

View File

@ -3,16 +3,20 @@
check_err() routine which checks the status code returned by check_err() routine which checks the status code returned by
OGR methods. OGR methods.
""" """
#### OGR & SRS Exceptions #### #### OGR & SRS Exceptions ####
class GDALException(Exception): class GDALException(Exception):
pass pass
class OGRException(Exception): class OGRException(Exception):
pass pass
class SRSException(Exception): class SRSException(Exception):
pass pass
class OGRIndexError(OGRException, KeyError): class OGRIndexError(OGRException, KeyError):
""" """
This exception is raised when an invalid index is encountered, and has This exception is raised when an invalid index is encountered, and has
@ -37,6 +41,7 @@ OGRERR_DICT = {
} }
OGRERR_NONE = 0 OGRERR_NONE = 0
def check_err(code): def check_err(code):
"Checks the given OGRERR, and raises an exception where appropriate." "Checks the given OGRERR, and raises an exception where appropriate."

View File

@ -11,6 +11,7 @@ from django.utils.encoding import force_bytes, force_text
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import xrange
# For more information, see the OGR C API source code: # For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html # http://www.gdal.org/ogr/ogr__api_8h.html
# #

View File

@ -102,6 +102,7 @@ class Field(GDALBase):
"Returns the width of this Field." "Returns the width of this Field."
return capi.get_field_width(self.ptr) return capi.get_field_width(self.ptr)
### The Field sub-classes for each OGR Field type. ### ### The Field sub-classes for each OGR Field type. ###
class OFTInteger(Field): class OFTInteger(Field):
_double = False _double = False
@ -125,22 +126,27 @@ class OFTInteger(Field):
""" """
return 0 return 0
class OFTReal(Field): class OFTReal(Field):
@property @property
def value(self): def value(self):
"Returns a float contained in this field." "Returns a float contained in this field."
return self.as_double() return self.as_double()
# String & Binary fields, just subclasses # String & Binary fields, just subclasses
class OFTString(Field): class OFTString(Field):
pass pass
class OFTWideString(Field): class OFTWideString(Field):
pass pass
class OFTBinary(Field): class OFTBinary(Field):
pass pass
# OFTDate, OFTTime, OFTDateTime fields. # OFTDate, OFTTime, OFTDateTime fields.
class OFTDate(Field): class OFTDate(Field):
@property @property
@ -152,6 +158,7 @@ class OFTDate(Field):
except (ValueError, OGRException): except (ValueError, OGRException):
return None return None
class OFTDateTime(Field): class OFTDateTime(Field):
@property @property
def value(self): def value(self):
@ -166,6 +173,7 @@ class OFTDateTime(Field):
except (ValueError, OGRException): except (ValueError, OGRException):
return None return None
class OFTTime(Field): class OFTTime(Field):
@property @property
def value(self): def value(self):
@ -176,16 +184,20 @@ class OFTTime(Field):
except (ValueError, OGRException): except (ValueError, OGRException):
return None return None
# List fields are also just subclasses # List fields are also just subclasses
class OFTIntegerList(Field): class OFTIntegerList(Field):
pass pass
class OFTRealList(Field): class OFTRealList(Field):
pass pass
class OFTStringList(Field): class OFTStringList(Field):
pass pass
class OFTWideStringList(Field): class OFTWideStringList(Field):
pass pass

View File

@ -67,7 +67,7 @@ from django.utils.six.moves import xrange
# #
# The OGR_G_* routines are relevant here. # The OGR_G_* routines are relevant here.
#### OGRGeometry Class ####
class OGRGeometry(GDALBase): class OGRGeometry(GDALBase):
"Generally encapsulates an OGR geometry." "Generally encapsulates an OGR geometry."

View File

@ -18,6 +18,7 @@ from django.utils.encoding import force_bytes, force_text
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import xrange
# For more information, see the OGR C API source code: # For more information, see the OGR C API source code:
# http://www.gdal.org/ogr/ogr__api_8h.html # http://www.gdal.org/ogr/ogr__api_8h.html
# #

View File

@ -328,6 +328,7 @@ class SpatialReference(GDALBase):
"Returns the XML representation of this Spatial Reference." "Returns the XML representation of this Spatial Reference."
return capi.to_xml(self.ptr, byref(c_char_p()), dialect) return capi.to_xml(self.ptr, byref(c_char_p()), dialect)
class CoordTransform(GDALBase): class CoordTransform(GDALBase):
"The coordinate system transformation object." "The coordinate system transformation object."

View File

@ -17,10 +17,12 @@ from django.utils.encoding import force_bytes
free_regex = re.compile(r'^GEO-\d{3}FREE') free_regex = re.compile(r'^GEO-\d{3}FREE')
lite_regex = re.compile(r'^GEO-\d{3}LITE') lite_regex = re.compile(r'^GEO-\d{3}LITE')
#### GeoIP classes #### #### GeoIP classes ####
class GeoIPException(Exception): class GeoIPException(Exception):
pass pass
class GeoIP(object): class GeoIP(object):
# The flags for GeoIP memory caching. # The flags for GeoIP memory caching.
# GEOIP_STANDARD - read database from filesystem, uses least memory. # GEOIP_STANDARD - read database from filesystem, uses least memory.

View File

@ -18,6 +18,7 @@ try:
except ImportError: except ImportError:
numpy = False numpy = False
class GEOSBase(object): class GEOSBase(object):
""" """
Base object for GEOS objects that has a pointer access property Base object for GEOS objects that has a pointer access property

View File

@ -6,12 +6,14 @@ reader and writer classes.
from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.geometry import GEOSGeometry
from django.contrib.gis.geos.prototypes.io import _WKTReader, _WKBReader, WKBWriter, WKTWriter from django.contrib.gis.geos.prototypes.io import _WKTReader, _WKBReader, WKBWriter, WKTWriter
# Public classes for (WKB|WKT)Reader, which return GEOSGeometry # Public classes for (WKB|WKT)Reader, which return GEOSGeometry
class WKBReader(_WKBReader): class WKBReader(_WKBReader):
def read(self, wkb): def read(self, wkb):
"Returns a GEOSGeometry for the given WKB buffer." "Returns a GEOSGeometry for the given WKB buffer."
return GEOSGeometry(super(WKBReader, self).read(wkb)) return GEOSGeometry(super(WKBReader, self).read(wkb))
class WKTReader(_WKTReader): class WKTReader(_WKTReader):
def read(self, wkt): def read(self, wkt):
"Returns a GEOSGeometry for the given WKT string." "Returns a GEOSGeometry for the given WKT string."

View File

@ -12,6 +12,7 @@ from django.utils.functional import total_ordering
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import xrange
@total_ordering @total_ordering
class ListMixin(object): class ListMixin(object):
""" """

View File

@ -6,6 +6,7 @@ from django.contrib.gis.geos import prototypes as capi
from django.utils import six from django.utils import six
from django.utils.six.moves import xrange from django.utils.six.moves import xrange
class Polygon(GEOSGeometry): class Polygon(GEOSGeometry):
_minlength = 1 _minlength = 1

View File

@ -2,6 +2,7 @@ from django.contrib.gis.geos.base import GEOSBase
from django.contrib.gis.geos.geometry import GEOSGeometry from django.contrib.gis.geos.geometry import GEOSGeometry
from django.contrib.gis.geos.prototypes import prepared as capi from django.contrib.gis.geos.prototypes import prepared as capi
class PreparedGeometry(GEOSBase): class PreparedGeometry(GEOSBase):
""" """
A geometry that is prepared for performing certain operations. A geometry that is prepared for performing certain operations.

View File

@ -44,6 +44,7 @@ from django.utils import six
NUMERIC_TYPES = six.integer_types + (float, Decimal) NUMERIC_TYPES = six.integer_types + (float, Decimal)
AREA_PREFIX = "sq_" AREA_PREFIX = "sq_"
def pretty_name(obj): def pretty_name(obj):
return obj.__name__ if obj.__class__ == type else obj.__class__.__name__ return obj.__name__ if obj.__class__ == type else obj.__class__.__name__
@ -218,6 +219,7 @@ class MeasureBase(object):
else: else:
raise Exception('Could not find a unit keyword associated with "%s"' % unit_str) raise Exception('Could not find a unit keyword associated with "%s"' % unit_str)
class Distance(MeasureBase): class Distance(MeasureBase):
STANDARD_UNIT = "m" STANDARD_UNIT = "m"
UNITS = { UNITS = {

View File

@ -5,6 +5,7 @@ from django.conf import settings
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
def compress_kml(kml): def compress_kml(kml):
"Returns compressed KMZ from the given KML string." "Returns compressed KMZ from the given KML string."
kmz = BytesIO() kmz = BytesIO()
@ -14,11 +15,13 @@ def compress_kml(kml):
kmz.seek(0) kmz.seek(0)
return kmz.read() return kmz.read()
def render_to_kml(*args, **kwargs): def render_to_kml(*args, **kwargs):
"Renders the response as KML (using the correct MIME type)." "Renders the response as KML (using the correct MIME type)."
return HttpResponse(loader.render_to_string(*args, **kwargs), return HttpResponse(loader.render_to_string(*args, **kwargs),
content_type='application/vnd.google-earth.kml+xml') content_type='application/vnd.google-earth.kml+xml')
def render_to_kmz(*args, **kwargs): def render_to_kmz(*args, **kwargs):
""" """
Compresses the KML content and returns as KMZ (using the correct Compresses the KML content and returns as KMZ (using the correct
@ -27,6 +30,7 @@ def render_to_kmz(*args, **kwargs):
return HttpResponse(compress_kml(loader.render_to_string(*args, **kwargs)), return HttpResponse(compress_kml(loader.render_to_string(*args, **kwargs)),
content_type='application/vnd.google-earth.kmz') content_type='application/vnd.google-earth.kmz')
def render_to_text(*args, **kwargs): def render_to_text(*args, **kwargs):
"Renders the response using the MIME type for plain text." "Renders the response using the MIME type for plain text."
return HttpResponse(loader.render_to_string(*args, **kwargs), return HttpResponse(loader.render_to_string(*args, **kwargs),

View File

@ -1,6 +1,7 @@
from django.core import urlresolvers from django.core import urlresolvers
from django.contrib.sitemaps import Sitemap from django.contrib.sitemaps import Sitemap
class GeoRSSSitemap(Sitemap): class GeoRSSSitemap(Sitemap):
""" """
A minimal hook to produce sitemaps for GeoRSS feeds. A minimal hook to produce sitemaps for GeoRSS feeds.

View File

@ -3,6 +3,7 @@ from django.contrib.sitemaps import Sitemap
from django.contrib.gis.db.models.fields import GeometryField from django.contrib.gis.db.models.fields import GeometryField
from django.db import models from django.db import models
class KMLSitemap(Sitemap): class KMLSitemap(Sitemap):
""" """
A minimal hook to produce KML sitemaps. A minimal hook to produce KML sitemaps.
@ -60,5 +61,7 @@ class KMLSitemap(Sitemap):
'field_name': obj[2], 'field_name': obj[2],
} }
) )
class KMZSitemap(KMLSitemap): class KMZSitemap(KMLSitemap):
geo_format = 'kmz' geo_format = 'kmz'

View File

@ -14,6 +14,7 @@ from django.utils.translation import ugettext as _
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
def index(request, sitemaps): def index(request, sitemaps):
""" """
This view generates a sitemap index that uses the proper view This view generates a sitemap index that uses the proper view

View File

@ -144,6 +144,7 @@ class DistanceTest(unittest.TestCase):
for nm, att in unit_tuple: for nm, att in unit_tuple:
self.assertEqual(att, D.unit_attname(nm)) self.assertEqual(att, D.unit_attname(nm))
class AreaTest(unittest.TestCase): class AreaTest(unittest.TestCase):
"Testing the Area object" "Testing the Area object"

View File

@ -14,17 +14,21 @@ def no_backend(test_func, backend):
else: else:
return test_func return test_func
# Decorators to disable entire test functions for specific # Decorators to disable entire test functions for specific
# spatial backends. # spatial backends.
def no_oracle(func): def no_oracle(func):
return no_backend(func, 'oracle') return no_backend(func, 'oracle')
def no_postgis(func): def no_postgis(func):
return no_backend(func, 'postgis') return no_backend(func, 'postgis')
def no_mysql(func): def no_mysql(func):
return no_backend(func, 'mysql') return no_backend(func, 'mysql')
def no_spatialite(func): def no_spatialite(func):
return no_backend(func, 'spatialite') return no_backend(func, 'spatialite')

View File

@ -3,6 +3,7 @@ from __future__ import unicode_literals
from django.http import Http404 from django.http import Http404
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def feed(request, url, feed_dict=None): def feed(request, url, feed_dict=None):
"""Provided for backwards compatibility.""" """Provided for backwards compatibility."""
if not feed_dict: if not feed_dict:

View File

@ -9,6 +9,7 @@ from django.contrib.sites.models import Site
from django.contrib.sites import models as site_app from django.contrib.sites import models as site_app
from django.core.management.color import no_style from django.core.management.color import no_style
def create_default_site(app, created_models, verbosity, db, **kwargs): def create_default_site(app, created_models, verbosity, db, **kwargs):
# Only create the default sites in databases where Django created the table # Only create the default sites in databases where Django created the table
if Site in created_models and router.allow_migrate(db, Site): if Site in created_models and router.allow_migrate(db, Site):

View File

@ -6,6 +6,7 @@ from django.utils.six.moves.urllib.request import url2pathname
from django.contrib.staticfiles import utils from django.contrib.staticfiles import utils
from django.contrib.staticfiles.views import serve from django.contrib.staticfiles.views import serve
class StaticFilesHandler(WSGIHandler): class StaticFilesHandler(WSGIHandler):
""" """
WSGI middleware that intercepts calls to the static files directory, as WSGI middleware that intercepts calls to the static files directory, as

View File

@ -3,6 +3,7 @@ from django.conf.urls.static import static
urlpatterns = [] urlpatterns = []
def staticfiles_urlpatterns(prefix=None): def staticfiles_urlpatterns(prefix=None):
""" """
Helper function to return a URL pattern for serving static files. Helper function to return a URL pattern for serving static files.