def add_subject_locator (self, subject_locator): """Adds a subject locator to this topic. If adding the specified subject locator would make this topic represent teh same subject as another topic and the feature 'automerge' (http://tmapi.org/features/automerge/) is disabled, an `IdentityConstraintException` is thrown. :param subject_locator: the subject locator to be added :type subject_locator: `Locator` """ if subject_locator is None: raise ModelConstraintException( self, 'The subject locator may not be None') address = subject_locator.to_external_form() try: topic = self.topic_map.topic_constructs.get( subject_locators__address=address) if topic == self: return elif self.topic_map.topic_map_system.get_feature( AUTOMERGE_FEATURE_STRING): self.merge_in(topic) else: raise IdentityConstraintException( self, topic, subject_locator, 'Another topic has the same subject locator and automerge is disabled') except Topic.DoesNotExist: sl = SubjectLocator(topic=self, address=address, containing_topic_map=self.topic_map) sl.save() self.subject_locators.add(sl)
def create_topic_by_subject_locator (self, subject_locator): """Returns a `Topic` instance with the specified subject locator. This method returns either an existing `Topic` or creates a new `Topic` instance with the specified subject locator. :param subject_locator: the subject locator the topic should contain :type subject_locator: `Locator` :rtype: `Topic` """ if subject_locator is None: raise ModelConstraintException( self, 'The subject locator may not be None') reference = subject_locator.to_external_form() try: topic = self.topic_constructs.get( subject_locators__address=reference) except Topic.DoesNotExist: topic = Topic(topic_map=self) topic.save() sl = SubjectLocator(topic=topic, address=reference, containing_topic_map=self) sl.save() topic.subject_locators.add(sl) return topic
def add_subject_locator(self, subject_locator): """Adds a subject locator to this topic. If adding the specified subject locator would make this topic represent teh same subject as another topic and the feature 'automerge' (http://tmapi.org/features/automerge/) is disabled, an `IdentityConstraintException` is thrown. :param subject_locator: the subject locator to be added :type subject_locator: `Locator` """ if subject_locator is None: raise ModelConstraintException( self, 'The subject locator may not be None') address = subject_locator.to_external_form() try: topic = self.topic_map.topic_constructs.get( subject_locators__address=address) if topic == self: return elif self.topic_map.topic_map_system.get_feature( AUTOMERGE_FEATURE_STRING): self.merge_in(topic) else: raise IdentityConstraintException( self, topic, subject_locator, 'Another topic has the same subject locator and automerge is disabled' ) except Topic.DoesNotExist: sl = SubjectLocator(topic=self, address=address, containing_topic_map=self.topic_map) sl.save() self.subject_locators.add(sl)
def create_topic_by_subject_locator(self, subject_locator): """Returns a `Topic` instance with the specified subject locator. This method returns either an existing `Topic` or creates a new `Topic` instance with the specified subject locator. :param subject_locator: the subject locator the topic should contain :type subject_locator: `Locator` :rtype: `Topic` """ if subject_locator is None: raise ModelConstraintException( self, 'The subject locator may not be None') reference = subject_locator.to_external_form() try: topic = self.topic_constructs.get( subject_locators__address=reference) except Topic.DoesNotExist: topic = Topic(topic_map=self) topic.save() sl = SubjectLocator(topic=topic, address=reference, containing_topic_map=self) sl.save() topic.subject_locators.add(sl) return topic