<commit_before>from csacompendium.research.models import (
    ExperimentObject,
    ObjectCategory,
)
# from csacompendium.research.api.researchobject.researchobjectserializers import research_object_serializers
from csacompendium.utils.hyperlinkedidentity import hyperlinked_identity
from csacompendium.utils.serializersutils import (
    FieldMethodSerializer,
    get_related_content,
    get_related_content_url
)
from rest_framework.serializers import (
    ModelSerializer,
    SerializerMethodField,
)


def experiment_object_serializers():
    """
    Experiment object serializers
    :return: All experiment object serializers
    :rtype: Object
    """

    class ExperimentObjectBaseSerializer(ModelSerializer):
        """
        Base serializer for DRY implementation.
        """
        class Meta:
            model = ExperimentObject
            fields = [
                'exp_object_code',
                'object_name',
                'latin_name',
            ]

    class ExperimentObjectListSerializer(ExperimentObjectBaseSerializer):
        """
        Serialize all records in given fields into an API
        """
        url = hyperlinked_identity('research_api:experiment_object_detail', 'slug')

        class Meta:
            model = ExperimentObject
            fields = ExperimentObjectBaseSerializer.Meta.fields + ['url', ]

    class ExperimentObjectDetailSerializer(ExperimentObjectBaseSerializer, FieldMethodSerializer):
        """
        Serialize single record into an API. This is dependent on fields given.
        """
        # research_object_serializers = research_object_serializers()
        object_category_url = SerializerMethodField()
        user = SerializerMethodField()
        modified_by = SerializerMethodField()
        research_object = SerializerMethodField()

        class Meta:
            common_fields = [
                'modified_by',
                'last_update',
                'time_created',
                'research_object',
            ]
            model = ExperimentObject
            fields = ['id', 'objectcategory', 'object_category_url', ] + \
                     ExperimentObjectBaseSerializer.Meta.fields + ['user', ] + common_fields
            read_only_fields = ['id', ] + common_fields

        def get_object_category_url(self, obj):
            """
            Get related content type/object url
            :param obj: Current record object
            :return: URL to related object
            :rtype: String
            """
            return get_related_content_url(ObjectCategory, obj.objectcategory.id)

        def get_research_object(self, obj):
            """
            :param obj: Current record object
            :return: Research object
            :rtype: Object/record
            """
            request = self.context['request']
            # ResearchObjectListSerializer = self.research_object_serializers['ResearchObjectListSerializer']
            # related_content = get_related_content(
            #     obj, ResearchObjectListSerializer, obj.research_object_relation, request
            # )
            # return related_content

    return {
        'ExperimentObjectListSerializer': ExperimentObjectListSerializer,
        'ExperimentObjectDetailSerializer': ExperimentObjectDetailSerializer
    }<commit_msg>Uncommented experiment object relation to research object<commit_after>from csacompendium.research.models import (
    ExperimentObject,
    ObjectCategory,
)
from csacompendium.research.api.researchobject.researchobjectserializers import research_object_serializers
from csacompendium.utils.hyperlinkedidentity import hyperlinked_identity
from csacompendium.utils.serializersutils import (
    FieldMethodSerializer,
    get_related_content,
    get_related_content_url
)
from rest_framework.serializers import (
    ModelSerializer,
    SerializerMethodField,
)


def experiment_object_serializers():
    """
    Experiment object serializers
    :return: All experiment object serializers
    :rtype: Object
    """

    class ExperimentObjectBaseSerializer(ModelSerializer):
        """
        Base serializer for DRY implementation.
        """
        class Meta:
            model = ExperimentObject
            fields = [
                'exp_object_code',
                'object_name',
                'latin_name',
            ]

    class ExperimentObjectListSerializer(ExperimentObjectBaseSerializer):
        """
        Serialize all records in given fields into an API
        """
        url = hyperlinked_identity('research_api:experiment_object_detail', 'slug')

        class Meta:
            model = ExperimentObject
            fields = ExperimentObjectBaseSerializer.Meta.fields + ['url', ]

    class ExperimentObjectDetailSerializer(ExperimentObjectBaseSerializer, FieldMethodSerializer):
        """
        Serialize single record into an API. This is dependent on fields given.
        """
        research_object_serializers = research_object_serializers()
        object_category_url = SerializerMethodField()
        user = SerializerMethodField()
        modified_by = SerializerMethodField()
        research_object = SerializerMethodField()

        class Meta:
            common_fields = [
                'modified_by',
                'last_update',
                'time_created',
                'research_object',
            ]
            model = ExperimentObject
            fields = ['id', 'objectcategory', 'object_category_url', ] + \
                     ExperimentObjectBaseSerializer.Meta.fields + ['user', ] + common_fields
            read_only_fields = ['id', ] + common_fields

        def get_object_category_url(self, obj):
            """
            Get related content type/object url
            :param obj: Current record object
            :return: URL to related object
            :rtype: String
            """
            return get_related_content_url(ObjectCategory, obj.objectcategory.id)

        def get_research_object(self, obj):
            """
            :param obj: Current record object
            :return: Research object
            :rtype: Object/record
            """
            request = self.context['request']
            ResearchObjectListSerializer = self.research_object_serializers['ResearchObjectListSerializer']
            related_content = get_related_content(
                obj, ResearchObjectListSerializer, obj.research_object_relation, request
            )
            return related_content

    return {
        'ExperimentObjectListSerializer': ExperimentObjectListSerializer,
        'ExperimentObjectDetailSerializer': ExperimentObjectDetailSerializer
    }
{'fraction_non_alphanumeric': 0.07057594747836467, 'fraction_numerical': 0.0, 'mean_word_length': 2.4198979591836736, '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': '7591993', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1547, 'n_words': 344}