<commit_before>from django.core.validators import RegexValidator
from rest_framework import serializers
from concepts.fields import LocalizedTextListField
from concepts.models import Concept, ConceptVersion
from oclapi.models import NAMESPACE_REGEX
from oclapi.serializers import ResourceVersionSerializer


class ConceptListSerializer(serializers.Serializer):
    id = serializers.CharField(source='mnemonic')
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    ownerType = serializers.CharField(source='owner_type')
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    url = serializers.CharField()
    ownerUrl = serializers.CharField(source='owner_url')

    class Meta:
        model = Concept


class ConceptDetailSerializer(serializers.Serializer):
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    names = LocalizedTextListField()
    descriptions = LocalizedTextListField()
    extras = serializers.WritableField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    url = serializers.CharField()
    ownerUrl = serializers.CharField(source='owner_url')

    class Meta:
        model = Concept


class ConceptCreateSerializer(serializers.Serializer):
    id = serializers.CharField(required=True, validators=[RegexValidator(regex=NAMESPACE_REGEX)], source='mnemonic')
    conceptClass = serializers.CharField(required=True, source='concept_class')
    datatype = serializers.CharField(required=False)
    names = LocalizedTextListField(required=True)
    descriptions = LocalizedTextListField(required=False)
    extras = serializers.WritableField(required=False)

    class Meta:
        model = Concept
        lookup_field = 'mnemonic'

    def restore_object(self, attrs, instance=None):
        concept = instance if instance else Concept()
        concept.mnemonic = attrs.get(self.Meta.lookup_field, concept.mnemonic)
        concept.concept_class = attrs.get('concept_class', concept.concept_class)
        concept.datatype = attrs.get('datatype', concept.datatype)
        concept.extras = attrs.get('extras', concept.extras)
        concept.names = attrs.get('names', concept.names)  # Is this desired behavior??
        concept.descriptions = attrs.get('descriptions', concept.descriptions)  # Is this desired behavior??
        return concept

    def save_object(self, obj, **kwargs):
        errors = Concept.persist_new(obj, **kwargs)
        self._errors.update(errors)


class ConceptVersionListSerializer(ResourceVersionSerializer):
    id = serializers.CharField(source='name')
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    ownerType = serializers.CharField(source='owner_type')
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    extras = serializers.WritableField()
    version = serializers.CharField(source='mnemonic')

    class Meta:
        model = ConceptVersion
        versioned_object_field_name = 'url'
        versioned_object_view_name = 'concept-detail'
        fields = ('id', 'conceptClass', 'datatype', 'extras', 'retired', 'source', 'owner', 'ownerType', 'displayName', 'displayLocale', 'url', 'versionUrl', 'version')


class ConceptVersionDetailSerializer(ResourceVersionSerializer):
    id = serializers.CharField(source='name')
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    names = LocalizedTextListField()
    descriptions = LocalizedTextListField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    version = serializers.CharField(source='mnemonic')
    extras = serializers.WritableField()

    class Meta:
        model = ConceptVersion
        versioned_object_field_name = 'url'


class ConceptVersionUpdateSerializer(serializers.Serializer):
    conceptClass = serializers.CharField(required=True, source='concept_class')
    datatype = serializers.CharField(required=False)
    names = LocalizedTextListField(required=True)
    descriptions = LocalizedTextListField(required=False)
    extras = serializers.WritableField(required=False)

    class Meta:
        model = ConceptVersion
<commit_msg>Move "extras" further up in the list<commit_after>from django.core.validators import RegexValidator
from rest_framework import serializers
from concepts.fields import LocalizedTextListField
from concepts.models import Concept, ConceptVersion
from oclapi.models import NAMESPACE_REGEX
from oclapi.serializers import ResourceVersionSerializer


class ConceptListSerializer(serializers.Serializer):
    id = serializers.CharField(source='mnemonic')
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    ownerType = serializers.CharField(source='owner_type')
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    url = serializers.CharField()
    ownerUrl = serializers.CharField(source='owner_url')

    class Meta:
        model = Concept


class ConceptDetailSerializer(serializers.Serializer):
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    names = LocalizedTextListField()
    descriptions = LocalizedTextListField()
    extras = serializers.WritableField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    url = serializers.CharField()
    ownerUrl = serializers.CharField(source='owner_url')

    class Meta:
        model = Concept


class ConceptCreateSerializer(serializers.Serializer):
    id = serializers.CharField(required=True, validators=[RegexValidator(regex=NAMESPACE_REGEX)], source='mnemonic')
    conceptClass = serializers.CharField(required=True, source='concept_class')
    datatype = serializers.CharField(required=False)
    names = LocalizedTextListField(required=True)
    descriptions = LocalizedTextListField(required=False)
    extras = serializers.WritableField(required=False)

    class Meta:
        model = Concept
        lookup_field = 'mnemonic'

    def restore_object(self, attrs, instance=None):
        concept = instance if instance else Concept()
        concept.mnemonic = attrs.get(self.Meta.lookup_field, concept.mnemonic)
        concept.concept_class = attrs.get('concept_class', concept.concept_class)
        concept.datatype = attrs.get('datatype', concept.datatype)
        concept.extras = attrs.get('extras', concept.extras)
        concept.names = attrs.get('names', concept.names)  # Is this desired behavior??
        concept.descriptions = attrs.get('descriptions', concept.descriptions)  # Is this desired behavior??
        return concept

    def save_object(self, obj, **kwargs):
        errors = Concept.persist_new(obj, **kwargs)
        self._errors.update(errors)


class ConceptVersionListSerializer(ResourceVersionSerializer):
    id = serializers.CharField(source='name')
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    ownerType = serializers.CharField(source='owner_type')
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    extras = serializers.WritableField()
    version = serializers.CharField(source='mnemonic')

    class Meta:
        model = ConceptVersion
        versioned_object_field_name = 'url'
        versioned_object_view_name = 'concept-detail'
        fields = ('id', 'conceptClass', 'datatype', 'extras', 'retired', 'source', 'owner', 'ownerType', 'displayName', 'displayLocale', 'url', 'versionUrl', 'version')


class ConceptVersionDetailSerializer(ResourceVersionSerializer):
    id = serializers.CharField(source='name')
    conceptClass = serializers.CharField(source='concept_class')
    datatype = serializers.CharField()
    displayName = serializers.CharField(source='display_name')
    displayLocale = serializers.CharField(source='display_locale')
    names = LocalizedTextListField()
    descriptions = LocalizedTextListField()
    extras = serializers.WritableField()
    retired = serializers.BooleanField()
    source = serializers.CharField(source='parent_resource')
    owner = serializers.CharField(source='owner_name')
    version = serializers.CharField(source='mnemonic')

    class Meta:
        model = ConceptVersion
        versioned_object_field_name = 'url'


class ConceptVersionUpdateSerializer(serializers.Serializer):
    conceptClass = serializers.CharField(required=True, source='concept_class')
    datatype = serializers.CharField(required=False)
    names = LocalizedTextListField(required=True)
    descriptions = LocalizedTextListField(required=False)
    extras = serializers.WritableField(required=False)

    class Meta:
        model = ConceptVersion

{'fraction_non_alphanumeric': 0.10128788612375327, 'fraction_numerical': 0.0, 'mean_word_length': 4.994196169471851, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '964190', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2785, 'n_words': 500}