app/soc/views/helper/surveys.py
changeset 2506 c98bf890156e
parent 2502 2e096acc8720
child 2507 4a6b8d6674b6
equal deleted inserted replaced
2505:77ac8273f7a2 2506:c98bf890156e
   770     context['grade_action'] = "/%s/grade/%s/%s/%s" % path
   770     context['grade_action'] = "/%s/grade/%s/%s/%s" % path
   771 
   771 
   772     markup = loader.render_to_string('soc/survey/results.html',
   772     markup = loader.render_to_string('soc/survey/results.html',
   773                                      dictionary=context).strip('\n')
   773                                      dictionary=context).strip('\n')
   774     return markup
   774     return markup
   775 
       
   776 
       
   777 def getSurveyResponseFromPost(survey, post_dict):
       
   778   """Returns the data for a SurveyRecord that answer the questions
       
   779   posed in the given Survey's schema.
       
   780 
       
   781   Args:
       
   782       survey: a Survey entity
       
   783       post_dict: dictionary with data from the POST request
       
   784   """
       
   785 
       
   786   # TODO(ljvderijk) deal with the comment fields neatly
       
   787 
       
   788   # get the schema for this survey
       
   789   schema = SurveyContentSchema(survey.survey_content.schema)
       
   790   schema_dict = schema.schema
       
   791 
       
   792   # fill a dictionary with the data to be stored in the SurveyRecord
       
   793   response_dict = {}
       
   794 
       
   795   for name, value in post_dict.items():
       
   796     # make sure name is a string
       
   797     name = name.encode()
       
   798 
       
   799     if name not in schema_dict:
       
   800       # property not in survey schema ignore
       
   801       continue
       
   802     else:
       
   803       pick_multi = schema.getType(name) == 'pick_multi'
       
   804 
       
   805       if pick_multi and hasattr(post_dict, 'getlist'): # it's a multidict
       
   806         # validation asks for a list of values
       
   807         value = post_dict.getlist(name)
       
   808 
       
   809     response_dict[name] = value
       
   810 
       
   811     # handle comments
       
   812     if schema.getHasComment(name):
       
   813       comment_name = COMMENT_PREFIX + name
       
   814       comment = post_dict.get(comment_name)
       
   815       if comment:
       
   816         response_dict[comment_name] = comment
       
   817 
       
   818   return response_dict
       
   819 
   775 
   820 
   776 
   821 def getRoleSpecificFields(survey, user, this_project, survey_form,
   777 def getRoleSpecificFields(survey, user, this_project, survey_form,
   822                           survey_record):
   778                           survey_record):
   823   """For evaluations, mentors get required Project and Grade fields, and
   779   """For evaluations, mentors get required Project and Grade fields, and