Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def create_empty_topic (self):
        """Returns a `Topic` instance with no other information.

        :rtype: `Topic`

        """
        topic = Topic(topic_map=self)
        topic.save()
        return topic
Ejemplo n.º 4
0
    def create_empty_topic(self):
        """Returns a `Topic` instance with no other information.

        :rtype: `Topic`

        """
        topic = Topic(topic_map=self)
        topic.save()
        return topic
Ejemplo n.º 5
0
    def create_topic_by_subject_identifier(self, subject_identifier):
        """Returns a `Topic` instance with the specified subject identifier.

        This method returns either an existing `Topic` or creates a
        new `Topic` instance with the specified subject identifier.

        If a topic with the specified subject identifier exists in
        this topic map, that topic is returned. If a topic with an
        item identifier equal to the specified subject identifier
        exists, the specified subject identifier is added to that
        topic and the topic is returned. If neither a topic with the
        specified subject identifier nor with an item identifier equal
        to the subject identifier exists, a topic with the subject
        identifier is created.

        :param subject_identifier: the subject identifier the topic
          should contain
        :type subject_identifier: `Locator`
        :rtype: `Topic`

        """
        if subject_identifier is None:
            raise ModelConstraintException(
                self, 'The subject identifier may not be None')
        reference = subject_identifier.to_external_form()
        try:
            topic = self.topic_constructs.get(
                subject_identifiers__address=reference)
        except Topic.DoesNotExist:
            try:
                topic = self.topic_constructs.get(
                    item_identifiers__address=reference)
            except Topic.DoesNotExist:
                topic = Topic(topic_map=self)
                topic.save()
            si = SubjectIdentifier(topic=topic,
                                   address=reference,
                                   containing_topic_map=self)
            si.save()
            topic.subject_identifiers.add(si)
        return topic
Ejemplo n.º 6
0
    def create_topic_by_subject_identifier (self, subject_identifier):
        """Returns a `Topic` instance with the specified subject identifier.

        This method returns either an existing `Topic` or creates a
        new `Topic` instance with the specified subject identifier.

        If a topic with the specified subject identifier exists in
        this topic map, that topic is returned. If a topic with an
        item identifier equal to the specified subject identifier
        exists, the specified subject identifier is added to that
        topic and the topic is returned. If neither a topic with the
        specified subject identifier nor with an item identifier equal
        to the subject identifier exists, a topic with the subject
        identifier is created.

        :param subject_identifier: the subject identifier the topic
          should contain
        :type subject_identifier: `Locator`
        :rtype: `Topic`

        """
        if subject_identifier is None:
            raise ModelConstraintException(
                self, 'The subject identifier may not be None')
        reference = subject_identifier.to_external_form()
        try:
            topic = self.topic_constructs.get(
                subject_identifiers__address=reference)
        except Topic.DoesNotExist:
            try:
                topic = self.topic_constructs.get(
                    item_identifiers__address=reference)
            except Topic.DoesNotExist:
                topic = Topic(topic_map=self)
                topic.save()
            si = SubjectIdentifier(topic=topic, address=reference,
                                   containing_topic_map=self)
            si.save()
            topic.subject_identifiers.add(si)
        return topic