예제 #1
0
    def choices(self):
        if self.type == 'sameas':
            return self.sameas().choices()

        res = None
        if 'samechoicesas' in parse_checks(self.checks):
            number_to_grab_from = parse_checks(self.checks)['samechoicesas']
            choicesource = Question.objects.get(number=number_to_grab_from, questionset__questionnaire=self.questionset.questionnaire)
            if not choicesource == None:
                res = Choice.objects.filter(question=choicesource).order_by('sortid')
        else:        
            res = Choice.objects.filter(question=self).order_by('sortid')
        return res
예제 #2
0
 def getcheckdict(self):
     """getcheckdict returns a dictionary of the values in self.checks"""
     if hasattr(self, "__checkdict_cached"):
         return self.__checkdict_cached
     try:
         self.__checkdict_cached = d = parse_checks(self.sameas().checks or "")
     except ParseException:
         raise Exception("Error Parsing Checks for Question %s: %s" % (self.number, self.sameas().checks))
     return d
예제 #3
0
 def getcheckdict(self):
     """getcheckdict returns a dictionary of the values in self.checks"""
     if(hasattr(self, '__checkdict_cached')):
         return self.__checkdict_cached
     try:
         self.__checkdict_cached = d = parse_checks(self.sameas().checks or '')
     except ParseException:
         raise Exception("Error Parsing Checks for Question %s: %s" % (
             self.number, self.sameas().checks))
     return d
예제 #4
0
 def getcheckdict(self):
     """getcheckdict returns a dictionary of the values in self.checks"""
     if(hasattr(self, '__checkdict_cached')):
         return self.__checkdict_cached
     try:
         self.__checkdict_cached = d = parse_checks(self.sameas().checks or '')
     except ParseException, e:
         logging.exception("Error Parsing Checks for Question %s: %s" % (
             self.number, self.sameas().checks))
         raise Exception("Error Parsing Checks for Question %s: %s" % (
             self.number, self.sameas().checks))
예제 #5
0
    def sameas(self):
        if self.type == 'sameas':
            try:
                kwargs = {}
                for check, value in parse_checks(self.checks):
                    if check == 'sameasid':
                        kwargs['id'] = value
                        break
                    elif check == 'sameas':
                        kwargs['number'] = value
                        kwargs['questionset__questionnaire'] = self.questionset.questionnaire
                        break

                self.__sameas = res = getattr(self, "__sameas", Question.objects.get(**kwargs))
                return res
            except Question.DoesNotExist:
                return Question(type='comment') # replace with something benign
        return self
예제 #6
0
    def sameas(self):
        if self.type == 'sameas':
            try:
                kwargs = {}
                for check, value in parse_checks(self.checks):
                    if check == 'sameasid':
                        kwargs['id'] = value
                        break
                    elif check == 'sameas':
                        kwargs['number'] = value
                        kwargs['questionset__questionnaire'] = self.questionset.questionnaire
                        break

                self.__sameas = res = getattr(self, "__sameas", Question.objects.get(**kwargs))
                return res
            except Question.DoesNotExist:
                return Question(type='comment') # replace with something benign
        return self
예제 #7
0
    def sameas(self):
        if self.type == "sameas":
            try:
                kwargs = {}
                for check, value in parse_checks(self.checks):
                    if check == "sameasid":
                        kwargs["id"] = value
                        break
                    elif check == "sameas":
                        kwargs["number"] = value
                        kwargs["questionset__questionnaire"] = self.questionset.questionnaire
                        break

                self.__sameas = res = getattr(self, "__sameas", Question.objects.get(**kwargs))
                return res
            except Question.DoesNotExist:
                # replace with something benign
                return Question(type="comment")
        return self