# HG changeset patch # User Madhusudan.C.S # Date 1253044998 -7200 # Node ID ac4f93519855b80eb148387269f26106697379b4 # Parent effa1cfb36070d35bfc12fb968c1ea6854e2f28e Changed the Student Model cleaner to deal with the new Student properties. Patch by: Madhusudan.C.S and Lennard de Rijk Reviewed by: to-be-reviewed diff -r effa1cfb3607 -r ac4f93519855 app/soc/logic/cleaning.py --- a/app/soc/logic/cleaning.py Tue Sep 15 22:01:16 2009 +0200 +++ b/app/soc/logic/cleaning.py Tue Sep 15 22:03:18 2009 +0200 @@ -673,13 +673,20 @@ return wrapper -def validate_student_age(birth_date_field, scope_field, - program_logic): - """Checks if the student has eligibility to sign up, given +def validate_student(birth_date_field, school_type_field, major_field, + degree_field, grade_field, scope_field, program_logic): + """Checks if the student is eligible to sign up, determined by his birth_date given in field_name. + Also checks if the school information has been correctly filled in. + Args: - birth_date_field: Field containing birth_date of student + birth_date_field: Field containing birth_date of student + school_type_field: The field containing the type of student + major_field: The field containing the major of a University student + degree_field: The field containing the type of degree for a University + student + grade_field: The field containing the grade of a High School student scope_field: Field containing scope_path of the student entity program_logic: Logic instance of the program @@ -707,6 +714,25 @@ raise forms.ValidationError( ugettext("No valid program found")) + school_type = cleaned_data.get(school_type_field) + major = cleaned_data.get(major_field) + degree = cleaned_data.get(degree_field) + + # if school_type is University, check for major + if school_type == 'University' and not major: + raise forms.ValidationError("Major cannot be left blank.") + + # if school_type is University, check for degree + if school_type == 'University' and not degree: + raise forms.ValidationError("Degree must be selected from " + "the given options.") + + grade = cleaned_data.get(grade_field) + + # if school_type is High School check for grade + if school_type == 'High School' and not grade: + raise forms.ValidationError("Grade cannot be left blank.") + if entity.student_min_age and entity.student_min_age_as_of: # only check if both the min_age and min_age_as_of are defined min_year = entity.student_min_age_as_of.year - entity.student_min_age @@ -748,7 +774,7 @@ rights = params['rights'] user = user_logic.getForCurrentAccount() - + # pylint: disable-msg=E1103 rights.setCurrentUser(user.account, user) diff -r effa1cfb3607 -r ac4f93519855 app/soc/views/models/student.py --- a/app/soc/views/models/student.py Tue Sep 15 22:01:16 2009 +0200 +++ b/app/soc/views/models/student.py Tue Sep 15 22:03:18 2009 +0200 @@ -18,6 +18,7 @@ """ __authors__ = [ + '"Madhusudan.C.S." ', '"Lennard de Rijk" ' ] @@ -91,6 +92,9 @@ new_params['module_name'] = "student" new_params['sidebar_grouping'] = 'Students' + new_params['create_template'] = 'soc/student/edit.html' + new_params['edit_template'] = 'soc/student/edit.html' + # add apply pattern patterns = [(r'^%(url_name)s/(?Papply)/%(scope)s$', '%(module_package)s.%(module_name)s.apply', @@ -112,8 +116,8 @@ 'expected_graduation': forms.TypedChoiceField( choices=[(x,x) for x in allowed_years], coerce=lambda val: int(val) - ) - } + ), + } new_params['create_dynafields'] = [ {'name': 'scope_path', @@ -147,8 +151,9 @@ 'link_id': forms.CharField(widget=forms.HiddenInput, required=True), 'clean_link_id': cleaning.clean_user_is_current('link_id'), - 'clean': cleaning.validate_student_age( - 'birth_date', 'scope_path', self._logic.getScopeLogic().logic), + 'clean': cleaning.validate_student( + 'birth_date', 'school_type', 'major', 'degree', 'grade', + 'scope_path', self._logic.getScopeLogic().logic), } user_create_form = dynaform.extendDynaForm(