예제 #1
0
    def update_from_base_question(self):
        """
        Overwrite the question with all fields from base question
        except preserves fields: .course and .base_question
        """

        from copy import copy

        base_question = self.base_question
        if base_question is None:
            return
        
        new_self = copy(base_question)
        new_self.id = self.id
        new_self.base_question = base_question
        new_self.course = self.course

        new_self.save()
        
        new_self.questionreferencepage_set.all().delete()
        for qrp in base_question.questionreferencepage_set.all():
            qrp.id = None
            qrp.question = new_self
            qrp.save()

        new_self.allowed_sympy_commands.clear()
        for asc in base_question.allowed_sympy_commands.all():
            new_self.allowed_sympy_commands.add(asc)
        new_self.allowed_user_sympy_commands.clear()
        for ausc in base_question.allowed_user_sympy_commands.all():
            new_self.allowed_user_sympy_commands.add(ausc)
        new_self.keywords.clear()
        for kw in base_question.keywords.all():
            new_self.keywords.add(kw)
        new_self.subjects.clear()
        for sb in base_question.subjects.all():
            new_self.subjects.add(sb)

        new_self.questionauthor_set.all().delete()
        for qa in base_question.questionauthor_set.all():
            qa.id = None
            qa.question = new_self
            qa.save()

        new_self.questionsubpart_set.all().delete()
        for qsp in base_question.questionsubpart_set.all():
            qsp.id = None
            qsp.question = new_self
            qsp.save()

        new_self.questionansweroption_set.all().delete()
        for qao in base_question.questionansweroption_set.all():
            qao.id = None
            qao.question = new_self
            qao.save()

        new_self.expression_set.all().delete()
        for expr in base_question.expression_set.all():
            expr.id = None
            expr.question = new_self
            expr.save()

        from mitesting.render_questions import process_expressions_from_answers
        process_expressions_from_answers(new_self)

        return new_self
예제 #2
0
    def save_as_new(self, course=None):
        """
        Create a new question and copy all fields to new question.

        Set course if specified.
        """

        from copy import copy

        new_q = copy(self)
        new_q.id = None

        if self.base_question:
            new_q.base_question = self.base_question
        else:
            new_q.base_question = self

        if course:
            new_q.course = course

        new_q.save()
        
        for qrp in self.questionreferencepage_set.all():
            qrp.id = None
            qrp.question = new_q
            qrp.save()
            
        for asc in self.allowed_sympy_commands.all():
            new_q.allowed_sympy_commands.add(asc)
        for ausc in self.allowed_user_sympy_commands.all():
            new_q.allowed_user_sympy_commands.add(ausc)
        for kw in self.keywords.all():
            new_q.keywords.add(kw)
        for sb in self.subjects.all():
            new_q.subjects.add(sb)

        for qa in self.questionauthor_set.all():
            qa.id = None
            qa.question = new_q
            qa.save()

        
        for qsp in self.questionsubpart_set.all():
            qsp.id = None
            qsp.question = new_q
            qsp.save()

        for qao in self.questionansweroption_set.all():
            qao.id = None
            qao.question = new_q
            qao.save()

        for expr in self.expression_set.all():
            expr.id = None
            expr.question = new_q
            expr.save()

        from mitesting.render_questions import process_expressions_from_answers
        process_expressions_from_answers(new_q)

        return new_q
예제 #3
0
    def overwrite_base_question(self):
        """
        Overwrite the base question with all fields of question
        except preserves fields: .course and .base_question
        """

        from copy import copy

        base_question = self.base_question
        if base_question is None:
            return
        
        base_q = copy(self)
        base_q.id = base_question.id
        base_q.base_question = base_question.base_question
        base_q.course = base_question.course

        base_q.save()
        
        base_q.questionreferencepage_set.all().delete()
        for qrp in self.questionreferencepage_set.all():
            qrp.id = None
            qrp.question = base_q
            qrp.save()

        base_q.allowed_sympy_commands.clear()
        for asc in self.allowed_sympy_commands.all():
            base_q.allowed_sympy_commands.add(asc)
        base_q.allowed_user_sympy_commands.clear()
        for ausc in self.allowed_user_sympy_commands.all():
            base_q.allowed_user_sympy_commands.add(ausc)
        base_q.keywords.clear()
        for kw in self.keywords.all():
            base_q.keywords.add(kw)
        base_q.subjects.clear()
        for sb in self.subjects.all():
            base_q.subjects.add(sb)

        base_q.questionauthor_set.all().delete()
        for qa in self.questionauthor_set.all():
            qa.id = None
            qa.question = base_q
            qa.save()

        base_q.questionsubpart_set.all().delete()
        for qsp in self.questionsubpart_set.all():
            qsp.id = None
            qsp.question = base_q
            qsp.save()

        base_q.questionansweroption_set.all().delete()
        for qao in self.questionansweroption_set.all():
            qao.id = None
            qao.question = base_q
            qao.save()

        base_q.expression_set.all().delete()
        for expr in self.expression_set.all():
            expr.id = None
            expr.question = base_q
            expr.save()

        from mitesting.render_questions import process_expressions_from_answers
        process_expressions_from_answers(base_q)

        return base_q
예제 #4
0
    def save_related(self, request, form, formsets, change):
        super(QuestionDatabaseAdmin, self).save_related(request, form, formsets, change)

        from mitesting.render_questions import process_expressions_from_answers
        process_expressions_from_answers(form.instance)