コード例 #1
0
ファイル: models.py プロジェクト: OpenConceptLab/oclapi2
    def parse(self):
        source = Source.objects.filter(**{
            self.get_owner_type_filter():
            self.get('owner')
        },
                                       mnemonic=self.get('source'),
                                       version=HEAD).first()
        self.data = self.get_filter_allowed_fields()
        self.data['parent'] = source

        if self.get('id'):
            self.data['mnemonic'] = self.data.pop('id')

        from_concept_code = self.data.get('from_concept_code')
        to_concept_code = self.data.get('to_concept_code')
        if from_concept_code and not is_url_encoded_string(from_concept_code):
            self.data['from_concept_code'] = encode_string(from_concept_code)
        if to_concept_code and not is_url_encoded_string(to_concept_code):
            self.data['to_concept_code'] = encode_string(to_concept_code)
コード例 #2
0
ファイル: models.py プロジェクト: OpenConceptLab/oclapi2
 def parse(self):
     source = Source.objects.filter(**{
         self.get_owner_type_filter():
         self.get('owner')
     },
                                    mnemonic=self.get('source'),
                                    version=HEAD).first()
     super().parse()
     self.data['parent'] = source
     self.data['name'] = self.data['mnemonic'] = self.data.pop('id')
     if not is_url_encoded_string(self.data['mnemonic']):
         self.data['mnemonic'] = encode_string(self.data['mnemonic'])
コード例 #3
0
ファイル: models.py プロジェクト: OpenConceptLab/oclapi2
        def get_concept(expression):
            concept = Concept.objects.filter(uri=expression).first()
            if concept:
                return concept
            concept = Concept.objects.filter(
                uri=encode_string(expression, safe='/')).first()
            if concept:
                return concept

            parent_uri = to_parent_uri(expression)
            code = expression.replace(parent_uri, '').replace('concepts/',
                                                              '').split('/')[0]
            return dict(mnemonic=code)
コード例 #4
0
ファイル: models.py プロジェクト: OpenConceptLab/oclapi2
    def populate_fields_from_relations(self, data):
        from core.concepts.models import Concept
        from core.sources.models import Source

        to_concept_url = data.get('to_concept_url', None)
        from_concept_url = data.get('from_concept_url', None)
        to_source_url = data.get('to_source_url', None)
        from_source_url = data.get('from_source_url', None)

        def get_concept(expression):
            concept = Concept.objects.filter(uri=expression).first()
            if concept:
                return concept
            concept = Concept.objects.filter(
                uri=encode_string(expression, safe='/')).first()
            if concept:
                return concept

            parent_uri = to_parent_uri(expression)
            code = expression.replace(parent_uri, '').replace('concepts/',
                                                              '').split('/')[0]
            return dict(mnemonic=code)

        def get_source_info(parent_uri, child_uri, existing_version, concept):
            if not parent_uri and not child_uri:
                return existing_version, get(concept, 'parent.uri')

            if parent_uri:
                version, uri = separate_version(parent_uri)
            else:
                version, uri = separate_version(to_parent_uri(child_uri))

            return version or existing_version, uri or get(
                concept, 'parent.uri')

        to_concept_code = data.get('to_concept_code')
        from_concept_code = data.get('from_concept_code')
        if to_concept_code and not is_url_encoded_string(to_concept_code):
            to_concept_code = encode_string(to_concept_code)
        if from_concept_code and not is_url_encoded_string(from_concept_code):
            from_concept_code = encode_string(from_concept_code)

        if not to_concept_url and not get(
                self, 'to_concept') and to_source_url and (
                    to_concept_code or self.to_concept_code):
            to_concept_code = to_concept_code or self.to_concept_code
            to_concept_url = to_source_url + 'concepts/' + to_concept_code + '/'

        if not from_concept_url and not get(
                self, 'from_concept') and from_source_url and (
                    from_concept_code or self.from_concept_code):
            from_concept_code = from_concept_code or self.from_concept_code
            from_concept_url = from_source_url + 'concepts/' + from_concept_code + '/'

        from_concept = get_concept(
            from_concept_url) if from_concept_url else get(
                self, 'from_concept')
        to_concept = get_concept(to_concept_url) if to_concept_url else get(
            self, 'to_concept')

        self.from_concept_id = get(from_concept, 'id')
        self.to_concept_id = get(to_concept, 'id')

        self.from_concept_code = data.get('from_concept_code', None) or get(
            from_concept, 'mnemonic') or self.from_concept_code
        self.from_concept_name = data.get('from_concept_name',
                                          None) or self.from_concept_name
        self.to_concept_code = data.get('to_concept_code', None) or get(
            to_concept, 'mnemonic') or self.to_concept_code
        self.to_concept_name = data.get('to_concept_name',
                                        None) or self.to_concept_name

        self.from_source_version, self.from_source_url = get_source_info(
            from_source_url, from_concept_url, self.from_source_version,
            from_concept)
        self.to_source_version, self.to_source_url = get_source_info(
            to_source_url, to_concept_url, self.to_source_version, to_concept)

        self.to_source = Source.objects.filter(
            models.Q(uri=self.to_source_url)
            | models.Q(canonical_url=self.to_source_url)).filter(
                version=HEAD).first()
        self.from_source = Source.objects.filter(
            models.Q(uri=self.from_source_url)
            | models.Q(canonical_url=self.from_source_url)).filter(
                version=HEAD).first()
コード例 #5
0
 def to_internal_value(self, data):
     string = super().to_internal_value(data)
     return string if is_url_encoded_string(string) else encode_string(
         string)