# HG changeset patch # User Lennard de Rijk # Date 1246531506 -7200 # Node ID be8a113ee02143a9e5b9a1c6b7dd26f2d2bfd7da # Parent 0e544df4d92566a2197a8f0a0e007d8d95d05237 Added getSurveyResponseFromPost method to Surveys Helper. This method will be used to read the POST dictionary from a request. And will transform it into the fields that need to be set in a SurveyRecord for the questions specified by the given Survey. A TODO has been added to handle the naming/handling of the comment fields. diff -r 0e544df4d925 -r be8a113ee021 app/soc/views/helper/surveys.py --- a/app/soc/views/helper/surveys.py Thu Jul 02 12:43:06 2009 +0200 +++ b/app/soc/views/helper/surveys.py Thu Jul 02 12:45:06 2009 +0200 @@ -597,6 +597,40 @@ return markup +def getSurveyResponseFromPost(survey, post_dict): + """Returns the data for a SurveyRecord that answer the questions + posed in the given Survey's schema. + + Args: + survey: a Survey entity + post_dict: dictionary with data from the POST request + """ + + # TODO(ljvderijk) deal with the comment fields + + # get the schema for this survey + schema = eval(survey.survey_content.schema) + + # fill a dictionary with the data to be stored in the SurveyRecord + response_dict = {} + + for name, value in post_dict.items(): + # make sure name is a string + name = name.encode() + if name not in schema: + # property not in survey schema ignore + continue + else: + pick_multi = schema[name]['type'] == 'pick_multi' + + if pick_multi and hasattr(post_dict, 'getlist'): # it's a multidict + response_dict[name] = ','.join(post_dict.getlist(name)) + else: + response_dict[name] = value + + return response_dict + + def getRoleSpecificFields(survey, user, this_project, survey_form, survey_record): """For evaluations, mentors get required Project and Grade fields, and