<commit_before>"""
Serilizers for the Agency application API
"""

from rest_framework import serializers

from muckrock.agency.models import Agency

# pylint: disable=too-few-public-methods

class AgencySerializer(serializers.ModelSerializer):
    """Serializer for Agency model"""
    types = serializers.StringRelatedField(many=True)
    appeal_agency = serializers.PrimaryKeyRelatedField(
            queryset=Agency.objects.all(),
            style={'base_template': 'input.html'})
    parent = serializers.PrimaryKeyRelatedField(
            queryset=Agency.objects.all(),
            style={'base_template': 'input.html'})

    def __init__(self, *args, **kwargs):
        """After initializing the serializer,
        check that the current user has permission
        to view agency email data."""
        # pylint: disable=super-on-old-class
        super(AgencySerializer, self).__init__(*args, **kwargs)
        request = self.context.get('request', None)
        if request is None or not request.user.is_staff:
            self.fields.pop('email')
            self.fields.pop('other_emails')

    class Meta:
        model = Agency
        fields = (
            # describes agency
            'id',
            'name',
            'slug',
            'status',
            'stale',
            'exempt',
            'types',
            # location
            'jurisdiction',
            'address',
            'location',
            # contact info
            'email',
            'other_emails',
            'phone',
            'fax',
            'website',
            'twitter',
            'twitter_handles',
            # connects to other agencies
            'parent',
            'appeal_agency',
            'can_email_appeals',
            # describes agency foia process
            'url',
            'foia_logs',
            'foia_guide',
            # misc
            'public_notes',
        )

<commit_msg>adds location JSONField to agency serializer<commit_after>"""
Serilizers for the Agency application API
"""

from rest_framework import serializers

from muckrock.agency.models import Agency

# pylint: disable=too-few-public-methods

class AgencySerializer(serializers.ModelSerializer):
    """Serializer for Agency model"""
    types = serializers.StringRelatedField(many=True)
    appeal_agency = serializers.PrimaryKeyRelatedField(
            queryset=Agency.objects.all(),
            style={'base_template': 'input.html'})
    parent = serializers.PrimaryKeyRelatedField(
            queryset=Agency.objects.all(),
            style={'base_template': 'input.html'})
    location = serializers.JSONField()

    def __init__(self, *args, **kwargs):
        """After initializing the serializer,
        check that the current user has permission
        to view agency email data."""
        # pylint: disable=super-on-old-class
        super(AgencySerializer, self).__init__(*args, **kwargs)
        request = self.context.get('request', None)
        if request is None or not request.user.is_staff:
            self.fields.pop('email')
            self.fields.pop('other_emails')

    class Meta:
        model = Agency
        fields = (
            # describes agency
            'id',
            'name',
            'slug',
            'status',
            'stale',
            'exempt',
            'types',
            # location
            'jurisdiction',
            'address',
            'location',
            # contact info
            'email',
            'other_emails',
            'phone',
            'fax',
            'website',
            'twitter',
            'twitter_handles',
            # connects to other agencies
            'parent',
            'appeal_agency',
            'can_email_appeals',
            # describes agency foia process
            'url',
            'foia_logs',
            'foia_guide',
            # misc
            'public_notes',
        )

{'fraction_non_alphanumeric': 0.1064099315936154, 'fraction_numerical': 0.0, 'mean_word_length': 1.7822410147991543, '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': '6250167', 'n_tokens_mistral': 1044, 'n_tokens_neox': 1019, 'n_words': 237}