<commit_before><commit_msg>Implement serializers for #243 . Serialized is readonly for now<commit_after>__author__ = 'sweemeng'
from popit.models import Person
from popit.models import Organization
from popit.models import Post
from popit.models import Membership
from popit.models import ContactDetail
from popit.models import Link
from popit.models import Identifier
from popit.models import OtherName
from hvad.contrib.restframework import TranslatableModelSerializer
from popit.serializers.base import BasePopitSerializer
from popit.serializers.misc import OtherNameSerializer
from popit.serializers.misc import IdentifierSerializer
from popit.serializers.misc import LinkSerializer
from popit.serializers.misc import ContactDetailSerializer


# Why not flat? Because it is not truly flat, we just remove some relationship, but not all
# This is mostly read only we won't be writing data to this
class MinPersonSerializer(TranslatableModelSerializer):
    other_names = OtherNameSerializer(many=True, required=False)
    identifiers = IdentifierSerializer(many=True, required=False)
    links = LinkSerializer(many=True, required=False)
    contact_details = ContactDetailSerializer(many=True, required=False)
 
    class Meta:
        model = Person
        extra_kwargs = {'id': {'read_only': False, 'required': False}}


class MinOrganizationSerializer(TranslatableModelSerializer):
    other_names = OtherNameSerializer(many=True, required=False)
    identifiers = IdentifierSerializer(many=True, required=False)
    links = LinkSerializer(many=True, required=False)
    contact_details = ContactDetailSerializer(many=True, required=False)
 
    class Meta:
        model = Organization
        extra_kwargs = {'id': {'read_only': False, 'required': False}}


class MinMembershipSerializer(TranslatableModelSerializer):
    links = LinkSerializer(many=True, required=False)
    contact_details = ContactDetailSerializer(many=True, required=False)

    class Meta:
        model = Membership
        extra_kwargs = {'id': {'read_only': False, 'required': False}}


class MinPostSerializer(TranslatableModelSerializer):
    other_labels = OtherNameSerializer(many=True, required=False)
    links = LinkSerializer(many=True, required=False)
    contact_details = ContactDetailSerializer(many=True, required=False)
 
    class Meta:
        model = Post
        extra_kwargs = {'id': {'read_only': False, 'required': False}}

{'fraction_non_alphanumeric': 0.08027995059695348, 'fraction_numerical': 0.0012350761630300535, 'mean_word_length': 5.462765957446808, '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': '2110941', 'n_tokens_mistral': 642, 'n_tokens_neox': 622, 'n_words': 182}