Exemplo n.º 1
0
    def get(self, exploration_id):
        """Populates the data on the individual exploration page.

        Args:
            exploration_id: str. The ID of the exploration.
        """
        version = self.request.get('v')
        version = int(version) if version else None

        try:
            exploration = exp_fetchers.get_exploration_by_id(
                exploration_id, version=version)
        except Exception as e:
            raise self.PageNotFoundException(e)

        exploration_rights = rights_manager.get_exploration_rights(
            exploration_id, strict=False)
        user_settings = user_services.get_user_settings(self.user_id)

        preferred_audio_language_code = None
        if user_settings is not None:
            preferred_audio_language_code = (
                user_settings.preferred_audio_language_code)

        # Retrieve all classifiers for the exploration.
        state_classifier_mapping = {}
        classifier_training_jobs = (
            classifier_services.get_classifier_training_jobs(
                exploration_id, exploration.version, exploration.states.keys()))
        for index, state_name in enumerate(exploration.states.keys()):
            if classifier_training_jobs[index] is not None:
                classifier_data = classifier_training_jobs[
                    index].classifier_data
                algorithm_id = classifier_training_jobs[index].algorithm_id
                data_schema_version = (
                    classifier_training_jobs[index].data_schema_version)
                state_classifier_mapping[state_name] = {
                    'algorithm_id': algorithm_id,
                    'classifier_data': classifier_data,
                    'data_schema_version': data_schema_version
                }

        self.values.update({
            'can_edit': (
                rights_manager.check_can_edit_activity(
                    self.user, exploration_rights)),
            'exploration': exploration.to_player_dict(),
            'exploration_id': exploration_id,
            'is_logged_in': bool(self.user_id),
            'session_id': utils.generate_new_session_id(),
            'version': exploration.version,
            'preferred_audio_language_code': preferred_audio_language_code,
            'state_classifier_mapping': state_classifier_mapping,
            'auto_tts_enabled': exploration.auto_tts_enabled,
            'correctness_feedback_enabled': (
                exploration.correctness_feedback_enabled),
            'record_playthrough_probability': (
                config_domain.RECORD_PLAYTHROUGH_PROBABILITY.value)
        })
        self.render_json(self.values)
Exemplo n.º 2
0
    def get(self, collection_id):
        """Populates the data on the individual collection page."""
        try:
            collection = collection_services.get_collection_by_id(
                collection_id)
        except Exception as e:
            raise self.PageNotFoundException(e)

        exp_ids = collection.exploration_ids

        exp_summaries = (
            exp_services.get_exploration_summaries_matching_ids(exp_ids))

        exp_titles_dict = {}
        for (ind, exp_id) in enumerate(exp_ids):
            exp_summary = exp_summaries[ind]
            exp_titles_dict[exp_id] = exp_summary.title if exp_summary else ''

        # TODO(bhenning): Users should not be recommended explorations they
        # have completed outside the context of a collection.
        next_exploration_ids = None
        completed_exploration_ids = None
        if self.user_id:
            completed_exploration_ids = (
                collection_services.get_completed_exploration_ids(
                    self.user_id, collection_id))
            next_exploration_ids = collection.get_next_exploration_ids(
                completed_exploration_ids)
        else:
            # If the user is not logged in or they have not completed any of
            # the explorations yet within the context of this collection,
            # recommend the initial explorations.
            next_exploration_ids = collection.init_exploration_ids
            completed_exploration_ids = []

        collection_dict = collection.to_dict()
        collection_dict['next_exploration_ids'] = next_exploration_ids
        collection_dict['completed_exploration_ids'] = (
            completed_exploration_ids)

        # Insert an 'exploration' dict into each collection node, where the
        # dict includes meta information about the exploration (ID and title).
        for collection_node in collection_dict['nodes']:
            collection_node['exploration'] = {
                'id': collection_node['exploration_id'],
                'title': exp_titles_dict[collection_node['exploration_id']]
            }

        self.values.update({
            'can_edit': (
                self.user_id and rights_manager.Actor(self.user_id).can_edit(
                    rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)),
            'collection': collection_dict,
            'info_card_image_url': utils.get_info_card_url_for_category(
                collection.category),
            'is_logged_in': bool(self.user_id),
            'session_id': utils.generate_new_session_id(),
        })

        self.render_json(self.values)
