Commits

Johnny Goodnow committed 3d93d7f

* Added query results to the map. Need to still try cache first then
ldap/google and reformat phone number.

Comments (0)

Files changed (4)

geolocator/forms.py

 	term = forms.CharField()
 	filter_type = forms.ChoiceField(initial = 'displayName', choices = FILTER_CHOICES)
 
-	results = []
+	#results = []
 	# TODO For each result in model, do the following:
-	results.append(r"""latlng = new google.maps.LatLng(37.216195,-80.449069);
-        contentString = '<div id="info">'+
-            '<div id="siteNotice">'+
-            '</div>'+
-            '<h1 id="firstHeading" class="firstHeading">displayName</h1>'+
-            '<div id="bodyContent">'+
-            '<p>localPostalAddress</p>'+
-            '<p>localPhone or phone</p>'+
-            '<p>email: uupid@vt.edu</p>'+
-            '<p>Major: major</p>'+
-            '</div>'+
-            '</div>';
+	#results.append(r"""latlng = new google.maps.LatLng(37.216195,-80.449069);
+     #   contentString = '<div id="info">'+
+      #      '<div id="siteNotice">'+
+      #      '</div>'+
+      #      '<h1 id="firstHeading" class="firstHeading">displayName</h1>'+
+      #      '<div id="bodyContent">'+
+      #      '<p>localPostalAddress</p>'+
+      #      '<p>localPhone or phone</p>'+
+      #      '<p>email: uupid@vt.edu</p>'+
+      #      '<p>Major: major</p>'+
+      #      '</div>'+
+      #      '</div>';
 
-        infowindow = new google.maps.InfoWindow({
-            content: contentString
-        });
-        marker = new google.maps.Marker({
-            position: latlng,
-            title: "displayName here"
-        });
-        google.maps.event.addListener(marker, 'click', function() {
-            infowindow.open(map,marker);
-        });
-        marker.setMap(map);""")
+      #  infowindow = new google.maps.InfoWindow({
+      #      content: contentString
+      #  });
+      #  marker = new google.maps.Marker({
+      #      position: latlng,
+      #      title: "displayName here"
+      #  });
+      #  google.maps.event.addListener(marker, 'click', function() {
+      #      infowindow.open(map,marker);
+      #  });
+       # marker.setMap(map);""")

geolocator/views.py

 # Build Google Maps JS calls from geocoded results and stored results
 # If 'Next' button is pressed, get next page of results, repeat above
 def hokie_finder_view(request):
+    personList = []
     if request.method == 'POST':
         form = forms.HokieFinderForm(request.POST)
         if form.is_valid():
                 newPerson = models.Person(pid = uupid, display_name = name, address = addr, phone_number = phone, \
                     major = major, longitude = lng, latitude = lat)
                 newPerson.save()
-				
-            return HttpResponseRedirect('/')
+                personList.append(newPerson)
     else:
         form = forms.HokieFinderForm()
-    return render_to_response("index.html", {'form': form},
+    return render_to_response("index.html", {'form': form, 'results': personList},
                               context_instance=RequestContext(request))
 
 def user_invalid_view(request):

resources/database/hokiefinderdb.sqlite3

Binary file modified.

resources/templates/index.html

         var map = new google.maps.Map(document.getElementById("map_canvas"),
             myOptions);
 
-        {% if form.results %}
-        var contentString, infowindow, marker;
-        {{ form.results }}
+        {% if results %}
+            var contentString, infowindow, marker, latlng;
+            var markers = [];
+            infowindow = new google.maps.InfoWindow();
+            {% for result in results %}
+                latlng = new google.maps.LatLng({{ result.latitude }}, {{ result.longitude }});
+                contentString = '<div id="info">'+
+                    '<div id="siteNotice">'+
+                    '</div>'+
+                    '<h1 id="firstHeading" class="firstHeading">{{ result.display_name }}</h1>'+
+                    '<div id="bodyContent">'+
+                    '<p>{{ result.address }}</p>'+
+                    '<p>Phone: {% if result.phone_number %}{{ result.phone_number }}{% else %}Not Listed{% endif %}</p>'+
+                    '<p>Email: {{ result.pid }}@vt.edu</p>'+
+                    '<p>Major: {% if result.major %}{{ result.major }}{% else %}Not Listed{% endif %}</p>'+
+                    '</div>'+
+                    '</div>';
+                marker = new google.maps.Marker({
+                    position: latlng,
+                    title: "{{ result.display_name }}"
+                });
+                createMarkerEvent(marker, map, contentString, infowindow);
+                marker.setMap(map);
+                markers.push(marker);
+            {% endfor %}
         {% endif %}
     }
+    function createMarkerEvent(marker, map, content, infowindow) {
+        google.maps.event.addListener(marker, 'click', function(event) {
+            infowindow.setContent(content)
+            infowindow.open(map,marker);
+        });
+    }
   </script>
 {% endblock %}
 
     </form>
     {% if form.results %}
         <div id="results">
-            <b>{{form.filter_type}}: {{form.term}}</b> {{form.results.count}} person{{form.results|pluralize}}
+            <!-- <b>{{form.filter_type}}: {{form.term}}</b> {{form.results.count}} person{{form.results|pluralize}} -->
         </div><button>Show 10 more</button>
     {% endif %}
 {% endblock %}