예제 #1
0
class EmergContactForm(FormUnrestrictedOtherUser):
    """ Contact form for emergency contacts """

    emerg_first_name = StrippedCharField(length=25, max_length=64)
    emerg_last_name = StrippedCharField(length=30, max_length=64)
    emerg_e_mail = forms.EmailField(required=False)
    emerg_phone_day = USPhoneNumberField()
    emerg_phone_cell = USPhoneNumberField(required=False)
    emerg_address_street = StrippedCharField(length=40, max_length=100)
    emerg_address_city = StrippedCharField(length=20, max_length=50)
    emerg_address_state = forms.ChoiceField(
        choices=zip(_states, _states),
        widget=forms.Select(attrs={'class': 'input-mini'}))
    emerg_address_zip = StrippedCharField(
        length=5,
        max_length=5,
        widget=forms.TextInput(attrs={'class': 'input-small'}))
    emerg_address_postal = forms.CharField(required=False,
                                           widget=forms.HiddenInput())

    def clean(self):
        super(EmergContactForm, self).clean()
        if self.cleaned_data.get('emerg_phone_day',
                                 '') == '' and self.cleaned_data.get(
                                     'emerg_phone_cell', '') == '':
            raise forms.ValidationError(
                "Please provide either a day phone or cell phone for your emergency contact."
            )
        return self.cleaned_data
예제 #2
0
class EmailPrefForm(forms.Form):
    email = ValidHostEmailField(label='E-Mail Address', required=True)
    confirm_email = ValidHostEmailField(
        label="Confirm email",
        help_text="<i>Please type your email address again.</i>")
    first_name = StrippedCharField(label='First Name',
                                   length=30,
                                   max_length=64,
                                   required=True)
    last_name = StrippedCharField(label='Last Name',
                                  length=30,
                                  max_length=64,
                                  required=True)
    sms_number = PhoneNumberField(
        label='Cell Phone',
        required=False,
        help_text=
        'Optional: If you provide us your cell phone number, we can send you SMS text notifications'
    )

    #    sms_opt_in = forms.BooleanField(label='Send Me Text Updates', initial = True, required = False)

    def clean_confirm_email(self):
        if not (('confirm_email' in self.cleaned_data) and
                ('email' in self.cleaned_data)) or (
                    self.cleaned_data['confirm_email'] !=
                    self.cleaned_data['email']):
            raise forms.ValidationError(
                'Ensure that you have correctly typed your email both times.')
        return self.cleaned_data['confirm_email']
