示例#1
0
    def get(self, entity_type, entity_id):
        """Handles the GET requests for learner answer info for an
        exploration state.
        """
        if not constants.ENABLE_SOLICIT_ANSWER_DETAILS_FEATURE:
            raise self.PageNotFoundException

        learner_answer_info_data = []

        if entity_type == feconf.ENTITY_TYPE_EXPLORATION:
            exp = exp_fetchers.get_exploration_by_id(entity_id)
            for state_name in exp.states:
                state_reference = (
                    stats_services.get_state_reference_for_exploration(
                        entity_id, state_name))
                learner_answer_details = (
                    stats_services.get_learner_answer_details(
                        feconf.ENTITY_TYPE_EXPLORATION, state_reference))
                if learner_answer_details is not None:
                    learner_answer_info_data.append({
                        'state_name':
                        state_name,
                        'interaction_id':
                        learner_answer_details.interaction_id,
                        'customization_args':
                        exp.states[state_name].interaction.to_dict()
                        ['customization_args'],
                        'learner_answer_info_dicts': [
                            learner_answer_info.to_dict()
                            for learner_answer_info in
                            learner_answer_details.learner_answer_info_list
                        ]
                    })
        elif entity_type == feconf.ENTITY_TYPE_QUESTION:
            question = question_services.get_question_by_id(entity_id)
            state_reference = stats_services.get_state_reference_for_question(
                entity_id)
            learner_answer_details = stats_services.get_learner_answer_details(
                feconf.ENTITY_TYPE_QUESTION, state_reference)
            if learner_answer_details is not None:
                learner_answer_info_dicts = [
                    learner_answer_info.to_dict() for learner_answer_info in
                    learner_answer_details.learner_answer_info_list
                ]
            learner_answer_info_data = {
                'interaction_id':
                learner_answer_details.interaction_id,
                'customization_args':
                question.question_state_data.interaction.to_dict()
                ['customization_args'],
                'learner_answer_info_dicts':
                learner_answer_info_dicts
            }

        self.render_json(
            {'learner_answer_info_data': learner_answer_info_data})
示例#2
0
    def get(self, entity_type, entity_id):
        """Handles the GET requests for learner answer info for an
        exploration state.
        """
        if not constants.ENABLE_SOLICIT_ANSWER_DETAILS_FEATURE:
            raise self.PageNotFoundException

        if entity_type == feconf.ENTITY_TYPE_EXPLORATION:
            state_name = self.request.get('state_name')
            if not state_name:
                raise self.InvalidInputException
            state_reference = (
                stats_services.get_state_reference_for_exploration(
                    entity_id, state_name))
        elif entity_type == feconf.ENTITY_TYPE_QUESTION:
            state_reference = (
                stats_services.get_state_reference_for_question(entity_id))

        learner_answer_details = stats_services.get_learner_answer_details(
            entity_type, state_reference)
        learner_answer_info_dict_list = []
        if learner_answer_details is not None:
            learner_answer_info_dict_list = [
                learner_answer_info.to_dict() for learner_answer_info in
                learner_answer_details.learner_answer_info_list
            ]
        self.render_json(
            {'learner_answer_info_dict_list': learner_answer_info_dict_list})