コード例 #1
0
    def __init__(self, user=None, *args, **kwargs):
        from esp.users.models import ESPUser
        super(StudentInfoForm, self).__init__(user, *args, **kwargs)

        self.allow_change_grade_level = Tag.getTag('allow_change_grade_level')

        ## All of these Tags may someday want to be made per-program somehow.
        ## We don't know the current program right now, though...
        show_studentrep_application = Tag.getTag('show_studentrep_application')
        if not show_studentrep_application:
            ## Only enable the Student Rep form optionally.
            del self.fields['studentrep']
        if (not show_studentrep_application
            ) or show_studentrep_application == "no_expl":
            del self.fields['studentrep_expl']

        if not Tag.getTag('show_student_tshirt_size_options'):
            del self.fields['shirt_size']
            del self.fields['shirt_type']
        elif Tag.getTag('studentinfo_shirt_type_selection') == 'False':
            del self.fields['shirt_type']

        if not Tag.getTag('show_student_vegetarianism_options'):
            del self.fields['food_preference']

        #   Allow grade range of students to be customized by a Tag (default is 7-12)
        self.fields['graduation_year'].choices = [('', '')] + [(str(
            ESPUser.YOGFromGrade(x)), str(x)) for x in ESPUser.grade_options()]

        #   Add user's current grade if it is out of range and they have already filled out the profile.
        if user and user.registrationprofile_set.count() > 0:
            user_grade = user.getGrade()
            grade_tup = (str(ESPUser.YOGFromGrade(user_grade)),
                         str(user_grade))
            if grade_tup not in self.fields['graduation_year'].choices:
                self.fields['graduation_year'].choices.insert(0, grade_tup)

        #   Honor several possible Tags for customizing the fields that are displayed.
        if Tag.getTag('show_student_graduation_years_not_grades'):
            current_grad_year = self.ESPUser.current_schoolyear()
            new_choices = []
            for x in self.fields['graduation_year'].choices:
                if len(x[0]) > 0:
                    new_choices.append(
                        (str(x[0]), "%s (%sth grade)" % (x[0], x[1])))
                else:
                    new_choices.append(x)
            self.fields['graduation_year'].choices = new_choices

        if not Tag.getBooleanTag('student_profile_gender_field'):
            del self.fields['gender']

        if not Tag.getTag('ask_student_about_transportation_to_program'):
            del self.fields['transportation']

        if not Tag.getTag('allow_change_grade_level'):
            if 'initial' in kwargs:
                initial_data = kwargs['initial']

                # Disable the age and grade fields if they already exist.
                if 'graduation_year' in initial_data and 'dob' in initial_data:
                    self.fields['graduation_year'].widget.attrs[
                        'disabled'] = "true"
                    self.fields['graduation_year'].required = False
                    self.fields['dob'].widget.attrs['disabled'] = "true"
                    self.fields['dob'].required = False

        #   Add field asking about medical needs if directed by the Tag
        if Tag.getTag('student_medical_needs'):
            self.fields['medical_needs'].widget = forms.Textarea(attrs={
                'cols': 40,
                'rows': 3
            })
        else:
            del self.fields['medical_needs']

        #   The unmatched_school field is for students to opt out of selecting a K12School.
        #   If we don't require a K12School to be selected, don't bother showing that field.
        if not Tag.getBooleanTag('require_school_field', default=False):
            del self.fields['unmatched_school']

        self._user = user
コード例 #2
0
 def __init__(self, *args, **kwargs):
     super(OnSiteRegForm, self).__init__(*args, **kwargs)
     self.fields['grade'].choices = ([('', '')] +
                                     [(x, x)
                                      for x in ESPUser.grade_options()])
コード例 #3
0
    def __init__(self, user=None, *args, **kwargs):
        from esp.users.models import ESPUser
        super(StudentInfoForm, self).__init__(user, *args, **kwargs)

        self.allow_change_grade_level = Tag.getTag('allow_change_grade_level')

        ## All of these Tags may someday want to be made per-program somehow.
        ## We don't know the current program right now, though...
        show_studentrep_application = Tag.getTag('show_studentrep_application')
        if not show_studentrep_application:
            ## Only enable the Student Rep form optionally.
            del self.fields['studentrep']
        if (not show_studentrep_application) or show_studentrep_application == "no_expl":
            del self.fields['studentrep_expl']

        if not Tag.getTag('show_student_tshirt_size_options'):
            del self.fields['shirt_size']
            del self.fields['shirt_type']
        elif Tag.getTag('studentinfo_shirt_type_selection') == 'False':
            del self.fields['shirt_type']

        if not Tag.getTag('show_student_vegetarianism_options'):
            del self.fields['food_preference']

        #   Allow grade range of students to be customized by a Tag (default is 7-12)
        self.fields['graduation_year'].choices = [('','')]+[(str(ESPUser.YOGFromGrade(x)), str(x)) for x in ESPUser.grade_options()]

        #   Add user's current grade if it is out of range and they have already filled out the profile.
        if user and user.registrationprofile_set.count() > 0:
            user_grade = user.getGrade()
            grade_tup = (str(ESPUser.YOGFromGrade(user_grade)), str(user_grade))
            if grade_tup not in self.fields['graduation_year'].choices:
                self.fields['graduation_year'].choices.insert(0, grade_tup)

        #   Honor several possible Tags for customizing the fields that are displayed.
        if Tag.getTag('show_student_graduation_years_not_grades'):
            current_grad_year = self.ESPUser.current_schoolyear()
            new_choices = []
            for x in self.fields['graduation_year'].choices:
                if len(x[0]) > 0:
                    new_choices.append((str(x[0]), "%s (%sth grade)" % (x[0], x[1])))
                else:
                    new_choices.append(x)
            self.fields['graduation_year'].choices = new_choices

        if not Tag.getBooleanTag('student_profile_gender_field'):
            del self.fields['gender']

        if not Tag.getTag('ask_student_about_transportation_to_program'):
            del self.fields['transportation']

        if not Tag.getTag('allow_change_grade_level'):
            if 'initial' in kwargs:
                initial_data = kwargs['initial']

                # Disable the age and grade fields if they already exist.
                if 'graduation_year' in initial_data and 'dob' in initial_data:
                    self.fields['graduation_year'].widget.attrs['disabled'] = "true"
                    self.fields['graduation_year'].required = False
                    self.fields['dob'].widget.attrs['disabled'] = "true"
                    self.fields['dob'].required = False

        #   Add field asking about medical needs if directed by the Tag
        if Tag.getTag('student_medical_needs'):
            self.fields['medical_needs'].widget = forms.Textarea(attrs={'cols': 40, 'rows': 3})
        else:
            del self.fields['medical_needs']

        #   The unmatched_school field is for students to opt out of selecting a K12School.
        #   If we don't require a K12School to be selected, don't bother showing that field.
        if not Tag.getBooleanTag('require_school_field', default=False):
            del self.fields['unmatched_school']

        self._user = user
コード例 #4
0
 def __init__(self, *args, **kwargs):
     super(OnSiteRegForm, self).__init__(*args, **kwargs)
     self.fields['grade'].choices = (
         [('', '')] + [(x, x) for x in ESPUser.grade_options()])