1. Johnny Goodnow
  2. hokiefinder

Commits

Johnny Goodnow  committed cca8856

* Added using cached results for pid's and user names.

  • Participants
  • Parent commits f42d612
  • Branches default

Comments (0)

Files changed (2)

File geolocator/views.py

View file
 # 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 = []
+    personList = None
     if request.method == 'POST':
         form = forms.HokieFinderForm(request.POST)
         if form.is_valid():
             query = form.cleaned_data
-            reader = Ldap_Reader(query['filter_type'], query['term'])
-            response = reader.get()
-            for person in response:
-                personInfo = person[1]
-                uupid = personInfo['uupid'][0]
-                name = personInfo['displayName'][0]
-                addr = personInfo['localPostalAddress'][0]
-                geo_loc = google_geocoding.get_location(addr)
-                if geo_loc == None:
-                    continue
-                else:
-                    addr, lat, lng = geo_loc
-                try:
-                    phone = personInfo['localPhone'][0]
-                except KeyError:
-                    phone = None
-                try:
-                    major = personInfo['major'][0]
-                except KeyError:
-                    major = None
-                newPerson = models.Person(pid = uupid, display_name = name, address = addr, phone_number = phone, \
-                    major = major, longitude = lng, latitude = lat)
-                newPerson.save()
-                personList.append(newPerson)
+            queryList = None
+            if query['filter_type'] == 'uupid':
+                queryList = models.Person.objects.filter(pid__icontains=query['term'])
+            elif query['filter_type'] == 'displayName':
+                queryList = models.Person.objects.filter(display_name__icontains=query['term'])
+            if len(queryList) > 0:
+                return render_to_response('index.html', {'form': form, 'results': queryList},
+                                            context_instance=RequestContext(request))                                
+            else:
+                reader = Ldap_Reader(query['filter_type'], query['term'])
+                response = reader.get()
+                personList = []
+                for person in response:
+                    personInfo = person[1]
+                    uupid = personInfo['uupid'][0]
+                    name = personInfo['displayName'][0]
+                    addr = personInfo['localPostalAddress'][0]
+                    geo_loc = google_geocoding.get_location(addr)
+                    if geo_loc == None:
+                        continue
+                    else:
+                        addr, lat, lng = geo_loc
+                    try:
+                        phone = personInfo['localPhone'][0]
+                    except KeyError:
+                        phone = None
+                    try:
+                        major = personInfo['major'][0]
+                    except KeyError:
+                        major = None
+                    newPerson = models.Person(pid = uupid, display_name = name, address = addr, phone_number = phone, \
+                        major = major, longitude = lng, latitude = lat)
+                    newPerson.save()
+                    personList.append(newPerson)
     else:
         form = forms.HokieFinderForm()
     return render_to_response("index.html", {'form': form, 'results': personList},

File resources/database/hokiefinderdb.sqlite3

Binary file modified.