From 933d3285a81ab4959dbcc33aae64762768ca372f Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 7 Apr 2018 23:03:19 -0400 Subject: [PATCH] Show previously used places on the map when selecting the venue for an event to allow reuse. Fixes #49 --- events/admin.py | 2 +- .../get_together/events/show_event.html | 1 + .../get_together/places/create_place.html | 26 ++++++++++++++++--- .../get_together/places/show_place.html | 4 +-- get_together/views/events.py | 2 ++ 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/events/admin.py b/events/admin.py index 01c1966..be22307 100644 --- a/events/admin.py +++ b/events/admin.py @@ -87,7 +87,7 @@ class MemberAdmin(admin.ModelAdmin): admin.site.register(Member, MemberAdmin) class AttendeeAdmin(admin.ModelAdmin): - list_display = ('__str__', 'role', 'status') + list_display = ('__str__', 'role', 'status', 'last_reminded') list_filter = ('role', 'status') admin.site.register(Attendee, AttendeeAdmin) diff --git a/get_together/templates/get_together/events/show_event.html b/get_together/templates/get_together/events/show_event.html index 92c186b..bde73b8 100644 --- a/get_together/templates/get_together/events/show_event.html +++ b/get_together/templates/get_together/events/show_event.html @@ -58,6 +58,7 @@ Place: {% if event.place %} {{ event.place.name }} + {% if can_edit_event %}Change{% endif %} {% elif can_edit_event %} No place selected yet. {% else %} diff --git a/get_together/templates/get_together/places/create_place.html b/get_together/templates/get_together/places/create_place.html index d0270a3..04339db 100644 --- a/get_together/templates/get_together/places/create_place.html +++ b/get_together/templates/get_together/places/create_place.html @@ -8,6 +8,7 @@

Choose your meeting place

{% csrf_token %} + {% include "events/place_form.html" %}

@@ -46,8 +47,8 @@ markers: [], html_addr: null, mapOptions: { - zoom: 4, - center: {lat: 51.8211, lng: 5.591}, + zoom: 12, + center: {lat: {{event.team.city.latitude}}, lng: {{event.team.city.longitude}}}, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false } @@ -72,7 +73,7 @@ name = this.long_name } }); - if (name != "") { + if (name != null && name != "") { $("#id_name").val(name); } $.getJSON("/api/find_city/?country="+country+"&spr="+spr+"&city="+city, @@ -93,7 +94,7 @@ }); if (options.html_lng && options.html_lat) { - if (location.lat() && location.lng()) { + if (location.lat() != null && location.lng() != null) { options.html_lat.val(location.lat()); options.html_lng.val(location.lng()); if (options.html_tz && options.html_country && options.html_continent) { @@ -191,6 +192,23 @@ location = new google.maps.LatLng(options.html_lat.val(), options.html_lng.val()); setMarker(map, location); } + + $.getJSON("/api/places/", function(data) { + for (let place of data) { + var position = new google.maps.LatLng(place['latitude'], place['longitude']) + var marker = new google.maps.Marker({ + position: position, + label: place['name'], + map: map, + }); + google.maps.event.addListener(marker, 'click',function(event) { + $("#id_id").val(place['id']); + $("#id_name").val(place['name']); + showPositionHTML(this.position); + }); + } + return; + }); }); } diff --git a/get_together/templates/get_together/places/show_place.html b/get_together/templates/get_together/places/show_place.html index 24050a9..daac306 100644 --- a/get_together/templates/get_together/places/show_place.html +++ b/get_together/templates/get_together/places/show_place.html @@ -18,7 +18,7 @@ {% block content %}
-
+

{{ place.name }} {% if can_edit_place %} Edit Place @@ -42,7 +42,7 @@ height="400" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/place?key={{ settings.GOOGLE_MAPS_API_KEY }} - &q={{place.name}},{{place.city}}" allowfullscreen> + &q={{place.name}},{{place.city}}" allowfullscreen>

diff --git a/get_together/views/events.py b/get_together/views/events.py index ed298fb..ec298b2 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -142,6 +142,8 @@ def add_place_to_event(request, event_id): elif request.method == 'POST': form = NewPlaceForm(request.POST) if form.is_valid: + if request.POST.get('id', None): + form.instance.id = request.POST.get('id') new_place = form.save() event.place = new_place event.save()