Fixed all the E203 violations
This commit is contained in:
parent
3351e94ffa
commit
b35ff0d920
|
@ -398,7 +398,7 @@ def admin_list_filter(cl, spec):
|
||||||
tpl = get_template(spec.template)
|
tpl = get_template(spec.template)
|
||||||
return tpl.render(Context({
|
return tpl.render(Context({
|
||||||
'title': spec.title,
|
'title': spec.title,
|
||||||
'choices' : list(spec.choices(cl)),
|
'choices': list(spec.choices(cl)),
|
||||||
'spec': spec,
|
'spec': spec,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
@ -60,10 +60,10 @@ def parse_rst(text, default_reference_context, thing_being_parsed=None):
|
||||||
Convert the string from reST to an XHTML fragment.
|
Convert the string from reST to an XHTML fragment.
|
||||||
"""
|
"""
|
||||||
overrides = {
|
overrides = {
|
||||||
'doctitle_xform' : True,
|
'doctitle_xform': True,
|
||||||
'inital_header_level' : 3,
|
'inital_header_level': 3,
|
||||||
"default_reference_context" : default_reference_context,
|
"default_reference_context": default_reference_context,
|
||||||
"link_base" : reverse('django-admindocs-docroot').rstrip('/')
|
"link_base": reverse('django-admindocs-docroot').rstrip('/')
|
||||||
}
|
}
|
||||||
if thing_being_parsed:
|
if thing_being_parsed:
|
||||||
thing_being_parsed = force_bytes("<%s>" % thing_being_parsed)
|
thing_being_parsed = force_bytes("<%s>" % thing_being_parsed)
|
||||||
|
@ -85,11 +85,11 @@ def parse_rst(text, default_reference_context, thing_being_parsed=None):
|
||||||
# reST roles
|
# reST roles
|
||||||
#
|
#
|
||||||
ROLES = {
|
ROLES = {
|
||||||
'model' : '%s/models/%s/',
|
'model': '%s/models/%s/',
|
||||||
'view' : '%s/views/%s/',
|
'view': '%s/views/%s/',
|
||||||
'template' : '%s/templates/%s/',
|
'template': '%s/templates/%s/',
|
||||||
'filter' : '%s/filters/#%s',
|
'filter': '%s/filters/#%s',
|
||||||
'tag' : '%s/tags/#%s',
|
'tag': '%s/tags/#%s',
|
||||||
}
|
}
|
||||||
|
|
||||||
def create_reference_role(rolename, urlbase):
|
def create_reference_role(rolename, urlbase):
|
||||||
|
|
|
@ -229,12 +229,12 @@ def model_detail(request, app_label, model_name):
|
||||||
fields.append({
|
fields.append({
|
||||||
'name': "%s.all" % field.name,
|
'name': "%s.all" % field.name,
|
||||||
"data_type": 'List',
|
"data_type": 'List',
|
||||||
'verbose': utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name),
|
'verbose': utils.parse_rst(_("all %s") % verbose, 'model', _('model:') + opts.model_name),
|
||||||
})
|
})
|
||||||
fields.append({
|
fields.append({
|
||||||
'name' : "%s.count" % field.name,
|
'name': "%s.count" % field.name,
|
||||||
'data_type' : 'Integer',
|
'data_type': 'Integer',
|
||||||
'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name),
|
'verbose': utils.parse_rst(_("number of %s") % verbose, 'model', _('model:') + opts.model_name),
|
||||||
})
|
})
|
||||||
|
|
||||||
# Gather model methods.
|
# Gather model methods.
|
||||||
|
@ -260,14 +260,14 @@ def model_detail(request, app_label, model_name):
|
||||||
verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': rel.opts.app_label, 'object_name': rel.opts.object_name}
|
verbose = _("related `%(app_label)s.%(object_name)s` objects") % {'app_label': rel.opts.app_label, 'object_name': rel.opts.object_name}
|
||||||
accessor = rel.get_accessor_name()
|
accessor = rel.get_accessor_name()
|
||||||
fields.append({
|
fields.append({
|
||||||
'name' : "%s.all" % accessor,
|
'name': "%s.all" % accessor,
|
||||||
'data_type' : 'List',
|
'data_type': 'List',
|
||||||
'verbose' : utils.parse_rst(_("all %s") % verbose , 'model', _('model:') + opts.model_name),
|
'verbose': utils.parse_rst(_("all %s") % verbose, 'model', _('model:') + opts.model_name),
|
||||||
})
|
})
|
||||||
fields.append({
|
fields.append({
|
||||||
'name' : "%s.count" % accessor,
|
'name': "%s.count" % accessor,
|
||||||
'data_type' : 'Integer',
|
'data_type': 'Integer',
|
||||||
'verbose' : utils.parse_rst(_("number of %s") % verbose , 'model', _('model:') + opts.model_name),
|
'verbose': utils.parse_rst(_("number of %s") % verbose, 'model', _('model:') + opts.model_name),
|
||||||
})
|
})
|
||||||
return render_to_response('admin_doc/model_detail.html', {
|
return render_to_response('admin_doc/model_detail.html', {
|
||||||
'root_path': urlresolvers.reverse('admin:index'),
|
'root_path': urlresolvers.reverse('admin:index'),
|
||||||
|
|
|
@ -86,39 +86,39 @@ class GeoModelAdmin(ModelAdmin):
|
||||||
wms_options = ["%s: '%s'" % pair for pair in self.wms_options.items()]
|
wms_options = ["%s: '%s'" % pair for pair in self.wms_options.items()]
|
||||||
wms_options = ', %s' % ', '.join(wms_options)
|
wms_options = ', %s' % ', '.join(wms_options)
|
||||||
|
|
||||||
params = {'default_lon' : self.default_lon,
|
params = {'default_lon': self.default_lon,
|
||||||
'default_lat' : self.default_lat,
|
'default_lat': self.default_lat,
|
||||||
'default_zoom' : self.default_zoom,
|
'default_zoom': self.default_zoom,
|
||||||
'display_wkt' : self.debug or self.display_wkt,
|
'display_wkt': self.debug or self.display_wkt,
|
||||||
'geom_type' : OGRGeomType(db_field.geom_type),
|
'geom_type': OGRGeomType(db_field.geom_type),
|
||||||
'field_name' : db_field.name,
|
'field_name': db_field.name,
|
||||||
'is_collection' : is_collection,
|
'is_collection': is_collection,
|
||||||
'scrollable' : self.scrollable,
|
'scrollable': self.scrollable,
|
||||||
'layerswitcher' : self.layerswitcher,
|
'layerswitcher': self.layerswitcher,
|
||||||
'collection_type' : collection_type,
|
'collection_type': collection_type,
|
||||||
'is_generic' : db_field.geom_type == 'GEOMETRY',
|
'is_generic': db_field.geom_type == 'GEOMETRY',
|
||||||
'is_linestring' : db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),
|
'is_linestring': db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),
|
||||||
'is_polygon' : db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),
|
'is_polygon': db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),
|
||||||
'is_point' : db_field.geom_type in ('POINT', 'MULTIPOINT'),
|
'is_point': db_field.geom_type in ('POINT', 'MULTIPOINT'),
|
||||||
'num_zoom' : self.num_zoom,
|
'num_zoom': self.num_zoom,
|
||||||
'max_zoom' : self.max_zoom,
|
'max_zoom': self.max_zoom,
|
||||||
'min_zoom' : self.min_zoom,
|
'min_zoom': self.min_zoom,
|
||||||
'units' : self.units, # likely should get from object
|
'units': self.units, # likely should get from object
|
||||||
'max_resolution' : self.max_resolution,
|
'max_resolution': self.max_resolution,
|
||||||
'max_extent' : self.max_extent,
|
'max_extent': self.max_extent,
|
||||||
'modifiable' : self.modifiable,
|
'modifiable': self.modifiable,
|
||||||
'mouse_position' : self.mouse_position,
|
'mouse_position': self.mouse_position,
|
||||||
'scale_text' : self.scale_text,
|
'scale_text': self.scale_text,
|
||||||
'map_width' : self.map_width,
|
'map_width': self.map_width,
|
||||||
'map_height' : self.map_height,
|
'map_height': self.map_height,
|
||||||
'point_zoom' : self.point_zoom,
|
'point_zoom': self.point_zoom,
|
||||||
'srid' : self.map_srid,
|
'srid': self.map_srid,
|
||||||
'display_srid' : self.display_srid,
|
'display_srid': self.display_srid,
|
||||||
'wms_url' : self.wms_url,
|
'wms_url': self.wms_url,
|
||||||
'wms_layer' : self.wms_layer,
|
'wms_layer': self.wms_layer,
|
||||||
'wms_name' : self.wms_name,
|
'wms_name': self.wms_name,
|
||||||
'wms_options' : wms_options,
|
'wms_options': wms_options,
|
||||||
'debug' : self.debug,
|
'debug': self.debug,
|
||||||
}
|
}
|
||||||
return OLMap
|
return OLMap
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.contrib.gis.geos import GEOSGeometry, GEOSException
|
||||||
|
|
||||||
# Creating a template context that contains Django settings
|
# Creating a template context that contains Django settings
|
||||||
# values needed by admin map templates.
|
# values needed by admin map templates.
|
||||||
geo_context = Context({'LANGUAGE_BIDI' : translation.get_language_bidi()})
|
geo_context = Context({'LANGUAGE_BIDI': translation.get_language_bidi()})
|
||||||
logger = logging.getLogger('django.contrib.gis')
|
logger = logging.getLogger('django.contrib.gis')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -109,33 +109,33 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
select = 'SDO_UTIL.TO_WKTGEOMETRY(%s)'
|
select = 'SDO_UTIL.TO_WKTGEOMETRY(%s)'
|
||||||
|
|
||||||
distance_functions = {
|
distance_functions = {
|
||||||
'distance_gt' : (SDODistance('>'), dtypes),
|
'distance_gt': (SDODistance('>'), dtypes),
|
||||||
'distance_gte' : (SDODistance('>='), dtypes),
|
'distance_gte': (SDODistance('>='), dtypes),
|
||||||
'distance_lt' : (SDODistance('<'), dtypes),
|
'distance_lt': (SDODistance('<'), dtypes),
|
||||||
'distance_lte' : (SDODistance('<='), dtypes),
|
'distance_lte': (SDODistance('<='), dtypes),
|
||||||
'dwithin' : (SDODWithin(), dtypes),
|
'dwithin': (SDODWithin(), dtypes),
|
||||||
}
|
}
|
||||||
|
|
||||||
geometry_functions = {
|
geometry_functions = {
|
||||||
'contains' : SDOOperation('SDO_CONTAINS'),
|
'contains': SDOOperation('SDO_CONTAINS'),
|
||||||
'coveredby' : SDOOperation('SDO_COVEREDBY'),
|
'coveredby': SDOOperation('SDO_COVEREDBY'),
|
||||||
'covers' : SDOOperation('SDO_COVERS'),
|
'covers': SDOOperation('SDO_COVERS'),
|
||||||
'disjoint' : SDOGeomRelate('DISJOINT'),
|
'disjoint': SDOGeomRelate('DISJOINT'),
|
||||||
'intersects' : SDOOperation('SDO_OVERLAPBDYINTERSECT'), # TODO: Is this really the same as ST_Intersects()?
|
'intersects': SDOOperation('SDO_OVERLAPBDYINTERSECT'), # TODO: Is this really the same as ST_Intersects()?
|
||||||
'equals' : SDOOperation('SDO_EQUAL'),
|
'equals': SDOOperation('SDO_EQUAL'),
|
||||||
'exact' : SDOOperation('SDO_EQUAL'),
|
'exact': SDOOperation('SDO_EQUAL'),
|
||||||
'overlaps' : SDOOperation('SDO_OVERLAPS'),
|
'overlaps': SDOOperation('SDO_OVERLAPS'),
|
||||||
'same_as' : SDOOperation('SDO_EQUAL'),
|
'same_as': SDOOperation('SDO_EQUAL'),
|
||||||
'relate' : (SDORelate, six.string_types), # Oracle uses a different syntax, e.g., 'mask=inside+touch'
|
'relate': (SDORelate, six.string_types), # Oracle uses a different syntax, e.g., 'mask=inside+touch'
|
||||||
'touches' : SDOOperation('SDO_TOUCH'),
|
'touches': SDOOperation('SDO_TOUCH'),
|
||||||
'within' : SDOOperation('SDO_INSIDE'),
|
'within': SDOOperation('SDO_INSIDE'),
|
||||||
}
|
}
|
||||||
geometry_functions.update(distance_functions)
|
geometry_functions.update(distance_functions)
|
||||||
|
|
||||||
gis_terms = set(['isnull'])
|
gis_terms = set(['isnull'])
|
||||||
gis_terms.update(geometry_functions)
|
gis_terms.update(geometry_functions)
|
||||||
|
|
||||||
truncate_params = {'relate' : None}
|
truncate_params = {'relate': None}
|
||||||
|
|
||||||
def convert_extent(self, clob):
|
def convert_extent(self, clob):
|
||||||
if clob:
|
if clob:
|
||||||
|
|
|
@ -32,14 +32,14 @@ class PostGISIntrospection(DatabaseIntrospection):
|
||||||
try:
|
try:
|
||||||
cursor.execute(oid_sql, ('geometry',))
|
cursor.execute(oid_sql, ('geometry',))
|
||||||
GEOM_TYPE = cursor.fetchone()[0]
|
GEOM_TYPE = cursor.fetchone()[0]
|
||||||
postgis_types = {GEOM_TYPE : 'GeometryField'}
|
postgis_types = {GEOM_TYPE: 'GeometryField'}
|
||||||
if self.connection.ops.geography:
|
if self.connection.ops.geography:
|
||||||
cursor.execute(oid_sql, ('geography',))
|
cursor.execute(oid_sql, ('geography',))
|
||||||
GEOG_TYPE = cursor.fetchone()[0]
|
GEOG_TYPE = cursor.fetchone()[0]
|
||||||
# The value for the geography type is actually a tuple
|
# The value for the geography type is actually a tuple
|
||||||
# to pass in the `geography=True` keyword to the field
|
# to pass in the `geography=True` keyword to the field
|
||||||
# definition.
|
# definition.
|
||||||
postgis_types[GEOG_TYPE] = ('GeometryField', {'geography' : True})
|
postgis_types[GEOG_TYPE] = ('GeometryField', {'geography': True})
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
|
|
@ -84,56 +84,56 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
self.geometry_operators = {
|
self.geometry_operators = {
|
||||||
# The "&<" operator returns true if A's bounding box overlaps or
|
# The "&<" operator returns true if A's bounding box overlaps or
|
||||||
# is to the left of B's bounding box.
|
# is to the left of B's bounding box.
|
||||||
'overlaps_left' : PostGISOperator('&<'),
|
'overlaps_left': PostGISOperator('&<'),
|
||||||
# The "&>" operator returns true if A's bounding box overlaps or
|
# The "&>" operator returns true if A's bounding box overlaps or
|
||||||
# is to the right of B's bounding box.
|
# is to the right of B's bounding box.
|
||||||
'overlaps_right' : PostGISOperator('&>'),
|
'overlaps_right': PostGISOperator('&>'),
|
||||||
# The "<<" operator returns true if A's bounding box is strictly
|
# The "<<" operator returns true if A's bounding box is strictly
|
||||||
# to the left of B's bounding box.
|
# to the left of B's bounding box.
|
||||||
'left' : PostGISOperator('<<'),
|
'left': PostGISOperator('<<'),
|
||||||
# The ">>" operator returns true if A's bounding box is strictly
|
# The ">>" operator returns true if A's bounding box is strictly
|
||||||
# to the right of B's bounding box.
|
# to the right of B's bounding box.
|
||||||
'right' : PostGISOperator('>>'),
|
'right': PostGISOperator('>>'),
|
||||||
# The "&<|" operator returns true if A's bounding box overlaps or
|
# The "&<|" operator returns true if A's bounding box overlaps or
|
||||||
# is below B's bounding box.
|
# is below B's bounding box.
|
||||||
'overlaps_below' : PostGISOperator('&<|'),
|
'overlaps_below': PostGISOperator('&<|'),
|
||||||
# The "|&>" operator returns true if A's bounding box overlaps or
|
# The "|&>" operator returns true if A's bounding box overlaps or
|
||||||
# is above B's bounding box.
|
# is above B's bounding box.
|
||||||
'overlaps_above' : PostGISOperator('|&>'),
|
'overlaps_above': PostGISOperator('|&>'),
|
||||||
# The "<<|" operator returns true if A's bounding box is strictly
|
# The "<<|" operator returns true if A's bounding box is strictly
|
||||||
# below B's bounding box.
|
# below B's bounding box.
|
||||||
'strictly_below' : PostGISOperator('<<|'),
|
'strictly_below': PostGISOperator('<<|'),
|
||||||
# The "|>>" operator returns true if A's bounding box is strictly
|
# The "|>>" operator returns true if A's bounding box is strictly
|
||||||
# above B's bounding box.
|
# above B's bounding box.
|
||||||
'strictly_above' : PostGISOperator('|>>'),
|
'strictly_above': PostGISOperator('|>>'),
|
||||||
# The "~=" operator is the "same as" operator. It tests actual
|
# The "~=" operator is the "same as" operator. It tests actual
|
||||||
# geometric equality of two features. So if A and B are the same feature,
|
# geometric equality of two features. So if A and B are the same feature,
|
||||||
# vertex-by-vertex, the operator returns true.
|
# vertex-by-vertex, the operator returns true.
|
||||||
'same_as' : PostGISOperator('~='),
|
'same_as': PostGISOperator('~='),
|
||||||
'exact' : PostGISOperator('~='),
|
'exact': PostGISOperator('~='),
|
||||||
# The "@" operator returns true if A's bounding box is completely contained
|
# The "@" operator returns true if A's bounding box is completely contained
|
||||||
# by B's bounding box.
|
# by B's bounding box.
|
||||||
'contained' : PostGISOperator('@'),
|
'contained': PostGISOperator('@'),
|
||||||
# The "~" operator returns true if A's bounding box completely contains
|
# The "~" operator returns true if A's bounding box completely contains
|
||||||
# by B's bounding box.
|
# by B's bounding box.
|
||||||
'bbcontains' : PostGISOperator('~'),
|
'bbcontains': PostGISOperator('~'),
|
||||||
# The "&&" operator returns true if A's bounding box overlaps
|
# The "&&" operator returns true if A's bounding box overlaps
|
||||||
# B's bounding box.
|
# B's bounding box.
|
||||||
'bboverlaps' : PostGISOperator('&&'),
|
'bboverlaps': PostGISOperator('&&'),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.geometry_functions = {
|
self.geometry_functions = {
|
||||||
'equals' : PostGISFunction(prefix, 'Equals'),
|
'equals': PostGISFunction(prefix, 'Equals'),
|
||||||
'disjoint' : PostGISFunction(prefix, 'Disjoint'),
|
'disjoint': PostGISFunction(prefix, 'Disjoint'),
|
||||||
'touches' : PostGISFunction(prefix, 'Touches'),
|
'touches': PostGISFunction(prefix, 'Touches'),
|
||||||
'crosses' : PostGISFunction(prefix, 'Crosses'),
|
'crosses': PostGISFunction(prefix, 'Crosses'),
|
||||||
'within' : PostGISFunction(prefix, 'Within'),
|
'within': PostGISFunction(prefix, 'Within'),
|
||||||
'overlaps' : PostGISFunction(prefix, 'Overlaps'),
|
'overlaps': PostGISFunction(prefix, 'Overlaps'),
|
||||||
'contains' : PostGISFunction(prefix, 'Contains'),
|
'contains': PostGISFunction(prefix, 'Contains'),
|
||||||
'intersects' : PostGISFunction(prefix, 'Intersects'),
|
'intersects': PostGISFunction(prefix, 'Intersects'),
|
||||||
'relate' : (PostGISRelate, six.string_types),
|
'relate': (PostGISRelate, six.string_types),
|
||||||
'coveredby' : PostGISFunction(prefix, 'CoveredBy'),
|
'coveredby': PostGISFunction(prefix, 'CoveredBy'),
|
||||||
'covers' : PostGISFunction(prefix, 'Covers'),
|
'covers': PostGISFunction(prefix, 'Covers'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Valid distance types and substitutions
|
# Valid distance types and substitutions
|
||||||
|
@ -141,16 +141,16 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
|
|
||||||
def get_dist_ops(operator):
|
def get_dist_ops(operator):
|
||||||
"Returns operations for both regular and spherical distances."
|
"Returns operations for both regular and spherical distances."
|
||||||
return {'cartesian' : PostGISDistance(prefix, operator),
|
return {'cartesian': PostGISDistance(prefix, operator),
|
||||||
'sphere' : PostGISSphereDistance(prefix, operator),
|
'sphere': PostGISSphereDistance(prefix, operator),
|
||||||
'spheroid' : PostGISSpheroidDistance(prefix, operator),
|
'spheroid': PostGISSpheroidDistance(prefix, operator),
|
||||||
}
|
}
|
||||||
self.distance_functions = {
|
self.distance_functions = {
|
||||||
'distance_gt' : (get_dist_ops('>'), dtypes),
|
'distance_gt': (get_dist_ops('>'), dtypes),
|
||||||
'distance_gte' : (get_dist_ops('>='), dtypes),
|
'distance_gte': (get_dist_ops('>='), dtypes),
|
||||||
'distance_lt' : (get_dist_ops('<'), dtypes),
|
'distance_lt': (get_dist_ops('<'), dtypes),
|
||||||
'distance_lte' : (get_dist_ops('<='), dtypes),
|
'distance_lte': (get_dist_ops('<='), dtypes),
|
||||||
'dwithin' : (PostGISFunctionParam(prefix, 'DWithin'), dtypes)
|
'dwithin': (PostGISFunctionParam(prefix, 'DWithin'), dtypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Adding the distance functions to the geometries lookup.
|
# Adding the distance functions to the geometries lookup.
|
||||||
|
|
|
@ -9,13 +9,13 @@ class GeoFlexibleFieldLookupDict(FlexibleFieldLookupDict):
|
||||||
"""
|
"""
|
||||||
base_data_types_reverse = FlexibleFieldLookupDict.base_data_types_reverse.copy()
|
base_data_types_reverse = FlexibleFieldLookupDict.base_data_types_reverse.copy()
|
||||||
base_data_types_reverse.update(
|
base_data_types_reverse.update(
|
||||||
{'point' : 'GeometryField',
|
{'point': 'GeometryField',
|
||||||
'linestring' : 'GeometryField',
|
'linestring': 'GeometryField',
|
||||||
'polygon' : 'GeometryField',
|
'polygon': 'GeometryField',
|
||||||
'multipoint' : 'GeometryField',
|
'multipoint': 'GeometryField',
|
||||||
'multilinestring' : 'GeometryField',
|
'multilinestring': 'GeometryField',
|
||||||
'multipolygon' : 'GeometryField',
|
'multipolygon': 'GeometryField',
|
||||||
'geometrycollection' : 'GeometryField',
|
'geometrycollection': 'GeometryField',
|
||||||
})
|
})
|
||||||
|
|
||||||
class SpatiaLiteIntrospection(DatabaseIntrospection):
|
class SpatiaLiteIntrospection(DatabaseIntrospection):
|
||||||
|
|
|
@ -86,31 +86,31 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
select = 'AsText(%s)'
|
select = 'AsText(%s)'
|
||||||
|
|
||||||
geometry_functions = {
|
geometry_functions = {
|
||||||
'equals' : SpatiaLiteFunction('Equals'),
|
'equals': SpatiaLiteFunction('Equals'),
|
||||||
'disjoint' : SpatiaLiteFunction('Disjoint'),
|
'disjoint': SpatiaLiteFunction('Disjoint'),
|
||||||
'touches' : SpatiaLiteFunction('Touches'),
|
'touches': SpatiaLiteFunction('Touches'),
|
||||||
'crosses' : SpatiaLiteFunction('Crosses'),
|
'crosses': SpatiaLiteFunction('Crosses'),
|
||||||
'within' : SpatiaLiteFunction('Within'),
|
'within': SpatiaLiteFunction('Within'),
|
||||||
'overlaps' : SpatiaLiteFunction('Overlaps'),
|
'overlaps': SpatiaLiteFunction('Overlaps'),
|
||||||
'contains' : SpatiaLiteFunction('Contains'),
|
'contains': SpatiaLiteFunction('Contains'),
|
||||||
'intersects' : SpatiaLiteFunction('Intersects'),
|
'intersects': SpatiaLiteFunction('Intersects'),
|
||||||
'relate' : (SpatiaLiteRelate, six.string_types),
|
'relate': (SpatiaLiteRelate, six.string_types),
|
||||||
# Returns true if B's bounding box completely contains A's bounding box.
|
# Returns true if B's bounding box completely contains A's bounding box.
|
||||||
'contained' : SpatiaLiteFunction('MbrWithin'),
|
'contained': SpatiaLiteFunction('MbrWithin'),
|
||||||
# Returns true if A's bounding box completely contains B's bounding box.
|
# Returns true if A's bounding box completely contains B's bounding box.
|
||||||
'bbcontains' : SpatiaLiteFunction('MbrContains'),
|
'bbcontains': SpatiaLiteFunction('MbrContains'),
|
||||||
# Returns true if A's bounding box overlaps B's bounding box.
|
# Returns true if A's bounding box overlaps B's bounding box.
|
||||||
'bboverlaps' : SpatiaLiteFunction('MbrOverlaps'),
|
'bboverlaps': SpatiaLiteFunction('MbrOverlaps'),
|
||||||
# These are implemented here as synonyms for Equals
|
# These are implemented here as synonyms for Equals
|
||||||
'same_as' : SpatiaLiteFunction('Equals'),
|
'same_as': SpatiaLiteFunction('Equals'),
|
||||||
'exact' : SpatiaLiteFunction('Equals'),
|
'exact': SpatiaLiteFunction('Equals'),
|
||||||
}
|
}
|
||||||
|
|
||||||
distance_functions = {
|
distance_functions = {
|
||||||
'distance_gt' : (get_dist_ops('>'), dtypes),
|
'distance_gt': (get_dist_ops('>'), dtypes),
|
||||||
'distance_gte' : (get_dist_ops('>='), dtypes),
|
'distance_gte': (get_dist_ops('>='), dtypes),
|
||||||
'distance_lt' : (get_dist_ops('<'), dtypes),
|
'distance_lt': (get_dist_ops('<'), dtypes),
|
||||||
'distance_lte' : (get_dist_ops('<='), dtypes),
|
'distance_lte': (get_dist_ops('<='), dtypes),
|
||||||
}
|
}
|
||||||
geometry_functions.update(distance_functions)
|
geometry_functions.update(distance_functions)
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ class SpatialOperation(object):
|
||||||
return self.sql_template % self.params(geo_col, geometry), []
|
return self.sql_template % self.params(geo_col, geometry), []
|
||||||
|
|
||||||
def params(self, geo_col, geometry):
|
def params(self, geo_col, geometry):
|
||||||
params = {'function' : self.function,
|
params = {'function': self.function,
|
||||||
'geo_col' : geo_col,
|
'geo_col': geo_col,
|
||||||
'geometry' : geometry,
|
'geometry': geometry,
|
||||||
'operator' : self.operator,
|
'operator': self.operator,
|
||||||
'result' : self.result,
|
'result': self.result,
|
||||||
}
|
}
|
||||||
params.update(self.extra)
|
params.update(self.extra)
|
||||||
return params
|
return params
|
||||||
|
@ -36,9 +36,9 @@ class SpatialFunction(SpatialOperation):
|
||||||
|
|
||||||
def __init__(self, func, result='', operator='', **kwargs):
|
def __init__(self, func, result='', operator='', **kwargs):
|
||||||
# Getting the function prefix.
|
# Getting the function prefix.
|
||||||
default = {'function' : func,
|
default = {'function': func,
|
||||||
'operator' : operator,
|
'operator': operator,
|
||||||
'result' : result
|
'result': result
|
||||||
}
|
}
|
||||||
kwargs.update(default)
|
kwargs.update(default)
|
||||||
super(SpatialFunction, self).__init__(**kwargs)
|
super(SpatialFunction, self).__init__(**kwargs)
|
||||||
|
|
|
@ -203,9 +203,9 @@ class GeometryField(Field):
|
||||||
return connection.ops.geo_db_type(self)
|
return connection.ops.geo_db_type(self)
|
||||||
|
|
||||||
def formfield(self, **kwargs):
|
def formfield(self, **kwargs):
|
||||||
defaults = {'form_class' : self.form_class,
|
defaults = {'form_class': self.form_class,
|
||||||
'geom_type' : self.geom_type,
|
'geom_type': self.geom_type,
|
||||||
'srid' : self.srid,
|
'srid': self.srid,
|
||||||
}
|
}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
if (self.dim > 2 and not 'widget' in kwargs and
|
if (self.dim > 2 and not 'widget' in kwargs and
|
||||||
|
|
|
@ -41,9 +41,9 @@ class GeoQuerySet(QuerySet):
|
||||||
# Peforming setup here rather than in `_spatial_attribute` so that
|
# Peforming setup here rather than in `_spatial_attribute` so that
|
||||||
# we can get the units for `AreaField`.
|
# we can get the units for `AreaField`.
|
||||||
procedure_args, geo_field = self._spatial_setup('area', field_name=kwargs.get('field_name', None))
|
procedure_args, geo_field = self._spatial_setup('area', field_name=kwargs.get('field_name', None))
|
||||||
s = {'procedure_args' : procedure_args,
|
s = {'procedure_args': procedure_args,
|
||||||
'geo_field' : geo_field,
|
'geo_field': geo_field,
|
||||||
'setup' : False,
|
'setup': False,
|
||||||
}
|
}
|
||||||
connection = connections[self.db]
|
connection = connections[self.db]
|
||||||
backend = connection.ops
|
backend = connection.ops
|
||||||
|
@ -170,9 +170,9 @@ class GeoQuerySet(QuerySet):
|
||||||
options = 1
|
options = 1
|
||||||
elif bbox:
|
elif bbox:
|
||||||
options = 2
|
options = 2
|
||||||
s = {'desc' : 'GeoJSON',
|
s = {'desc': 'GeoJSON',
|
||||||
'procedure_args' : {'precision' : precision, 'options' : options},
|
'procedure_args': {'precision': precision, 'options': options},
|
||||||
'procedure_fmt' : '%(geo_col)s,%(precision)s,%(options)s',
|
'procedure_fmt': '%(geo_col)s,%(precision)s,%(options)s',
|
||||||
}
|
}
|
||||||
return self._spatial_attribute('geojson', s, **kwargs)
|
return self._spatial_attribute('geojson', s, **kwargs)
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ class GeoQuerySet(QuerySet):
|
||||||
The `precision` keyword may be used to custom the number of
|
The `precision` keyword may be used to custom the number of
|
||||||
_characters_ used in the output GeoHash, the default is 20.
|
_characters_ used in the output GeoHash, the default is 20.
|
||||||
"""
|
"""
|
||||||
s = {'desc' : 'GeoHash',
|
s = {'desc': 'GeoHash',
|
||||||
'procedure_args': {'precision': precision},
|
'procedure_args': {'precision': precision},
|
||||||
'procedure_fmt': '%(geo_col)s,%(precision)s',
|
'procedure_fmt': '%(geo_col)s,%(precision)s',
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ class GeoQuerySet(QuerySet):
|
||||||
on each element of the GeoQuerySet.
|
on each element of the GeoQuerySet.
|
||||||
"""
|
"""
|
||||||
backend = connections[self.db].ops
|
backend = connections[self.db].ops
|
||||||
s = {'desc' : 'GML', 'procedure_args' : {'precision' : precision}}
|
s = {'desc': 'GML', 'procedure_args': {'precision': precision}}
|
||||||
if backend.postgis:
|
if backend.postgis:
|
||||||
# PostGIS AsGML() aggregate function parameter order depends on the
|
# PostGIS AsGML() aggregate function parameter order depends on the
|
||||||
# version -- uggh.
|
# version -- uggh.
|
||||||
|
@ -204,7 +204,7 @@ class GeoQuerySet(QuerySet):
|
||||||
s['procedure_fmt'] = '%(version)s,%(geo_col)s,%(precision)s'
|
s['procedure_fmt'] = '%(version)s,%(geo_col)s,%(precision)s'
|
||||||
else:
|
else:
|
||||||
s['procedure_fmt'] = '%(geo_col)s,%(precision)s,%(version)s'
|
s['procedure_fmt'] = '%(geo_col)s,%(precision)s,%(version)s'
|
||||||
s['procedure_args'] = {'precision' : precision, 'version' : version}
|
s['procedure_args'] = {'precision': precision, 'version': version}
|
||||||
|
|
||||||
return self._spatial_attribute('gml', s, **kwargs)
|
return self._spatial_attribute('gml', s, **kwargs)
|
||||||
|
|
||||||
|
@ -221,9 +221,9 @@ class GeoQuerySet(QuerySet):
|
||||||
Returns KML representation of the geometry field in a `kml`
|
Returns KML representation of the geometry field in a `kml`
|
||||||
attribute on each element of this GeoQuerySet.
|
attribute on each element of this GeoQuerySet.
|
||||||
"""
|
"""
|
||||||
s = {'desc' : 'KML',
|
s = {'desc': 'KML',
|
||||||
'procedure_fmt' : '%(geo_col)s,%(precision)s',
|
'procedure_fmt': '%(geo_col)s,%(precision)s',
|
||||||
'procedure_args' : {'precision' : kwargs.pop('precision', 8)},
|
'procedure_args': {'precision': kwargs.pop('precision', 8)},
|
||||||
}
|
}
|
||||||
return self._spatial_attribute('kml', s, **kwargs)
|
return self._spatial_attribute('kml', s, **kwargs)
|
||||||
|
|
||||||
|
@ -300,14 +300,14 @@ class GeoQuerySet(QuerySet):
|
||||||
if connections[self.db].ops.spatialite:
|
if connections[self.db].ops.spatialite:
|
||||||
if z != 0.0:
|
if z != 0.0:
|
||||||
raise NotImplementedError('SpatiaLite does not support 3D scaling.')
|
raise NotImplementedError('SpatiaLite does not support 3D scaling.')
|
||||||
s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s',
|
s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s',
|
||||||
'procedure_args' : {'x' : x, 'y' : y},
|
'procedure_args': {'x': x, 'y': y},
|
||||||
'select_field' : GeomField(),
|
'select_field': GeomField(),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
||||||
'procedure_args' : {'x' : x, 'y' : y, 'z' : z},
|
'procedure_args': {'x': x, 'y': y, 'z': z},
|
||||||
'select_field' : GeomField(),
|
'select_field': GeomField(),
|
||||||
}
|
}
|
||||||
return self._spatial_attribute('scale', s, **kwargs)
|
return self._spatial_attribute('scale', s, **kwargs)
|
||||||
|
|
||||||
|
@ -327,22 +327,22 @@ class GeoQuerySet(QuerySet):
|
||||||
if nargs == 1:
|
if nargs == 1:
|
||||||
size = args[0]
|
size = args[0]
|
||||||
procedure_fmt = '%(geo_col)s,%(size)s'
|
procedure_fmt = '%(geo_col)s,%(size)s'
|
||||||
procedure_args = {'size' : size}
|
procedure_args = {'size': size}
|
||||||
elif nargs == 2:
|
elif nargs == 2:
|
||||||
xsize, ysize = args
|
xsize, ysize = args
|
||||||
procedure_fmt = '%(geo_col)s,%(xsize)s,%(ysize)s'
|
procedure_fmt = '%(geo_col)s,%(xsize)s,%(ysize)s'
|
||||||
procedure_args = {'xsize' : xsize, 'ysize' : ysize}
|
procedure_args = {'xsize': xsize, 'ysize': ysize}
|
||||||
elif nargs == 4:
|
elif nargs == 4:
|
||||||
xsize, ysize, xorigin, yorigin = args
|
xsize, ysize, xorigin, yorigin = args
|
||||||
procedure_fmt = '%(geo_col)s,%(xorigin)s,%(yorigin)s,%(xsize)s,%(ysize)s'
|
procedure_fmt = '%(geo_col)s,%(xorigin)s,%(yorigin)s,%(xsize)s,%(ysize)s'
|
||||||
procedure_args = {'xsize' : xsize, 'ysize' : ysize,
|
procedure_args = {'xsize': xsize, 'ysize': ysize,
|
||||||
'xorigin' : xorigin, 'yorigin' : yorigin}
|
'xorigin': xorigin, 'yorigin': yorigin}
|
||||||
else:
|
else:
|
||||||
raise ValueError('Must provide 1, 2, or 4 arguments to `snap_to_grid`.')
|
raise ValueError('Must provide 1, 2, or 4 arguments to `snap_to_grid`.')
|
||||||
|
|
||||||
s = {'procedure_fmt' : procedure_fmt,
|
s = {'procedure_fmt': procedure_fmt,
|
||||||
'procedure_args' : procedure_args,
|
'procedure_args': procedure_args,
|
||||||
'select_field' : GeomField(),
|
'select_field': GeomField(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return self._spatial_attribute('snap_to_grid', s, **kwargs)
|
return self._spatial_attribute('snap_to_grid', s, **kwargs)
|
||||||
|
@ -362,10 +362,10 @@ class GeoQuerySet(QuerySet):
|
||||||
relative = int(bool(relative))
|
relative = int(bool(relative))
|
||||||
if not isinstance(precision, six.integer_types):
|
if not isinstance(precision, six.integer_types):
|
||||||
raise TypeError('SVG precision keyword argument must be an integer.')
|
raise TypeError('SVG precision keyword argument must be an integer.')
|
||||||
s = {'desc' : 'SVG',
|
s = {'desc': 'SVG',
|
||||||
'procedure_fmt' : '%(geo_col)s,%(rel)s,%(precision)s',
|
'procedure_fmt': '%(geo_col)s,%(rel)s,%(precision)s',
|
||||||
'procedure_args' : {'rel' : relative,
|
'procedure_args': {'rel': relative,
|
||||||
'precision' : precision,
|
'precision': precision,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self._spatial_attribute('svg', s, **kwargs)
|
return self._spatial_attribute('svg', s, **kwargs)
|
||||||
|
@ -385,14 +385,14 @@ class GeoQuerySet(QuerySet):
|
||||||
if connections[self.db].ops.spatialite:
|
if connections[self.db].ops.spatialite:
|
||||||
if z != 0.0:
|
if z != 0.0:
|
||||||
raise NotImplementedError('SpatiaLite does not support 3D translation.')
|
raise NotImplementedError('SpatiaLite does not support 3D translation.')
|
||||||
s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s',
|
s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s',
|
||||||
'procedure_args' : {'x' : x, 'y' : y},
|
'procedure_args': {'x': x, 'y': y},
|
||||||
'select_field' : GeomField(),
|
'select_field': GeomField(),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
s = {'procedure_fmt' : '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
s = {'procedure_fmt': '%(geo_col)s,%(x)s,%(y)s,%(z)s',
|
||||||
'procedure_args' : {'x' : x, 'y' : y, 'z' : z},
|
'procedure_args': {'x': x, 'y': y, 'z': z},
|
||||||
'select_field' : GeomField(),
|
'select_field': GeomField(),
|
||||||
}
|
}
|
||||||
return self._spatial_attribute('translate', s, **kwargs)
|
return self._spatial_attribute('translate', s, **kwargs)
|
||||||
|
|
||||||
|
@ -455,7 +455,7 @@ class GeoQuerySet(QuerySet):
|
||||||
(desc, connection.ops.name))
|
(desc, connection.ops.name))
|
||||||
|
|
||||||
# Initializing the procedure arguments.
|
# Initializing the procedure arguments.
|
||||||
procedure_args = {'function' : func}
|
procedure_args = {'function': func}
|
||||||
|
|
||||||
# Is there a geographic field in the model to perform this
|
# Is there a geographic field in the model to perform this
|
||||||
# operation on?
|
# operation on?
|
||||||
|
@ -580,7 +580,7 @@ class GeoQuerySet(QuerySet):
|
||||||
# Finally, setting the extra selection attribute with
|
# Finally, setting the extra selection attribute with
|
||||||
# the format string expanded with the stored procedure
|
# the format string expanded with the stored procedure
|
||||||
# arguments.
|
# arguments.
|
||||||
return self.extra(select={model_att : fmt % settings['procedure_args']},
|
return self.extra(select={model_att: fmt % settings['procedure_args']},
|
||||||
select_params=settings['select_params'])
|
select_params=settings['select_params'])
|
||||||
|
|
||||||
def _distance_attribute(self, func, geom=None, tolerance=0.05, spheroid=False, **kwargs):
|
def _distance_attribute(self, func, geom=None, tolerance=0.05, spheroid=False, **kwargs):
|
||||||
|
@ -695,29 +695,29 @@ class GeoQuerySet(QuerySet):
|
||||||
if spheroid:
|
if spheroid:
|
||||||
# Call to distance_spheroid() requires spheroid param as well.
|
# Call to distance_spheroid() requires spheroid param as well.
|
||||||
procedure_fmt += ",'%(spheroid)s'"
|
procedure_fmt += ",'%(spheroid)s'"
|
||||||
procedure_args.update({'function' : backend.distance_spheroid, 'spheroid' : params[1]})
|
procedure_args.update({'function': backend.distance_spheroid, 'spheroid': params[1]})
|
||||||
else:
|
else:
|
||||||
procedure_args.update({'function' : backend.distance_sphere})
|
procedure_args.update({'function': backend.distance_sphere})
|
||||||
elif length or perimeter:
|
elif length or perimeter:
|
||||||
procedure_fmt = '%(geo_col)s'
|
procedure_fmt = '%(geo_col)s'
|
||||||
if not geography and geodetic and length:
|
if not geography and geodetic and length:
|
||||||
# There's no `length_sphere`, and `length_spheroid` also
|
# There's no `length_sphere`, and `length_spheroid` also
|
||||||
# works on 3D geometries.
|
# works on 3D geometries.
|
||||||
procedure_fmt += ",'%(spheroid)s'"
|
procedure_fmt += ",'%(spheroid)s'"
|
||||||
procedure_args.update({'function' : backend.length_spheroid, 'spheroid' : params[1]})
|
procedure_args.update({'function': backend.length_spheroid, 'spheroid': params[1]})
|
||||||
elif geom_3d and backend.postgis:
|
elif geom_3d and backend.postgis:
|
||||||
# Use 3D variants of perimeter and length routines on PostGIS.
|
# Use 3D variants of perimeter and length routines on PostGIS.
|
||||||
if perimeter:
|
if perimeter:
|
||||||
procedure_args.update({'function' : backend.perimeter3d})
|
procedure_args.update({'function': backend.perimeter3d})
|
||||||
elif length:
|
elif length:
|
||||||
procedure_args.update({'function' : backend.length3d})
|
procedure_args.update({'function': backend.length3d})
|
||||||
|
|
||||||
# Setting up the settings for `_spatial_attribute`.
|
# Setting up the settings for `_spatial_attribute`.
|
||||||
s = {'select_field' : DistanceField(dist_att),
|
s = {'select_field': DistanceField(dist_att),
|
||||||
'setup' : False,
|
'setup': False,
|
||||||
'geo_field' : geo_field,
|
'geo_field': geo_field,
|
||||||
'procedure_args' : procedure_args,
|
'procedure_args': procedure_args,
|
||||||
'procedure_fmt' : procedure_fmt,
|
'procedure_fmt': procedure_fmt,
|
||||||
}
|
}
|
||||||
if geom_args:
|
if geom_args:
|
||||||
s['geom_args'] = ('geom',)
|
s['geom_args'] = ('geom',)
|
||||||
|
@ -736,7 +736,7 @@ class GeoQuerySet(QuerySet):
|
||||||
s = {'select_field': GeomField()}
|
s = {'select_field': GeomField()}
|
||||||
if connections[self.db].ops.oracle:
|
if connections[self.db].ops.oracle:
|
||||||
s['procedure_fmt'] = '%(geo_col)s,%(tolerance)s'
|
s['procedure_fmt'] = '%(geo_col)s,%(tolerance)s'
|
||||||
s['procedure_args'] = {'tolerance' : tolerance}
|
s['procedure_args'] = {'tolerance': tolerance}
|
||||||
return self._spatial_attribute(func, s, **kwargs)
|
return self._spatial_attribute(func, s, **kwargs)
|
||||||
|
|
||||||
def _geomset_attribute(self, func, geom, tolerance=0.05, **kwargs):
|
def _geomset_attribute(self, func, geom, tolerance=0.05, **kwargs):
|
||||||
|
@ -746,10 +746,10 @@ class GeoQuerySet(QuerySet):
|
||||||
for geometry set-like operations (e.g., intersection, difference,
|
for geometry set-like operations (e.g., intersection, difference,
|
||||||
union, sym_difference).
|
union, sym_difference).
|
||||||
"""
|
"""
|
||||||
s = {'geom_args' : ('geom',),
|
s = {'geom_args': ('geom',),
|
||||||
'select_field' : GeomField(),
|
'select_field': GeomField(),
|
||||||
'procedure_fmt' : '%(geo_col)s,%(geom)s',
|
'procedure_fmt': '%(geo_col)s,%(geom)s',
|
||||||
'procedure_args' : {'geom' : geom},
|
'procedure_args': {'geom': geom},
|
||||||
}
|
}
|
||||||
if connections[self.db].ops.oracle:
|
if connections[self.db].ops.oracle:
|
||||||
s['procedure_fmt'] += ',%(tolerance)s'
|
s['procedure_fmt'] += ',%(tolerance)s'
|
||||||
|
|
|
@ -67,9 +67,9 @@ class GeoQuery(sql.Query):
|
||||||
elif isinstance(field, DistanceField):
|
elif isinstance(field, DistanceField):
|
||||||
# Using the field's distance attribute, can instantiate
|
# Using the field's distance attribute, can instantiate
|
||||||
# `Distance` with the right context.
|
# `Distance` with the right context.
|
||||||
value = Distance(**{field.distance_att : value})
|
value = Distance(**{field.distance_att: value})
|
||||||
elif isinstance(field, AreaField):
|
elif isinstance(field, AreaField):
|
||||||
value = Area(**{field.area_att : value})
|
value = Area(**{field.area_att: value})
|
||||||
elif isinstance(field, (GeomField, GeometryField)) and value:
|
elif isinstance(field, (GeomField, GeometryField)) and value:
|
||||||
value = Geometry(value)
|
value = Geometry(value)
|
||||||
elif field is not None:
|
elif field is not None:
|
||||||
|
|
|
@ -133,7 +133,7 @@ class Feed(BaseFeed):
|
||||||
feed_type = GeoRSSFeed
|
feed_type = GeoRSSFeed
|
||||||
|
|
||||||
def feed_extra_kwargs(self, obj):
|
def feed_extra_kwargs(self, obj):
|
||||||
return {'geometry' : self.__get_dynamic_attr('geometry', obj)}
|
return {'geometry': self.__get_dynamic_attr('geometry', obj)}
|
||||||
|
|
||||||
def item_extra_kwargs(self, item):
|
def item_extra_kwargs(self, item):
|
||||||
return {'geometry' : self.__get_dynamic_attr('item_geometry', item)}
|
return {'geometry': self.__get_dynamic_attr('item_geometry', item)}
|
||||||
|
|
|
@ -19,10 +19,10 @@ class GeometryField(forms.Field):
|
||||||
geom_type = 'GEOMETRY'
|
geom_type = 'GEOMETRY'
|
||||||
|
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
'required' : _('No geometry value provided.'),
|
'required': _('No geometry value provided.'),
|
||||||
'invalid_geom' : _('Invalid geometry value.'),
|
'invalid_geom': _('Invalid geometry value.'),
|
||||||
'invalid_geom_type' : _('Invalid geometry type.'),
|
'invalid_geom_type': _('Invalid geometry type.'),
|
||||||
'transform_error' : _('An error occurred when transforming the geometry '
|
'transform_error': _('An error occurred when transforming the geometry '
|
||||||
'to the SRID of the geometry form field.'),
|
'to the SRID of the geometry form field.'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ class Driver(GDALBase):
|
||||||
"Wraps an OGR Data Source Driver."
|
"Wraps an OGR Data Source Driver."
|
||||||
|
|
||||||
# Case-insensitive aliases for OGR Drivers.
|
# Case-insensitive aliases for OGR Drivers.
|
||||||
_alias = {'esri' : 'ESRI Shapefile',
|
_alias = {'esri': 'ESRI Shapefile',
|
||||||
'shp' : 'ESRI Shapefile',
|
'shp': 'ESRI Shapefile',
|
||||||
'shape' : 'ESRI Shapefile',
|
'shape': 'ESRI Shapefile',
|
||||||
'tiger' : 'TIGER',
|
'tiger': 'TIGER',
|
||||||
'tiger/line' : 'TIGER',
|
'tiger/line': 'TIGER',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, dr_input):
|
def __init__(self, dr_input):
|
||||||
|
|
|
@ -711,19 +711,19 @@ class MultiPolygon(GeometryCollection):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Class mapping dictionary (using the OGRwkbGeometryType as the key)
|
# Class mapping dictionary (using the OGRwkbGeometryType as the key)
|
||||||
GEO_CLASSES = {1 : Point,
|
GEO_CLASSES = {1: Point,
|
||||||
2 : LineString,
|
2: LineString,
|
||||||
3 : Polygon,
|
3: Polygon,
|
||||||
4 : MultiPoint,
|
4: MultiPoint,
|
||||||
5 : MultiLineString,
|
5: MultiLineString,
|
||||||
6 : MultiPolygon,
|
6: MultiPolygon,
|
||||||
7 : GeometryCollection,
|
7: GeometryCollection,
|
||||||
101: LinearRing,
|
101: LinearRing,
|
||||||
1 + OGRGeomType.wkb25bit : Point,
|
1 + OGRGeomType.wkb25bit: Point,
|
||||||
2 + OGRGeomType.wkb25bit : LineString,
|
2 + OGRGeomType.wkb25bit: LineString,
|
||||||
3 + OGRGeomType.wkb25bit : Polygon,
|
3 + OGRGeomType.wkb25bit: Polygon,
|
||||||
4 + OGRGeomType.wkb25bit : MultiPoint,
|
4 + OGRGeomType.wkb25bit: MultiPoint,
|
||||||
5 + OGRGeomType.wkb25bit : MultiLineString,
|
5 + OGRGeomType.wkb25bit: MultiLineString,
|
||||||
6 + OGRGeomType.wkb25bit : MultiPolygon,
|
6 + OGRGeomType.wkb25bit: MultiPolygon,
|
||||||
7 + OGRGeomType.wkb25bit : GeometryCollection,
|
7 + OGRGeomType.wkb25bit: GeometryCollection,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,23 +9,23 @@ class OGRGeomType(object):
|
||||||
wkb25bit = -2147483648
|
wkb25bit = -2147483648
|
||||||
|
|
||||||
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
|
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
|
||||||
_types = {0 : 'Unknown',
|
_types = {0: 'Unknown',
|
||||||
1 : 'Point',
|
1: 'Point',
|
||||||
2 : 'LineString',
|
2: 'LineString',
|
||||||
3 : 'Polygon',
|
3: 'Polygon',
|
||||||
4 : 'MultiPoint',
|
4: 'MultiPoint',
|
||||||
5 : 'MultiLineString',
|
5: 'MultiLineString',
|
||||||
6 : 'MultiPolygon',
|
6: 'MultiPolygon',
|
||||||
7 : 'GeometryCollection',
|
7: 'GeometryCollection',
|
||||||
100 : 'None',
|
100: 'None',
|
||||||
101 : 'LinearRing',
|
101: 'LinearRing',
|
||||||
1 + wkb25bit: 'Point25D',
|
1 + wkb25bit: 'Point25D',
|
||||||
2 + wkb25bit: 'LineString25D',
|
2 + wkb25bit: 'LineString25D',
|
||||||
3 + wkb25bit: 'Polygon25D',
|
3 + wkb25bit: 'Polygon25D',
|
||||||
4 + wkb25bit: 'MultiPoint25D',
|
4 + wkb25bit: 'MultiPoint25D',
|
||||||
5 + wkb25bit : 'MultiLineString25D',
|
5 + wkb25bit: 'MultiLineString25D',
|
||||||
6 + wkb25bit : 'MultiPolygon25D',
|
6 + wkb25bit: 'MultiPolygon25D',
|
||||||
7 + wkb25bit : 'GeometryCollection25D',
|
7 + wkb25bit: 'GeometryCollection25D',
|
||||||
}
|
}
|
||||||
# Reverse type dictionary, keyed by lower-case of the name.
|
# Reverse type dictionary, keyed by lower-case of the name.
|
||||||
_str_types = dict((v.lower(), k) for k, v in _types.items())
|
_str_types = dict((v.lower(), k) for k, v in _types.items())
|
||||||
|
|
|
@ -12,10 +12,10 @@ valid_drivers = ('ESRI Shapefile', 'MapInfo File', 'TIGER', 'S57', 'DGN',
|
||||||
|
|
||||||
invalid_drivers = ('Foo baz', 'clucka', 'ESRI Shp')
|
invalid_drivers = ('Foo baz', 'clucka', 'ESRI Shp')
|
||||||
|
|
||||||
aliases = {'eSrI' : 'ESRI Shapefile',
|
aliases = {'eSrI': 'ESRI Shapefile',
|
||||||
'TigER/linE' : 'TIGER',
|
'TigER/linE': 'TIGER',
|
||||||
'SHAPE' : 'ESRI Shapefile',
|
'SHAPE': 'ESRI Shapefile',
|
||||||
'sHp' : 'ESRI Shapefile',
|
'sHp': 'ESRI Shapefile',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -195,8 +195,8 @@ class GeoIP(object):
|
||||||
'24.124.1.80' and 'djangoproject.com' are valid parameters.
|
'24.124.1.80' and 'djangoproject.com' are valid parameters.
|
||||||
"""
|
"""
|
||||||
# Returning the country code and name
|
# Returning the country code and name
|
||||||
return {'country_code' : self.country_code(query),
|
return {'country_code': self.country_code(query),
|
||||||
'country_name' : self.country_name(query),
|
'country_name': self.country_name(query),
|
||||||
}
|
}
|
||||||
|
|
||||||
#### Coordinate retrieval routines ####
|
#### Coordinate retrieval routines ####
|
||||||
|
|
|
@ -80,7 +80,7 @@ class GeoIPTest(unittest.TestCase):
|
||||||
self.assertEqual('US', func(query))
|
self.assertEqual('US', func(query))
|
||||||
for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
|
for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
|
||||||
self.assertEqual('United States', func(query))
|
self.assertEqual('United States', func(query))
|
||||||
self.assertEqual({'country_code' : 'US', 'country_name' : 'United States'},
|
self.assertEqual({'country_code': 'US', 'country_name': 'United States'},
|
||||||
g.country(query))
|
g.country(query))
|
||||||
|
|
||||||
@skipUnless(HAS_GEOS, "Geos is required")
|
@skipUnless(HAS_GEOS, "Geos is required")
|
||||||
|
@ -96,7 +96,7 @@ class GeoIPTest(unittest.TestCase):
|
||||||
self.assertEqual('US', func(query))
|
self.assertEqual('US', func(query))
|
||||||
for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
|
for func in (g.country_name, g.country_name_by_addr, g.country_name_by_name):
|
||||||
self.assertEqual('United States', func(query))
|
self.assertEqual('United States', func(query))
|
||||||
self.assertEqual({'country_code' : 'US', 'country_name' : 'United States'},
|
self.assertEqual({'country_code': 'US', 'country_name': 'United States'},
|
||||||
g.country(query))
|
g.country(query))
|
||||||
|
|
||||||
# City information dictionary.
|
# City information dictionary.
|
||||||
|
|
|
@ -707,14 +707,14 @@ from django.contrib.gis.geos.linestring import LineString, LinearRing
|
||||||
from django.contrib.gis.geos.point import Point
|
from django.contrib.gis.geos.point import Point
|
||||||
from django.contrib.gis.geos.polygon import Polygon
|
from django.contrib.gis.geos.polygon import Polygon
|
||||||
from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
|
from django.contrib.gis.geos.collections import GeometryCollection, MultiPoint, MultiLineString, MultiPolygon
|
||||||
GEOS_CLASSES = {0 : Point,
|
GEOS_CLASSES = {0: Point,
|
||||||
1 : LineString,
|
1: LineString,
|
||||||
2 : LinearRing,
|
2: LinearRing,
|
||||||
3 : Polygon,
|
3: Polygon,
|
||||||
4 : MultiPoint,
|
4: MultiPoint,
|
||||||
5 : MultiLineString,
|
5: MultiLineString,
|
||||||
6 : MultiPolygon,
|
6: MultiPolygon,
|
||||||
7 : GeometryCollection,
|
7: GeometryCollection,
|
||||||
}
|
}
|
||||||
|
|
||||||
# If supported, import the PreparedGeometry class.
|
# If supported, import the PreparedGeometry class.
|
||||||
|
|
|
@ -239,7 +239,7 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
|
||||||
# an invalid type.
|
# an invalid type.
|
||||||
for g in (p, ls):
|
for g in (p, ls):
|
||||||
self.assertNotEqual(g, None)
|
self.assertNotEqual(g, None)
|
||||||
self.assertNotEqual(g, {'foo' : 'bar'})
|
self.assertNotEqual(g, {'foo': 'bar'})
|
||||||
self.assertNotEqual(g, False)
|
self.assertNotEqual(g, False)
|
||||||
|
|
||||||
def test_points(self):
|
def test_points(self):
|
||||||
|
|
|
@ -103,9 +103,9 @@ class Command(LabelCommand):
|
||||||
if show_mapping:
|
if show_mapping:
|
||||||
# Constructing the keyword arguments for `mapping`, and
|
# Constructing the keyword arguments for `mapping`, and
|
||||||
# calling it on the data source.
|
# calling it on the data source.
|
||||||
kwargs = {'geom_name' : options['geom_name'],
|
kwargs = {'geom_name': options['geom_name'],
|
||||||
'layer_key' : options['layer_key'],
|
'layer_key': options['layer_key'],
|
||||||
'multi_geom' : options['multi_geom'],
|
'multi_geom': options['multi_geom'],
|
||||||
}
|
}
|
||||||
mapping_dict = mapping(ds, **kwargs)
|
mapping_dict = mapping(ds, **kwargs)
|
||||||
# This extra legwork is so that the dictionary definition comes
|
# This extra legwork is so that the dictionary definition comes
|
||||||
|
|
|
@ -98,16 +98,16 @@ class GoogleMap(object):
|
||||||
"""
|
"""
|
||||||
Generates the JavaScript necessary for displaying this Google Map.
|
Generates the JavaScript necessary for displaying this Google Map.
|
||||||
"""
|
"""
|
||||||
params = {'calc_zoom' : self.calc_zoom,
|
params = {'calc_zoom': self.calc_zoom,
|
||||||
'center' : self.center,
|
'center': self.center,
|
||||||
'dom_id' : self.dom_id,
|
'dom_id': self.dom_id,
|
||||||
'js_module' : self.js_module,
|
'js_module': self.js_module,
|
||||||
'kml_urls' : self.kml_urls,
|
'kml_urls': self.kml_urls,
|
||||||
'zoom' : self.zoom,
|
'zoom': self.zoom,
|
||||||
'polygons' : self.polygons,
|
'polygons': self.polygons,
|
||||||
'polylines' : self.polylines,
|
'polylines': self.polylines,
|
||||||
'icons': self.icons,
|
'icons': self.icons,
|
||||||
'markers' : self.markers,
|
'markers': self.markers,
|
||||||
}
|
}
|
||||||
params.update(self.extra_context)
|
params.update(self.extra_context)
|
||||||
return render_to_string(self.template, params)
|
return render_to_string(self.template, params)
|
||||||
|
@ -211,10 +211,10 @@ class GoogleMapSet(GoogleMap):
|
||||||
Generates the JavaScript for the collection of Google Maps in
|
Generates the JavaScript for the collection of Google Maps in
|
||||||
this set.
|
this set.
|
||||||
"""
|
"""
|
||||||
params = {'js_module' : self.js_module,
|
params = {'js_module': self.js_module,
|
||||||
'dom_ids' : self.dom_ids,
|
'dom_ids': self.dom_ids,
|
||||||
'load_map_js' : self.load_map_js(),
|
'load_map_js': self.load_map_js(),
|
||||||
'icons' : self.icons,
|
'icons': self.icons,
|
||||||
}
|
}
|
||||||
params.update(self.extra_context)
|
params.update(self.extra_context)
|
||||||
return render_to_string(self.template, params)
|
return render_to_string(self.template, params)
|
||||||
|
|
|
@ -221,77 +221,77 @@ class MeasureBase(object):
|
||||||
class Distance(MeasureBase):
|
class Distance(MeasureBase):
|
||||||
STANDARD_UNIT = "m"
|
STANDARD_UNIT = "m"
|
||||||
UNITS = {
|
UNITS = {
|
||||||
'chain' : 20.1168,
|
'chain': 20.1168,
|
||||||
'chain_benoit' : 20.116782,
|
'chain_benoit': 20.116782,
|
||||||
'chain_sears' : 20.1167645,
|
'chain_sears': 20.1167645,
|
||||||
'british_chain_benoit' : 20.1167824944,
|
'british_chain_benoit': 20.1167824944,
|
||||||
'british_chain_sears' : 20.1167651216,
|
'british_chain_sears': 20.1167651216,
|
||||||
'british_chain_sears_truncated' : 20.116756,
|
'british_chain_sears_truncated': 20.116756,
|
||||||
'cm' : 0.01,
|
'cm': 0.01,
|
||||||
'british_ft' : 0.304799471539,
|
'british_ft': 0.304799471539,
|
||||||
'british_yd' : 0.914398414616,
|
'british_yd': 0.914398414616,
|
||||||
'clarke_ft' : 0.3047972654,
|
'clarke_ft': 0.3047972654,
|
||||||
'clarke_link' : 0.201166195164,
|
'clarke_link': 0.201166195164,
|
||||||
'fathom' : 1.8288,
|
'fathom': 1.8288,
|
||||||
'ft': 0.3048,
|
'ft': 0.3048,
|
||||||
'german_m' : 1.0000135965,
|
'german_m': 1.0000135965,
|
||||||
'gold_coast_ft' : 0.304799710181508,
|
'gold_coast_ft': 0.304799710181508,
|
||||||
'indian_yd' : 0.914398530744,
|
'indian_yd': 0.914398530744,
|
||||||
'inch' : 0.0254,
|
'inch': 0.0254,
|
||||||
'km': 1000.0,
|
'km': 1000.0,
|
||||||
'link' : 0.201168,
|
'link': 0.201168,
|
||||||
'link_benoit' : 0.20116782,
|
'link_benoit': 0.20116782,
|
||||||
'link_sears' : 0.20116765,
|
'link_sears': 0.20116765,
|
||||||
'm': 1.0,
|
'm': 1.0,
|
||||||
'mi': 1609.344,
|
'mi': 1609.344,
|
||||||
'mm' : 0.001,
|
'mm': 0.001,
|
||||||
'nm': 1852.0,
|
'nm': 1852.0,
|
||||||
'nm_uk' : 1853.184,
|
'nm_uk': 1853.184,
|
||||||
'rod' : 5.0292,
|
'rod': 5.0292,
|
||||||
'sears_yd' : 0.91439841,
|
'sears_yd': 0.91439841,
|
||||||
'survey_ft' : 0.304800609601,
|
'survey_ft': 0.304800609601,
|
||||||
'um' : 0.000001,
|
'um': 0.000001,
|
||||||
'yd': 0.9144,
|
'yd': 0.9144,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unit aliases for `UNIT` terms encountered in Spatial Reference WKT.
|
# Unit aliases for `UNIT` terms encountered in Spatial Reference WKT.
|
||||||
ALIAS = {
|
ALIAS = {
|
||||||
'centimeter' : 'cm',
|
'centimeter': 'cm',
|
||||||
'foot' : 'ft',
|
'foot': 'ft',
|
||||||
'inches' : 'inch',
|
'inches': 'inch',
|
||||||
'kilometer' : 'km',
|
'kilometer': 'km',
|
||||||
'kilometre' : 'km',
|
'kilometre': 'km',
|
||||||
'meter' : 'm',
|
'meter': 'm',
|
||||||
'metre' : 'm',
|
'metre': 'm',
|
||||||
'micrometer' : 'um',
|
'micrometer': 'um',
|
||||||
'micrometre' : 'um',
|
'micrometre': 'um',
|
||||||
'millimeter' : 'mm',
|
'millimeter': 'mm',
|
||||||
'millimetre' : 'mm',
|
'millimetre': 'mm',
|
||||||
'mile' : 'mi',
|
'mile': 'mi',
|
||||||
'yard' : 'yd',
|
'yard': 'yd',
|
||||||
'British chain (Benoit 1895 B)' : 'british_chain_benoit',
|
'British chain (Benoit 1895 B)': 'british_chain_benoit',
|
||||||
'British chain (Sears 1922)' : 'british_chain_sears',
|
'British chain (Sears 1922)': 'british_chain_sears',
|
||||||
'British chain (Sears 1922 truncated)' : 'british_chain_sears_truncated',
|
'British chain (Sears 1922 truncated)': 'british_chain_sears_truncated',
|
||||||
'British foot (Sears 1922)' : 'british_ft',
|
'British foot (Sears 1922)': 'british_ft',
|
||||||
'British foot' : 'british_ft',
|
'British foot': 'british_ft',
|
||||||
'British yard (Sears 1922)' : 'british_yd',
|
'British yard (Sears 1922)': 'british_yd',
|
||||||
'British yard' : 'british_yd',
|
'British yard': 'british_yd',
|
||||||
"Clarke's Foot" : 'clarke_ft',
|
"Clarke's Foot": 'clarke_ft',
|
||||||
"Clarke's link" : 'clarke_link',
|
"Clarke's link": 'clarke_link',
|
||||||
'Chain (Benoit)' : 'chain_benoit',
|
'Chain (Benoit)': 'chain_benoit',
|
||||||
'Chain (Sears)' : 'chain_sears',
|
'Chain (Sears)': 'chain_sears',
|
||||||
'Foot (International)' : 'ft',
|
'Foot (International)': 'ft',
|
||||||
'German legal metre' : 'german_m',
|
'German legal metre': 'german_m',
|
||||||
'Gold Coast foot' : 'gold_coast_ft',
|
'Gold Coast foot': 'gold_coast_ft',
|
||||||
'Indian yard' : 'indian_yd',
|
'Indian yard': 'indian_yd',
|
||||||
'Link (Benoit)': 'link_benoit',
|
'Link (Benoit)': 'link_benoit',
|
||||||
'Link (Sears)': 'link_sears',
|
'Link (Sears)': 'link_sears',
|
||||||
'Nautical Mile' : 'nm',
|
'Nautical Mile': 'nm',
|
||||||
'Nautical Mile (UK)' : 'nm_uk',
|
'Nautical Mile (UK)': 'nm_uk',
|
||||||
'US survey foot' : 'survey_ft',
|
'US survey foot': 'survey_ft',
|
||||||
'U.S. Foot' : 'survey_ft',
|
'U.S. Foot': 'survey_ft',
|
||||||
'Yard (Indian)' : 'indian_yd',
|
'Yard (Indian)': 'indian_yd',
|
||||||
'Yard (Sears)' : 'sears_yd'
|
'Yard (Sears)': 'sears_yd'
|
||||||
}
|
}
|
||||||
LALIAS = dict((k.lower(), v) for k, v in ALIAS.items())
|
LALIAS = dict((k.lower(), v) for k, v in ALIAS.items())
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ class KMLSitemap(Sitemap):
|
||||||
|
|
||||||
def location(self, obj):
|
def location(self, obj):
|
||||||
return urlresolvers.reverse('django.contrib.gis.sitemaps.views.%s' % self.geo_format,
|
return urlresolvers.reverse('django.contrib.gis.sitemaps.views.%s' % self.geo_format,
|
||||||
kwargs={'label' : obj[0],
|
kwargs={'label': obj[0],
|
||||||
'model' : obj[1],
|
'model': obj[1],
|
||||||
'field_name': obj[2],
|
'field_name': obj[2],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -106,7 +106,7 @@ def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB
|
||||||
render = render_to_kmz
|
render = render_to_kmz
|
||||||
else:
|
else:
|
||||||
render = render_to_kml
|
render = render_to_kml
|
||||||
return render('gis/kml/placemarks.kml', {'places' : placemarks})
|
return render('gis/kml/placemarks.kml', {'places': placemarks})
|
||||||
|
|
||||||
def kmz(request, label, model, field_name=None, using=DEFAULT_DB_ALIAS):
|
def kmz(request, label, model, field_name=None, using=DEFAULT_DB_ALIAS):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -46,10 +46,10 @@ city_dict = dict((name, coords) for name, coords in city_data)
|
||||||
interstate_data = (
|
interstate_data = (
|
||||||
('I-45',
|
('I-45',
|
||||||
'LINESTRING(-95.3708481 29.7765870 11.339,-95.3694580 29.7787980 4.536,-95.3690305 29.7797359 9.762,-95.3691886 29.7812450 12.448,-95.3696447 29.7850144 10.457,-95.3702511 29.7868518 9.418,-95.3706724 29.7881286 14.858,-95.3711632 29.7896157 15.386,-95.3714525 29.7936267 13.168,-95.3717848 29.7955007 15.104,-95.3717719 29.7969804 16.516,-95.3717305 29.7982117 13.923,-95.3717254 29.8000778 14.385,-95.3719875 29.8013539 15.160,-95.3720575 29.8026785 15.544,-95.3721321 29.8040912 14.975,-95.3722074 29.8050998 15.688,-95.3722779 29.8060430 16.099,-95.3733818 29.8076750 15.197,-95.3741563 29.8103686 17.268,-95.3749458 29.8129927 19.857,-95.3763564 29.8144557 15.435)',
|
'LINESTRING(-95.3708481 29.7765870 11.339,-95.3694580 29.7787980 4.536,-95.3690305 29.7797359 9.762,-95.3691886 29.7812450 12.448,-95.3696447 29.7850144 10.457,-95.3702511 29.7868518 9.418,-95.3706724 29.7881286 14.858,-95.3711632 29.7896157 15.386,-95.3714525 29.7936267 13.168,-95.3717848 29.7955007 15.104,-95.3717719 29.7969804 16.516,-95.3717305 29.7982117 13.923,-95.3717254 29.8000778 14.385,-95.3719875 29.8013539 15.160,-95.3720575 29.8026785 15.544,-95.3721321 29.8040912 14.975,-95.3722074 29.8050998 15.688,-95.3722779 29.8060430 16.099,-95.3733818 29.8076750 15.197,-95.3741563 29.8103686 17.268,-95.3749458 29.8129927 19.857,-95.3763564 29.8144557 15.435)',
|
||||||
(11.339, 4.536, 9.762, 12.448, 10.457, 9.418, 14.858,
|
(11.339, 4.536, 9.762, 12.448, 10.457, 9.418, 14.858,
|
||||||
15.386, 13.168, 15.104, 16.516, 13.923, 14.385, 15.16 ,
|
15.386, 13.168, 15.104, 16.516, 13.923, 14.385, 15.16,
|
||||||
15.544, 14.975, 15.688, 16.099, 15.197, 17.268, 19.857,
|
15.544, 14.975, 15.688, 16.099, 15.197, 17.268, 19.857,
|
||||||
15.435),
|
15.435),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -131,8 +131,8 @@ class Geo3DTest(TestCase):
|
||||||
"""
|
"""
|
||||||
Testing LayerMapping on 3D models.
|
Testing LayerMapping on 3D models.
|
||||||
"""
|
"""
|
||||||
point_mapping = {'point' : 'POINT'}
|
point_mapping = {'point': 'POINT'}
|
||||||
mpoint_mapping = {'mpoint' : 'MULTIPOINT'}
|
mpoint_mapping = {'mpoint': 'MULTIPOINT'}
|
||||||
|
|
||||||
# The VRT is 3D, but should still be able to map sans the Z.
|
# The VRT is 3D, but should still be able to map sans the Z.
|
||||||
lm = LayerMapping(Point2D, vrt_file, point_mapping, transform=False)
|
lm = LayerMapping(Point2D, vrt_file, point_mapping, transform=False)
|
||||||
|
|
|
@ -56,11 +56,11 @@ class TestW3CGeo3(TestGeoRSS1):
|
||||||
|
|
||||||
# The feed dictionary to use for URLs.
|
# The feed dictionary to use for URLs.
|
||||||
feed_dict = {
|
feed_dict = {
|
||||||
'rss1' : TestGeoRSS1,
|
'rss1': TestGeoRSS1,
|
||||||
'rss2' : TestGeoRSS2,
|
'rss2': TestGeoRSS2,
|
||||||
'atom1' : TestGeoAtom1,
|
'atom1': TestGeoAtom1,
|
||||||
'atom2' : TestGeoAtom2,
|
'atom2': TestGeoAtom2,
|
||||||
'w3cgeo1' : TestW3CGeo1,
|
'w3cgeo1': TestW3CGeo1,
|
||||||
'w3cgeo2' : TestW3CGeo2,
|
'w3cgeo2': TestW3CGeo2,
|
||||||
'w3cgeo3' : TestW3CGeo3,
|
'w3cgeo3': TestW3CGeo3,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ from .feeds import feed_dict
|
||||||
from .models import City, Country
|
from .models import City, Country
|
||||||
|
|
||||||
|
|
||||||
sitemaps = {'kml' : KMLSitemap([City, Country]),
|
sitemaps = {'kml': KMLSitemap([City, Country]),
|
||||||
'kmz' : KMZSitemap([City, Country]),
|
'kmz': KMZSitemap([City, Country]),
|
||||||
'georss' : GeoRSSSitemap(feed_dict),
|
'georss': GeoRSSSitemap(feed_dict),
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,11 @@ class GeoRegressionTests(TestCase):
|
||||||
def test_kmz(self):
|
def test_kmz(self):
|
||||||
"Testing `render_to_kmz` with non-ASCII data. See #11624."
|
"Testing `render_to_kmz` with non-ASCII data. See #11624."
|
||||||
name = "Åland Islands"
|
name = "Åland Islands"
|
||||||
places = [{'name' : name,
|
places = [{'name': name,
|
||||||
'description' : name,
|
'description': name,
|
||||||
'kml' : '<Point><coordinates>5.0,23.0</coordinates></Point>'
|
'kml': '<Point><coordinates>5.0,23.0</coordinates></Point>'
|
||||||
}]
|
}]
|
||||||
render_to_kmz('gis/kml/placemarks.kml', {'places' : places})
|
render_to_kmz('gis/kml/placemarks.kml', {'places': places})
|
||||||
|
|
||||||
@no_spatialite
|
@no_spatialite
|
||||||
@no_mysql
|
@no_mysql
|
||||||
|
|
|
@ -534,7 +534,7 @@ class GeoQuerySetTest(TestCase):
|
||||||
|
|
||||||
def test_gml(self):
|
def test_gml(self):
|
||||||
"Testing GML output from the database using GeoQuerySet.gml()."
|
"Testing GML output from the database using GeoQuerySet.gml()."
|
||||||
if mysql or (spatialite and not connection.ops.gml) :
|
if mysql or (spatialite and not connection.ops.gml):
|
||||||
self.assertRaises(NotImplementedError, Country.objects.all().gml, field_name='mpoly')
|
self.assertRaises(NotImplementedError, Country.objects.all().gml, field_name='mpoly')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -635,15 +635,15 @@ class GeoQuerySetTest(TestCase):
|
||||||
# Reference values.
|
# Reference values.
|
||||||
if oracle:
|
if oracle:
|
||||||
# SELECT SDO_UTIL.TO_WKTGEOMETRY(SDO_GEOM.SDO_POINTONSURFACE(GEOAPP_COUNTRY.MPOLY, 0.05)) FROM GEOAPP_COUNTRY;
|
# SELECT SDO_UTIL.TO_WKTGEOMETRY(SDO_GEOM.SDO_POINTONSURFACE(GEOAPP_COUNTRY.MPOLY, 0.05)) FROM GEOAPP_COUNTRY;
|
||||||
ref = {'New Zealand' : fromstr('POINT (174.616364 -36.100861)', srid=4326),
|
ref = {'New Zealand': fromstr('POINT (174.616364 -36.100861)', srid=4326),
|
||||||
'Texas' : fromstr('POINT (-103.002434 36.500397)', srid=4326),
|
'Texas': fromstr('POINT (-103.002434 36.500397)', srid=4326),
|
||||||
}
|
}
|
||||||
|
|
||||||
elif postgis or spatialite:
|
elif postgis or spatialite:
|
||||||
# Using GEOSGeometry to compute the reference point on surface values
|
# Using GEOSGeometry to compute the reference point on surface values
|
||||||
# -- since PostGIS also uses GEOS these should be the same.
|
# -- since PostGIS also uses GEOS these should be the same.
|
||||||
ref = {'New Zealand' : Country.objects.get(name='New Zealand').mpoly.point_on_surface,
|
ref = {'New Zealand': Country.objects.get(name='New Zealand').mpoly.point_on_surface,
|
||||||
'Texas' : Country.objects.get(name='Texas').mpoly.point_on_surface
|
'Texas': Country.objects.get(name='Texas').mpoly.point_on_surface
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in Country.objects.point_on_surface():
|
for c in Country.objects.point_on_surface():
|
||||||
|
|
|
@ -11,8 +11,8 @@ urlpatterns = patterns('',
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns += patterns('django.contrib.gis.sitemaps.views',
|
urlpatterns += patterns('django.contrib.gis.sitemaps.views',
|
||||||
(r'^sitemap.xml$', 'index', {'sitemaps' : sitemaps}),
|
(r'^sitemap.xml$', 'index', {'sitemaps': sitemaps}),
|
||||||
(r'^sitemaps/(?P<section>\w+)\.xml$', 'sitemap', {'sitemaps' : sitemaps}),
|
(r'^sitemaps/(?P<section>\w+)\.xml$', 'sitemap', {'sitemaps': sitemaps}),
|
||||||
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', 'kml'),
|
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', 'kml'),
|
||||||
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),
|
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -69,9 +69,9 @@ class GeographyTest(TestCase):
|
||||||
# Getting the shapefile and mapping dictionary.
|
# Getting the shapefile and mapping dictionary.
|
||||||
shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data'))
|
shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data'))
|
||||||
co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
|
co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
|
||||||
co_mapping = {'name' : 'Name',
|
co_mapping = {'name': 'Name',
|
||||||
'state' : 'State',
|
'state': 'State',
|
||||||
'mpoly' : 'MULTIPOLYGON',
|
'mpoly': 'MULTIPOLYGON',
|
||||||
}
|
}
|
||||||
|
|
||||||
# Reference county names, number of polygons, and state names.
|
# Reference county names, number of polygons, and state names.
|
||||||
|
|
|
@ -48,23 +48,23 @@ class Invalid(models.Model):
|
||||||
point = models.PointField()
|
point = models.PointField()
|
||||||
|
|
||||||
# Mapping dictionaries for the models above.
|
# Mapping dictionaries for the models above.
|
||||||
co_mapping = {'name' : 'Name',
|
co_mapping = {'name': 'Name',
|
||||||
'state' : {'name' : 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case).
|
'state': {'name': 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case).
|
||||||
'mpoly' : 'MULTIPOLYGON', # Will convert POLYGON features into MULTIPOLYGONS.
|
'mpoly': 'MULTIPOLYGON', # Will convert POLYGON features into MULTIPOLYGONS.
|
||||||
}
|
}
|
||||||
|
|
||||||
cofeat_mapping = {'name' : 'Name',
|
cofeat_mapping = {'name': 'Name',
|
||||||
'poly' : 'POLYGON',
|
'poly': 'POLYGON',
|
||||||
}
|
}
|
||||||
|
|
||||||
city_mapping = {'name' : 'Name',
|
city_mapping = {'name': 'Name',
|
||||||
'population' : 'Population',
|
'population': 'Population',
|
||||||
'density' : 'Density',
|
'density': 'Density',
|
||||||
'dt' : 'Created',
|
'dt': 'Created',
|
||||||
'point' : 'POINT',
|
'point': 'POINT',
|
||||||
}
|
}
|
||||||
|
|
||||||
inter_mapping = {'name' : 'Name',
|
inter_mapping = {'name': 'Name',
|
||||||
'length' : 'Length',
|
'length': 'Length',
|
||||||
'path' : 'LINESTRING',
|
'path': 'LINESTRING',
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ class LayerMapTest(TestCase):
|
||||||
bad_fk_map1 = copy(co_mapping)
|
bad_fk_map1 = copy(co_mapping)
|
||||||
bad_fk_map1['state'] = 'name'
|
bad_fk_map1['state'] = 'name'
|
||||||
bad_fk_map2 = copy(co_mapping)
|
bad_fk_map2 = copy(co_mapping)
|
||||||
bad_fk_map2['state'] = {'nombre' : 'State'}
|
bad_fk_map2['state'] = {'nombre': 'State'}
|
||||||
self.assertRaises(TypeError, LayerMapping, County, co_shp, bad_fk_map1, transform=False)
|
self.assertRaises(TypeError, LayerMapping, County, co_shp, bad_fk_map1, transform=False)
|
||||||
self.assertRaises(LayerMapError, LayerMapping, County, co_shp, bad_fk_map2, transform=False)
|
self.assertRaises(LayerMapError, LayerMapping, County, co_shp, bad_fk_map2, transform=False)
|
||||||
|
|
||||||
|
@ -262,11 +262,11 @@ class LayerMapTest(TestCase):
|
||||||
|
|
||||||
def test_model_inheritance(self):
|
def test_model_inheritance(self):
|
||||||
"Tests LayerMapping on inherited models. See #12093."
|
"Tests LayerMapping on inherited models. See #12093."
|
||||||
icity_mapping = {'name' : 'Name',
|
icity_mapping = {'name': 'Name',
|
||||||
'population' : 'Population',
|
'population': 'Population',
|
||||||
'density' : 'Density',
|
'density': 'Density',
|
||||||
'point' : 'POINT',
|
'point': 'POINT',
|
||||||
'dt' : 'Created',
|
'dt': 'Created',
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parent model has geometry field.
|
# Parent model has geometry field.
|
||||||
|
|
|
@ -6,29 +6,29 @@ from django.contrib.gis.tests.utils import (no_mysql, oracle, postgis,
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
test_srs = ({'srid' : 4326,
|
test_srs = ({'srid': 4326,
|
||||||
'auth_name' : ('EPSG', True),
|
'auth_name': ('EPSG', True),
|
||||||
'auth_srid' : 4326,
|
'auth_srid': 4326,
|
||||||
# Only the beginning, because there are differences depending on installed libs
|
# Only the beginning, because there are differences depending on installed libs
|
||||||
'srtext' : 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"',
|
'srtext': 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"',
|
||||||
# +ellps=WGS84 has been removed in the 4326 proj string in proj-4.8
|
# +ellps=WGS84 has been removed in the 4326 proj string in proj-4.8
|
||||||
'proj4_re' : r'\+proj=longlat (\+ellps=WGS84 )?\+datum=WGS84 \+no_defs ',
|
'proj4_re': r'\+proj=longlat (\+ellps=WGS84 )?\+datum=WGS84 \+no_defs ',
|
||||||
'spheroid' : 'WGS 84', 'name' : 'WGS 84',
|
'spheroid': 'WGS 84', 'name': 'WGS 84',
|
||||||
'geographic' : True, 'projected' : False, 'spatialite' : True,
|
'geographic': True, 'projected': False, 'spatialite': True,
|
||||||
'ellipsoid' : (6378137.0, 6356752.3, 298.257223563), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
|
'ellipsoid': (6378137.0, 6356752.3, 298.257223563), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
|
||||||
'eprec' : (1, 1, 9),
|
'eprec': (1, 1, 9),
|
||||||
},
|
},
|
||||||
{'srid' : 32140,
|
{'srid': 32140,
|
||||||
'auth_name' : ('EPSG', False),
|
'auth_name': ('EPSG', False),
|
||||||
'auth_srid' : 32140,
|
'auth_srid': 32140,
|
||||||
'srtext' : 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980"',
|
'srtext': 'PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980"',
|
||||||
'proj4_re' : r'\+proj=lcc \+lat_1=30.28333333333333 \+lat_2=28.38333333333333 \+lat_0=27.83333333333333 '
|
'proj4_re': r'\+proj=lcc \+lat_1=30.28333333333333 \+lat_2=28.38333333333333 \+lat_0=27.83333333333333 '
|
||||||
r'\+lon_0=-99 \+x_0=600000 \+y_0=4000000 (\+ellps=GRS80 )?'
|
r'\+lon_0=-99 \+x_0=600000 \+y_0=4000000 (\+ellps=GRS80 )?'
|
||||||
r'(\+datum=NAD83 |\+towgs84=0,0,0,0,0,0,0 )?\+units=m \+no_defs ',
|
r'(\+datum=NAD83 |\+towgs84=0,0,0,0,0,0,0 )?\+units=m \+no_defs ',
|
||||||
'spheroid' : 'GRS 1980', 'name' : 'NAD83 / Texas South Central',
|
'spheroid': 'GRS 1980', 'name': 'NAD83 / Texas South Central',
|
||||||
'geographic' : False, 'projected' : True, 'spatialite' : False,
|
'geographic': False, 'projected': True, 'spatialite': False,
|
||||||
'ellipsoid' : (6378137.0, 6356752.31414, 298.257222101), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
|
'ellipsoid': (6378137.0, 6356752.31414, 298.257222101), # From proj's "cs2cs -le" and Wikipedia (semi-minor only)
|
||||||
'eprec' : (1, 5, 10),
|
'eprec': (1, 5, 10),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -40,32 +40,32 @@ class LayerMapping(object):
|
||||||
"A class that maps OGR Layers to GeoDjango Models."
|
"A class that maps OGR Layers to GeoDjango Models."
|
||||||
|
|
||||||
# Acceptable 'base' types for a multi-geometry type.
|
# Acceptable 'base' types for a multi-geometry type.
|
||||||
MULTI_TYPES = {1 : OGRGeomType('MultiPoint'),
|
MULTI_TYPES = {1: OGRGeomType('MultiPoint'),
|
||||||
2 : OGRGeomType('MultiLineString'),
|
2: OGRGeomType('MultiLineString'),
|
||||||
3 : OGRGeomType('MultiPolygon'),
|
3: OGRGeomType('MultiPolygon'),
|
||||||
OGRGeomType('Point25D').num : OGRGeomType('MultiPoint25D'),
|
OGRGeomType('Point25D').num: OGRGeomType('MultiPoint25D'),
|
||||||
OGRGeomType('LineString25D').num : OGRGeomType('MultiLineString25D'),
|
OGRGeomType('LineString25D').num: OGRGeomType('MultiLineString25D'),
|
||||||
OGRGeomType('Polygon25D').num : OGRGeomType('MultiPolygon25D'),
|
OGRGeomType('Polygon25D').num: OGRGeomType('MultiPolygon25D'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Acceptable Django field types and corresponding acceptable OGR
|
# Acceptable Django field types and corresponding acceptable OGR
|
||||||
# counterparts.
|
# counterparts.
|
||||||
FIELD_TYPES = {
|
FIELD_TYPES = {
|
||||||
models.AutoField : OFTInteger,
|
models.AutoField: OFTInteger,
|
||||||
models.IntegerField : (OFTInteger, OFTReal, OFTString),
|
models.IntegerField: (OFTInteger, OFTReal, OFTString),
|
||||||
models.FloatField : (OFTInteger, OFTReal),
|
models.FloatField: (OFTInteger, OFTReal),
|
||||||
models.DateField : OFTDate,
|
models.DateField: OFTDate,
|
||||||
models.DateTimeField : OFTDateTime,
|
models.DateTimeField: OFTDateTime,
|
||||||
models.EmailField : OFTString,
|
models.EmailField: OFTString,
|
||||||
models.TimeField : OFTTime,
|
models.TimeField: OFTTime,
|
||||||
models.DecimalField : (OFTInteger, OFTReal),
|
models.DecimalField: (OFTInteger, OFTReal),
|
||||||
models.CharField : OFTString,
|
models.CharField: OFTString,
|
||||||
models.SlugField : OFTString,
|
models.SlugField: OFTString,
|
||||||
models.TextField : OFTString,
|
models.TextField: OFTString,
|
||||||
models.URLField : OFTString,
|
models.URLField: OFTString,
|
||||||
models.BigIntegerField : (OFTInteger, OFTReal, OFTString),
|
models.BigIntegerField: (OFTInteger, OFTReal, OFTString),
|
||||||
models.SmallIntegerField : (OFTInteger, OFTReal, OFTString),
|
models.SmallIntegerField: (OFTInteger, OFTReal, OFTString),
|
||||||
models.PositiveSmallIntegerField : (OFTInteger, OFTReal, OFTString),
|
models.PositiveSmallIntegerField: (OFTInteger, OFTReal, OFTString),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, model, data, mapping, layer=0,
|
def __init__(self, model, data, mapping, layer=0,
|
||||||
|
@ -322,7 +322,7 @@ class LayerMapping(object):
|
||||||
of the feature kwargs.
|
of the feature kwargs.
|
||||||
"""
|
"""
|
||||||
if isinstance(self.unique, six.string_types):
|
if isinstance(self.unique, six.string_types):
|
||||||
return {self.unique : kwargs[self.unique]}
|
return {self.unique: kwargs[self.unique]}
|
||||||
else:
|
else:
|
||||||
return dict((fld, kwargs[fld]) for fld in self.unique)
|
return dict((fld, kwargs[fld]) for fld in self.unique)
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,10 @@ def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
|
||||||
|
|
||||||
# Initializing the keyword arguments dictionary for both PostGIS
|
# Initializing the keyword arguments dictionary for both PostGIS
|
||||||
# and SpatiaLite.
|
# and SpatiaLite.
|
||||||
kwargs = {'srid' : srs.srid,
|
kwargs = {'srid': srs.srid,
|
||||||
'auth_name' : auth_name,
|
'auth_name': auth_name,
|
||||||
'auth_srid' : auth_srid or srs.srid,
|
'auth_srid': auth_srid or srs.srid,
|
||||||
'proj4text' : srs.proj4,
|
'proj4text': srs.proj4,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Backend-specific fields for the SpatialRefSys model.
|
# Backend-specific fields for the SpatialRefSys model.
|
||||||
|
|
|
@ -11,7 +11,7 @@ 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):
|
||||||
# The default settings set SITE_ID = 1, and some tests in Django's test
|
# The default settings set SITE_ID = 1, and some tests in Django's test
|
||||||
# suite rely on this value. However, if database sequences are reused
|
# suite rely on this value. However, if database sequences are reused
|
||||||
# (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
|
# (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
|
||||||
|
|
|
@ -10,8 +10,8 @@ Usage::
|
||||||
To add your own serializers, use the SERIALIZATION_MODULES setting::
|
To add your own serializers, use the SERIALIZATION_MODULES setting::
|
||||||
|
|
||||||
SERIALIZATION_MODULES = {
|
SERIALIZATION_MODULES = {
|
||||||
"csv" : "path.to.csv.serializer",
|
"csv": "path.to.csv.serializer",
|
||||||
"txt" : "path.to.txt.serializer",
|
"txt": "path.to.txt.serializer",
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -24,10 +24,10 @@ from django.core.serializers.base import SerializerDoesNotExist
|
||||||
|
|
||||||
# Built-in serializers
|
# Built-in serializers
|
||||||
BUILTIN_SERIALIZERS = {
|
BUILTIN_SERIALIZERS = {
|
||||||
"xml" : "django.core.serializers.xml_serializer",
|
"xml": "django.core.serializers.xml_serializer",
|
||||||
"python" : "django.core.serializers.python",
|
"python": "django.core.serializers.python",
|
||||||
"json" : "django.core.serializers.json",
|
"json": "django.core.serializers.json",
|
||||||
"yaml" : "django.core.serializers.pyyaml",
|
"yaml": "django.core.serializers.pyyaml",
|
||||||
}
|
}
|
||||||
|
|
||||||
_serializers = {}
|
_serializers = {}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Serializer(base.Serializer):
|
||||||
"""
|
"""
|
||||||
self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
|
self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
|
||||||
self.xml.startDocument()
|
self.xml.startDocument()
|
||||||
self.xml.startElement("django-objects", {"version" : "1.0"})
|
self.xml.startElement("django-objects", {"version": "1.0"})
|
||||||
|
|
||||||
def end_serialization(self):
|
def end_serialization(self):
|
||||||
"""
|
"""
|
||||||
|
@ -68,8 +68,8 @@ class Serializer(base.Serializer):
|
||||||
"""
|
"""
|
||||||
self.indent(2)
|
self.indent(2)
|
||||||
self.xml.startElement("field", {
|
self.xml.startElement("field", {
|
||||||
"name" : field.name,
|
"name": field.name,
|
||||||
"type" : field.get_internal_type()
|
"type": field.get_internal_type()
|
||||||
})
|
})
|
||||||
|
|
||||||
# Get a "string version" of the object's data.
|
# Get a "string version" of the object's data.
|
||||||
|
@ -125,7 +125,7 @@ class Serializer(base.Serializer):
|
||||||
else:
|
else:
|
||||||
def handle_m2m(value):
|
def handle_m2m(value):
|
||||||
self.xml.addQuickElement("object", attrs={
|
self.xml.addQuickElement("object", attrs={
|
||||||
'pk' : smart_text(value._get_pk_val())
|
'pk': smart_text(value._get_pk_val())
|
||||||
})
|
})
|
||||||
for relobj in getattr(obj, field.name).iterator():
|
for relobj in getattr(obj, field.name).iterator():
|
||||||
handle_m2m(relobj)
|
handle_m2m(relobj)
|
||||||
|
@ -138,9 +138,9 @@ class Serializer(base.Serializer):
|
||||||
"""
|
"""
|
||||||
self.indent(2)
|
self.indent(2)
|
||||||
self.xml.startElement("field", {
|
self.xml.startElement("field", {
|
||||||
"name" : field.name,
|
"name": field.name,
|
||||||
"rel" : field.rel.__class__.__name__,
|
"rel": field.rel.__class__.__name__,
|
||||||
"to" : smart_text(field.rel.to._meta),
|
"to": smart_text(field.rel.to._meta),
|
||||||
})
|
})
|
||||||
|
|
||||||
class Deserializer(base.Deserializer):
|
class Deserializer(base.Deserializer):
|
||||||
|
|
|
@ -331,7 +331,7 @@ class RegexURLResolver(LocaleRegexProvider):
|
||||||
return ResolverMatch(sub_match.func, sub_match.args, sub_match_dict, sub_match.url_name, self.app_name or sub_match.app_name, [self.namespace] + sub_match.namespaces)
|
return ResolverMatch(sub_match.func, sub_match.args, sub_match_dict, sub_match.url_name, self.app_name or sub_match.app_name, [self.namespace] + sub_match.namespaces)
|
||||||
tried.append([pattern])
|
tried.append([pattern])
|
||||||
raise Resolver404({'tried': tried, 'path': new_path})
|
raise Resolver404({'tried': tried, 'path': new_path})
|
||||||
raise Resolver404({'path' : path})
|
raise Resolver404({'path': path})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def urlconf_module(self):
|
def urlconf_module(self):
|
||||||
|
|
|
@ -423,8 +423,8 @@ def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False,
|
||||||
attrs = {'form': form, 'extra': extra,
|
attrs = {'form': form, 'extra': extra,
|
||||||
'can_order': can_order, 'can_delete': can_delete,
|
'can_order': can_order, 'can_delete': can_delete,
|
||||||
'min_num': min_num, 'max_num': max_num,
|
'min_num': min_num, 'max_num': max_num,
|
||||||
'absolute_max': absolute_max, 'validate_min' : validate_min,
|
'absolute_max': absolute_max, 'validate_min': validate_min,
|
||||||
'validate_max' : validate_max}
|
'validate_max': validate_max}
|
||||||
return type(form.__name__ + str('FormSet'), (formset,), attrs)
|
return type(form.__name__ + str('FormSet'), (formset,), attrs)
|
||||||
|
|
||||||
def all_valid(formsets):
|
def all_valid(formsets):
|
||||||
|
|
|
@ -149,7 +149,7 @@ class RootElement(Element):
|
||||||
|
|
||||||
|
|
||||||
class Parser(HTMLParser):
|
class Parser(HTMLParser):
|
||||||
SELF_CLOSING_TAGS = ('br' , 'hr', 'input', 'img', 'meta', 'spacer',
|
SELF_CLOSING_TAGS = ('br', 'hr', 'input', 'img', 'meta', 'spacer',
|
||||||
'link', 'frame', 'base', 'col')
|
'link', 'frame', 'base', 'col')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -665,7 +665,7 @@ def parse_accept_lang_header(lang_string):
|
||||||
if pieces[-1]:
|
if pieces[-1]:
|
||||||
return []
|
return []
|
||||||
for i in range(0, len(pieces) - 1, 3):
|
for i in range(0, len(pieces) - 1, 3):
|
||||||
first, lang, priority = pieces[i : i + 3]
|
first, lang, priority = pieces[i:i + 3]
|
||||||
if first:
|
if first:
|
||||||
return []
|
return []
|
||||||
if priority:
|
if priority:
|
||||||
|
|
|
@ -303,7 +303,7 @@ class ExceptionReporter(object):
|
||||||
'sys_version_info': '%d.%d.%d' % sys.version_info[0:3],
|
'sys_version_info': '%d.%d.%d' % sys.version_info[0:3],
|
||||||
'server_time': datetime.datetime.now(),
|
'server_time': datetime.datetime.now(),
|
||||||
'django_version_info': get_version(),
|
'django_version_info': get_version(),
|
||||||
'sys_path' : sys.path,
|
'sys_path': sys.path,
|
||||||
'template_info': self.template_info,
|
'template_info': self.template_info,
|
||||||
'template_does_not_exist': self.template_does_not_exist,
|
'template_does_not_exist': self.template_does_not_exist,
|
||||||
'loader_debug_info': self.loader_debug_info,
|
'loader_debug_info': self.loader_debug_info,
|
||||||
|
@ -592,7 +592,7 @@ TECHNICAL_500_TEMPLATE = """
|
||||||
for (var i = 0; i < arguments.length; i++) {
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
var e = document.getElementById(arguments[i]);
|
var e = document.getElementById(arguments[i]);
|
||||||
if (e) {
|
if (e) {
|
||||||
e.style.display = e.style.display == 'none' ? 'block' : 'none';
|
e.style.display = e.style.display == 'none' ? 'block': 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -608,7 +608,7 @@ TECHNICAL_500_TEMPLATE = """
|
||||||
function switchPastebinFriendly(link) {
|
function switchPastebinFriendly(link) {
|
||||||
s1 = "Switch to copy-and-paste view";
|
s1 = "Switch to copy-and-paste view";
|
||||||
s2 = "Switch back to interactive view";
|
s2 = "Switch back to interactive view";
|
||||||
link.innerHTML = link.innerHTML == s1 ? s2 : s1;
|
link.innerHTML = link.innerHTML == s1 ? s2: s1;
|
||||||
toggle('browserTraceback', 'pastebinTraceback');
|
toggle('browserTraceback', 'pastebinTraceback');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ def serve(request, path, document_root=None, show_indexes=False):
|
||||||
|
|
||||||
To use, put a URL pattern such as::
|
To use, put a URL pattern such as::
|
||||||
|
|
||||||
(r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root' : '/path/to/my/files/'})
|
(r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/path/to/my/files/'})
|
||||||
|
|
||||||
in your URLconf. You must provide the ``document_root`` param. You may
|
in your URLconf. You must provide the ``document_root`` param. You may
|
||||||
also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
|
also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
|
||||||
|
@ -108,8 +108,8 @@ def directory_index(path, fullpath):
|
||||||
f += '/'
|
f += '/'
|
||||||
files.append(f)
|
files.append(f)
|
||||||
c = Context({
|
c = Context({
|
||||||
'directory' : path + '/',
|
'directory': path + '/',
|
||||||
'file_list' : files,
|
'file_list': files,
|
||||||
})
|
})
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ ROLES = (
|
||||||
'func',
|
'func',
|
||||||
'lookup',
|
'lookup',
|
||||||
'meth',
|
'meth',
|
||||||
'mod' ,
|
'mod',
|
||||||
"djadminopt",
|
"djadminopt",
|
||||||
"ref",
|
"ref",
|
||||||
"setting",
|
"setting",
|
||||||
|
|
|
@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py
|
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py
|
||||||
ignore=E124,E125,E127,E128,E226,E241,E251,E302,E501,E203,E261,F401,F403,W601
|
ignore=E124,E125,E127,E128,E226,E241,E251,E302,E501,E261,F401,F403,W601
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
license-file = LICENSE
|
license-file = LICENSE
|
||||||
|
|
|
@ -45,7 +45,7 @@ callable_year.admin_order_field = 'date'
|
||||||
class ArticleInline(admin.TabularInline):
|
class ArticleInline(admin.TabularInline):
|
||||||
model = Article
|
model = Article
|
||||||
prepopulated_fields = {
|
prepopulated_fields = {
|
||||||
'title' : ('content',)
|
'title': ('content',)
|
||||||
}
|
}
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
('Some fields', {
|
('Some fields', {
|
||||||
|
@ -382,7 +382,7 @@ class SubPostInline(admin.TabularInline):
|
||||||
model = PrePopulatedSubPost
|
model = PrePopulatedSubPost
|
||||||
|
|
||||||
prepopulated_fields = {
|
prepopulated_fields = {
|
||||||
'subslug' : ('subtitle',)
|
'subslug': ('subtitle',)
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_readonly_fields(self, request, obj=None):
|
def get_readonly_fields(self, request, obj=None):
|
||||||
|
@ -399,7 +399,7 @@ class SubPostInline(admin.TabularInline):
|
||||||
class PrePopulatedPostAdmin(admin.ModelAdmin):
|
class PrePopulatedPostAdmin(admin.ModelAdmin):
|
||||||
list_display = ['title', 'slug']
|
list_display = ['title', 'slug']
|
||||||
prepopulated_fields = {
|
prepopulated_fields = {
|
||||||
'slug' : ('title',)
|
'slug': ('title',)
|
||||||
}
|
}
|
||||||
|
|
||||||
inlines = [SubPostInline]
|
inlines = [SubPostInline]
|
||||||
|
@ -569,7 +569,7 @@ class AlbumAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
class PrePopulatedPostLargeSlugAdmin(admin.ModelAdmin):
|
class PrePopulatedPostLargeSlugAdmin(admin.ModelAdmin):
|
||||||
prepopulated_fields = {
|
prepopulated_fields = {
|
||||||
'slug' : ('title',)
|
'slug': ('title',)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ class AggregationTests(TestCase):
|
||||||
|
|
||||||
# Aggregate overrides extra selected column
|
# Aggregate overrides extra selected column
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
Book.objects.extra(select={'price_per_page' : 'price / pages'}).aggregate(Sum('pages')),
|
Book.objects.extra(select={'price_per_page': 'price / pages'}).aggregate(Sum('pages')),
|
||||||
{'pages__sum': 3703}
|
{'pages__sum': 3703}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class AggregationTests(TestCase):
|
||||||
self.assertTrue(obj.manufacture_cost == 11.545 or obj.manufacture_cost == Decimal('11.545'))
|
self.assertTrue(obj.manufacture_cost == 11.545 or obj.manufacture_cost == Decimal('11.545'))
|
||||||
|
|
||||||
# Order of the annotate/extra in the query doesn't matter
|
# Order of the annotate/extra in the query doesn't matter
|
||||||
obj = Book.objects.extra(select={'manufacture_cost' : 'price * .5'}).annotate(mean_auth_age=Avg('authors__age')).get(pk=2)
|
obj = Book.objects.extra(select={'manufacture_cost': 'price * .5'}).annotate(mean_auth_age=Avg('authors__age')).get(pk=2)
|
||||||
self.assertObjectAttrs(obj,
|
self.assertObjectAttrs(obj,
|
||||||
contact_id=3,
|
contact_id=3,
|
||||||
id=2,
|
id=2,
|
||||||
|
@ -153,7 +153,7 @@ class AggregationTests(TestCase):
|
||||||
self.assertTrue(obj.manufacture_cost == 11.545 or obj.manufacture_cost == Decimal('11.545'))
|
self.assertTrue(obj.manufacture_cost == 11.545 or obj.manufacture_cost == Decimal('11.545'))
|
||||||
|
|
||||||
# Values queries can be combined with annotate and extra
|
# Values queries can be combined with annotate and extra
|
||||||
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost' : 'price * .5'}).values().get(pk=2)
|
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost': 'price * .5'}).values().get(pk=2)
|
||||||
manufacture_cost = obj['manufacture_cost']
|
manufacture_cost = obj['manufacture_cost']
|
||||||
self.assertTrue(manufacture_cost == 11.545 or manufacture_cost == Decimal('11.545'))
|
self.assertTrue(manufacture_cost == 11.545 or manufacture_cost == Decimal('11.545'))
|
||||||
del obj['manufacture_cost']
|
del obj['manufacture_cost']
|
||||||
|
@ -172,7 +172,7 @@ class AggregationTests(TestCase):
|
||||||
|
|
||||||
# The order of the (empty) values, annotate and extra clauses doesn't
|
# The order of the (empty) values, annotate and extra clauses doesn't
|
||||||
# matter
|
# matter
|
||||||
obj = Book.objects.values().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost' : 'price * .5'}).get(pk=2)
|
obj = Book.objects.values().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost': 'price * .5'}).get(pk=2)
|
||||||
manufacture_cost = obj['manufacture_cost']
|
manufacture_cost = obj['manufacture_cost']
|
||||||
self.assertTrue(manufacture_cost == 11.545 or manufacture_cost == Decimal('11.545'))
|
self.assertTrue(manufacture_cost == 11.545 or manufacture_cost == Decimal('11.545'))
|
||||||
del obj['manufacture_cost']
|
del obj['manufacture_cost']
|
||||||
|
@ -191,12 +191,12 @@ class AggregationTests(TestCase):
|
||||||
|
|
||||||
# If the annotation precedes the values clause, it won't be included
|
# If the annotation precedes the values clause, it won't be included
|
||||||
# unless it is explicitly named
|
# unless it is explicitly named
|
||||||
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page' : 'price / pages'}).values('name').get(pk=1)
|
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page': 'price / pages'}).values('name').get(pk=1)
|
||||||
self.assertEqual(obj, {
|
self.assertEqual(obj, {
|
||||||
"name": 'The Definitive Guide to Django: Web Development Done Right',
|
"name": 'The Definitive Guide to Django: Web Development Done Right',
|
||||||
})
|
})
|
||||||
|
|
||||||
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page' : 'price / pages'}).values('name', 'mean_auth_age').get(pk=1)
|
obj = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page': 'price / pages'}).values('name', 'mean_auth_age').get(pk=1)
|
||||||
self.assertEqual(obj, {
|
self.assertEqual(obj, {
|
||||||
'mean_auth_age': 34.5,
|
'mean_auth_age': 34.5,
|
||||||
'name': 'The Definitive Guide to Django: Web Development Done Right',
|
'name': 'The Definitive Guide to Django: Web Development Done Right',
|
||||||
|
@ -214,7 +214,7 @@ class AggregationTests(TestCase):
|
||||||
|
|
||||||
# The annotations are added to values output if values() precedes
|
# The annotations are added to values output if values() precedes
|
||||||
# annotate()
|
# annotate()
|
||||||
obj = Book.objects.values('name').annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page' : 'price / pages'}).get(pk=1)
|
obj = Book.objects.values('name').annotate(mean_auth_age=Avg('authors__age')).extra(select={'price_per_page': 'price / pages'}).get(pk=1)
|
||||||
self.assertEqual(obj, {
|
self.assertEqual(obj, {
|
||||||
'mean_auth_age': 34.5,
|
'mean_auth_age': 34.5,
|
||||||
'name': 'The Definitive Guide to Django: Web Development Done Right',
|
'name': 'The Definitive Guide to Django: Web Development Done Right',
|
||||||
|
@ -575,7 +575,7 @@ class AggregationTests(TestCase):
|
||||||
|
|
||||||
# Regression for #10290 - extra selects with parameters can be used for
|
# Regression for #10290 - extra selects with parameters can be used for
|
||||||
# grouping.
|
# grouping.
|
||||||
qs = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'sheets' : '(pages + %s) / %s'}, select_params=[1, 2]).order_by('sheets').values('sheets')
|
qs = Book.objects.annotate(mean_auth_age=Avg('authors__age')).extra(select={'sheets': '(pages + %s) / %s'}, select_params=[1, 2]).order_by('sheets').values('sheets')
|
||||||
self.assertQuerysetEqual(
|
self.assertQuerysetEqual(
|
||||||
qs, [
|
qs, [
|
||||||
150,
|
150,
|
||||||
|
|
|
@ -119,13 +119,13 @@ class DummyCacheTests(unittest.TestCase):
|
||||||
def test_data_types(self):
|
def test_data_types(self):
|
||||||
"All data types are ignored equally by the dummy cache"
|
"All data types are ignored equally by the dummy cache"
|
||||||
stuff = {
|
stuff = {
|
||||||
'string' : 'this is a string',
|
'string': 'this is a string',
|
||||||
'int' : 42,
|
'int': 42,
|
||||||
'list' : [1, 2, 3, 4],
|
'list': [1, 2, 3, 4],
|
||||||
'tuple' : (1, 2, 3, 4),
|
'tuple': (1, 2, 3, 4),
|
||||||
'dict' : {'A': 1, 'B' : 2},
|
'dict': {'A': 1, 'B': 2},
|
||||||
'function' : f,
|
'function': f,
|
||||||
'class' : C,
|
'class': C,
|
||||||
}
|
}
|
||||||
self.cache.set("stuff", stuff)
|
self.cache.set("stuff", stuff)
|
||||||
self.assertEqual(self.cache.get("stuff"), None)
|
self.assertEqual(self.cache.get("stuff"), None)
|
||||||
|
@ -149,7 +149,7 @@ class DummyCacheTests(unittest.TestCase):
|
||||||
'ascii': 'ascii_value',
|
'ascii': 'ascii_value',
|
||||||
'unicode_ascii': 'Iñtërnâtiônàlizætiøn1',
|
'unicode_ascii': 'Iñtërnâtiônàlizætiøn1',
|
||||||
'Iñtërnâtiônàlizætiøn': 'Iñtërnâtiônàlizætiøn2',
|
'Iñtërnâtiônàlizætiøn': 'Iñtërnâtiônàlizætiøn2',
|
||||||
'ascii2': {'x' : 1}
|
'ascii2': {'x': 1}
|
||||||
}
|
}
|
||||||
for (key, value) in stuff.items():
|
for (key, value) in stuff.items():
|
||||||
self.cache.set(key, value)
|
self.cache.set(key, value)
|
||||||
|
@ -231,8 +231,8 @@ class BaseCacheTests(object):
|
||||||
self.cache.set('b', 'b')
|
self.cache.set('b', 'b')
|
||||||
self.cache.set('c', 'c')
|
self.cache.set('c', 'c')
|
||||||
self.cache.set('d', 'd')
|
self.cache.set('d', 'd')
|
||||||
self.assertEqual(self.cache.get_many(['a', 'c', 'd']), {'a' : 'a', 'c' : 'c', 'd' : 'd'})
|
self.assertEqual(self.cache.get_many(['a', 'c', 'd']), {'a': 'a', 'c': 'c', 'd': 'd'})
|
||||||
self.assertEqual(self.cache.get_many(['a', 'b', 'e']), {'a' : 'a', 'b' : 'b'})
|
self.assertEqual(self.cache.get_many(['a', 'b', 'e']), {'a': 'a', 'b': 'b'})
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
# Cache keys can be deleted
|
# Cache keys can be deleted
|
||||||
|
@ -282,13 +282,13 @@ class BaseCacheTests(object):
|
||||||
def test_data_types(self):
|
def test_data_types(self):
|
||||||
# Many different data types can be cached
|
# Many different data types can be cached
|
||||||
stuff = {
|
stuff = {
|
||||||
'string' : 'this is a string',
|
'string': 'this is a string',
|
||||||
'int' : 42,
|
'int': 42,
|
||||||
'list' : [1, 2, 3, 4],
|
'list': [1, 2, 3, 4],
|
||||||
'tuple' : (1, 2, 3, 4),
|
'tuple': (1, 2, 3, 4),
|
||||||
'dict' : {'A': 1, 'B' : 2},
|
'dict': {'A': 1, 'B': 2},
|
||||||
'function' : f,
|
'function': f,
|
||||||
'class' : C,
|
'class': C,
|
||||||
}
|
}
|
||||||
self.cache.set("stuff", stuff)
|
self.cache.set("stuff", stuff)
|
||||||
self.assertEqual(self.cache.get("stuff"), stuff)
|
self.assertEqual(self.cache.get("stuff"), stuff)
|
||||||
|
@ -353,7 +353,7 @@ class BaseCacheTests(object):
|
||||||
'ascii': 'ascii_value',
|
'ascii': 'ascii_value',
|
||||||
'unicode_ascii': 'Iñtërnâtiônàlizætiøn1',
|
'unicode_ascii': 'Iñtërnâtiônàlizætiøn1',
|
||||||
'Iñtërnâtiônàlizætiøn': 'Iñtërnâtiônàlizætiøn2',
|
'Iñtërnâtiônàlizætiøn': 'Iñtërnâtiônàlizætiøn2',
|
||||||
'ascii2': {'x' : 1}
|
'ascii2': {'x': 1}
|
||||||
}
|
}
|
||||||
# Test `set`
|
# Test `set`
|
||||||
for (key, value) in stuff.items():
|
for (key, value) in stuff.items():
|
||||||
|
@ -1221,16 +1221,16 @@ class CacheUtils(TestCase):
|
||||||
def test_patch_cache_control(self):
|
def test_patch_cache_control(self):
|
||||||
tests = (
|
tests = (
|
||||||
# Initial Cache-Control, kwargs to patch_cache_control, expected Cache-Control parts
|
# Initial Cache-Control, kwargs to patch_cache_control, expected Cache-Control parts
|
||||||
(None, {'private' : True}, set(['private'])),
|
(None, {'private': True}, set(['private'])),
|
||||||
|
|
||||||
# Test whether private/public attributes are mutually exclusive
|
# Test whether private/public attributes are mutually exclusive
|
||||||
('private', {'private' : True}, set(['private'])),
|
('private', {'private': True}, set(['private'])),
|
||||||
('private', {'public' : True}, set(['public'])),
|
('private', {'public': True}, set(['public'])),
|
||||||
('public', {'public' : True}, set(['public'])),
|
('public', {'public': True}, set(['public'])),
|
||||||
('public', {'private' : True}, set(['private'])),
|
('public', {'private': True}, set(['private'])),
|
||||||
('must-revalidate,max-age=60,private', {'public' : True}, set(['must-revalidate', 'max-age=60', 'public'])),
|
('must-revalidate,max-age=60,private', {'public': True}, set(['must-revalidate', 'max-age=60', 'public'])),
|
||||||
('must-revalidate,max-age=60,public', {'private' : True}, set(['must-revalidate', 'max-age=60', 'private'])),
|
('must-revalidate,max-age=60,public', {'private': True}, set(['must-revalidate', 'max-age=60', 'private'])),
|
||||||
('must-revalidate,max-age=60', {'public' : True}, set(['must-revalidate', 'max-age=60', 'public'])),
|
('must-revalidate,max-age=60', {'public': True}, set(['must-revalidate', 'max-age=60', 'public'])),
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_delim_re = re.compile(r'\s*,\s*')
|
cc_delim_re = re.compile(r'\s*,\s*')
|
||||||
|
|
|
@ -1793,17 +1793,17 @@ class FormsTestCase(TestCase):
|
||||||
class NameForm(Form):
|
class NameForm(Form):
|
||||||
name = NameField(validators=[bad_names])
|
name = NameField(validators=[bad_names])
|
||||||
|
|
||||||
form = NameForm(data={'name' : ['bad', 'value']})
|
form = NameForm(data={'name': ['bad', 'value']})
|
||||||
form.full_clean()
|
form.full_clean()
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form.errors, {'name': ['bad value not allowed']})
|
self.assertEqual(form.errors, {'name': ['bad value not allowed']})
|
||||||
form = NameForm(data={'name' : ['should be overly', 'long for the field names']})
|
form = NameForm(data={'name': ['should be overly', 'long for the field names']})
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form.errors, {'name': ['Ensure this value has at most 10 characters (it has 16).',
|
self.assertEqual(form.errors, {'name': ['Ensure this value has at most 10 characters (it has 16).',
|
||||||
'Ensure this value has at most 10 characters (it has 24).']})
|
'Ensure this value has at most 10 characters (it has 24).']})
|
||||||
form = NameForm(data={'name' : ['fname', 'lname']})
|
form = NameForm(data={'name': ['fname', 'lname']})
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
self.assertEqual(form.cleaned_data, {'name' : 'fname lname'})
|
self.assertEqual(form.cleaned_data, {'name': 'fname lname'})
|
||||||
|
|
||||||
def test_multivalue_deep_copy(self):
|
def test_multivalue_deep_copy(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1912,7 +1912,7 @@ class FormsTestCase(TestCase):
|
||||||
|
|
||||||
form = JSONForm(data={'json': '{}'})
|
form = JSONForm(data={'json': '{}'})
|
||||||
form.full_clean()
|
form.full_clean()
|
||||||
self.assertEqual(form.cleaned_data, {'json' : {}})
|
self.assertEqual(form.cleaned_data, {'json': {}})
|
||||||
|
|
||||||
def test_boundfield_label_tag(self):
|
def test_boundfield_label_tag(self):
|
||||||
class SomeForm(Form):
|
class SomeForm(Form):
|
||||||
|
|
|
@ -1751,7 +1751,7 @@ class OldFormForXTests(TestCase):
|
||||||
self.assertHTMLEqual(six.text_type(CustomFieldForExclusionForm()),
|
self.assertHTMLEqual(six.text_type(CustomFieldForExclusionForm()),
|
||||||
'''<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="10" /></td></tr>''')
|
'''<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" maxlength="10" /></td></tr>''')
|
||||||
|
|
||||||
def test_iterable_model_m2m(self) :
|
def test_iterable_model_m2m(self):
|
||||||
colour = Colour.objects.create(name='Blue')
|
colour = Colour.objects.create(name='Blue')
|
||||||
form = ColourfulItemForm()
|
form = ColourfulItemForm()
|
||||||
self.maxDiff = 1024
|
self.maxDiff = 1024
|
||||||
|
@ -1763,7 +1763,7 @@ class OldFormForXTests(TestCase):
|
||||||
</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>"""
|
</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></p>"""
|
||||||
% {'blue_pk': colour.pk})
|
% {'blue_pk': colour.pk})
|
||||||
|
|
||||||
def test_custom_error_messages(self) :
|
def test_custom_error_messages(self):
|
||||||
data = {'name1': '@#$!!**@#$', 'name2': '@#$!!**@#$'}
|
data = {'name1': '@#$!!**@#$', 'name2': '@#$!!**@#$'}
|
||||||
errors = CustomErrorMessageForm(data).errors
|
errors = CustomErrorMessageForm(data).errors
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
|
@ -1775,7 +1775,7 @@ class OldFormForXTests(TestCase):
|
||||||
'<ul class="errorlist"><li>Model custom error message.</li></ul>'
|
'<ul class="errorlist"><li>Model custom error message.</li></ul>'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_model_clean_error_messages(self) :
|
def test_model_clean_error_messages(self):
|
||||||
data = {'name1': 'FORBIDDEN_VALUE', 'name2': 'ABC'}
|
data = {'name1': 'FORBIDDEN_VALUE', 'name2': 'ABC'}
|
||||||
errors = CustomErrorMessageForm(data).errors
|
errors = CustomErrorMessageForm(data).errors
|
||||||
self.assertHTMLEqual(
|
self.assertHTMLEqual(
|
||||||
|
|
|
@ -28,7 +28,7 @@ from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
SERIALIZATION_MODULES = {
|
SERIALIZATION_MODULES = {
|
||||||
"json2" : "django.core.serializers.json",
|
"json2": "django.core.serializers.json",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
class SerializerRegistrationTests(TestCase):
|
class SerializerRegistrationTests(TestCase):
|
||||||
|
|
|
@ -38,16 +38,16 @@ def get_filter_tests():
|
||||||
# NOTE: \xa0 avoids wrapping between value and unit
|
# NOTE: \xa0 avoids wrapping between value and unit
|
||||||
return {
|
return {
|
||||||
# Default compare with datetime.now()
|
# Default compare with datetime.now()
|
||||||
'filter-timesince01' : ('{{ a|timesince }}', {'a': datetime.now() + timedelta(minutes=-1, seconds = -10)}, '1\xa0minute'),
|
'filter-timesince01': ('{{ a|timesince }}', {'a': datetime.now() + timedelta(minutes=-1, seconds = -10)}, '1\xa0minute'),
|
||||||
'filter-timesince02' : ('{{ a|timesince }}', {'a': datetime.now() - timedelta(days=1, minutes = 1)}, '1\xa0day'),
|
'filter-timesince02': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(days=1, minutes = 1)}, '1\xa0day'),
|
||||||
'filter-timesince03' : ('{{ a|timesince }}', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds = 10)}, '1\xa0hour, 25\xa0minutes'),
|
'filter-timesince03': ('{{ a|timesince }}', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds = 10)}, '1\xa0hour, 25\xa0minutes'),
|
||||||
|
|
||||||
# Compare to a given parameter
|
# Compare to a given parameter
|
||||||
'filter-timesince04' : ('{{ a|timesince:b }}', {'a': now - timedelta(days=2), 'b': now - timedelta(days=1)}, '1\xa0day'),
|
'filter-timesince04': ('{{ a|timesince:b }}', {'a': now - timedelta(days=2), 'b': now - timedelta(days=1)}, '1\xa0day'),
|
||||||
'filter-timesince05' : ('{{ a|timesince:b }}', {'a': now - timedelta(days=2, minutes=1), 'b': now - timedelta(days=2)}, '1\xa0minute'),
|
'filter-timesince05': ('{{ a|timesince:b }}', {'a': now - timedelta(days=2, minutes=1), 'b': now - timedelta(days=2)}, '1\xa0minute'),
|
||||||
|
|
||||||
# Check that timezone is respected
|
# Check that timezone is respected
|
||||||
'filter-timesince06' : ('{{ a|timesince:b }}', {'a': now_tz - timedelta(hours=8), 'b': now_tz}, '8\xa0hours'),
|
'filter-timesince06': ('{{ a|timesince:b }}', {'a': now_tz - timedelta(hours=8), 'b': now_tz}, '8\xa0hours'),
|
||||||
|
|
||||||
# Regression for #7443
|
# Regression for #7443
|
||||||
'filter-timesince07': ('{{ earlier|timesince }}', {'earlier': now - timedelta(days=7)}, '1\xa0week'),
|
'filter-timesince07': ('{{ earlier|timesince }}', {'earlier': now - timedelta(days=7)}, '1\xa0week'),
|
||||||
|
@ -57,25 +57,25 @@ def get_filter_tests():
|
||||||
|
|
||||||
# Ensures that differing timezones are calculated correctly
|
# Ensures that differing timezones are calculated correctly
|
||||||
# Tests trying to compare a timezone-aware 'now' to now aren't supported on no-tz-support systems (e.g Windows).
|
# Tests trying to compare a timezone-aware 'now' to now aren't supported on no-tz-support systems (e.g Windows).
|
||||||
'filter-timesince11' : ('{{ a|timesince }}', {'a': now}, '0\xa0minutes'),
|
'filter-timesince11': ('{{ a|timesince }}', {'a': now}, '0\xa0minutes'),
|
||||||
'filter-timesince12' : ('{{ a|timesince }}', {'a': now_tz}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
'filter-timesince12': ('{{ a|timesince }}', {'a': now_tz}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
||||||
'filter-timesince13' : ('{{ a|timesince }}', {'a': now_tz_i}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
'filter-timesince13': ('{{ a|timesince }}', {'a': now_tz_i}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
||||||
'filter-timesince14' : ('{{ a|timesince:b }}', {'a': now_tz, 'b': now_tz_i}, '0\xa0minutes'),
|
'filter-timesince14': ('{{ a|timesince:b }}', {'a': now_tz, 'b': now_tz_i}, '0\xa0minutes'),
|
||||||
'filter-timesince15' : ('{{ a|timesince:b }}', {'a': now, 'b': now_tz_i}, ''),
|
'filter-timesince15': ('{{ a|timesince:b }}', {'a': now, 'b': now_tz_i}, ''),
|
||||||
'filter-timesince16' : ('{{ a|timesince:b }}', {'a': now_tz_i, 'b': now}, ''),
|
'filter-timesince16': ('{{ a|timesince:b }}', {'a': now_tz_i, 'b': now}, ''),
|
||||||
|
|
||||||
# Regression for #9065 (two date objects).
|
# Regression for #9065 (two date objects).
|
||||||
'filter-timesince17' : ('{{ a|timesince:b }}', {'a': today, 'b': today}, '0\xa0minutes'),
|
'filter-timesince17': ('{{ a|timesince:b }}', {'a': today, 'b': today}, '0\xa0minutes'),
|
||||||
'filter-timesince18' : ('{{ a|timesince:b }}', {'a': today, 'b': today + timedelta(hours=24)}, '1\xa0day'),
|
'filter-timesince18': ('{{ a|timesince:b }}', {'a': today, 'b': today + timedelta(hours=24)}, '1\xa0day'),
|
||||||
|
|
||||||
# Default compare with datetime.now()
|
# Default compare with datetime.now()
|
||||||
'filter-timeuntil01' : ('{{ a|timeuntil }}', {'a': datetime.now() + timedelta(minutes=2, seconds=10)}, '2\xa0minutes'),
|
'filter-timeuntil01': ('{{ a|timeuntil }}', {'a': datetime.now() + timedelta(minutes=2, seconds=10)}, '2\xa0minutes'),
|
||||||
'filter-timeuntil02' : ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(days=1, seconds=10))}, '1\xa0day'),
|
'filter-timeuntil02': ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(days=1, seconds=10))}, '1\xa0day'),
|
||||||
'filter-timeuntil03' : ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds = 10))}, '8\xa0hours, 10\xa0minutes'),
|
'filter-timeuntil03': ('{{ a|timeuntil }}', {'a': (datetime.now() + timedelta(hours=8, minutes=10, seconds = 10))}, '8\xa0hours, 10\xa0minutes'),
|
||||||
|
|
||||||
# Compare to a given parameter
|
# Compare to a given parameter
|
||||||
'filter-timeuntil04' : ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=1), 'b': now - timedelta(days=2)}, '1\xa0day'),
|
'filter-timeuntil04': ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=1), 'b': now - timedelta(days=2)}, '1\xa0day'),
|
||||||
'filter-timeuntil05' : ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=2), 'b': now - timedelta(days=2, minutes=1)}, '1\xa0minute'),
|
'filter-timeuntil05': ('{{ a|timeuntil:b }}', {'a': now - timedelta(days=2), 'b': now - timedelta(days=2, minutes=1)}, '1\xa0minute'),
|
||||||
|
|
||||||
# Regression for #7443
|
# Regression for #7443
|
||||||
'filter-timeuntil06': ('{{ earlier|timeuntil }}', {'earlier': now - timedelta(days=7)}, '0\xa0minutes'),
|
'filter-timeuntil06': ('{{ earlier|timeuntil }}', {'earlier': now - timedelta(days=7)}, '0\xa0minutes'),
|
||||||
|
@ -85,13 +85,13 @@ def get_filter_tests():
|
||||||
|
|
||||||
# Ensures that differing timezones are calculated correctly
|
# Ensures that differing timezones are calculated correctly
|
||||||
# Tests trying to compare a timezone-aware 'now' to now aren't supported on no-tz-support systems (e.g Windows).
|
# Tests trying to compare a timezone-aware 'now' to now aren't supported on no-tz-support systems (e.g Windows).
|
||||||
'filter-timeuntil10' : ('{{ a|timeuntil }}', {'a': now_tz}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
'filter-timeuntil10': ('{{ a|timeuntil }}', {'a': now_tz}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
||||||
'filter-timeuntil11' : ('{{ a|timeuntil }}', {'a': now_tz_i}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
'filter-timeuntil11': ('{{ a|timeuntil }}', {'a': now_tz_i}, '0\xa0minutes') if TZ_SUPPORT else ('', {}, ''),
|
||||||
'filter-timeuntil12' : ('{{ a|timeuntil:b }}', {'a': now_tz_i, 'b': now_tz}, '0\xa0minutes'),
|
'filter-timeuntil12': ('{{ a|timeuntil:b }}', {'a': now_tz_i, 'b': now_tz}, '0\xa0minutes'),
|
||||||
|
|
||||||
# Regression for #9065 (two date objects).
|
# Regression for #9065 (two date objects).
|
||||||
'filter-timeuntil13' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today}, '0\xa0minutes'),
|
'filter-timeuntil13': ('{{ a|timeuntil:b }}', {'a': today, 'b': today}, '0\xa0minutes'),
|
||||||
'filter-timeuntil14' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today - timedelta(hours=24)}, '1\xa0day'),
|
'filter-timeuntil14': ('{{ a|timeuntil:b }}', {'a': today, 'b': today - timedelta(hours=24)}, '1\xa0day'),
|
||||||
|
|
||||||
'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"),
|
'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"),
|
||||||
'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"),
|
'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, r"<a>\' <a>\'"),
|
||||||
|
@ -135,8 +135,8 @@ def get_filter_tests():
|
||||||
". a<b. . a<b."),
|
". a<b. . a<b."),
|
||||||
|
|
||||||
# Test the title filter
|
# Test the title filter
|
||||||
'filter-title1' : ('{{ a|title }}', {'a' : 'JOE\'S CRAB SHACK'}, 'Joe's Crab Shack'),
|
'filter-title1': ('{{ a|title }}', {'a': 'JOE\'S CRAB SHACK'}, 'Joe's Crab Shack'),
|
||||||
'filter-title2' : ('{{ a|title }}', {'a' : '555 WEST 53RD STREET'}, '555 West 53rd Street'),
|
'filter-title2': ('{{ a|title }}', {'a': '555 WEST 53RD STREET'}, '555 West 53rd Street'),
|
||||||
|
|
||||||
'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}',
|
'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}',
|
||||||
{"a": "alpha & bravo", "b": mark_safe("alpha & bravo")}, "alpha & ... alpha & ..."),
|
{"a": "alpha & bravo", "b": mark_safe("alpha & bravo")}, "alpha & ... alpha & ..."),
|
||||||
|
|
|
@ -107,61 +107,61 @@ register.simple_tag(lambda x: x - 1, name='minusone')
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_no_params():
|
def inclusion_no_params():
|
||||||
"""Expected inclusion_no_params __doc__"""
|
"""Expected inclusion_no_params __doc__"""
|
||||||
return {"result" : "inclusion_no_params - Expected result"}
|
return {"result": "inclusion_no_params - Expected result"}
|
||||||
inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
|
inclusion_no_params.anything = "Expected inclusion_no_params __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_no_params_from_template():
|
def inclusion_no_params_from_template():
|
||||||
"""Expected inclusion_no_params_from_template __doc__"""
|
"""Expected inclusion_no_params_from_template __doc__"""
|
||||||
return {"result" : "inclusion_no_params_from_template - Expected result"}
|
return {"result": "inclusion_no_params_from_template - Expected result"}
|
||||||
inclusion_no_params_from_template.anything = "Expected inclusion_no_params_from_template __dict__"
|
inclusion_no_params_from_template.anything = "Expected inclusion_no_params_from_template __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
def inclusion_one_param(arg):
|
def inclusion_one_param(arg):
|
||||||
"""Expected inclusion_one_param __doc__"""
|
"""Expected inclusion_one_param __doc__"""
|
||||||
return {"result" : "inclusion_one_param - Expected result: %s" % arg}
|
return {"result": "inclusion_one_param - Expected result: %s" % arg}
|
||||||
inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
|
inclusion_one_param.anything = "Expected inclusion_one_param __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'))
|
@register.inclusion_tag(get_template('inclusion.html'))
|
||||||
def inclusion_one_param_from_template(arg):
|
def inclusion_one_param_from_template(arg):
|
||||||
"""Expected inclusion_one_param_from_template __doc__"""
|
"""Expected inclusion_one_param_from_template __doc__"""
|
||||||
return {"result" : "inclusion_one_param_from_template - Expected result: %s" % arg}
|
return {"result": "inclusion_one_param_from_template - Expected result: %s" % arg}
|
||||||
inclusion_one_param_from_template.anything = "Expected inclusion_one_param_from_template __dict__"
|
inclusion_one_param_from_template.anything = "Expected inclusion_one_param_from_template __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html', takes_context=False)
|
@register.inclusion_tag('inclusion.html', takes_context=False)
|
||||||
def inclusion_explicit_no_context(arg):
|
def inclusion_explicit_no_context(arg):
|
||||||
"""Expected inclusion_explicit_no_context __doc__"""
|
"""Expected inclusion_explicit_no_context __doc__"""
|
||||||
return {"result" : "inclusion_explicit_no_context - Expected result: %s" % arg}
|
return {"result": "inclusion_explicit_no_context - Expected result: %s" % arg}
|
||||||
inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
|
inclusion_explicit_no_context.anything = "Expected inclusion_explicit_no_context __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'), takes_context=False)
|
@register.inclusion_tag(get_template('inclusion.html'), takes_context=False)
|
||||||
def inclusion_explicit_no_context_from_template(arg):
|
def inclusion_explicit_no_context_from_template(arg):
|
||||||
"""Expected inclusion_explicit_no_context_from_template __doc__"""
|
"""Expected inclusion_explicit_no_context_from_template __doc__"""
|
||||||
return {"result" : "inclusion_explicit_no_context_from_template - Expected result: %s" % arg}
|
return {"result": "inclusion_explicit_no_context_from_template - Expected result: %s" % arg}
|
||||||
inclusion_explicit_no_context_from_template.anything = "Expected inclusion_explicit_no_context_from_template __dict__"
|
inclusion_explicit_no_context_from_template.anything = "Expected inclusion_explicit_no_context_from_template __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html', takes_context=True)
|
@register.inclusion_tag('inclusion.html', takes_context=True)
|
||||||
def inclusion_no_params_with_context(context):
|
def inclusion_no_params_with_context(context):
|
||||||
"""Expected inclusion_no_params_with_context __doc__"""
|
"""Expected inclusion_no_params_with_context __doc__"""
|
||||||
return {"result" : "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
|
return {"result": "inclusion_no_params_with_context - Expected result (context value: %s)" % context['value']}
|
||||||
inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
|
inclusion_no_params_with_context.anything = "Expected inclusion_no_params_with_context __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
||||||
def inclusion_no_params_with_context_from_template(context):
|
def inclusion_no_params_with_context_from_template(context):
|
||||||
"""Expected inclusion_no_params_with_context_from_template __doc__"""
|
"""Expected inclusion_no_params_with_context_from_template __doc__"""
|
||||||
return {"result" : "inclusion_no_params_with_context_from_template - Expected result (context value: %s)" % context['value']}
|
return {"result": "inclusion_no_params_with_context_from_template - Expected result (context value: %s)" % context['value']}
|
||||||
inclusion_no_params_with_context_from_template.anything = "Expected inclusion_no_params_with_context_from_template __dict__"
|
inclusion_no_params_with_context_from_template.anything = "Expected inclusion_no_params_with_context_from_template __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html', takes_context=True)
|
@register.inclusion_tag('inclusion.html', takes_context=True)
|
||||||
def inclusion_params_and_context(context, arg):
|
def inclusion_params_and_context(context, arg):
|
||||||
"""Expected inclusion_params_and_context __doc__"""
|
"""Expected inclusion_params_and_context __doc__"""
|
||||||
return {"result" : "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
|
return {"result": "inclusion_params_and_context - Expected result (context value: %s): %s" % (context['value'], arg)}
|
||||||
inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
|
inclusion_params_and_context.anything = "Expected inclusion_params_and_context __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
@register.inclusion_tag(get_template('inclusion.html'), takes_context=True)
|
||||||
def inclusion_params_and_context_from_template(context, arg):
|
def inclusion_params_and_context_from_template(context, arg):
|
||||||
"""Expected inclusion_params_and_context_from_template __doc__"""
|
"""Expected inclusion_params_and_context_from_template __doc__"""
|
||||||
return {"result" : "inclusion_params_and_context_from_template - Expected result (context value: %s): %s" % (context['value'], arg)}
|
return {"result": "inclusion_params_and_context_from_template - Expected result (context value: %s): %s" % (context['value'], arg)}
|
||||||
inclusion_params_and_context_from_template.anything = "Expected inclusion_params_and_context_from_template __dict__"
|
inclusion_params_and_context_from_template.anything = "Expected inclusion_params_and_context_from_template __dict__"
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion.html')
|
@register.inclusion_tag('inclusion.html')
|
||||||
|
|
|
@ -668,7 +668,7 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
'basic-syntax02': ("{{ headline }}", {'headline': 'Success'}, "Success"),
|
'basic-syntax02': ("{{ headline }}", {'headline': 'Success'}, "Success"),
|
||||||
|
|
||||||
# More than one replacement variable is allowed in a template
|
# More than one replacement variable is allowed in a template
|
||||||
'basic-syntax03': ("{{ first }} --- {{ second }}", {"first" : 1, "second" : 2}, "1 --- 2"),
|
'basic-syntax03': ("{{ first }} --- {{ second }}", {"first": 1, "second": 2}, "1 --- 2"),
|
||||||
|
|
||||||
# Fail silently when a variable is not found in the current context
|
# Fail silently when a variable is not found in the current context
|
||||||
'basic-syntax04': ("as{{ missing }}df", {}, ("asdf", "asINVALIDdf")),
|
'basic-syntax04': ("as{{ missing }}df", {}, ("asdf", "asINVALIDdf")),
|
||||||
|
@ -899,8 +899,8 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
'cycle17': ("{% cycle 'a' 'b' 'c' as abc silent %}{% cycle abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}", {}, ""),
|
'cycle17': ("{% cycle 'a' 'b' 'c' as abc silent %}{% cycle abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}", {}, ""),
|
||||||
'cycle18': ("{% cycle 'a' 'b' 'c' as foo invalid_flag %}", {}, template.TemplateSyntaxError),
|
'cycle18': ("{% cycle 'a' 'b' 'c' as foo invalid_flag %}", {}, template.TemplateSyntaxError),
|
||||||
'cycle19': ("{% cycle 'a' 'b' as silent %}{% cycle silent %}", {}, "ab"),
|
'cycle19': ("{% cycle 'a' 'b' as silent %}{% cycle silent %}", {}, "ab"),
|
||||||
'cycle20': ("{% cycle one two as foo %} & {% cycle foo %}", {'one' : 'A & B', 'two' : 'C & D'}, "A & B & C & D"),
|
'cycle20': ("{% cycle one two as foo %} & {% cycle foo %}", {'one': 'A & B', 'two': 'C & D'}, "A & B & C & D"),
|
||||||
'cycle21': ("{% filter force_escape %}{% cycle one two as foo %} & {% cycle foo %}{% endfilter %}", {'one' : 'A & B', 'two' : 'C & D'}, "A & B & C & D"),
|
'cycle21': ("{% filter force_escape %}{% cycle one two as foo %} & {% cycle foo %}{% endfilter %}", {'one': 'A & B', 'two': 'C & D'}, "A & B & C & D"),
|
||||||
'cycle22': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ x }}{% endfor %}", {'values': [1, 2, 3, 4]}, "1234"),
|
'cycle22': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ x }}{% endfor %}", {'values': [1, 2, 3, 4]}, "1234"),
|
||||||
'cycle23': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ abc }}{{ x }}{% endfor %}", {'values': [1, 2, 3, 4]}, "a1b2c3a4"),
|
'cycle23': ("{% for x in values %}{% cycle 'a' 'b' 'c' as abc silent %}{{ abc }}{{ x }}{% endfor %}", {'values': [1, 2, 3, 4]}, "a1b2c3a4"),
|
||||||
'included-cycle': ('{{ abc }}', {'abc': 'xxx'}, 'xxx'),
|
'included-cycle': ('{{ abc }}', {'abc': 'xxx'}, 'xxx'),
|
||||||
|
@ -1398,9 +1398,9 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
'spaceless01': ("{% spaceless %} <b> <i> text </i> </b> {% endspaceless %}", {}, "<b><i> text </i></b>"),
|
'spaceless01': ("{% spaceless %} <b> <i> text </i> </b> {% endspaceless %}", {}, "<b><i> text </i></b>"),
|
||||||
'spaceless02': ("{% spaceless %} <b> \n <i> text </i> \n </b> {% endspaceless %}", {}, "<b><i> text </i></b>"),
|
'spaceless02': ("{% spaceless %} <b> \n <i> text </i> \n </b> {% endspaceless %}", {}, "<b><i> text </i></b>"),
|
||||||
'spaceless03': ("{% spaceless %}<b><i>text</i></b>{% endspaceless %}", {}, "<b><i>text</i></b>"),
|
'spaceless03': ("{% spaceless %}<b><i>text</i></b>{% endspaceless %}", {}, "<b><i>text</i></b>"),
|
||||||
'spaceless04': ("{% spaceless %}<b> <i>{{ text }}</i> </b>{% endspaceless %}", {'text' : 'This & that'}, "<b><i>This & that</i></b>"),
|
'spaceless04': ("{% spaceless %}<b> <i>{{ text }}</i> </b>{% endspaceless %}", {'text': 'This & that'}, "<b><i>This & that</i></b>"),
|
||||||
'spaceless05': ("{% autoescape off %}{% spaceless %}<b> <i>{{ text }}</i> </b>{% endspaceless %}{% endautoescape %}", {'text' : 'This & that'}, "<b><i>This & that</i></b>"),
|
'spaceless05': ("{% autoescape off %}{% spaceless %}<b> <i>{{ text }}</i> </b>{% endspaceless %}{% endautoescape %}", {'text': 'This & that'}, "<b><i>This & that</i></b>"),
|
||||||
'spaceless06': ("{% spaceless %}<b> <i>{{ text|safe }}</i> </b>{% endspaceless %}", {'text' : 'This & that'}, "<b><i>This & that</i></b>"),
|
'spaceless06': ("{% spaceless %}<b> <i>{{ text|safe }}</i> </b>{% endspaceless %}", {'text': 'This & that'}, "<b><i>This & that</i></b>"),
|
||||||
|
|
||||||
# simple translation of a string delimited by '
|
# simple translation of a string delimited by '
|
||||||
'i18n01': ("{% load i18n %}{% trans 'xxxyyyxxx' %}", {}, "xxxyyyxxx"),
|
'i18n01': ("{% load i18n %}{% trans 'xxxyyyxxx' %}", {}, "xxxyyyxxx"),
|
||||||
|
|
|
@ -191,7 +191,7 @@ def _permission_protected_view(request):
|
||||||
"A simple view that is permission protected."
|
"A simple view that is permission protected."
|
||||||
t = Template('This is a permission protected test. '
|
t = Template('This is a permission protected test. '
|
||||||
'Username is {{ user.username }}. '
|
'Username is {{ user.username }}. '
|
||||||
'Permissions are {{ user.get_all_permissions }}.' ,
|
'Permissions are {{ user.get_all_permissions }}.',
|
||||||
name='Permissions Template')
|
name='Permissions Template')
|
||||||
c = Context({'user': request.user})
|
c = Context({'user': request.user})
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
@ -211,7 +211,7 @@ class _ViewManager(object):
|
||||||
def permission_protected_view(self, request):
|
def permission_protected_view(self, request):
|
||||||
t = Template('This is a permission protected test using a method. '
|
t = Template('This is a permission protected test using a method. '
|
||||||
'Username is {{ user.username }}. '
|
'Username is {{ user.username }}. '
|
||||||
'Permissions are {{ user.get_all_permissions }}.' ,
|
'Permissions are {{ user.get_all_permissions }}.',
|
||||||
name='Permissions Template')
|
name='Permissions Template')
|
||||||
c = Context({'user': request.user})
|
c = Context({'user': request.user})
|
||||||
return HttpResponse(t.render(c))
|
return HttpResponse(t.render(c))
|
||||||
|
|
|
@ -322,7 +322,7 @@ class HTMLEqualTests(TestCase):
|
||||||
self.assertEqual(dom.children[0], "<p>foo</p> '</scr'+'ipt>' <span>bar</span>")
|
self.assertEqual(dom.children[0], "<p>foo</p> '</scr'+'ipt>' <span>bar</span>")
|
||||||
|
|
||||||
def test_self_closing_tags(self):
|
def test_self_closing_tags(self):
|
||||||
self_closing_tags = ('br' , 'hr', 'input', 'img', 'meta', 'spacer',
|
self_closing_tags = ('br', 'hr', 'input', 'img', 'meta', 'spacer',
|
||||||
'link', 'frame', 'base', 'col')
|
'link', 'frame', 'base', 'col')
|
||||||
for tag in self_closing_tags:
|
for tag in self_closing_tags:
|
||||||
dom = parse_html('<p>Hello <%s> world</p>' % tag)
|
dom = parse_html('<p>Hello <%s> world</p>' % tag)
|
||||||
|
|
Loading…
Reference in New Issue