def update_story(committer_id, story_id, change_list, commit_message): """Updates a story. Commits changes. Args: committer_id: str. The id of the user who is performing the update action. story_id: str. The story id. change_list: list(StoryChange). These changes are applied in sequence to produce the resulting story. commit_message: str or None. A description of changes made to the story. Raises: ValidationError. Exploration is already linked to a different story. """ if not commit_message: raise ValueError('Expected a commit message but received none.') old_story = story_fetchers.get_story_by_id(story_id) new_story, exp_ids_removed_from_story, exp_ids_added_to_story = ( apply_change_list(story_id, change_list)) story_is_published = _is_story_published_and_present_in_topic(new_story) if (old_story.url_fragment != new_story.url_fragment and does_story_exist_with_url_fragment(new_story.url_fragment)): raise utils.ValidationError( 'Story Url Fragment is not unique across the site.') _save_story(committer_id, new_story, commit_message, change_list, story_is_published) create_story_summary(new_story.id) if story_is_published and _is_topic_published(new_story): opportunity_services.update_exploration_opportunities( old_story, new_story) suggestion_services.auto_reject_translation_suggestions_for_exp_ids( exp_ids_removed_from_story) exploration_context_models_to_be_deleted = ( exp_models.ExplorationContextModel.get_multi( exp_ids_removed_from_story)) exploration_context_models_to_be_deleted = [ model for model in exploration_context_models_to_be_deleted if model is not None ] exp_models.ExplorationContextModel.delete_multi( exploration_context_models_to_be_deleted) exploration_context_models_collisions_list = ( exp_models.ExplorationContextModel.get_multi(exp_ids_added_to_story)) for context_model in exploration_context_models_collisions_list: if context_model is not None and context_model.story_id != story_id: raise utils.ValidationError( 'The exploration with ID %s is already linked to story ' 'with ID %s' % (context_model.id, context_model.story_id)) new_exploration_context_models = [ exp_models.ExplorationContextModel(id=exp_id, story_id=story_id) for exp_id in exp_ids_added_to_story ] exp_models.ExplorationContextModel.put_multi( new_exploration_context_models)
def update_story(committer_id, story_id, change_list, commit_message): """Updates a story. Commits changes. Args: committer_id: str. The id of the user who is performing the update action. story_id: str. The story id. change_list: list(StoryChange).These changes are applied in sequence to produce the resulting story. commit_message: str or None. A description of changes made to the story. """ if not commit_message: raise ValueError('Expected a commit message but received none.') old_story = story_fetchers.get_story_by_id(story_id) new_story = apply_change_list(story_id, change_list) _save_story(committer_id, new_story, commit_message, change_list) create_story_summary(new_story.id) opportunity_services.update_exploration_opportunities(old_story, new_story)