예제 #1
0
 def test_generate_new_session_id(self) -> None:
     test_string = utils.generate_new_session_id()
     self.assertEqual(24, len(test_string))
     self.assertIsInstance(test_string, str)
     list_not_allowed = ['+', '/']
     for i in list_not_allowed:
         self.assertNotIn(i, test_string)
예제 #2
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.normalized_request.get('v')

        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)
예제 #3
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)