<commit_before>from accounts.models import Child, DemographicData, Organization, User
from api.serializers import (ModelSerializer, UUIDResourceRelatedField,
                             UUIDSerializerMixin)
from rest_framework_json_api import serializers
from studies.models import Response, Study


class StudySerializer(UUIDSerializerMixin, ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='study-detail',
        lookup_field='uuid'
    )
    organization = UUIDResourceRelatedField(
        queryset=Organization.objects,
        related_link_view_name='organization-detail',
        related_link_lookup_field='uuid', many=False
    )
    creator = UUIDResourceRelatedField(
        queryset=User.objects,
        related_link_view_name='user-detail',
        related_link_lookup_field='uuid', many=False
    )
    responses = UUIDResourceRelatedField(
        queryset=Response.objects,
        many=True,
        related_link_view_name='study-responses-list',
        related_link_url_kwarg='study_uuid',
        related_link_lookup_field='uuid',
    )

    class Meta:
        model = Study
        fields = (
            'url',
            'name',
            'date_modified',
            'short_description',
            'long_description',
            'criteria',
            'duration',
            'contact_info',
            'image',
            'structure',
            'display_full_screen',
            'exit_url',
            'state',
            'public',
            'organization',
            'creator',
            'responses',
        )


class ResponseSerializer(UUIDSerializerMixin, ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='response-detail',
        lookup_field='uuid'
    )
    study = UUIDResourceRelatedField(
        queryset=Study.objects,
        many=False,
        related_link_view_name='study-detail',
        related_link_lookup_field='uuid',
    )
    user = UUIDResourceRelatedField(
        source='child.user',
        queryset=User.objects,
        many=False,
        related_link_view_name='user-list',
        related_link_lookup_field='uuid',
        required=False
    )
    child = UUIDResourceRelatedField(
        queryset=Child.objects,
        many=False,
        related_link_view_name='child-detail',
        related_link_lookup_field='uuid',
    )
    demographic_snapshot = UUIDResourceRelatedField(
        queryset=DemographicData.objects,
        many=False,
        related_link_view_name='demographicdata-detail',
        related_link_lookup_field='uuid'
    )<commit_msg>Don't require demographic snapshot when posting responses.<commit_after>from accounts.models import Child, DemographicData, Organization, User
from api.serializers import (ModelSerializer, UUIDResourceRelatedField,
                             UUIDSerializerMixin)
from rest_framework_json_api import serializers
from studies.models import Response, Study


class StudySerializer(UUIDSerializerMixin, ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='study-detail',
        lookup_field='uuid'
    )
    organization = UUIDResourceRelatedField(
        queryset=Organization.objects,
        related_link_view_name='organization-detail',
        related_link_lookup_field='uuid', many=False
    )
    creator = UUIDResourceRelatedField(
        queryset=User.objects,
        related_link_view_name='user-detail',
        related_link_lookup_field='uuid', many=False
    )
    responses = UUIDResourceRelatedField(
        queryset=Response.objects,
        many=True,
        related_link_view_name='study-responses-list',
        related_link_url_kwarg='study_uuid',
        related_link_lookup_field='uuid',
    )

    class Meta:
        model = Study
        fields = (
            'url',
            'name',
            'date_modified',
            'short_description',
            'long_description',
            'criteria',
            'duration',
            'contact_info',
            'image',
            'structure',
            'display_full_screen',
            'exit_url',
            'state',
            'public',
            'organization',
            'creator',
            'responses',
        )


class ResponseSerializer(UUIDSerializerMixin, ModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='response-detail',
        lookup_field='uuid'
    )
    study = UUIDResourceRelatedField(
        queryset=Study.objects,
        many=False,
        related_link_view_name='study-detail',
        related_link_lookup_field='uuid',
    )
    user = UUIDResourceRelatedField(
        source='child.user',
        queryset=User.objects,
        many=False,
        related_link_view_name='user-list',
        related_link_lookup_field='uuid',
        required=False
    )
    child = UUIDResourceRelatedField(
        queryset=Child.objects,
        many=False,
        related_link_view_name='child-detail',
        related_link_lookup_field='uuid',
    )
    demographic_snapshot = UUIDResourceRelatedField(
        queryset=DemographicData.objects,
        many=False,
        related_link_view_name='demographicdata-detail',
        related_link_lookup_field='uuid',
        required = False
    )
{'fraction_non_alphanumeric': 0.08721918066830281, 'fraction_numerical': 0.0, 'mean_word_length': 2.4924192485168093, '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': '6164160', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1417, 'n_words': 214}