Exemplo n.º 3
0
    def get(self, exploration_id):
        """Populates the data on the individual exploration page."""
        version = self.request.get('v')
        version = int(version) if version else None

        try:
            exploration = exp_services.get_exploration_by_id(exploration_id,
                                                             version=version)
        except Exception as e:
            raise self.PageNotFoundException(e)

        self.values.update({
            'can_edit':
            (self.user_id and rights_manager.Actor(self.user_id).can_edit(
                feconf.ACTIVITY_TYPE_EXPLORATION, exploration_id)),
            'exploration':
            exploration.to_player_dict(),
            'is_logged_in':
            bool(self.user_id),
            'session_id':
            utils.generate_new_session_id(),
            'version':
            exploration.version,
        })
        self.render_json(self.values)
Exemplo n.º 4
0
    def get(self, collection_id):
        """Populates the data on the individual collection page."""
        allow_invalid_explorations = bool(
            self.request.get('allow_invalid_explorations'))

        try:
            collection_dict = (
                collection_services.get_learner_collection_dict_by_id(
                    collection_id,
                    self.user_id,
                    allow_invalid_explorations=allow_invalid_explorations))
        except Exception as e:
            raise self.PageNotFoundException(e)

        self.values.update({
            'can_edit':
            (self.user_id and rights_manager.Actor(self.user_id).can_edit(
                rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)),
            'collection':
            collection_dict,
            'info_card_image_url':
            utils.get_info_card_url_for_category(collection_dict['category']),
            'is_logged_in':
            bool(self.user_id),
            'session_id':
            utils.generate_new_session_id(),
        })

        self.render_json(self.values)
Exemplo n.º 5
0
    def get(self, exploration_id):
        """Populates the data on the individual exploration page."""
        version = self.request.get('v')
        version = int(version) if version else None

        try:
            exploration = exp_services.get_exploration_by_id(exploration_id,
                                                             version=version)
        except Exception as e:
            raise self.PageNotFoundException(e)

        exploration_rights = rights_manager.get_exploration_rights(
            exploration_id, strict=False)
        user_settings = user_services.get_user_settings(self.user_id)

        preferred_audio_language_code = None
        if user_settings is not None:
            preferred_audio_language_code = (
                user_settings.preferred_audio_language_code)

        # Retrieve all classifiers for the exploration.
        state_classifier_mapping = {}
        classifier_training_jobs = (
            classifier_services.get_classifier_training_jobs(
                exploration_id, exploration.version, exploration.states))
        for index, state_name in enumerate(exploration.states):
            if classifier_training_jobs[index] is not None:
                classifier_data = classifier_training_jobs[
                    index].classifier_data
                algorithm_id = classifier_training_jobs[index].algorithm_id
                data_schema_version = (
                    classifier_training_jobs[index].data_schema_version)
                state_classifier_mapping[state_name] = {
                    'algorithm_id': algorithm_id,
                    'classifier_data': classifier_data,
                    'data_schema_version': data_schema_version
                }

        self.values.update({
            'can_edit':
            (rights_manager.check_can_edit_activity(self.user,
                                                    exploration_rights)),
            'exploration':
            exploration.to_player_dict(),
            'exploration_id':
            exploration_id,
            'is_logged_in':
            bool(self.user_id),
            'session_id':
            utils.generate_new_session_id(),
            'version':
            exploration.version,
            'preferred_audio_language_code':
            preferred_audio_language_code,
            'state_classifier_mapping':
            state_classifier_mapping
        })
        self.render_json(self.values)
Exemplo n.º 6
0
    def get(self, exploration_id):
        """Populates the data on the individual exploration page.

        Args:
            exploration_id: str. The ID of the exploration.
        """
        version = self.request.get('v')
        version = int(version) if version else None

        exploration = exp_fetchers.get_exploration_by_id(exploration_id,
                                                         strict=False,
                                                         version=version)
        if exploration is None:
            raise self.PageNotFoundException()

        exploration_rights = rights_manager.get_exploration_rights(
            exploration_id, strict=False)
        user_settings = user_services.get_user_settings(self.user_id)

        preferred_audio_language_code = None
        preferred_language_codes = None

        if user_settings is not None:
            preferred_audio_language_code = (
                user_settings.preferred_audio_language_code)
            preferred_language_codes = (user_settings.preferred_language_codes)

        self.values.update({
            'can_edit':
            (rights_manager.check_can_edit_activity(self.user,
                                                    exploration_rights)),
            'exploration':
            exploration.to_player_dict(),
            'exploration_id':
            exploration_id,
            'is_logged_in':
            bool(self.user_id),
            'session_id':
            utils.generate_new_session_id(),
            'version':
            exploration.version,
            'preferred_audio_language_code':
            preferred_audio_language_code,
            'preferred_language_codes':
            preferred_language_codes,
            'auto_tts_enabled':
            exploration.auto_tts_enabled,
            'correctness_feedback_enabled':
            (exploration.correctness_feedback_enabled),
            'record_playthrough_probability':
            (config_domain.RECORD_PLAYTHROUGH_PROBABILITY.value),
        })
        self.render_json(self.values)
