comparison 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
comparison
equal deleted inserted replaced
148:35a0e6345815 149:ab7830b067b3
13 from django.conf import settings 13 from django.conf import settings
14 from django.core.files.base import ContentFile 14 from django.core.files.base import ContentFile
15 from django.contrib.auth.models import User 15 from django.contrib.auth.models import User
16 16
17 from bio.models import UserProfile 17 from bio.models import UserProfile
18 from core.widgets import AutoCompleteUserInput
18 19
19 20
20 class EditUserForm(forms.ModelForm): 21 class EditUserForm(forms.ModelForm):
21 """Form for editing the fields of the User model.""" 22 """Form for editing the fields of the User model."""
22 email = forms.EmailField(label='Email', required=True) 23 email = forms.EmailField(label='Email', required=True)
110 return None 111 return None
111 112
112 def get_filename(self): 113 def get_filename(self):
113 return self.cleaned_data['avatar_file'].name 114 return self.cleaned_data['avatar_file'].name
114 115
116
117 class SearchUsersForm(forms.Form):
118 """
119 A form to search for users.
120 """
121 username = forms.CharField(max_length=30, widget=AutoCompleteUserInput())
122
123 def clean_username(self):
124 username = self.cleaned_data['username']
125 try:
126 User.objects.get(username=username, is_active=True)
127 except User.DoesNotExist:
128 raise forms.ValidationError("That username does not exist.")
129 return username