예제 #3
0
class UserContactForm(FormUnrestrictedOtherUser, FormWithTagInitialValues):
    """ Base for contact form """

    first_name = StrippedCharField(length=25, max_length=64)
    last_name = StrippedCharField(length=30, max_length=64)
    e_mail = forms.EmailField()
    phone_day = USPhoneNumberField(required=False)
    phone_cell = USPhoneNumberField(required=False)
    receive_txt_message = forms.BooleanField(required=False)
    address_street = StrippedCharField(length=40, max_length=100)
    address_city = StrippedCharField(length=20, max_length=50)
    address_state = forms.ChoiceField(choices=zip(_states,_states))
    address_zip = StrippedCharField(length=5, max_length=5)
    address_postal = forms.CharField(required=False, widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        super(UserContactForm, self).__init__(*args, **kwargs)
        if Tag.getTag('request_student_phonenum', default='True') == 'False':
            del self.fields['phone_day']
        if not Tag.getTag('text_messages_to_students'):
            del self.fields['receive_txt_message']

    def clean(self):
        super(UserContactForm, self).clean()
        if self.user.isTeacher() or Tag.getTag('request_student_phonenum', default='True') != 'False':
            if self.cleaned_data.get('phone_day','') == '' and self.cleaned_data.get('phone_cell','') == '':
                raise forms.ValidationError("Please provide either a day phone or cell phone number in your personal contact information.")
        if self.cleaned_data.get('receive_txt_message', None) and self.cleaned_data.get('phone_cell','') == '':
            raise forms.ValidationError("Please specify your cellphone number if you ask to receive text messages.")
        return self.cleaned_data
예제 #4
0
class GuardContactForm(FormUnrestrictedOtherUser):
    """ Contact form for guardians """

    guard_first_name = StrippedCharField(length=25, max_length=64)
    guard_last_name = StrippedCharField(length=30, max_length=64)
    guard_no_e_mail = forms.BooleanField(required=False)
    guard_e_mail = forms.EmailField(required=False)
    guard_phone_day = USPhoneNumberField()
    guard_phone_cell = USPhoneNumberField(required=False)

    def __init__(self, *args, **kwargs):
        super(GuardContactForm, self).__init__(*args, **kwargs)
    
        if not Tag.getTag('allow_guardian_no_email'):
            if Tag.getTag('require_guardian_email'):
                self.fields['guard_e_mail'].required = True
            del self.fields['guard_no_e_mail']

    def clean_guard_e_mail(self):
        if 'guard_e_mail' not in self.cleaned_data or len(self.cleaned_data['guard_e_mail']) < 3:
            if Tag.getTag('require_guardian_email') and not self.cleaned_data['guard_no_e_mail']:
                if Tag.getTag('allow_guardian_no_email'):
                    raise forms.ValidationError("Please enter the e-mail address of your parent/guardian.  If they do not have access to e-mail, check the appropriate box.")
                else:
                    raise forms.ValidationError("Please enter the e-mail address of your parent/guardian.")
        else:
            return self.cleaned_data['guard_e_mail']

    def clean(self):
        super(GuardContactForm, self).clean()
        if self.cleaned_data.get('guard_phone_day','') == '' and self.cleaned_data.get('guard_phone_cell','') == '':
            raise forms.ValidationError("Please provide either a day phone or cell phone for your parent/guardian.")
        return self.cleaned_data
예제 #5
0
class UserContactForm(FormUnrestrictedOtherUser, FormWithTagInitialValues):
    """ Base for contact form """

    first_name = StrippedCharField(length=25, max_length=64)
    last_name = StrippedCharField(length=30, max_length=64)
    e_mail = forms.EmailField()
    phone_day = USPhoneNumberField(required=False)
    phone_cell = USPhoneNumberField(required=False)
    receive_txt_message = forms.TypedChoiceField(coerce=lambda x: x =='True', choices=((True, 'Yes'),(False, 'No')), widget=forms.RadioSelect)
    address_street = StrippedCharField(required=False, length=40, max_length=100)
    address_city = StrippedCharField(required=False, length=20, max_length=50)
    address_state = forms.ChoiceField(required=False, choices=zip(_states,_states), widget=forms.Select(attrs={'class': 'input-mini'}))
    address_zip = StrippedCharField(required=False, length=5, max_length=5, widget=forms.TextInput(attrs={'class': 'input-small'}))
    address_postal = forms.CharField(required=False, widget=forms.HiddenInput())

    def __init__(self, *args, **kwargs):
        super(UserContactForm, self).__init__(*args, **kwargs)
        if not Tag.getBooleanTag('request_student_phonenum', default=True):
            del self.fields['phone_day']
        if not Tag.getBooleanTag('text_messages_to_students') or not self.user.isStudent():
            del self.fields['receive_txt_message']
        if not self.user.isTeacher() or Tag.getBooleanTag('teacher_address_required', default = True):
            self.fields['address_street'].required = True
            self.fields['address_city'].required = True
            self.fields['address_state'].required = True
            self.fields['address_zip'].required = True

    def clean(self):
        super(UserContactForm, self).clean()
        if self.user.isTeacher() or Tag.getBooleanTag('request_student_phonenum', default=True):
            if self.cleaned_data.get('phone_day','') == '' and self.cleaned_data.get('phone_cell','') == '':
                raise forms.ValidationError("Please provide either a day phone or cell phone number in your personal contact information.")
        if self.cleaned_data.get('receive_txt_message', None) and self.cleaned_data.get('phone_cell','') == '':
            raise forms.ValidationError("Please specify your cellphone number if you ask to receive text messages.")
        return self.cleaned_data
예제 #6
0
class MinimalUserInfo(FormUnrestrictedOtherUser):
    first_name = StrippedCharField(length=25, max_length=64)
    last_name = StrippedCharField(length=30, max_length=64)
    e_mail = forms.EmailField()
    address_street = StrippedCharField(length=40, max_length=100)
    address_city = StrippedCharField(length=20, max_length=50)
    address_state = forms.ChoiceField(choices=zip(_states,_states))
    address_zip = StrippedCharField(length=5, max_length=5)
    address_postal = forms.CharField(required=False, widget=forms.HiddenInput())
예제 #7
0
class GuardContactForm(FormUnrestrictedOtherUser):
    """ Contact form for guardians """

    guard_first_name = StrippedCharField(length=25, max_length=64)
    guard_last_name = StrippedCharField(length=30, max_length=64)
    guard_e_mail = forms.EmailField(required=False)
    guard_phone_day = USPhoneNumberField()
    guard_phone_cell = USPhoneNumberField(required=False)

    def clean(self):
        super(GuardContactForm, self).clean()
        if self.cleaned_data.get('guard_phone_day','') == '' and self.cleaned_data.get('guard_phone_cell','') == '':
            raise forms.ValidationError("Please provide either a day phone or cell phone for your parent/guardian.")
        return self.cleaned_data
예제 #8
0
class EmailPrefForm(forms.Form):
    email = ValidHostEmailField(label='E-Mail Address', required=True)
    first_name = StrippedCharField(label='First Name',
                                   length=30,
                                   max_length=64,
                                   required=True)
    last_name = StrippedCharField(label='Last Name',
                                  length=30,
                                  max_length=64,
                                  required=True)
    sms_number = PhoneNumberField(
        label='Cell Phone',
        required=False,
        help_text=
        'Optional: If you provide us your cell phone number, we can send you SMS text notifications'
    )
예제 #9
0
class TeacherClassRegForm(FormWithRequiredCss):
    location_choices = [(
        True,
        "I will use my own space for this class (e.g. space in my laboratory).  I have explained this in 'Message for Directors' below."
    ), (False, "I would like a classroom to be provided for my class.")]
    lateness_choices = [(
        True,
        "Students may join this class up to 20 minutes after the official start time."
    ), (False, "My class is not suited to late additions.")]
    hardness_choices = [
        (
            "*",
            "*    - Should be understandable to everyone in the class.",
        ),
        (
            "**",
            "**   - Should not be too difficult for most students.",
        ),
        (
            "***",
            "***  - Will move quickly and will have many difficult parts.",
        ),
        (
            "****",
            "**** - You should not expect to be able to understand most of this class.",
        ),
    ]

    # Grr, TypedChoiceField doesn't seem to exist yet
    title = StrippedCharField(label='Course Title', length=50, max_length=200)
    category = forms.ChoiceField(label='Course Category',
                                 choices=[],
                                 widget=BlankSelectWidget())
    class_info = StrippedCharField(
        label='Course Description',
        widget=forms.Textarea(),
        help_text=
        '<span class="tex2jax_ignore">Want to enter math? Use <tt>$$ Your-LaTeX-code-here $$</tt>. (e.g. use $$\pi$$ to mention &pi;)</span>'
    )
    prereqs = forms.CharField(
        label='Course Prerequisites',
        widget=forms.Textarea(attrs={'rows': 4}),
        required=False,
        help_text=
        'If your course does not have prerequisites, leave this box blank.')

    duration = forms.ChoiceField(label='Duration of a Class Meeting',
                                 help_text='(hours:minutes)',
                                 choices=[('0.0', 'Program default')],
                                 widget=BlankSelectWidget())
    num_sections = forms.ChoiceField(
        label='Number of Sections',
        choices=[(1, 1)],
        widget=BlankSelectWidget(),
        help_text=
        '(How many independent sections (copies) of your class would you like to teach?)'
    )
    session_count = forms.ChoiceField(
        label='Number of Days of Class',
        choices=[(1, 1)],
        widget=BlankSelectWidget(),
        help_text='(How many days will your class take to complete?)')

    grade_min = forms.ChoiceField(label='Minimum Grade Level',
                                  choices=[(7, 7)],
                                  widget=BlankSelectWidget())
    grade_max = forms.ChoiceField(label='Maximum Grade Level',
                                  choices=[(12, 12)],
                                  widget=BlankSelectWidget())
    class_size_max = forms.ChoiceField(
        label='Maximum Number of Students',
        choices=[(0, 0)],
        widget=BlankSelectWidget(),
        help_text=
        'The above class-size and grade-range values are absolute, not the "optimum" nor "recommended" amounts. We will not allow any more students than you specify, nor allow any students in grades outside the range that you specify. Please contact us later if you would like to make an exception for a specific student.'
    )
    class_size_optimal = forms.IntegerField(
        label='Optimal Number of Students',
        help_text=
        "This is the number of students you would have in your class in the most ideal situation.  This number is not a hard limit, but we'll do what we can to try to honor this."
    )
    optimal_class_size_range = forms.ChoiceField(
        label='Optimal Class Size Range',
        choices=[(0, 0)],
        widget=BlankSelectWidget())
    allowable_class_size_ranges = forms.MultipleChoiceField(
        label='Allowable Class Size Ranges',
        choices=[(0, 0)],
        widget=forms.CheckboxSelectMultiple(),
        help_text=
        "Please select all class size ranges you are comfortable teaching.")
    hardness_rating = forms.ChoiceField(
        label='Difficulty',
        choices=hardness_choices,
        initial="**",
        help_text=
        "Which best describes how hard your class will be for your students?")
    allow_lateness = forms.ChoiceField(label='Punctuality',
                                       choices=lateness_choices,
                                       widget=forms.RadioSelect())

    has_own_space = forms.ChoiceField(label='Location',
                                      choices=location_choices,
                                      widget=forms.RadioSelect(),
                                      required=False)
    requested_room = forms.CharField(
        label='Room Request',
        required=False,
        help_text=
        'If you have a specific room or type of room in mind, name a room at %s that would be ideal for you.'
        % settings.INSTITUTION_NAME)

    global_resources = forms.MultipleChoiceField(
        label='Equipment and Classroom Options',
        choices=[],
        widget=forms.CheckboxSelectMultiple(),
        required=False,
        help_text=
        "Check all that apply. We can usually supply these common resources at your request. But if your class is truly uncommon, ESP may also have access to unusual rooms and supplies. These can be entered in the next section, 'Special Requests.'"
    )
    resources = forms.MultipleChoiceField(
        label='Other Resources',
        choices=[],
        widget=forms.CheckboxSelectMultiple(),
        required=False)
    requested_special_resources = forms.CharField(
        label='Special Requests',
        widget=forms.Textarea(),
        required=False,
        help_text=
        "Write in any specific resources you need, like a piano, empty room, or kitchen. We cannot guarantee you any of the special resources you request, but we will contact you if we are unable to get you the resources you need. Please include any necessary explanations in the 'Message for Directors' box! "
    )

    purchase_requests = forms.CharField(
        label='Planned Purchases',
        widget=forms.Textarea(),
        required=False,
        help_text=
        'We give all teachers a $30 budget per class section for their classes; we can reimburse you if you turn in an itemized receipt with attached reimbursement form before the end of the program.  If you would like to exceed this budget, please type a budget proposal here stating what you would like to buy, what it will cost, and why you would like to purchase it.'
    )

    message_for_directors = forms.CharField(
        label='Message for Directors',
        widget=forms.Textarea(),
        required=False,
        help_text=
        'Please explain any special circumstances and equipment requests. Remember that you can be reimbursed for up to $30 (or more with the directors\' approval) for class expenses if you submit itemized receipts.'
    )

    def __init__(self, module, *args, **kwargs):
        from esp.program.controllers.classreg import get_custom_fields

        def hide_field(field, default=None):
            field.widget = forms.HiddenInput()
            if default is not None:
                field.initial = default

        def hide_choice_if_useless(field):
            """ Hide a choice field if there's only one choice """
            if len(field.choices) == 1:
                hide_field(field, default=field.choices[0][0])

        super(TeacherClassRegForm, self).__init__(*args, **kwargs)

        prog = module.get_program()

        section_numbers = module.allowed_sections_actual
        section_numbers = zip(section_numbers, section_numbers)

        class_sizes = module.getClassSizes()
        class_sizes = zip(class_sizes, class_sizes)

        class_grades = module.getClassGrades()
        class_grades = zip(class_grades, class_grades)

        class_ranges = ClassSizeRange.get_ranges_for_program(prog)
        class_ranges = [(range.id, range.range_str())
                        for range in class_ranges]

        # num_sections: section_list; hide if useless
        self.fields['num_sections'].choices = section_numbers
        hide_choice_if_useless(self.fields['num_sections'])
        # category: program.class_categories.all()
        self.fields['category'].choices = [
            (x.id, x.category) for x in prog.class_categories.all()
        ]
        # grade_min, grade_max: module.getClassGrades
        self.fields['grade_min'].choices = class_grades
        self.fields['grade_max'].choices = class_grades
        if module.use_class_size_max:
            # class_size_max: module.getClassSizes
            self.fields['class_size_max'].choices = class_sizes
        else:
            del self.fields['class_size_max']

        if Tag.getTag('use_class_size_optimal', default=False):
            if not module.use_class_size_optimal:
                del self.fields['class_size_optimal']

            if module.use_optimal_class_size_range:
                self.fields['optimal_class_size_range'].choices = class_ranges
            else:
                del self.fields['optimal_class_size_range']

            if module.use_allowable_class_size_ranges:
                self.fields[
                    'allowable_class_size_ranges'].choices = class_ranges
            else:
                del self.fields['allowable_class_size_ranges']
        else:
            del self.fields['class_size_optimal']
            del self.fields['optimal_class_size_range']
            del self.fields['allowable_class_size_ranges']

        # global_resources: module.getResourceTypes(is_global=True)
        self.fields['global_resources'].choices = module.getResourceTypes(
            is_global=True)
        # resources: module.getResourceTypes(is_global=False)
        resource_choices = module.getResourceTypes(is_global=False)

        # decide whether to display certain fields
        # resources
        if len(resource_choices) > 0:
            self.fields['resources'].choices = resource_choices
        else:
            self.fields['resources'].widget = forms.HiddenInput()

        # prereqs
        if not module.set_prereqs:
            self.fields['prereqs'].widget = forms.HiddenInput()

        # allow_lateness
        if not module.allow_lateness:
            self.fields['allow_lateness'].widget = forms.HiddenInput()
            self.fields['allow_lateness'].initial = 'False'

        self.fields['duration'].choices = sorted(module.getDurations())
        hide_choice_if_useless(self.fields['duration'])

        # session_count
        if module.session_counts:
            session_count_choices = module.session_counts_ints
            session_count_choices = zip(session_count_choices,
                                        session_count_choices)
            self.fields['session_count'].choices = session_count_choices
        hide_choice_if_useless(self.fields['session_count'])

        # requested_room
        if not module.ask_for_room:
            hide_field(self.fields['requested_room'])

        #   Hide resource fields since separate forms are now being used. - Michael P
        resource_fields = [
            'has_own_space', 'global_resources', 'resources',
            'requested_special_resources'
        ]
        for field in resource_fields:
            self.fields[field].widget = forms.HiddenInput()

        #   Add program-custom form components (for inlining additional questions without
        #   introducing a separate program module)
        custom_fields = get_custom_fields()
        for field_name in custom_fields:
            self.fields[field_name] = custom_fields[field_name]

        #   Modify help text on these fields if necessary.
        custom_helptext_fields = [
            'duration', 'class_size_max', 'num_sections', 'requested_room',
            'message_for_directors', 'purchase_requests', 'class_info'
        ] + custom_fields.keys()
        for field in custom_helptext_fields:
            tag_data = Tag.getTag('teacherreg_label_%s' % field)
            if tag_data:
                self.fields[field].label = tag_data
            tag_data = Tag.getTag('teacherreg_help_text_%s' % field)
            if tag_data:
                self.fields[field].help_text = tag_data

        #   Hide fields as desired.
        tag_data = Tag.getProgramTag('teacherreg_hide_fields', prog)
        if tag_data:
            for field_name in tag_data.split(','):
                hide_field(self.fields[field_name])

        tag_data = Tag.getProgramTag('teacherreg_default_min_grade', prog)
        if tag_data:
            print tag_data
            self.fields['grade_min'].initial = tag_data

        tag_data = Tag.getProgramTag('teacherreg_default_max_grade', prog)
        if tag_data:
            print tag_data
            self.fields['grade_max'].initial = tag_data

        tag_data = Tag.getProgramTag('teacherreg_default_class_size_max', prog)
        if tag_data:
            print tag_data
            self.fields['class_size_max'].initial = tag_data

        #   Rewrite difficulty label/choices if desired:
        if Tag.getTag('teacherreg_difficulty_choices'):
            self.fields['hardness_rating'].choices = json.loads(
                Tag.getTag('teacherreg_difficulty_choices'))
        if Tag.getTag('teacherreg_difficulty_label'):
            self.fields['hardness_rating'].label = Tag.getTag(
                'teacherreg_difficulty_label')

        # plus subprogram section wizard

    def clean(self):
        cleaned_data = self.cleaned_data

        # Make sure grade_min <= grade_max
        # We need to cast here until we can make the ChoiceFields into TypedChoiceFields.
        grade_min = cleaned_data.get('grade_min')
        grade_max = cleaned_data.get('grade_max')
        if grade_min and grade_max:
            grade_min = int(grade_min)
            grade_max = int(grade_max)
            if grade_min > grade_max:
                msg = u'Minimum grade must be less than the maximum grade.'
                self._errors['grade_min'] = forms.util.ErrorList([msg])
                self._errors['grade_max'] = forms.util.ErrorList([msg])
                del cleaned_data['grade_min']
                del cleaned_data['grade_max']

        # Make sure the optimal class size <= maximum class size.
        class_size_optimal = cleaned_data.get('class_size_optimal')
        class_size_max = cleaned_data.get('class_size_max')
        if class_size_optimal and class_size_max:
            class_size_optimal = int(class_size_optimal)
            class_size_max = int(class_size_max)
            if class_size_optimal > class_size_max:
                msg = u'Optimal class size must be less than or equal to the maximum class size.'
                self._errors['class_size_optimal'] = forms.util.ErrorList(
                    [msg])
                self._errors['class_size_max'] = forms.util.ErrorList([msg])
                del cleaned_data['class_size_optimal']
                del cleaned_data['class_size_max']

        if class_size_optimal == '':
            cleaned_data['class_size_optimal'] = None

        # Return cleaned data
        return cleaned_data

    def _get_total_time_requested(self):
        """ Get total time requested. Do not call before validation. """
        return float(self.cleaned_data['duration']) * int(
            self.cleaned_data['num_sections'])
예제 #10
0
class UserRegForm(forms.Form):
    """
    A form for users to register for the ESP web site.
    """
    first_name = StrippedCharField(max_length=30)
    last_name = StrippedCharField(max_length=30)

    username = forms.CharField(min_length=5, max_length=30)

    password = forms.CharField(widget=forms.PasswordInput(), min_length=5)

    confirm_password = forms.CharField(widget=forms.PasswordInput(),
                                       min_length=5)

    #   The choices for this field will be set later in __init__()
    initial_role = forms.ChoiceField(choices=[])

    email = ValidHostEmailField(
        help_text=
        "<i>Please provide an email address that you check regularly.</i>",
        max_length=75,
        widget=HiddenInput)
    confirm_email = ValidHostEmailField(
        label="Confirm email",
        help_text="<i>Please type your email address again.</i>",
        max_length=75,
        widget=HiddenInput)

    def clean_initial_role(self):
        data = self.cleaned_data['initial_role']
        if data == u'':
            raise forms.ValidationError('Please select an initial role')
        return data

    def clean_username(self):
        """ Make sure that 'username' (as provided as input to this form)
            only contains letters and numbers, and doesn't already exist """

        data = self.cleaned_data['username']

        import string
        good_chars = set(string.letters + string.digits)

        set_of_data = set(data)
        if not (good_chars & set_of_data == set_of_data):
            raise forms.ValidationError(
                'Username contains invalid characters.')

        #   Check for duplicate accounts, but avoid triggering for users that are:
        #   - awaiting initial activation
        #   - currently on the e-mail list only (they can be 'upgraded' to a full account)
        awaiting_activation = Q(is_active=False, password__regex='\$(.*)_')
        if ESPUser.objects.filter(username__iexact=data).exclude(
                password='******').exclude(awaiting_activation).count() > 0:
            raise forms.ValidationError('Username already in use.')

        data = data.strip()
        return data

    def clean_confirm_password(self):
        if not (('confirm_password' in self.cleaned_data) and
                ('password' in self.cleaned_data)) or (
                    self.cleaned_data['confirm_password'] !=
                    self.cleaned_data['password']):
            raise forms.ValidationError(
                'Ensure the password and password confirmation are equal.')
        return self.cleaned_data['confirm_password']

    def clean_confirm_email(self):
        if not (('confirm_email' in self.cleaned_data) and
                ('email' in self.cleaned_data)) or (
                    self.cleaned_data['confirm_email'] !=
                    self.cleaned_data['email']):
            raise forms.ValidationError(
                'Ensure that you have correctly typed your email both times.')
        return self.cleaned_data['confirm_email']

    def __init__(self, *args, **kwargs):
        #   Set up the default form
        super(UserRegForm, self).__init__(*args, **kwargs)

        #   Adjust initial_role choices
        role_choices = [(item[0], item[1]['label'])
                        for item in ESPUser.getAllUserTypes()]
        self.fields['initial_role'].choices = [('', 'Pick one...')
                                               ] + role_choices