You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by rg...@apache.org on 2009/12/29 18:19:58 UTC

svn commit: r894448 - in /comdev/nearby_people: nearby/views.py readme.txt urls.py

Author: rgardler
Date: Tue Dec 29 17:19:57 2009
New Revision: 894448

URL: http://svn.apache.org/viewvc?rev=894448&view=rev
Log:
Add ability to retrieve the data as a JSON file

Modified:
    comdev/nearby_people/nearby/views.py
    comdev/nearby_people/readme.txt
    comdev/nearby_people/urls.py

Modified: comdev/nearby_people/nearby/views.py
URL: http://svn.apache.org/viewvc/comdev/nearby_people/nearby/views.py?rev=894448&r1=894447&r2=894448&view=diff
==============================================================================
--- comdev/nearby_people/nearby/views.py (original)
+++ comdev/nearby_people/nearby/views.py Tue Dec 29 17:19:57 2009
@@ -23,6 +23,7 @@
 from nearby_people.nearby.shortcuts import *
 
 import geoname
+import json
 #geoname.DEBUG=1
 
 comdev_foaf = FOAF(COMDEV_DOAP)
@@ -65,7 +66,10 @@
 	})
 
 def find_people(request):
-	form = LocationForm(request.GET)
+	data = retrieve_people_data(LocationForm(request.GET))
+	return render(request, "people.html", data)
+
+def retrieve_people_data(form):
 	if not form.is_valid():
 		return HttpResponseRedirect("/pick_place/?location_missing")
 
@@ -92,10 +96,15 @@
 	center_lat = (min_lat+max_lat)/2
 	center_long = (min_long+max_long)/2
 
-	# All done
-	return render(request, "people.html", {
+	data = {
 		'location': location, 'people':people,
 		'center_lat': center_lat, 'center_long': center_long,
 		'bl_lat': min_lat, 'bl_long': min_long,
 		'tr_lat': max_lat, 'tr_long': max_long,
-	})
+	}
+	
+	return data
+	
+def find_people_json(request):
+	data = retrieve_people_data(LocationForm(request.GET))
+	return HttpResponse(json.dumps(data), mimetype='application/javascript')

Modified: comdev/nearby_people/readme.txt
URL: http://svn.apache.org/viewvc/comdev/nearby_people/readme.txt?rev=894448&r1=894447&r2=894448&view=diff
==============================================================================
--- comdev/nearby_people/readme.txt (original)
+++ comdev/nearby_people/readme.txt Tue Dec 29 17:19:57 2009
@@ -17,6 +17,24 @@
 Copy local_settings.py.example to local_settings.py and tell it where the checkouts are. 
 Finally, do ./manage.py runserver and then http://localhost:8000/ will be it.
 
+RESTful API
+===========
+
+If you want to write an alternative interface to the data we provide a RESTful API as follows:
+
+Find people nearby
+------------------
+
+http://localhost:8000//find_people_json/?latitude=51.7522210026&longitude=-1.25596046448&type=lm
+
+Will return a JSON file containing the people nearby the point defined in the
+latitude and longitude values.
+
+Type is either "lm" for "local mentors" or "sp" for "speakers"
+
+Links
+=====
+
 [1] https://svn.apache.org/repos/asf/comdev/nearby_people
 [2] https://svn.apache.org/repos/private/committers/info
 [3] https://svn.apache.org/repos/asf/comdev/subprojects  
\ No newline at end of file

Modified: comdev/nearby_people/urls.py
URL: http://svn.apache.org/viewvc/comdev/nearby_people/urls.py?rev=894448&r1=894447&r2=894448&view=diff
==============================================================================
--- comdev/nearby_people/urls.py (original)
+++ comdev/nearby_people/urls.py Tue Dec 29 17:19:57 2009
@@ -25,6 +25,7 @@
 	(r'^$',              'nearby_people.nearby.views.welcome'),
 	(r'^pick_place/$',  'nearby_people.nearby.views.pick_place'),
 	(r'^find_people/$', 'nearby_people.nearby.views.find_people'),
+	(r'^find_people_json/$', 'nearby_people.nearby.views.find_people_json'),
 
     # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
     # to INSTALLED_APPS to enable admin documentation: