def get_story_from_model(story_model): """Returns a story domain object given a story model loaded from the datastore. Args: story_model: StoryModel. The story model loaded from the datastore. Returns: story. A Story domain object corresponding to the given story model. """ # Ensure the original story model does not get altered. versioned_story_contents = { 'schema_version': story_model.story_contents_schema_version, 'story_contents': copy.deepcopy(story_model.story_contents) } # Migrate the story contents if it is not using the latest schema version. if (story_model.story_contents_schema_version != feconf.CURRENT_STORY_CONTENTS_SCHEMA_VERSION): _migrate_story_contents_to_latest_schema( versioned_story_contents) return story_domain.Story( story_model.id, story_model.title, story_model.description, story_model.notes, story_domain.StoryContents.from_dict( versioned_story_contents['story_contents']), versioned_story_contents['schema_version'], story_model.language_code, story_model.corresponding_topic_id, story_model.version, story_model.created_on, story_model.last_updated)
def get_story_from_model(story_model, run_conversion=True): """Returns a story domain object given a story model loaded from the datastore. Args: story_model: StoryModel. The story model loaded from the datastore. run_conversion: bool. If true, the the story's schema version will be checked against the current schema version. If they do not match, the story will be automatically updated to the latest schema version. Returns: story. A Story domain object corresponding to the given story model. """ # Ensure the original story model does not get altered. versioned_story_contents = { 'schema_version': story_model.schema_version, 'story_contents': copy.deepcopy(story_model.story_contents) } # Migrate the story if it is not using the latest schema version. if (run_conversion and story_model.schema_version != feconf.CURRENT_STORY_CONTENTS_SCHEMA_VERSION): _migrate_story_contents_to_latest_schema(versioned_story_contents) return story_domain.Story( story_model.id, story_model.title, story_model.description, story_model.notes, story_domain.StoryContents.from_dict( versioned_story_contents['story_contents']), versioned_story_contents['schema_version'], story_model.language_code, story_model.version, story_model.created_on, story_model.last_updated)