def test_BRStateSelect(self): f = BRStateSelect() out = u'''<select name="states"> <option value="AC">Acre</option> <option value="AL">Alagoas</option> <option value="AP">Amap\xe1</option> <option value="AM">Amazonas</option> <option value="BA">Bahia</option> <option value="CE">Cear\xe1</option> <option value="DF">Distrito Federal</option> <option value="ES">Esp\xedrito Santo</option> <option value="GO">Goi\xe1s</option> <option value="MA">Maranh\xe3o</option> <option value="MT">Mato Grosso</option> <option value="MS">Mato Grosso do Sul</option> <option value="MG">Minas Gerais</option> <option value="PA">Par\xe1</option> <option value="PB">Para\xedba</option> <option value="PR" selected="selected">Paran\xe1</option> <option value="PE">Pernambuco</option> <option value="PI">Piau\xed</option> <option value="RJ">Rio de Janeiro</option> <option value="RN">Rio Grande do Norte</option> <option value="RS">Rio Grande do Sul</option> <option value="RO">Rond\xf4nia</option> <option value="RR">Roraima</option> <option value="SC">Santa Catarina</option> <option value="SP">S\xe3o Paulo</option> <option value="SE">Sergipe</option> <option value="TO">Tocantins</option> </select>''' self.assertHTMLEqual(f.render('states', 'PR'), out)
class Meta: model = Profile exclude = ('user', 'is_bikeanjo', 'service_routes', 'service_accompaniment', 'service_teach', 'service_institute', 'know_tech', 'know_security', 'know_law', 'know_routes', 'agreement_bikeanjo', 'cycling_since', 'commute_by_bike', 'other_groups', 'social_networks', 'active', 'approved', 'revisado') widgets = {'state': BRStateSelect()}
class UserProfileForm(forms.ModelForm): name = forms.RegexField(label=_('Full name'), regex=r'^.+\s+.+$') email = forms.EmailField(label=_('E-mail')) enrollment_year = forms.RegexField(label=_('Enrollment year'), regex=r'^\d{4}$') institution_state = forms.CharField(label=_('State'), widget=BRStateSelect()) birth_date = forms.DateField(label=_('Birth date'), input_formats=['%d/%m/%Y']) class Meta: model = UserProfile exclude = ('user', 'registration_date', 'last_update') fields = [ 'name', 'email', 'birth_date', 'institution_name', 'institution_city', 'institution_state', 'course', 'enrollment_year', ] def save(self, commit, *args, **kwargs): obj = super(UserProfileForm, self).save(commit=commit) if not commit: obj.name = self.cleaned_data['name'] obj.email = self.cleaned_data['email'] return obj def clean_enrollment_year(self): value = int(self.cleaned_data['enrollment_year']) if value > datetime.now().year or value < 1900: raise forms.ValidationError(_('Please enter a valid year')) return value
class Meta: model = Profile exclude = ('user', 'is_bikeanjo', 'revisado' 'approved') widgets = {'state': BRStateSelect()}