2020from django .db import models
2121from django .utils .encoding import force_str
2222
23- __all__ = (' AddressField' , ' GeoLocationField' )
23+ __all__ = (" AddressField" , " GeoLocationField" )
2424
2525
2626def typename (obj ):
2727 """Returns the type of obj as a string. More descriptive and specific than
2828 type(obj), and safe for any object, unlike __class__."""
29- if hasattr (obj , ' __class__' ):
30- return getattr (obj , ' __class__' ).__name__
29+ if hasattr (obj , " __class__" ):
30+ return getattr (obj , " __class__" ).__name__
3131 else :
3232 return type (obj ).__name__
3333
@@ -57,7 +57,7 @@ def __init__(self, lat, lon=None):
5757 def __str__ (self ):
5858 if self .lat is not None and self .lon is not None :
5959 return "%s,%s" % (self .lat , self .lon )
60- return ''
60+ return ""
6161
6262 def __eq__ (self , other ):
6363 if isinstance (other , GeoPt ):
@@ -69,24 +69,22 @@ def __len__(self):
6969 def _split_geo_point (self , geo_point ):
7070 """splits the geo point into lat and lon"""
7171 try :
72- lat , lon = geo_point .split (',' )
72+ lat , lon = geo_point .split ("," )
7373 return lat , lon
7474 except (AttributeError , ValueError ):
7575 m = 'Expected a "lat,long" formatted string; received %s (a %s).'
76- raise exceptions .ValidationError (m % (geo_point ,
77- typename (geo_point )))
76+ raise exceptions .ValidationError (m % (geo_point , typename (geo_point )))
7877
7978 def _validate_geo_range (self , geo_part , range_val ):
8079 try :
8180 geo_part = float (geo_part )
8281 if abs (geo_part ) > range_val :
83- m = 'Must be between -%s and %s; received %s'
84- raise exceptions .ValidationError (m % (range_val , range_val ,
85- geo_part ))
82+ m = "Must be between -%s and %s; received %s"
83+ raise exceptions .ValidationError (m % (range_val , range_val , geo_part ))
8684 except (TypeError , ValueError ):
8785 raise exceptions .ValidationError (
88- ' Expected float, received %s (a %s).' % (geo_part ,
89- typename ( geo_part )) )
86+ " Expected float, received %s (a %s)." % (geo_part , typename ( geo_part ))
87+ )
9088 return geo_part
9189
9290
@@ -107,10 +105,11 @@ class GeoLocationField(models.CharField):
107105 serialized string, or if lat and lon are not valid floating points in the
108106 ranges [-90, 90] and [-180, 180], respectively.
109107 """
108+
110109 description = "A geographical point, specified by floating-point latitude and longitude coordinates."
111110
112111 def __init__ (self , * args , ** kwargs ):
113- kwargs [' max_length' ] = 100
112+ kwargs [" max_length" ] = 100
114113 super (GeoLocationField , self ).__init__ (* args , ** kwargs )
115114
116115 def from_db_value (self , value , * args , ** kwargs ):
0 commit comments