Skip to content

Commit 5a5efbe

Browse files
authored
Cleanup (#96)
* Style: Run black formatter * Peripheral: remove travis-ci from readme. Using github actions now.
1 parent e56039b commit 5a5efbe

File tree

7 files changed

+49
-50
lines changed

7 files changed

+49
-50
lines changed

README.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,3 @@ When you're displaying the address back to the user, just request the map
9999
using the geocoordinates that were saved in your model. Maybe sometime when
100100
I get around to it I'll see if I can create a method that will build that
101101
into the model.
102-
103-
.. |Build Status| image:: https://travis-ci.org/madisona/django-google-maps.png
104-
:target: https://travis-ci.org/madisona/django-google-maps

django_google_maps/fields.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
from django.db import models
2121
from django.utils.encoding import force_str
2222

23-
__all__ = ('AddressField', 'GeoLocationField')
23+
__all__ = ("AddressField", "GeoLocationField")
2424

2525

2626
def 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):

django_google_maps/tests/test_geolocation_field.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@
55

66
class GeoLocationFieldTests(test.TestCase):
77
def test_getting_lat_lon_from_model_given_string(self):
8-
sut_create = models.Person.objects.create(geolocation='45,90')
8+
sut_create = models.Person.objects.create(geolocation="45,90")
99
sut = models.Person.objects.get(pk=sut_create.pk)
1010
self.assertEqual(45, sut.geolocation.lat)
1111
self.assertEqual(90, sut.geolocation.lon)
1212

1313
def test_getting_lat_lon_from_model_given_pt(self):
14-
sut_create = models.Person.objects.create(geolocation=GeoPt('45,90'))
14+
sut_create = models.Person.objects.create(geolocation=GeoPt("45,90"))
1515
sut = models.Person.objects.get(pk=sut_create.pk)
1616
self.assertEqual(45, sut.geolocation.lat)
1717
self.assertEqual(90, sut.geolocation.lon)
1818

1919
def test_getting_lat_lon_from_model_in_db_given_string(self):
20-
sut_create = models.Person.objects.create(geolocation='45,90')
20+
sut_create = models.Person.objects.create(geolocation="45,90")
2121
sut = models.Person.objects.get(pk=sut_create.pk)
2222
self.assertEqual(45, sut.geolocation.lat)
2323
self.assertEqual(90, sut.geolocation.lon)
2424

2525
def test_exact_match_query(self):
26-
sut = models.Person.objects.create(geolocation='45,90')
27-
result = models.Person.objects.get(geolocation__exact=GeoPt('45,90'))
26+
sut = models.Person.objects.create(geolocation="45,90")
27+
result = models.Person.objects.get(geolocation__exact=GeoPt("45,90"))
2828
self.assertEqual(result, sut)
2929

3030
def test_in_match_query(self):
31-
sut = models.Person.objects.create(geolocation='45,90')
32-
result = models.Person.objects.get(geolocation__in=[GeoPt('45,90')])
31+
sut = models.Person.objects.create(geolocation="45,90")
32+
result = models.Person.objects.get(geolocation__in=[GeoPt("45,90")])
3333
self.assertEqual(result, sut)
3434

3535
def test_value_to_string_with_point(self):
36-
sut = models.Person.objects.create(geolocation=GeoPt('45,90'))
36+
sut = models.Person.objects.create(geolocation=GeoPt("45,90"))
3737
field = models.Person._meta.fields[-1]
38-
self.assertEqual('45.0,90.0', field.value_to_string(sut))
38+
self.assertEqual("45.0,90.0", field.value_to_string(sut))
3939

4040
def test_value_to_string_with_string(self):
41-
sut = models.Person.objects.create(geolocation='45,90')
41+
sut = models.Person.objects.create(geolocation="45,90")
4242
field = models.Person._meta.fields[-1]
43-
self.assertEqual('45.0,90.0', field.value_to_string(sut))
43+
self.assertEqual("45.0,90.0", field.value_to_string(sut))
4444

4545
def test_get_prep_value_returns_none_when_none(self):
4646
field = models.Person._meta.fields[-1]

django_google_maps/tests/test_geopt_field.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ def test_is_not_equal_when_comparison_is_not_GeoPt_object(self):
3737
self.assertNotEqual(geo_pt_1, geo_pt_2)
3838

3939
def test_allows_GeoPt_instantiated_with_empty_string(self):
40-
geo_pt = fields.GeoPt('')
40+
geo_pt = fields.GeoPt("")
4141
self.assertEqual(None, geo_pt.lat)
4242
self.assertEqual(None, geo_pt.lon)
4343

4444
def test_uses_empty_string_as_unicode_representation_for_empty_GeoPt(self):
45-
geo_pt = fields.GeoPt('')
46-
self.assertEqual('', force_str(geo_pt))
45+
geo_pt = fields.GeoPt("")
46+
self.assertEqual("", force_str(geo_pt))
4747