Exemplo n.º 7
0
    def get(self, collection_id):
        """Populates the data on the individual collection page."""
        try:
            collection_dict = (
                summary_services.get_learner_collection_dict_by_id(
                    collection_id, self.user,
                    allow_invalid_explorations=False))
        except Exception as e:
            raise self.PageNotFoundException(e)
        collection_rights = rights_manager.get_collection_rights(
            collection_id, strict=False)
        self.values.update({
            'can_edit': rights_manager.check_can_edit_activity(
                self.user, collection_rights),
            'collection': collection_dict,
            'is_logged_in': bool(self.user_id),
            'session_id': utils.generate_new_session_id(),
        })

        self.render_json(self.values)
Exemplo n.º 8
0
    def get(self, collection_id):
        """Populates the data on the individual collection page."""

        try:
            collection_dict = (
                summary_services.get_learner_collection_dict_by_id(
                    collection_id, self.user_id,
                    allow_invalid_explorations=False))
        except Exception as e:
            raise self.PageNotFoundException(e)

        self.values.update({
            'can_edit': (
                self.user_id and rights_manager.Actor(self.user_id).can_edit(
                    feconf.ACTIVITY_TYPE_COLLECTION, collection_id)),
            'collection': collection_dict,
            'is_logged_in': bool(self.user_id),
            'session_id': utils.generate_new_session_id(),
        })

        self.render_json(self.values)
Exemplo n.º 9
0
    def get(self, exploration_id):
        """Populates the data on the individual exploration page."""
        version = self.request.get('v')
        version = int(version) if version else None

        try:
            exploration = exp_services.get_exploration_by_id(
                exploration_id, version=version)
        except Exception as e:
            raise self.PageNotFoundException(e)

        self.values.update({
            'can_edit': (
                self.user_id and
                rights_manager.Actor(self.user_id).can_edit(
                    feconf.ACTIVITY_TYPE_EXPLORATION, exploration_id)),
            'exploration': exploration.to_player_dict(),
            'is_logged_in': bool(self.user_id),
            'session_id': utils.generate_new_session_id(),
            'version': exploration.version,
        })
        self.render_json(self.values)
Exemplo n.º 10
0
    def get(self, collection_id):
        """Populates the data on the individual collection page."""
        collection_dict = (summary_services.get_learner_collection_dict_by_id(
            collection_id, self.user, allow_invalid_explorations=False))

        collection_rights = rights_manager.get_collection_rights(collection_id,
                                                                 strict=False)
        self.values.update({
            'can_edit':
            rights_manager.check_can_edit_activity(self.user,
                                                   collection_rights),
            'collection':
            collection_dict,
            'is_logged_in':
            bool(self.user_id),
            'session_id':
            utils.generate_new_session_id(),
            'meta_name':
            collection_dict['title'],
            'meta_description':
            utils.capitalize_string(collection_dict['objective'])
        })

        self.render_json(self.values)
