Mercurial > public > sg101
comparison bio/forms.py @ 1078:6bf83070b19f
Convert member search to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 22 Apr 2016 22:20:47 -0500 |
parents | 21c592cac71c |
children | ce6a0c12cbf3 |
comparison
equal
deleted
inserted
replaced
1077:26f2b83e7468 | 1078:6bf83070b19f |
---|---|
7 from StringIO import StringIO | 7 from StringIO import StringIO |
8 | 8 |
9 from django import forms | 9 from django import forms |
10 from django.conf import settings | 10 from django.conf import settings |
11 from django.core.files.base import ContentFile | 11 from django.core.files.base import ContentFile |
12 from django.core.urlresolvers import reverse | |
12 from django.contrib.auth.models import User | 13 from django.contrib.auth.models import User |
13 | 14 |
14 import pytz | 15 import pytz |
15 | 16 |
16 from bio.models import UserProfile | 17 from bio.models import UserProfile |
17 from core.html import image_check | 18 from core.html import image_check |
18 from core.html import ImageCheckError | 19 from core.html import ImageCheckError |
19 from core.images.utils import parse_image, downscale_image_square | 20 from core.images.utils import parse_image, downscale_image_square |
20 from core.markup import site_markup | 21 from core.markup import site_markup |
21 from core.widgets import AutoCompleteUserInput | |
22 | 22 |
23 | 23 |
24 class EditUserForm(forms.ModelForm): | 24 class EditUserForm(forms.ModelForm): |
25 """Form for editing the fields of the User model.""" | 25 """Form for editing the fields of the User model.""" |
26 email = forms.EmailField(label='Email', required=True) | 26 email = forms.EmailField(label='Email', required=True) |
132 | 132 |
133 class SearchUsersForm(forms.Form): | 133 class SearchUsersForm(forms.Form): |
134 """ | 134 """ |
135 A form to search for users. | 135 A form to search for users. |
136 """ | 136 """ |
137 username = forms.CharField(max_length=30, widget=AutoCompleteUserInput()) | 137 username = forms.CharField( |
138 max_length=30, | |
139 widget=forms.TextInput(attrs={ | |
140 'class': 'sg101-autocomplete', | |
141 })) | |
142 | |
143 def __init__(self, *args, **kwargs): | |
144 super(SearchUsersForm, self).__init__(*args, **kwargs) | |
145 url = reverse('core-ajax_users') | |
146 self.fields['username'].widget.attrs['data-autocomplete-url'] = url | |
138 | 147 |
139 def clean_username(self): | 148 def clean_username(self): |
140 username = self.cleaned_data['username'].strip() | 149 username = self.cleaned_data['username'].strip() |
141 try: | 150 try: |
142 User.objects.get(username=username, is_active=True) | 151 User.objects.get(username=username, is_active=True) |
143 except User.DoesNotExist: | 152 except User.DoesNotExist: |
144 raise forms.ValidationError("That username does not exist.") | 153 raise forms.ValidationError("That username does not exist.") |
145 return username | 154 return username |