Commits

Johnny Goodnow committed 9d5c67e

* Added proper formatting for phone numbers (it even works with google voice now!)

  • Participants
  • Parent commits 3d93d7f
  • Branches mapsmarkers

Comments (0)

Files changed (4)

geolocator/models.py

 from django.contrib.auth.models import User
 
 class Person(models.Model):
-	pid = models.CharField(max_length = 50, primary_key = True)
-	display_name = models.CharField(max_length = 30)
-	address = models.CharField(max_length = 120)
-	phone_number = models.PositiveIntegerField(null = True)
-	major = models.CharField(max_length = 30, null = True)
-	longitude = models.FloatField()
-	latitude = models.FloatField()
+    pid = models.CharField(max_length = 50, primary_key = True)
+    display_name = models.CharField(max_length = 30)
+    address = models.CharField(max_length = 120)
+    phone_number = models.PositiveIntegerField(null = True)
+    major = models.CharField(max_length = 30, null = True)
+    longitude = models.FloatField()
+    latitude = models.FloatField()
+    
+    def display_number(self):
+        if not self.phone_number:
+            return None
+        number = str(self.phone_number)
+        length = len(number)
+        if length > 10:
+            number = '+%s (%s)-%s-%s' % (number[:-10], number[-10:-7], number[-7:-4], number[-4:])
+        elif length == 10:
+            number = '(%s)-%s-%s' % (number[0:3], number[3:6], number[6:])
+        return number
 
-	def __unicode__(self):
-		return self.display_name
+    def __unicode__(self):
+        return self.display_name
 
-	class Meta:
-		verbose_name = 'person'
-		verbose_name_plural = 'people'
-		db_table = 'geolocator_people'
+    class Meta:
+        verbose_name = 'person'
+        verbose_name_plural = 'people'
+        db_table = 'geolocator_people'
 
 class UserProfile(models.Model):
-	friends = models.ManyToManyField(Person)
-	user = models.OneToOneField(User)
+    friends = models.ManyToManyField(Person)
+    user = models.OneToOneField(User)

geolocator/views.py

         form = forms.HokieFinderForm(request.POST)
         if form.is_valid():
             query = form.cleaned_data
-            print query['filter_type']
             reader = Ldap_Reader(query['filter_type'], query['term'])
             response = reader.get()
             for person in response:

resources/database/hokiefinderdb.sqlite3

Binary file modified.

resources/templates/index.html

                     '<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>Phone: {% if result.phone_number %}{{ result.display_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>'+