<commit_before># -*- coding: utf-8 -*-

from __future__ import unicode_literals # py2

from public_api.models import Tag, Category, User, Artist, Post, Comment, Entry

from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.serializers import ModelSerializer, SerializerMethodField
from rest_framework.filters import OrderingFilter

from django.db.models import Count


def gen_serializer(name='CustomSerializer', base=ModelSerializer, **kwargs):
    meta = type(str('Meta'), (object,), kwargs)
    return type(str(name), (base,), {'Meta': meta})


class ApiViewSet(ReadOnlyModelViewSet):
    serializers_mapping = {
        'retrieve': ReadOnlyModelViewSet.serializer_class,
        'list': ReadOnlyModelViewSet.serializer_class,
    }

    def get_serializer_class(self):
        return self.serializers_mapping.get(self.action) or\
            super(PostViewSet, self).get_serializer_class()


class TagSerializer(ModelSerializer):
    class Meta:
        exclude = ('posts',)
        model = Tag

class TagViewSet(ReadOnlyModelViewSet):
    queryset = Tag.objects.all()

    serializer_class = TagSerializer
    search_fields = ('title',)



class CategoryListSerializer(ModelSerializer):
    class Meta:
        exclude = ('posts',)
        model = Category

class CategoryViewSet(ReadOnlyModelViewSet):
    queryset = Category.objects.all()

    serializer_class = CategoryListSerializer
    search_fields = ('title',)



class CommentViewSet(ReadOnlyModelViewSet):
    queryset = Category.objects.all()

    filter_fields = ('author', 'post',)
    ordering = ('-date',)



class PostDetailSerializer(ModelSerializer):
    entries = gen_serializer(exclude=('post',), model=Entry)(many=True)
    author = gen_serializer(fields=('id', 'name', 'avatar_url',), model=User)()

    class CommentPostDetailSerializer(ModelSerializer):
        author = gen_serializer(fields=('id', 'name', 'avatar_url',), model=User)()

        class Meta:
            model = Comment
            exclude = ('post',)


    comments = CommentPostDetailSerializer(many=True)
    artists = gen_serializer(fields=('id', 'name', 'avatar_url',), model=Artist)()
    tags = gen_serializer(exclude=('posts',), model=Tag)(many=True)
    categories = gen_serializer(exclude=('posts',), model=Category)(many=True)


    class Meta:
        model = Post

<commit_msg>fix mistake introduced in e49f123<commit_after># -*- coding: utf-8 -*-

from __future__ import unicode_literals # py2

from public_api.models import Tag, Category, User, Artist, Post, Comment, Entry

from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.serializers import ModelSerializer, SerializerMethodField
from rest_framework.filters import OrderingFilter

from django.db.models import Count


def gen_serializer(name='CustomSerializer', base=ModelSerializer, **kwargs):
    meta = type(str('Meta'), (object,), kwargs)
    return type(str(name), (base,), {'Meta': meta})


class ApiViewSet(ReadOnlyModelViewSet):
    serializers_mapping = {
        'retrieve': ReadOnlyModelViewSet.serializer_class,
        'list': ReadOnlyModelViewSet.serializer_class,
    }

    def get_serializer_class(self):
        return self.serializers_mapping.get(self.action) or\
            super(PostViewSet, self).get_serializer_class()


class TagSerializer(ModelSerializer):
    class Meta:
        exclude = ('posts',)
        model = Tag

class TagViewSet(ReadOnlyModelViewSet):
    queryset = Tag.objects.all()

    serializer_class = TagSerializer
    search_fields = ('title',)



class CategoryListSerializer(ModelSerializer):
    class Meta:
        exclude = ('posts',)
        model = Category

class CategoryViewSet(ReadOnlyModelViewSet):
    queryset = Category.objects.all()

    serializer_class = CategoryListSerializer
    search_fields = ('title',)



class CommentViewSet(ReadOnlyModelViewSet):
    queryset = Comment.objects.all()

    filter_fields = ('author', 'post',)
    ordering = ('-date',)



class PostDetailSerializer(ModelSerializer):
    entries = gen_serializer(exclude=('post',), model=Entry)(many=True)
    author = gen_serializer(fields=('id', 'name', 'avatar_url',), model=User)()

    class CommentPostDetailSerializer(ModelSerializer):
        author = gen_serializer(fields=('id', 'name', 'avatar_url',), model=User)()

        class Meta:
            model = Comment
            exclude = ('post',)


    comments = CommentPostDetailSerializer(many=True)
    artists = gen_serializer(fields=('id', 'name', 'avatar_url',), model=Artist)()
    tags = gen_serializer(exclude=('posts',), model=Tag)(many=True)
    categories = gen_serializer(exclude=('posts',), model=Category)(many=True)


    class Meta:
        model = Post


{'fraction_non_alphanumeric': 0.12206969376979937, 'fraction_numerical': 0.0019007391763463568, 'mean_word_length': 4.327334083239595, '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': '2712712', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1356, 'n_words': 290}