def __init__(self, index=None, attrs=None, proj=None): """ :param index: Index record or name of Index :type index: text.Index|string :return: """ super(VersionState, self).__init__(attrs) if not index: # so that basic model tests can run if getattr(self, "title", None): try: self.index = library.get_index(self.title) except BookNameError as e: logger.warning(u"Failed to load Index for VersionState - {}: {} (Normal on Index name change)".format(self.title, e)) return if not isinstance(index, AbstractIndex): try: index = library.get_index(index) except BookNameError as e: logger.warning("Failed to load Index for VersionState {}: {}".format(index, e)) raise self.index = index self._versions = {} self.is_new_state = False if not self.load({"title": index.title}, proj=proj): if not getattr(self, "flags", None): # allow flags to be set in initial attrs self.flags = {} self.content = self.index.nodes.create_content(lambda n: {}) self.title = index.title self.refresh() self.is_new_state = True # variable naming: don't override 'is_new' - a method of the superclass
def __init__(self, index=None, attrs=None, proj=None): """ :param index: Index record or name of Index :type index: text.Index|text.CommentaryIndex|string :return: """ super(VersionState, self).__init__(attrs) if not index: # so that basic model tests can run if getattr(self, "title", None): try: self.index = library.get_index(self.title) except BookNameError as e: logger.warning(u"Failed to load Index for VersionState - {}: {} (Normal on Index name change)".format(self.title, e)) return if not isinstance(index, AbstractIndex): try: index = library.get_index(index) except BookNameError as e: logger.warning("Failed to load Index for VersionState {}: {}".format(index, e)) self.index = index self._versions = {} self.is_new_state = False if not self.load({"title": index.title}, proj=proj): if not getattr(self, "flags", None): # allow flags to be set in initial attrs self.flags = {} self.content = self.index.nodes.create_content(lambda n: {}) self.title = index.title self.refresh() self.is_new_state = True # variable naming: don't override 'is_new' - a method of the superclass