<commit_before>from rest_framework import serializers

from editorsnotes.auth.models import Project, User

from ..fields import CustomLookupHyperlinkedField, IdentityURLField
from ..ld import ROOT_NAMESPACE
from .base import EmbeddedItemsMixin


__all__ = ['ProjectSerializer', 'UserSerializer']


class ProjectSerializer(serializers.ModelSerializer):
    url = IdentityURLField()

    type = serializers.SerializerMethodField()

    notes = CustomLookupHyperlinkedField(
        view_name='api:notes-list',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    topics = CustomLookupHyperlinkedField(
        view_name='api:topics-list',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    documents = CustomLookupHyperlinkedField(
        view_name='api:documents-list',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    activity = CustomLookupHyperlinkedField(
        view_name='api:projects-activity',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    class Meta:
        model = Project
        fields = (
            'url',
            'type',

            'name',
            'markup',
            'markup_html',

            'notes',
            'topics',
            'documents',
            'activity',

            # FIXME
            # 'featured_items',
            # 'references',
        )

    def get_type(self, obj):
        return ROOT_NAMESPACE + 'Project'



class UserSerializer(EmbeddedItemsMixin, serializers.ModelSerializer):
    url = IdentityURLField()

    type = serializers.SerializerMethodField()

    projects = serializers.HyperlinkedRelatedField(
        source='get_affiliated_projects',
        many=True,
        read_only=True,
        view_name='api:projects-detail',
        lookup_field='slug',
        lookup_url_kwarg='project_slug'
    )

    activity = serializers.HyperlinkedRelatedField(
        source='*',
        read_only=True,
        view_name='api:users-activity',
        lookup_field='username',
        lookup_url_kwarg='username'
    )

    class Meta:
        model = User
        fields = (
            'url',
            'profile',

            'projects',

            'activity',
            'display_name',
            'date_joined',
            'last_login'

            # FIXME
            # 'email',
        )
        embedded_fields = ('projects',)

    def get_type(self, obj):
        return ROOT_NAMESPACE + 'User'<commit_msg>Add missing `type` field in user serializer<commit_after>from rest_framework import serializers

from editorsnotes.auth.models import Project, User

from ..fields import CustomLookupHyperlinkedField, IdentityURLField
from ..ld import ROOT_NAMESPACE
from .base import EmbeddedItemsMixin


__all__ = ['ProjectSerializer', 'UserSerializer']


class ProjectSerializer(serializers.ModelSerializer):
    url = IdentityURLField()

    type = serializers.SerializerMethodField()

    notes = CustomLookupHyperlinkedField(
        view_name='api:notes-list',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    topics = CustomLookupHyperlinkedField(
        view_name='api:topics-list',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    documents = CustomLookupHyperlinkedField(
        view_name='api:documents-list',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    activity = CustomLookupHyperlinkedField(
        view_name='api:projects-activity',
        lookup_kwarg_attrs={'project_slug': 'slug'},
        read_only=True
    )

    class Meta:
        model = Project
        fields = (
            'url',
            'type',

            'name',
            'markup',
            'markup_html',

            'notes',
            'topics',
            'documents',
            'activity',

            # FIXME
            # 'featured_items',
            # 'references',
        )

    def get_type(self, obj):
        return ROOT_NAMESPACE + 'Project'



class UserSerializer(EmbeddedItemsMixin, serializers.ModelSerializer):
    url = IdentityURLField()

    type = serializers.SerializerMethodField()

    projects = serializers.HyperlinkedRelatedField(
        source='get_affiliated_projects',
        many=True,
        read_only=True,
        view_name='api:projects-detail',
        lookup_field='slug',
        lookup_url_kwarg='project_slug'
    )

    activity = serializers.HyperlinkedRelatedField(
        source='*',
        read_only=True,
        view_name='api:users-activity',
        lookup_field='username',
        lookup_url_kwarg='username'
    )

    class Meta:
        model = User
        fields = (
            'url',
            'type',
            'profile',

            'projects',

            'activity',
            'display_name',
            'date_joined',
            'last_login'

            # FIXME
            # 'email',
        )
        embedded_fields = ('projects',)

    def get_type(self, obj):
        return ROOT_NAMESPACE + 'User'
{'fraction_non_alphanumeric': 0.10202887241513851, 'fraction_numerical': 0.0, 'mean_word_length': 2.212406015037594, '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': '2347546', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1430, 'n_words': 250}