Exemplo n.º 11
0
    def get(self, collection_id):
        """Populates the data on the individual collection page."""
        try:
            collection = collection_services.get_collection_by_id(
                collection_id)
        except Exception as e:
            raise self.PageNotFoundException(e)

        exp_ids = collection.exploration_ids
        exp_summaries = (
            exp_services.get_exploration_summaries_matching_ids(exp_ids))
        exp_summaries_dict = {
            exp_id: exp_summaries[ind]
            for (ind, exp_id) in enumerate(exp_ids)
        }

        # TODO(bhenning): Users should not be recommended explorations they
        # have completed outside the context of a collection.
        next_exploration_ids = None
        completed_exploration_ids = None
        if self.user_id:
            completed_exploration_ids = (
                collection_services.get_completed_exploration_ids(
                    self.user_id, collection_id))
            next_exploration_ids = collection.get_next_exploration_ids(
                completed_exploration_ids)
        else:
            # If the user is not logged in or they have not completed any of
            # the explorations yet within the context of this collection,
            # recommend the initial explorations.
            next_exploration_ids = collection.init_exploration_ids
            completed_exploration_ids = []

        collection_dict = collection.to_dict()
        collection_dict['next_exploration_ids'] = next_exploration_ids
        collection_dict['completed_exploration_ids'] = (
            completed_exploration_ids)

        # Insert an 'exploration' dict into each collection node, where the
        # dict includes meta information about the exploration (ID and title).
        for collection_node in collection_dict['nodes']:
            summary = exp_summaries_dict.get(collection_node['exploration_id'])
            collection_node['exploration'] = {
                'id':
                collection_node['exploration_id'],
                'title':
                summary.title if summary else None,
                'category':
                summary.category if summary else None,
                'objective':
                summary.objective if summary else None,
                'ratings':
                summary.ratings if summary else None,
                'last_updated_msec':
                utils.get_time_in_millisecs(
                    summary.exploration_model_last_updated)
                if summary else None,
                'thumbnail_icon_url':
                utils.get_thumbnail_icon_url_for_category(summary.category),
                'thumbnail_bg_color':
                utils.get_hex_color_for_category(summary.category),
            }

        self.values.update({
            'can_edit':
            (self.user_id and rights_manager.Actor(self.user_id).can_edit(
                rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)),
            'collection':
            collection_dict,
            'info_card_image_url':
            utils.get_info_card_url_for_category(collection.category),
            'is_logged_in':
            bool(self.user_id),
            'session_id':
            utils.generate_new_session_id(),
        })

        self.render_json(self.values)
Exemplo n.º 12
0
    def get(self, exploration_id):
        """Populates the data on the individual exploration page.

        Args:
            exploration_id: str. The ID of the exploration.
        """
        version = self.request.get('v')
        story_id = self.request.get('story_id')
        version = int(version) if version else None

        try:
            exploration = exp_services.get_exploration_by_id(
                exploration_id, version=version)
        except Exception as e:
            raise self.PageNotFoundException(e)

        exploration_rights = rights_manager.get_exploration_rights(
            exploration_id, strict=False)
        user_settings = user_services.get_user_settings(self.user_id)

        preferred_audio_language_code = None
        if user_settings is not None:
            preferred_audio_language_code = (
                user_settings.preferred_audio_language_code)

        # Retrieve all classifiers for the exploration.
        state_classifier_mapping = {}
        classifier_training_jobs = (
            classifier_services.get_classifier_training_jobs(
                exploration_id, exploration.version, exploration.states))
        for index, state_name in enumerate(exploration.states):
            if classifier_training_jobs[index] is not None:
                classifier_data = classifier_training_jobs[
                    index].classifier_data
                algorithm_id = classifier_training_jobs[index].algorithm_id
                data_schema_version = (
                    classifier_training_jobs[index].data_schema_version)
                state_classifier_mapping[state_name] = {
                    'algorithm_id': algorithm_id,
                    'classifier_data': classifier_data,
                    'data_schema_version': data_schema_version
                }

        pretest_question_dicts = []
        next_cursor = None
        if story_id:
            story = story_services.get_story_by_id(story_id, strict=False)
            if story is None:
                raise self.InvalidInputException

            if not story.has_exploration(exploration_id):
                raise self.InvalidInputException

            pretest_questions, next_cursor = (
                question_services.get_questions_by_skill_ids(
                    feconf.NUM_PRETEST_QUESTIONS,
                    story.get_prerequisite_skill_ids_for_exp_id(exploration_id),
                    '')
            )
            pretest_question_dicts = [
                question.to_dict() for question in pretest_questions
            ]

        self.values.update({
            'can_edit': (
                rights_manager.check_can_edit_activity(
                    self.user, exploration_rights)),
            'exploration': exploration.to_player_dict(),
            'exploration_id': exploration_id,
            'pretest_question_dicts': pretest_question_dicts,
            'next_cursor_for_pretests': next_cursor,
            'is_logged_in': bool(self.user_id),
            'session_id': utils.generate_new_session_id(),
            'version': exploration.version,
            'preferred_audio_language_code': preferred_audio_language_code,
            'state_classifier_mapping': state_classifier_mapping,
            'auto_tts_enabled': exploration.auto_tts_enabled,
            'correctness_feedback_enabled': (
                exploration.correctness_feedback_enabled),
        })
        self.render_json(self.values)