Esempio n. 1
0
    def put(self, entity_type, entity_id):
        """"Handles the PUT requests. Stores the answer details submitted
        by the learner.
        """
        if not constants.ENABLE_SOLICIT_ANSWER_DETAILS_FEATURE:
            raise self.PageNotFoundException

        interaction_id = self.payload.get('interaction_id')
        if entity_type == feconf.ENTITY_TYPE_EXPLORATION:
            state_name = self.payload.get('state_name')
            state_reference = (
                stats_services.get_state_reference_for_exploration(
                    entity_id, state_name))
            if interaction_id != exp_services.get_interaction_id_for_state(
                    entity_id, state_name):
                raise utils.InvalidInputException(
                    'Interaction id given does not match with the '
                    'interaction id of the state')
        elif entity_type == feconf.ENTITY_TYPE_QUESTION:
            state_reference = (
                stats_services.get_state_reference_for_question(entity_id))
            if interaction_id != (
                    question_services.get_interaction_id_for_question(
                        entity_id)):
                raise utils.InvalidInputException(
                    'Interaction id given does not match with the '
                    'interaction id of the question')

        answer = self.payload.get('answer')
        answer_details = self.payload.get('answer_details')
        stats_services.record_learner_answer_info(
            entity_type, state_reference,
            interaction_id, answer, answer_details)
        self.render_json({})
Esempio n. 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})
Esempio n. 3
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})
Esempio n. 4
0
    def delete(self, entity_type, entity_id):
        """Deletes the learner answer info by the given id."""

        if not constants.ENABLE_SOLICIT_ANSWER_DETAILS_FEATURE:
            raise self.PageNotFoundException

        if entity_type == feconf.ENTITY_TYPE_EXPLORATION:
            state_name = self.normalized_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_info_id = (
            self.normalized_request.get('learner_answer_info_id'))

        stats_services.delete_learner_answer_info(entity_type, state_reference,
                                                  learner_answer_info_id)
        self.render_json({})