def get_topic_from_model(topic_model): """Returns a topic domain object given a topic model loaded from the datastore. Args: topic_model: TopicModel. The topic model loaded from the datastore. Returns: topic. A Topic domain object corresponding to the given topic model. """ versioned_subtopics = { 'schema_version': topic_model.subtopic_schema_version, 'subtopics': copy.deepcopy(topic_model.subtopics) } if (topic_model.subtopic_schema_version != feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION): _migrate_subtopics_to_latest_schema(versioned_subtopics) return topic_domain.Topic( topic_model.id, topic_model.name, topic_model.description, topic_model.canonical_story_ids, topic_model.additional_story_ids, topic_model.uncategorized_skill_ids, [ topic_domain.Subtopic.from_dict(subtopic) for subtopic in versioned_subtopics['subtopics'] ], versioned_subtopics['schema_version'], topic_model.next_subtopic_id, topic_model.language_code, topic_model.version, topic_model.created_on, topic_model.last_updated)
def get_topic_from_model(topic_model, run_conversion=True): """Returns a topic domain object given a topic model loaded from the datastore. Args: topic_model: TopicModel. The topic model loaded from the datastore. run_conversion: bool. If true, the the topic's schema version will be checked against the current schema version. If they do not match, the topic will be automatically updated to the latest schema version. Returns: topic. A Topic domain object corresponding to the given topic model. """ versioned_subtopics = { 'schema_version': topic_model.subtopic_schema_version, 'subtopics': copy.deepcopy(topic_model.subtopics) } if (run_conversion and topic_model.subtopic_schema_version != feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION): _migrate_subtopics_to_latest_schema(versioned_subtopics) return topic_domain.Topic( topic_model.id, topic_model.name, topic_model.description, topic_model.canonical_story_ids, topic_model.additional_story_ids, topic_model.uncategorized_skill_ids, [ topic_domain.Subtopic.from_dict(subtopic) for subtopic in versioned_subtopics['subtopics'] ], versioned_subtopics['schema_version'], topic_model.next_subtopic_id, topic_model.language_code, topic_model.version, topic_model.created_on, topic_model.last_updated)
def get_topic_from_model(topic_model): """Returns a topic domain object given a topic model loaded from the datastore. Args: topic_model: TopicModel. The topic model loaded from the datastore. Returns: topic. A Topic domain object corresponding to the given topic model. """ versioned_subtopics = { 'schema_version': topic_model.subtopic_schema_version, 'subtopics': copy.deepcopy(topic_model.subtopics) } versioned_canonical_story_references = { 'schema_version': topic_model.story_reference_schema_version, 'story_references': topic_model.canonical_story_references } versioned_additional_story_references = { 'schema_version': topic_model.story_reference_schema_version, 'story_references': topic_model.additional_story_references } if (topic_model.subtopic_schema_version != feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION): _migrate_subtopics_to_latest_schema(versioned_subtopics) if (topic_model.story_reference_schema_version != feconf.CURRENT_STORY_REFERENCE_SCHEMA_VERSION): _migrate_story_references_to_latest_schema( versioned_canonical_story_references) _migrate_story_references_to_latest_schema( versioned_additional_story_references) return topic_domain.Topic( topic_model.id, topic_model.name, topic_model.abbreviated_name, topic_model.url_fragment, topic_model.thumbnail_filename, topic_model.thumbnail_bg_color, topic_model.description, [ topic_domain.StoryReference.from_dict(reference) for reference in versioned_canonical_story_references[ 'story_references'] ], [ topic_domain.StoryReference.from_dict(reference) for reference in versioned_additional_story_references[ 'story_references'] ], topic_model.uncategorized_skill_ids, [ topic_domain.Subtopic.from_dict(subtopic) for subtopic in versioned_subtopics['subtopics'] ], versioned_subtopics['schema_version'], topic_model.next_subtopic_id, topic_model.language_code, topic_model.version, feconf.CURRENT_STORY_REFERENCE_SCHEMA_VERSION, topic_model.meta_tag_content, topic_model.practice_tab_is_displayed, topic_model.page_title_fragment_for_web, topic_model.created_on, topic_model.last_updated)
def get_topic_from_model(topic_model): """Returns a topic domain object given a topic model loaded from the datastore. Args: topic_model: TopicModel. The topic model loaded from the datastore. Returns: topic. A Topic domain object corresponding to the given topic model. """ return topic_domain.Topic( topic_model.id, topic_model.name, topic_model.description, topic_model.canonical_story_ids, topic_model.additional_story_ids, topic_model.skill_ids, topic_model.language_code, topic_model.version, topic_model.created_on, topic_model.last_updated)