Mercurial > public > sg101
diff gpp/bio/forms.py @ 149:ab7830b067b3
Implement ticket #40. Added a simple way to search for usernames and then view their profile. Moved this ajax username search feature out of the messages app and into core.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 14 Dec 2009 05:07:28 +0000 |
parents | c515b7401078 |
children | 2baadae33f2e |
line wrap: on
line diff
--- a/gpp/bio/forms.py Sun Dec 13 21:57:34 2009 +0000 +++ b/gpp/bio/forms.py Mon Dec 14 05:07:28 2009 +0000 @@ -15,6 +15,7 @@ from django.contrib.auth.models import User from bio.models import UserProfile +from core.widgets import AutoCompleteUserInput class EditUserForm(forms.ModelForm): @@ -112,3 +113,17 @@ def get_filename(self): return self.cleaned_data['avatar_file'].name + +class SearchUsersForm(forms.Form): + """ + A form to search for users. + """ + username = forms.CharField(max_length=30, widget=AutoCompleteUserInput()) + + def clean_username(self): + username = self.cleaned_data['username'] + try: + User.objects.get(username=username, is_active=True) + except User.DoesNotExist: + raise forms.ValidationError("That username does not exist.") + return username