Patches

I figure these should all be grouped together.

Aspect Ratio

Here is a nice way to keep the aspect ratio correct on uploaded pictures:

in person/models.py, class Person
def save(self):
....if self.picture:
........name = 'media/%s' % self.picture
........im = Image.open(name)
........width, height = im.size
........im = im.resize((200, height*200/width),)
........im.save(name)
....super(Person, self).save()

It will keep the width at a constant 200px, and change the height depending on the aspect ratio. (this is how facebook does it)

Search Feature

Heres some code for a simple search box:
in person/views.py:
from django.db.models import Q
def search(request):
....results = []
....if request.has_key('q'):
........keywords = request['q'].split(" ")
........results = Person.objects.all()
........for x in keywords:
............results = results.filter(Q(first_name__icontains=x) | Q(last_name__icontains=x))
....return render_to_response('person_search.html', {'persons': results })

in urls.py

(r'^search/$', 'directory.person.views.search'),

Here are the templates:
http://acm.cs.umn.edu/~sweecoo/person_search.html
http://acm.cs.umn.edu/~sweecoo/base.html
I can't get the search box to go exactly where I want it, but maybe someone else can fix it.

Search Feature Security

The search page is still not secure. This should secure it.
in person/views.py:
from django.contrib.auth.decorators import login_required
def search(request):
....etc
....return render_to_response('person_search.html', {'persons': results })
search = login_required(search)

Alphabetical Sorting

To sort the names of branches and people by name, heres an easy way to do it:
in person/models.py:
in class BranchArea:
....class Meta:
........ordering = ('name',)

in class Division:
....class Meta:
........ordering = ('name',)

in class Person:
....class Meta:
........ordering = ('last_name','first_name')

Edit Profile Template Correction

if edit.html extend index.html, instead of base.html, it would look a lot nicer:
in templates/profile/edit.html:
first line should be
{% extends "index.html" %}

That should look a ton better.

Latest Updates

Thanks for the patches, Collin--they're all good work. They're now live.

David Salmon