예제 #1
0
    def populate_correctResponsesPattern(self, act_def, interactionFlag):
        crp = models.activity_def_correctresponsespattern(activity_definition=self.activity.activity_definition)
        crp.save()

        log_message(self.log_dict, "Populating correct responses pattern", __name__, self.populate_correctResponsesPattern.__name__)                    

        #For each answer in the pattern save it
        for i in act_def['correctResponsesPattern']:
            answer = models.correctresponsespattern_answer(answer=i, correctresponsespattern=crp)
            answer.save()

        #Depending on which type of interaction, save the unique fields accordingly
        if interactionFlag == 'choices' or interactionFlag == 'sequencing':
            for c in act_def['choices']:
                choice = models.activity_definition_choice(choice_id=c['id'], activity_definition=self.activity.activity_definition)
                choice.save()
                #Save description as string, not a dictionary
                for desc_lang_map in c['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self.save_lang_map(desc_lang_map, choice)
                        choice.save()
                    else:
                        choice.delete()
                        err_msg = "Choice description must be a language map"
                        log_message(self.log_dict, err_msg, __name__, self.populate_correctResponsesPattern.__name__, True)  
                        update_parent_log_status(self.log_dict, 400)                  
                        raise exceptions.ParamError(err_msg)

        elif interactionFlag == 'scale':
            for s in act_def['scale']:
                scale = models.activity_definition_scale(scale_id=s['id'], activity_definition=self.activity.activity_definition)        
                scale.save()
                # Save description as string, not a dictionary
                for desc_lang_map in s['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self.save_lang_map(desc_lang_map, scale)
                        scale.save()
                    else:
                        scale.delete()
                        err_msg = "Scale description must be a language map"
                        log_message(self.log_dict, err_msg, __name__, self.populate_correctResponsesPattern.__name__, True) 
                        update_parent_log_status(self.log_dict, 400)                   
                        raise exceptions.ParamError(err_msg)

        elif interactionFlag == 'steps':
            for s in act_def['steps']:
                step = models.activity_definition_step(step_id=s['id'], activity_definition=self.activity.activity_definition)
                step.save()
                #Save description as string, not a dictionary
                for desc_lang_map in s['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self.save_lang_map(desc_lang_map, step)
                        step.save()
                    else:
                        step.delete()
                        err_msg = "Step description must be a language map"
                        log_message(self.log_dict, err_msg, __name__, self.populate_correctResponsesPattern.__name__, True) 
                        update_parent_log_status(self.log_dict, 400)                   
                        raise exceptions.ParamError(err_msg)  

        elif interactionFlag == 'source':
            for s in act_def['source']:
                source = models.activity_definition_source(source_id=s['id'], activity_definition=self.activity.activity_definition)
                source.save()                        
                #Save description as string, not a dictionary
                for desc_lang_map in s['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self.save_lang_map(desc_lang_map, source)
                        source.save()
                    else:
                        source.delete()
                        err_msg = "Source description must be a language map"
                        log_message(self.log_dict, err_msg, __name__, self.populate_correctResponsesPattern.__name__, True) 
                        update_parent_log_status(self.log_dict, 400)                   
                        raise exceptions.ParamError(err_msg)

            for t in act_def['target']:
                target = models.activity_definition_target(target_id=t['id'], activity_definition=self.activity.activity_definition)
                target.save()
                #Save description as string, not a dictionary
                for desc_lang_map in t['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self.save_lang_map(desc_lang_map, target)
                        target.save()
                    else:
                        target.delete()
                        err_msg = "Target description must be a language map"
                        log_message(self.log_dict, err_msg, __name__, self.populate_correctResponsesPattern.__name__, True) 
                        update_parent_log_status(self.log_dict, 400)                   
                        raise exceptions.ParamError(err_msg)
예제 #2
0
    def _populate_correctResponsesPattern(self, act_def, interactionFlag):
        # crp = models.activity_def_correctresponsespattern(activity_definition=self.activity_definition)
        crp = models.activity_def_correctresponsespattern()
        crp.save()
        self.activity_definition.correctresponsespattern = crp
        self.activity_definition.save()
        self.correctResponsesPattern = crp
        
        #For each answer in the pattern save it
        self.answers = []
        for i in act_def['correctResponsesPattern']:
            answer = models.correctresponsespattern_answer(answer=i, correctresponsespattern=self.correctResponsesPattern)
            answer.save()
            self.answers.append(answer)

        #Depending on which type of interaction, save the unique fields accordingly
        if interactionFlag == 'choices' or interactionFlag == 'sequencing':
            self.choices = []
            for c in act_def['choices']:
                choice = models.activity_definition_choice(choice_id=c['id'], activity_definition=self.activity_definition)
                choice.save()
                #Save description as string, not a dictionary
                for desc_lang_map in c['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self._save_lang_map(desc_lang_map)
                        choice.description.add(lang_map)
                        choice.save()
                    else:
                        raise exceptions.ParamError("Choice description must be a language map")

                self.choices.append(choice)
        
        elif interactionFlag == 'scale':
            self.scale_choices = []
            for s in act_def['scale']:
                scale = models.activity_definition_scale(scale_id=s['id'], activity_definition=self.activity_definition)        
                scale.save()
                # Save description as string, not a dictionary
                for desc_lang_map in s['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self._save_lang_map(desc_lang_map)
                        scale.description.add(lang_map)
                        scale.save()
                    else:
                        raise exceptions.ParamError("Scale description must be a language map")                        

                self.scale_choices.append(scale)

        elif interactionFlag == 'steps':
            self.steps = []
            for s in act_def['steps']:
                step = models.activity_definition_step(step_id=s['id'], activity_definition=self.activity_definition)
                step.save()
                #Save description as string, not a dictionary
                for desc_lang_map in s['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self._save_lang_map(desc_lang_map)
                        step.description.add(lang_map)
                        step.save()
                    else:
                        raise exceptions.ParamError("Step description must be a language map")                        

                self.steps.append(step)

        elif interactionFlag == 'source':
            self.source_choices = []
            self.target_choices = []
            for s in act_def['source']:
                source = models.activity_definition_source(source_id=s['id'], activity_definition=self.activity_definition)
                source.save()                        
                #Save description as string, not a dictionary
                for desc_lang_map in s['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self._save_lang_map(desc_lang_map)
                        source.description.add(lang_map)
                        source.save()
                    else:
                        raise exceptions.ParamError("Source description must be a language map")                        
                self.source_choices.append(source)
            
            for t in act_def['target']:
                target = models.activity_definition_target(target_id=t['id'], activity_definition=self.activity_definition)
                target.save()
                #Save description as string, not a dictionary
                for desc_lang_map in t['description'].items():
                    if isinstance(desc_lang_map, tuple):
                        lang_map = self._save_lang_map(desc_lang_map)
                        target.description.add(lang_map)
                        target.save()
                    else:
                        raise exceptions.ParamError("Target description must be a language map")                        

                self.target_choices.append(target)