app/soc/views/helper/surveys.py
changeset 2483 be8a113ee021
parent 2478 985fd974e095
child 2489 7c23f90d87cd
equal deleted inserted replaced
2482:0e544df4d925 2483:be8a113ee021
   593     context['grade_action'] = "/%s/grade/%s/%s/%s" % path
   593     context['grade_action'] = "/%s/grade/%s/%s/%s" % path
   594 
   594 
   595     markup = loader.render_to_string('soc/survey/results.html',
   595     markup = loader.render_to_string('soc/survey/results.html',
   596                                      dictionary=context).strip('\n')
   596                                      dictionary=context).strip('\n')
   597     return markup
   597     return markup
       
   598 
       
   599 
       
   600 def getSurveyResponseFromPost(survey, post_dict):
       
   601   """Returns the data for a SurveyRecord that answer the questions
       
   602      posed in the given Survey's schema.
       
   603 
       
   604   Args:
       
   605       survey: a Survey entity
       
   606       post_dict: dictionary with data from the POST request
       
   607   """
       
   608 
       
   609   # TODO(ljvderijk) deal with the comment fields
       
   610 
       
   611   # get the schema for this survey
       
   612   schema = eval(survey.survey_content.schema)
       
   613 
       
   614   # fill a dictionary with the data to be stored in the SurveyRecord
       
   615   response_dict = {}
       
   616 
       
   617   for name, value in post_dict.items():
       
   618     # make sure name is a string
       
   619     name = name.encode()
       
   620     if name not in schema:
       
   621       # property not in survey schema ignore
       
   622       continue
       
   623     else:
       
   624       pick_multi = schema[name]['type'] == 'pick_multi'
       
   625 
       
   626       if pick_multi and hasattr(post_dict, 'getlist'): # it's a multidict
       
   627         response_dict[name] = ','.join(post_dict.getlist(name))
       
   628       else:
       
   629         response_dict[name] = value
       
   630 
       
   631   return response_dict
   598 
   632 
   599 
   633 
   600 def getRoleSpecificFields(survey, user, this_project, survey_form,
   634 def getRoleSpecificFields(survey, user, this_project, survey_form,
   601                           survey_record):
   635                           survey_record):
   602   """For evaluations, mentors get required Project and Grade fields, and
   636   """For evaluations, mentors get required Project and Grade fields, and