Example #1
0
    def _add_subject_identifier (self, address):
        """Adds a subject identifier to this topic.

        This method performs only the actual database operation to add
        the subject identifier, and is only called after appropriate
        checking in add_subject_identifier().

        :param address: external form of a locator
        :type address: string
        
        """
        si = SubjectIdentifier(topic=self, address=address,
                               containing_topic_map=self.topic_map)
        si.save()
        self.subject_identifiers.add(si)
Example #2
0
    def _add_subject_identifier(self, address):
        """Adds a subject identifier to this topic.

        This method performs only the actual database operation to add
        the subject identifier, and is only called after appropriate
        checking in add_subject_identifier().

        :param address: external form of a locator
        :type address: string

        """
        si = SubjectIdentifier(topic=self,
                               address=address,
                               containing_topic_map=self.topic_map)
        si.save()
        self.subject_identifiers.add(si)
Example #3
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
Example #4
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