Commits

Johnny Goodnow committed c400ed9

* Fixed bugs with caching users.

  • Participants
  • Parent commits 6e73a8b

Comments (0)

Files changed (4)

File geolocator/ldap_reader.py

 from ldap.controls import SimplePagedResultsControl
 
 class Ldap_Reader:
-	url = 'ldap://directory.vt.edu'
-	basedn = 'ou=People,dc=vt,dc=edu'
-	page_size = 10
+    url = 'ldap://directory.vt.edu'
+    basedn = 'ou=People,dc=vt,dc=edu'
+    page_size = 10
 
-	def __init__(self, search_key, search_value):
-		self.con = ldap.initialize(self.__class__.url)
-		self.con.protocol_version = 3
-		self.con.simple_bind_s()
-	
-		self.control = SimplePagedResultsControl(
-			ldap.LDAP_CONTROL_PAGE_OID, True, (self.__class__.page_size, '')
-		)
-		if search_key is 'uupid':
-			self.search_filter = r'(&(!(suppressedAttribute=localPostalAddress))(uupid=*' + search_value + '*))'
-		elif search_key is 'displayName':
-			self.search_filter = r'(&(!(suppressedAttribute=localPostalAddress))(displayName=*' + search_value + '*))'
-		elif search_key is 'major':
-			self.search_filter = r'(&(!(suppressedAttribute=localPostalAddress))(major=*' + search_value + '*))'
-		else:
-			raise ValueError('Searched by an unsupported key')	
+    def __init__(self, search_key, search_value):
+        self.con = ldap.initialize(self.__class__.url)
+        self.con.protocol_version = 3
+        self.con.simple_bind_s()
+    
+        self.control = SimplePagedResultsControl(
+            ldap.LDAP_CONTROL_PAGE_OID, True, (self.__class__.page_size, '')
+        )
+        if search_key == 'uupid':
+            self.search_filter = r'(&(!(suppressedAttribute=localPostalAddress))(uupid=*' + search_value + '*))'
+        elif search_key == 'displayName':
+            self.search_filter = r'(&(!(suppressedAttribute=localPostalAddress))(displayName=*' + search_value + '*))'
+        elif search_key == 'major':
+            self.search_filter = r'(&(!(suppressedAttribute=localPostalAddress))(major=*' + search_value + '*))'
+        else:
+            raise ValueError('Searched by an unsupported key')    
 
-		self.msgid = self.con.search_ext(
-			self.__class__.basedn,
-			ldap.SCOPE_SUBTREE,
-			self.search_filter,
-			serverctrls=[self.control]
-		)
+        self.msgid = self.con.search_ext(
+            self.__class__.basedn,
+            ldap.SCOPE_SUBTREE,
+            self.search_filter,
+            serverctrls=[self.control]
+        )
 
-	def get(self):
-		rtype, rdata, rmsgid, serverctrls = self.con.result3(self.msgid)
-		pctrls = [c for c in serverctrls if c.controlType == ldap.LDAP_CONTROL_PAGE_OID]
-		if pctrls:
-			est, cookie = pctrls[0].controlValue
-			if cookie:
-				self.control.controlValue = (self.__class__.page_size, cookie)
-				self.msgid = self.con.search_ext(
-					self.__class__.basedn,
-					ldap.SCOPE_SUBTREE,
-					self.search_filter,
-					serverctrls=[self.control],
-					)
-		else:
-			raise Warning("Warning:  Server ignores RFC 2696 control.")
-		for person in rdata:
-			info = person[1]
-			if 'localPostalAddress' in info:
-				info['localPostalAddress'][0] = info['localPostalAddress'][0].replace('$',',')
+    def get(self):
+        rtype, rdata, rmsgid, serverctrls = self.con.result3(self.msgid)
+        pctrls = [c for c in serverctrls if c.controlType == ldap.LDAP_CONTROL_PAGE_OID]
+        if pctrls:
+            est, cookie = pctrls[0].controlValue
+            if cookie:
+                self.control.controlValue = (self.__class__.page_size, cookie)
+                self.msgid = self.con.search_ext(
+                    self.__class__.basedn,
+                    ldap.SCOPE_SUBTREE,
+                    self.search_filter,
+                    serverctrls=[self.control],
+                    )
+        else:
+            raise Warning("Warning:  Server ignores RFC 2696 control.")
+        for person in rdata:
+            info = person[1]
+            if 'localPostalAddress' in info:
+                info['localPostalAddress'][0] = info['localPostalAddress'][0].replace('$',',')
 
-		return rdata
+        return rdata
 
-	def close(self):
-		self.con.unbind()
+    def close(self):
+        self.con.unbind()

File geolocator/views.py

 from django.contrib import auth
 from django.http import HttpResponseRedirect
 
-import hokiefinder.geolocator.google_geocoding
+from hokiefinder.geolocator import google_geocoding
 from hokiefinder.geolocator import models
 from hokiefinder.geolocator import forms
 from hokiefinder.geolocator.ldap_reader import Ldap_Reader
 
+
 # TODO Pass query to ldap reader
 # Store results in database, check if we have cached geocoded results
 # Geocode results not yet geocoded in cache
         form = forms.HokieFinderForm(request.POST)
         if form.is_valid():
             query = form.cleaned_data
-            reader = Ldap_Reader(query['term'], query['filter_type'])
+            print query['filter_type']
+            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]
-				addr, lat, lng = google_geocoding(addr)
-				if addr == None:
-					continue
-				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()
+            for person in response:
+                personInfo = person[1]
+                uupid = personInfo['uupid'][0]
+                name = personInfo['displayName'][0]
+                addr = personInfo['localPostalAddress'][0]
+                addr, lat, lng = google_geocoding.get_location(addr)
+                if addr == None:
+                    continue
+                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()
 				
             return HttpResponseRedirect('/')
     else:

File resources/database/hokiefinderdb.sqlite3

Binary file modified.
     (r'^accounts/login/$', views.user_login_view),
     (r'^accounts/logout/$', views.user_logout_view),
     (r'^accounts/logout/success/$', views.user_logout_complete_view),
-    (r'^friends/$', views.friends_view),
+    #(r'^friends/$', views.friends_view),
 
     (r'^static_media/(?P<path>.*)$', 'django.views.static.serve',
         {'document_root': settings.STATIC_MEDIA_ROOT}),