4848
def test_splits_geo_point_on_comma(self):
4949
pt = fields.GeoPt("15.001,32.001")
50-
self.assertEqual('15.001', str(pt.lat))
51-
self.assertEqual('32.001', str(pt.lon))
50+
self.assertEqual("15.001", str(pt.lat))
51+
self.assertEqual("32.001", str(pt.lon))
5252

5353
def test_raises_error_when_attribute_error_on_split(self):
5454
class Fake(object):
@@ -62,25 +62,25 @@ def test_raises_error_when_type_error_on_split(self):
6262
x, y = fields.GeoPt("x,x")
6363

6464
def test_returns_float_value_when_valid_value(self):
65-
geo_pt = fields.GeoPt('45.005,180')
65+
geo_pt = fields.GeoPt("45.005,180")
6666
self.assertEqual(45.005, geo_pt.lat)
6767

6868
def test_raises_exception_when_value_is_out_of_upper_range(self):
6969
with self.assertRaises(exceptions.ValidationError):
70-
fields.GeoPt('180,180')
70+
fields.GeoPt("180,180")
7171

7272
def test_raises_exception_when_value_is_out_of_lower_range(self):
7373
with self.assertRaises(exceptions.ValidationError):
74-
fields.GeoPt('-180,180')
74+
fields.GeoPt("-180,180")
7575

7676
def test_len_returns_len_of_unicode_value(self):
7777
geo_pt = fields.GeoPt("84,12")
7878
self.assertEqual(9, len(geo_pt))
7979

8080
def test_raises_exception_not_enough_values_to_unpack(self):
8181
with self.assertRaises(exceptions.ValidationError):
82-
fields.GeoPt('22')
82+
fields.GeoPt("22")
8383

8484
def test_raises_exception_too_many_values_to_unpack(self):
8585
with self.assertRaises(exceptions.ValidationError):
86-
fields.GeoPt('22,50,90')
86+
fields.GeoPt("22,50,90")

django_google_maps/tests/test_typename.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
class TypeNameTests(test.TestCase):
66
def test_simple_type_returns_type_name_as_string(self):
7-
self.assertEqual('str', typename("x"))
7+
self.assertEqual("str", typename("x"))
88

99
def test_class_object(self):
1010
class X:
1111
pass
1212

13-
self.assertEqual('type', typename(X))
13+
self.assertEqual("type", typename(X))

django_google_maps/tests/test_widget.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
class WidgetTests(test.TestCase):
77
def test_render_returns_xxxxxxx(self):
88
widget = GoogleMapsAddressWidget()
9-
results = widget.render('name', 'value', attrs={'a1': 1, 'a2': 2})
9+
results = widget.render("name", "value", attrs={"a1": 1, "a2": 2})
1010
expected = '<input a1="1" a2="2" name="name" type="text" value="value" />'
1111
expected += '<div class="map_canvas_wrapper">'
1212
expected += '<div id="map_canvas"></div></div>'
1313
self.assertHTMLEqual(expected, results)
1414

1515
def test_render_returns_blank_for_value_when_none(self):
1616
widget = GoogleMapsAddressWidget()
17-
results = widget.render('name', None, attrs={'a1': 1, 'a2': 2})
17+
results = widget.render("name", None, attrs={"a1": 1, "a2": 2})
1818
expected = '<input a1="1" a2="2" name="name" type="text" />'
1919
expected += '<div class="map_canvas_wrapper">'
2020
expected += '<div id="map_canvas"></div></div>'
2121
self.assertHTMLEqual(expected, results)
2222

2323
def test_maps_js_uses_api_key(self):
2424
widget = GoogleMapsAddressWidget()
25-
google_maps_js = "https://maps.google.com/maps/api/js?key={}&libraries=places".format(
26-
settings.GOOGLE_MAPS_API_KEY)
25+
google_maps_js = (
26+
"https://maps.google.com/maps/api/js?key={}&libraries=places".format(
27+
settings.GOOGLE_MAPS_API_KEY
28+
)
29+
)
2730
self.assertEqual(google_maps_js, widget.Media().js[1])

django_google_maps/widgets.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
class GoogleMapsAddressWidget(widgets.TextInput):
66
"""a widget that will place a google map right after the #id_address field"""
7+
78
template_name = "django_google_maps/widgets/map_widget.html"
89

910
class Media:
10-
css = {
11-
'all': ('django_google_maps/css/google-maps-admin.css', )
12-
}
11+
css = {"all": ("django_google_maps/css/google-maps-admin.css",)}
1312
js = (
14-
'https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js',
15-
'https://maps.google.com/maps/api/js?key={}&libraries=places'.format(
16-
settings.GOOGLE_MAPS_API_KEY),
17-
'django_google_maps/js/google-maps-admin.js',
13+
"https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js",
14+
"https://maps.google.com/maps/api/js?key={}&libraries=places".format(
15+
settings.GOOGLE_MAPS_API_KEY
16+
),
17+
"django_google_maps/js/google-maps-admin.js",
1818
)

0 commit comments

Comments
 (0)