<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from rest_framework.serializers import \
    Serializer, CharField, DateTimeField, IntegerField
from rest_framework_gis.serializers import GeometryField


class ResourceLinkSerializer(Serializer):
    href = CharField()
    type = CharField()


class ResourceSerializer(Serializer):
    id = CharField()
    title = CharField()
    description = CharField()
    author = CharField()
    links = ResourceLinkSerializer(many=True)
    created_at = DateTimeField()
    updated_at = DateTimeField()
    geom = GeometryField()


class ResourceListSerializer(Serializer):
    catalog = CharField()
    api_url = CharField()
    results = ResourceSerializer(many=True)
    count = IntegerField()<commit_msg>Dynamic serialization of resource lists<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from rest_framework.serializers import \
    Serializer, CharField, DateTimeField, IntegerField, SerializerMethodField
from rest_framework_gis.serializers import GeometryField


class ResourceLinkSerializer(Serializer):
    href = CharField()
    type = CharField()


class ResourceSerializer(Serializer):
    id = CharField()
    title = CharField()
    description = CharField()
    author = CharField()
    links = ResourceLinkSerializer(many=True)
    created_at = DateTimeField()
    updated_at = DateTimeField()
    geom = GeometryField()


class ResourceListSerializer(Serializer):
    catalog = CharField()
    api_url = CharField()
    results = SerializerMethodField()
    count = IntegerField()

    def get_results(self, obj):
        serializer = self.context.get('serializer', ResourceSerializer)
        return [serializer(r).data for r in obj.results]
{'fraction_non_alphanumeric': 0.08398950131233596, 'fraction_numerical': 0.0010498687664041995, 'mean_word_length': 4.508670520231214, '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': '5755342', 'n_tokens_mistral': 507, 'n_tokens_neox': 491, 'n_words': 136}