class EducatorInfoForm(FormWithRequiredCss): """ Extra educator-specific information """ subject_taught = SizedCharField(length=12, max_length=64, required=False) grades_taught = SizedCharField(length=10, max_length=16, required=False) school = SizedCharField(length=24, max_length=128, required=False) position = SizedCharField(length=10, max_length=32, required=False)
class UserPasswdForm(FormWithRequiredCss): password = SizedCharField(length=12, max_length=32, widget=forms.PasswordInput()) newpasswd = SizedCharField(length=12, max_length=32, widget=forms.PasswordInput()) newpasswdconfirm = SizedCharField(length=12, max_length=32, widget=forms.PasswordInput()) def __init__(self, user, *args, **kwargs): self.user = user super(UserPasswdForm, self).__init__(*args, **kwargs) def clean_password(self): if self.user is None: raise forms.ValidationError('Error: Not logged in.') current_passwd = self.cleaned_data['password'] if not self.user.check_password(current_passwd): raise forms.ValidationError(mark_safe('As a security measure, please enter your <strong>current</strong> password.')) return current_passwd def clean_newpasswdconfirm(self): new_passwd = self.cleaned_data['newpasswdconfirm'].strip() if not 'newpasswd' in self.cleaned_data: raise forms.ValidationError('Invalid password; confirmation failed') if self.cleaned_data['newpasswd'] != new_passwd: raise forms.ValidationError('Password and confirmation are not equal.') return new_passwd
class TeacherInfoForm(FormWithRequiredCss): """ Extra teacher-specific information """ from esp.users.models import shirt_sizes, shirt_types reimbursement_choices = [(False, 'I will pick up my reimbursement.'), (True, 'Please mail me my reimbursement.')] from_here_answers = [ (True, "Yes"), (False, "No") ] graduation_year = SizedCharField(length=4, max_length=4, required=False) is_graduate_student = forms.BooleanField(required=False, label='Graduate student?') from_here = forms.ChoiceField(choices=from_here_answers, widget = forms.RadioSelect(), label='Are you currently enrolled at %s?' % settings.INSTITUTION_NAME) school = SizedCharField(length=24, max_length=128, required=False) major = SizedCharField(length=30, max_length=32, required=False) shirt_size = forms.ChoiceField(choices=([('','')]+list(shirt_sizes)), required=False) shirt_type = forms.ChoiceField(choices=([('','')]+list(shirt_types)), required=False) full_legal_name = SizedCharField(length=24, max_length=128, required=False) university_email = forms.EmailField(required=False) student_id = SizedCharField(length=24, max_length=128, required=False) mail_reimbursement = forms.ChoiceField(choices=reimbursement_choices, widget=forms.RadioSelect(), required=False) def __init__(self, *args, **kwargs): super(TeacherInfoForm, self).__init__(*args, **kwargs) if not Tag.getTag('teacherinfo_reimbursement_options', default=False): reimbursement_fields = ['full_legal_name', 'university_email', 'student_id', 'mail_reimbursement'] for field_name in reimbursement_fields: del self.fields[field_name] if Tag.getTag('teacherinfo_shirt_options') == 'False': del self.fields['shirt_size'] del self.fields['shirt_type'] elif Tag.getTag('teacherinfo_shirt_type_selection') == 'False': del self.fields['shirt_type'] if Tag.getTag('teacherinfo_shirt_size_required'): self.fields['shirt_size'].required = True self.fields['shirt_size'].widget.attrs['class'] = 'required' if Tag.getTag('teacherinfo_reimbursement_checks') == 'False': del self.fields['mail_reimbursement'] def clean(self): super(TeacherInfoForm, self).clean() cleaned_data = self.cleaned_data # If teacher is not from MIT, make sure they've filled in the next box from_here = cleaned_data.get('from_here') school = cleaned_data.get('school') if from_here == "False" and school == "": msg = u'Please enter your affiliation if you are not from %s.' % settings.INSTITUTION_NAME self._errors['school'] = forms.util.ErrorList([msg]) del cleaned_data['from_here'] del cleaned_data['school'] return cleaned_data
class AlumProfileForm(MinimalUserInfo, FormWithTagInitialValues): """ This is the visiting-teacher contact form as used by UChicago's Ripple program """ graduation_year = SizedCharField(length=4, max_length=4, required=False) major = SizedCharField(length=30, max_length=32, required=False) def clean_graduation_year(self): gy = self.cleaned_data['graduation_year'].strip() try: gy = str(abs(int(gy))) except: if gy != 'G': gy = 'N/A' return gy
class VisitingGenericUserProfileForm(MinimalUserInfo, FormWithTagInitialValues): """ This is a form for a generic visitor user """ major = SizedCharField(length=30, max_length=32, label="Profession", required=False)
class TeacherInfoForm(FormWithRequiredCss): """ Extra teacher-specific information """ from esp.users.models import shirt_sizes, shirt_types reimbursement_choices = [(False, 'I will pick up my reimbursement.'), (True, 'Please mail me my reimbursement.')] from_here_answers = [(True, "Yes"), (False, "No")] graduation_year = SizedCharField(length=4, max_length=4, required=False) is_graduate_student = forms.BooleanField(required=False, label='Graduate student?') from_here = forms.ChoiceField(choices=from_here_answers, widget=forms.RadioSelect(), label='Are you currently enrolled at %s?' % settings.INSTITUTION_NAME) school = SizedCharField(length=24, max_length=128, required=False) major = SizedCharField(length=30, max_length=32, required=False) shirt_size = forms.ChoiceField(choices=([('', '')] + list(shirt_sizes)), required=False) shirt_type = forms.ChoiceField(choices=([('', '')] + list(shirt_types)), required=False) def __init__(self, *args, **kwargs): super(TeacherInfoForm, self).__init__(*args, **kwargs) if Tag.getTag('teacherinfo_shirt_options') == 'False': del self.fields['shirt_size'] del self.fields['shirt_type'] elif Tag.getTag('teacherinfo_shirt_type_selection') == 'False': del self.fields['shirt_type'] def clean(self): super(TeacherInfoForm, self).clean() cleaned_data = self.cleaned_data # If teacher is not from MIT, make sure they've filled in the next box from_here = cleaned_data.get('from_here') school = cleaned_data.get('school') if from_here == "False" and school == "": msg = u'Please enter your affiliation if you are not from %s.' % settings.INSTITUTION_NAME self.add_error('school', msg) return cleaned_data
class TeacherInfoForm(FormWithRequiredCss): """ Extra teacher-specific information """ from esp.users.models import shirt_sizes, shirt_types reimbursement_choices = [(False, 'I will pick up my reimbursement.'), (True, 'Please mail me my reimbursement.')] from_here_answers = [ (True, "Yes"), (False, "No") ] graduation_year = SizedCharField(length=4, max_length=4, required=False) affiliation = DropdownOtherField(required=False, widget=DropdownOtherWidget(choices=AFFILIATION_CHOICES), label ='What is your affiliation with %s?' % settings.INSTITUTION_NAME) major = SizedCharField(length=30, max_length=32, required=False) shirt_size = forms.ChoiceField(choices=([('','')]+list(shirt_sizes)), required=False) shirt_type = forms.ChoiceField(choices=([('','')]+list(shirt_types)), required=False) def __init__(self, *args, **kwargs): super(TeacherInfoForm, self).__init__(*args, **kwargs) if Tag.getTag('teacherinfo_shirt_options') == 'False': del self.fields['shirt_size'] del self.fields['shirt_type'] elif Tag.getTag('teacherinfo_shirt_type_selection') == 'False': del self.fields['shirt_type'] def clean(self): super(TeacherInfoForm, self).clean() cleaned_data = self.cleaned_data affiliation_field = self.fields['affiliation'] affiliation, school = affiliation_field.widget.decompress(cleaned_data.get('affiliation')) if affiliation == '': msg = u'Please select your affiliation with %s.' % settings.INSTITUTION_NAME self.add_error('affiliation', msg) elif affiliation in (AFFILIATION_UNDERGRAD, AFFILIATION_GRAD, AFFILIATION_POSTDOC): cleaned_data['affiliation'] = affiliation_field.compress([affiliation, '']) # ignore the box else: # OTHER or NONE -- Make sure they entered something into the other box if school.strip() == '': msg = u'Please select your affiliation with %s.' % settings.INSTITUTION_NAME if affiliation == AFFILIATION_OTHER: msg = u'Please enter your affiliation with %s.' % settings.INSTITUTION_NAME elif affiliation == AFFILIATION_NONE: msg = u'Please enter your school or employer.' self.add_error('affiliation', msg) return cleaned_data
class UofCProfileForm(MinimalUserInfo, FormWithTagInitialValues): graduation_year = forms.ChoiceField(choices=zip(_grad_years, _grad_years)) major = SizedCharField(length=30, max_length=32, required=False) def clean_graduation_year(self): gy = self.cleaned_data['graduation_year'].strip() try: gy = str(abs(int(gy))) except: if gy != 'G': gy = 'N/A' return gy
class UofCProfForm(MinimalUserInfo, FormWithTagInitialValues): major = SizedCharField(length=30, max_length=32, label="Department", required=False)
class VisitingUserInfo(FormUnrestrictedOtherUser): profession = SizedCharField(length=12, max_length=64, required=False)