Beispiel #1
0
    def save(self, response):
        # response = super(ResponseWizardFrom, self).save(commit=False)
        for field_name, field_value in self.cleaned_data.iteritems():
            if field_name.startswith("question_"):
                # warning: this way of extracting the id is very fragile and
                # entirely dependent on the way the question_id is encoded in the
                # field name in the __init__ method of this form class.
                q_id = int(field_name.split("_")[1])
                q = Question.objects.get(pk=q_id)

                if q.question_type == Question.TEXT:
                    a = AnswerText(question=q)
                    a.body = field_value
                elif q.question_type == Question.RADIO:
                    a = AnswerRadio(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT:
                    a = AnswerSelect(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT_MULTIPLE:
                    a = AnswerSelectMultiple(question=q)
                    a.body = field_value
                elif q.question_type == Question.INTEGER:
                    a = AnswerInteger(question=q)
                    a.body = field_value
                # print "creating answer to question %d of type %s" % (q_id, a.question.question_type)
                # print a.question.text
                # print 'answer value:'
                # print field_value
                a.response = response
                a.save()
Beispiel #2
0
 def save(self, commit=True):
   # create an answer object for each question and associate it with this
   # response.
   for field_name, field_value in self.cleaned_data.iteritems():
     if field_name.startswith("question_"):
       # warning: this way of extracting the id is very fragile and
       # entirely dependent on the way the question_id is encoded in the
       # field name in the __init__ method of this form class.
       q_id = int(field_name.split("_")[1])
       q = Question.objects.get(pk=q_id)
       
       if q.question_type == Question.TEXT:
         a = AnswerText(question = q)
         a.body = field_value
       elif q.question_type == Question.RADIO:
         a = AnswerRadio(question = q)  
         a.body = field_value
       elif q.question_type == Question.SELECT:
         a = AnswerSelect(question = q)  
         a.body = field_value
       elif q.question_type == Question.SELECT_MULTIPLE:
         a = AnswerSelectMultiple(question = q)  
         a.body = field_value
       elif q.question_type == Question.INTEGER:  
         a = AnswerInteger(question = q)  
         a.body = field_value
       print "creating answer to question %d of type %s" % (q_id, a.question.question_type) 
       print a.question.text
       print 'answer value:'
       print field_value
       question_finder(a.question.text, field_value)
       print 'after question finder'
       a.response = self.response
       a.save()
   return self.response
Beispiel #3
0
    def save(self, commit=True):
        # save the response object
        response = super(ResponseForm, self).save(commit=False)
        response.survey = self.survey
        response.interview_uuid = self.uuid
        response.real_ip = self.real_ip
        response.browser = self.browser
        response.extra = self.extra
        # track people
        track = TrackPeople.objects.filter(slug=self.track_people_slug).first()
        if track and str(track.id) == self.track_people_id:
            response.slug = track
        response.save()

        # create an answer object for each question and associate it with this
        # response.
        for field_name, field_value in self.cleaned_data.iteritems():
            if field_name.startswith("question_"):
                # warning: this way of extracting the id is very fragile and
                # entirely dependent on the way the question_id is encoded in the
                # field name in the __init__ method of this form class.
                q_id = int(field_name.split("_")[1])
                q = Question.objects.get(pk=q_id)

                if q.question_type == Question.TEXT:
                    a = AnswerText(question=q)
                    a.body = field_value
                elif q.question_type == Question.RADIO:
                    a = AnswerRadio(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT:
                    a = AnswerSelect(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT_MULTIPLE:
                    field_value = '\n'.join(field_value)
                    a = AnswerSelectMultiple(question=q)
                    a.body = field_value
                elif q.question_type == Question.INTEGER:
                    a = AnswerInteger(question=q)
                    a.body = field_value
                a.response = response
                a.save()
        return response
Beispiel #4
0
    def save(self, commit=True):
        # save the response object
        response = super(ResponseForm, self).save(commit=False)
        response.survey = self.survey
        response.interview_uuid = self.uuid
        #response.user_uuid=self.user_uuid
        response.save()

        # create an answer object for each question and associate it with this
        # response.
        for field_name, field_value in self.cleaned_data.iteritems():
            if field_name.startswith("question_"):
                # warning: this way of extracting the id is very fragile and
                # entirely dependent on the way the question_id is encoded in the
                # field name in the __init__ method of this form class.
                q_id = int(field_name.split("_")[1])
                q = Question.objects.get(pk=q_id)

                if q.question_type == Question.TEXT:
                    a = AnswerText(question=q)
                    a.body = field_value
                elif q.question_type == Question.RADIO:
                    a = AnswerRadio(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT:
                    a = AnswerSelect(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT_MULTIPLE:
                    a = AnswerSelectMultiple(question=q)
                    a.body = field_value
                elif q.question_type == Question.INTEGER:
                    a = AnswerInteger(question=q)
                    a.body = field_value
                print "creating answer to question %d of type %s" % (
                    q_id, a.question.question_type)
                print a.question.text
                print 'answer value:'
                print field_value
                a.response = response
                a.save()
        return response
Beispiel #5
0
	def save(self, commit=True):
		# save the response object
		response = super(ResponseForm, self).save(commit=False)
		response.survey = self.survey
		response.interview_uuid = self.uuid
		response.save()

		# create an answer object for each question and associate it with this
		# response.

		questions = { q.number: q for q in self.survey.question_set.all() }

		for field_name, field_value in self.cleaned_data.iteritems():
			if field_name.startswith("question_"):
				# warning: this way of extracting the id is very fragile and
				# entirely dependent on the way the question_id is encoded in the
				# field name in the __init__ method of this form class.
				q_number = field_name.split("_")[1]
				#q = Question.objects.get(survey=self.survey ,number=q_number)
				q = questions[q_number]

				if q.question_type == Question.TEXT:
					a = AnswerText(question = q)
					a.body = field_value
				elif q.question_type == Question.RADIO:
					a = AnswerRadio(question = q)	
					a.body = field_value
				elif q.question_type == Question.SELECT:
					a = AnswerSelect(question = q)	
					a.body = field_value
				elif q.question_type == Question.SELECT_MULTIPLE:
					a = AnswerSelectMultiple(question = q)	
					a.body = field_value
				elif q.question_type == Question.INTEGER:	
					a = AnswerInteger(question = q)	
					a.body = field_value
				a.response = response
				a.save()
		return response
Beispiel #6
0
    def save(self, commit=True):
        # save the response object
        response = super(ResponseForm, self).save(commit=False)
        response.survey = self.survey
        response.interview_uuid = self.uuid
        if self.user.is_authenticated():
            response.user = self.user
        response.save()

        # response "raw" data as dict (for signal)
        data = {
            'survey_id': response.survey.id,
            'interview_uuid': response.interview_uuid,
            'responses': []
        }
        # create an answer object for each question and associate it with this
        # response.
        for field_name, field_value in self.cleaned_data.iteritems():
            if field_name.startswith("question_"):
                # warning: this way of extracting the id is very fragile and
                # entirely dependent on the way the question_id is encoded in the
                # field name in the __init__ method of this form class.
                q_id = int(field_name.split("_")[1])
                q = Question.objects.get(pk=q_id)

                if q.question_type == Question.TEXT or q.question_type == Question.SHORT_TEXT:
                    a = AnswerText(question=q)
                    a.body = field_value
                elif q.question_type == Question.RADIO:
                    a = AnswerRadio(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT:
                    a = AnswerSelect(question=q)
                    a.body = field_value
                elif q.question_type == Question.SELECT_IMAGE:
                    a = AnswerSelect(question=q)
                    value, img_src = field_value.split(":", 1)
                    a.body = value
                elif q.question_type == Question.SELECT_MULTIPLE:
                    a = AnswerSelectMultiple(question=q)
                    a.body = field_value
                elif q.question_type == Question.INTEGER:
                    a = AnswerInteger(question=q)
                    a.body = field_value
                data['responses'].append((a.question.id, a.body))
                logging.debug("creating answer to question %d of type %s" %
                              (q_id, a.question.question_type))
                logging.debug(a.question.text)
                logging.debug('answer value:')
                logging.debug(field_value)

                a.response = response
                a.save()
        survey_completed.send(sender=Response, instance=response, data=data)
        return response
Beispiel #7
0
    def save(self, commit=True):
        # save the response object
        response = super(ResponseForm, self).save(commit=False)
        response.survey = self.survey
        response.interview_uuid = self.uuid
        if self.user.is_authenticated():
            response.user = self.user
        response.save()

        # response "raw" data as dict (for signal)
        data = {
            'survey_id': response.survey.id,
            'interview_uuid': response.interview_uuid,
            'responses': []
        }
        # create an answer object for each question and associate it with this
        # response.
        for field_name, field_value in self.cleaned_data.iteritems():
            if field_name.startswith("question_"):
                # warning: this way of extracting the id is very fragile and
                # entirely dependent on the way the question_id is encoded in the
                # field name in the __init__ method of this form class.
                q_id = int(field_name.split("_")[1])
                q = Question.objects.get(pk=q_id)
                
                if q.question_type == Question.TEXT or q.question_type == Question.SHORT_TEXT:
                    a = AnswerText(question = q)
                    a.body = field_value
                elif q.question_type == Question.RADIO:
                    a = AnswerRadio(question = q)   
                    a.body = field_value
                elif q.question_type == Question.SELECT:
                    a = AnswerSelect(question = q)  
                    a.body = field_value
                elif q.question_type == Question.SELECT_IMAGE:
                    a = AnswerSelect(question = q)
                    value, img_src = field_value.split(":", 1)
                    a.body = value
                elif q.question_type == Question.SELECT_MULTIPLE:
                    a = AnswerSelectMultiple(question = q)  
                    a.body = field_value
                elif q.question_type == Question.INTEGER:   
                    a = AnswerInteger(question = q) 
                    a.body = field_value
                data['responses'].append((a.question.id, a.body))
                logging.debug("creating answer to question %d of type %s" % (q_id, a.question.question_type))
                logging.debug(a.question.text)
                logging.debug('answer value:')
                logging.debug(field_value)

                a.response = response
                a.save()
        survey_completed.send(sender=Response, instance=response, data=data)
        return response