app/soc/views/models/grading_project_survey.py
changeset 2564 81b36f56d61a
parent 2542 a9dec4763c6b
child 2576 7a1138f8a0e2
equal deleted inserted replaced
2563:eec0d98b38a1 2564:81b36f56d61a
   153       grade_choices: pair of tuples representing the grading choices
   153       grade_choices: pair of tuples representing the grading choices
   154     """
   154     """
   155 
   155 
   156     self.grade_choices = kwargs.pop('grade_choices', None)
   156     self.grade_choices = kwargs.pop('grade_choices', None)
   157 
   157 
   158     if self.grade_choices:
       
   159       # add grade field to self.data, respecting the data kwarg if present
       
   160       if kwargs.get('data') and kwargs['data'].get('grade'):
       
   161         data = {}
       
   162         data['grade'] = kwargs['data']['grade']
       
   163         self.data = data
       
   164 
       
   165     super(GradeSurveyTakeForm, self).__init__(*args, **kwargs)
   158     super(GradeSurveyTakeForm, self).__init__(*args, **kwargs)
       
   159 
       
   160   def setCleaners(self, post_dict=None):
       
   161     """Ensures that the grade field is added to the clean data.
       
   162 
       
   163     For args see surveys.SurveyTakeForm.setCleaners().
       
   164     """
       
   165 
       
   166     clean_data = super(GradeSurveyTakeForm, self).setCleaners(
       
   167         post_dict=post_dict)
       
   168 
       
   169     if post_dict:
       
   170       clean_data['grade'] = post_dict.get('grade', None)
       
   171 
       
   172     return clean_data
   166 
   173 
   167   def clean_grade(self):
   174   def clean_grade(self):
   168     """Validate the grade field.
   175     """Validate the grade field.
   169     """
   176     """
   170 
   177 
   184     # fetch value from post_dict if it's there
   191     # fetch value from post_dict if it's there
   185     post_dict = post_dict or {}
   192     post_dict = post_dict or {}
   186     grade = post_dict.get('grade', None)
   193     grade = post_dict.get('grade', None)
   187 
   194 
   188     # otherwise, try to fetch from survey_record
   195     # otherwise, try to fetch from survey_record
   189     if not grade and hasattr(self.survey_record, 'grade'):
   196     if grade == None and hasattr(self.survey_record, 'grade'):
   190       grade = self.survey_record.grade
   197       grade = self.survey_record.grade
   191 
   198 
   192     # remap bool to string values as the ChoiceField validates on 'choices'.
   199     # remap bool to string values as the ChoiceField validates on 'choices'.
   193     vals_grade = {True: 'pass', False: 'fail'}
   200     vals_grade = {True: 'pass', False: 'fail'}
   194 
   201