From 585d27c5410afba9fc9988eb3a05c91ecee11077 Mon Sep 17 00:00:00 2001 From: Alja Isakovic Date: Wed, 6 Aug 2014 22:36:32 +0200 Subject: [PATCH 1/4] using get_or_create when testing for group membership --- web/tests/test_user_processors.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/tests/test_user_processors.py b/web/tests/test_user_processors.py index 524641df..1c74d226 100644 --- a/web/tests/test_user_processors.py +++ b/web/tests/test_user_processors.py @@ -30,12 +30,13 @@ def setUp(self): pub_date=datetime.datetime.now(), tags=["tag1", "tag2"]) - @pytest.mark.xfail def test_get_ambassadors_for_country(self): self.up1.country = "SI" self.up1.save() - group = Group.objects.get(name="ambassadors") + group, created = Group.objects.get_or_create(name="ambassadors") + if created: + group.save() group.user_set.add(self.u1) From fc4f642cdd0de658764c807a547f0a5ee6d2b838 Mon Sep 17 00:00:00 2001 From: Alja Isakovic Date: Wed, 13 Aug 2014 18:26:01 +0200 Subject: [PATCH 2/4] add note about test that has to be fixed --- web/tests/test_user_processors.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/tests/test_user_processors.py b/web/tests/test_user_processors.py index 1c74d226..bd371bcb 100644 --- a/web/tests/test_user_processors.py +++ b/web/tests/test_user_processors.py @@ -34,6 +34,8 @@ def test_get_ambassadors_for_country(self): self.up1.country = "SI" self.up1.save() + # temporary workaround because South migrations don't work yet + # fix me in the future group, created = Group.objects.get_or_create(name="ambassadors") if created: group.save() From a3f5d142d48d2da706b1691cf4bae7d4f8f7906c Mon Sep 17 00:00:00 2001 From: Alja Isakovic Date: Wed, 13 Aug 2014 19:51:06 +0200 Subject: [PATCH 3/4] make sure address updates on paste Also made sure the country updates when the marker is being manually marked and fixed a few other smaller issues related to that. --- static/js/events.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/static/js/events.js b/static/js/events.js index 075eea5f..425c4e9d 100644 --- a/static/js/events.js +++ b/static/js/events.js @@ -66,11 +66,20 @@ var Codeweek = window.Codeweek || {}; map = new google.maps.Map(document.getElementById('view-event-map'), mapOptions); } + function updateCountrySelection(country) { + var choice = document.getElementById('id_country'); + selectItemByValue(choice, country); + } + + function updateAddress(new_position) { geocoder = new google.maps.Geocoder(); geocoder.geocode({'latLng': new_position}, function (results, status) { if (status === google.maps.GeocoderStatus.OK) { document.getElementById("autocomplete").value = results[0].formatted_address; + // the last item in the geocoder for latLng results array is the country + var country = results[results.length - 1].address_components[0].short_name + updateCountrySelection(country); } }); } @@ -107,13 +116,19 @@ var Codeweek = window.Codeweek || {}; } } + function listenForPastedAddress() { + var address_field = document.getElementById('autocomplete'); + address_field.addEventListener('focusout',function () { + var address_value = address_field.value; + if (address_value) { + getAddress(address_value); + } + }, true); + } + function fillInAddress() { - var i, - component, - choice, - place = autocomplete.getPlace(), + var place = autocomplete.getPlace(), components = place.address_components, - country = null, output = autocomplete.getPlace().geometry.location, outputLat = output.lat(), outputLng = output.lng(), @@ -123,13 +138,7 @@ var Codeweek = window.Codeweek || {}; document.getElementById("id_geoposition_1").value = outputLng; createMarker(locLatlng); - for (i = 0; component = components[i]; i = i + 1) { - if (component.types[0] === 'country') { - country = component.short_name; - choice = document.getElementById('id_country'); - selectItemByValue(choice, country); - } - } + updateCountrySelection(output); } @@ -155,6 +164,7 @@ var Codeweek = window.Codeweek || {}; var updated_location = results[0].geometry.location; createMarker(updated_location); updateLatLng(updated_location.lat(), updated_location.lng()); + updateAddress(updated_location); } }); } @@ -165,7 +175,7 @@ var Codeweek = window.Codeweek || {}; createMap(initialCenter, 4); auto_complete(); getAddress(address); - + listenForPastedAddress(); } var add = function (address) { From 2752f4f73605109d99676ba6e61886e845f943ba Mon Sep 17 00:00:00 2001 From: Alja Isakovic Date: Wed, 13 Aug 2014 21:18:24 +0200 Subject: [PATCH 4/4] refactoring and making the events.js code more readable Getting read of some unused variables, making variable names more readable. --- static/js/events.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/static/js/events.js b/static/js/events.js index 425c4e9d..9ac0c2d5 100644 --- a/static/js/events.js +++ b/static/js/events.js @@ -71,10 +71,9 @@ var Codeweek = window.Codeweek || {}; selectItemByValue(choice, country); } - - function updateAddress(new_position) { + function updateAddress(new_latLng) { geocoder = new google.maps.Geocoder(); - geocoder.geocode({'latLng': new_position}, function (results, status) { + geocoder.geocode({'latLng': new_latLng}, function (results, status) { if (status === google.maps.GeocoderStatus.OK) { document.getElementById("autocomplete").value = results[0].formatted_address; // the last item in the geocoder for latLng results array is the country @@ -127,19 +126,11 @@ var Codeweek = window.Codeweek || {}; } function fillInAddress() { - var place = autocomplete.getPlace(), - components = place.address_components, - output = autocomplete.getPlace().geometry.location, - outputLat = output.lat(), - outputLng = output.lng(), - locLatlng = new google.maps.LatLng(outputLat, outputLng); - - document.getElementById("id_geoposition_0").value = outputLat; - document.getElementById("id_geoposition_1").value = outputLng; - - createMarker(locLatlng); - updateCountrySelection(output); - + // geoLatLng contains the Google Maps geocoded latitude, longitude + var geoLatLng = autocomplete.getPlace().geometry.location; + + createMarker(geoLatLng); + updateAddress(geoLatLng); } function auto_complete() {