def _are_nodes_valid_for_publishing(story_nodes): """Validates the story nodes before publishing. Args: story_nodes: list(dict(str, *)). The list of story nodes dicts. Raises: Exception. The story node doesn't contain any exploration id or the exploration id is invalid or isn't published yet. """ exploration_id_list = [] for node in story_nodes: if not node.exploration_id: raise Exception('Story node with id %s does not contain an ' 'exploration id.' % node.id) exploration_id_list.append(node.exploration_id) story_services.validate_explorations_for_story(exploration_id_list, True)
def get(self, _): """Handler that receives a list of exploration IDs, checks whether the corresponding explorations are supported on mobile and returns the validation error messages (if any). """ comma_separated_exp_ids = self.request.get('comma_separated_exp_ids') if not comma_separated_exp_ids: raise self.InvalidInputException( 'Expected comma_separated_exp_ids parameter to be present.') exp_ids = comma_separated_exp_ids.split(',') validation_error_messages = ( story_services.validate_explorations_for_story(exp_ids, False)) self.values.update( {'validation_error_messages': validation_error_messages}) self.render_json(self.values)
def map(item): if item.deleted: yield (StoryExplorationsAuditOneOffJob._DELETED_KEY, 1) return story = story_fetchers.get_story_by_id(item.id) exp_ids = story.story_contents.get_all_linked_exp_ids() validation_errors = story_services.validate_explorations_for_story( exp_ids, False) if validation_errors: yield (StoryExplorationsAuditOneOffJob._ERROR_KEY, 'Failed to validate explorations for story %s: %s' % (item.id, validation_errors)) return yield (StoryExplorationsAuditOneOffJob._PROCESSED_KEY, 1)