예제 #1
0
파일: models.py 프로젝트: sunu/oppia-test-2
    def create(cls, user, title, category, exploration_id=None, init_state_name="Activity 1", image_id=None):
        """Creates and returns a new exploration."""
        # Generate a new exploration id, if one wasn't passed in.
        exploration_id = exploration_id or cls.get_new_id(title)

        # Temporarily create a fake initial state key.
        state_id = State.get_new_id(init_state_name)
        fake_state_key = ndb.Key(Exploration, exploration_id, State, state_id)

        # Note that demo explorations do not have owners, so user may be None.
        exploration = cls(
            id=exploration_id,
            title=title,
            init_state=fake_state_key,
            category=category,
            image_id=image_id,
            states=[fake_state_key],
            editors=[user] if user else [],
        )
        exploration.put()

        # Finally, create the initial state and check that it has the right key.
        new_init_state = State.create(exploration, init_state_name, state_id=state_id)
        assert fake_state_key == new_init_state.key

        return exploration