Beispiel #1
0
    def set_questions(self):
        new_user = ESPUser(self.user)
        existing_list = self.questions.all().values_list('id', flat=True)
        new_list = list(
            StudentAppQuestion.objects.filter(
                program=self.program).values_list('id', flat=True))
        new_list += list(
            StudentAppQuestion.objects.filter(
                subject__in=new_user.getAppliedClasses(
                    self.program)).values_list('id', flat=True))

        to_remove = [e for e in existing_list if (e not in new_list)]
        for i in to_remove:
            self.questions.remove(i)
        to_add = [e for e in new_list if (e not in existing_list)]
        for i in to_add:
            self.questions.add(i)
Beispiel #2
0
    def get_forms(self, data={}):
        """ Get a list of forms for the student to fill out.
        This function sets a target attribute on each form so that
        the update function can be called directly on target. """

        #   Get forms for already existing responses.
        forms = []
        new_user = ESPUser(self.user)
        applied_classes = new_user.getAppliedClasses(self.program)
        for r in self.responses.filter(question__subject__in=applied_classes):
            f = r.get_form(data)
            f.target = r
            forms.append(f)

        #   Create responses if necessary for the other questions, and get their forms.
        for q in self.questions.all():
            if self.responses.filter(question=q).count() == 0:
                r = StudentAppResponse(question=q)
                r.save()
                self.responses.add(r)
                f = r.get_form(data)
                forms.append(f)

        return forms