<commit_before>from rest_framework import serializers

from .models import (
    Classroom, DeviceOwner, Facility, FacilityUser, LearnerGroup, Membership,
    Role
)


class FacilityUserSerializer(serializers.ModelSerializer):

    class Meta:
        model = FacilityUser
        exclude = ("dataset", "last_login")
        extra_kwargs = {'password': {'<PASSWORD>': True}}

    def create(self, validated_data):
        user = FacilityUser(**validated_data)
        user.set_password(validated_data['password'])
        user.save()
        return user


class DeviceOwnerSerializer(serializers.ModelSerializer):

    class Meta:
        model = DeviceOwner
        exclude = ("last_login",)
        extra_kwargs = {'password': {'<PASSWORD>': True}}

    def create(self, validated_data):
        user = DeviceOwner(**validated_data)
        user.set_password(validated_data['password'])
        user.save()
        return user


class MembershipSerializer(serializers.ModelSerializer):

    class Meta:
        model = Membership
        exclude = ("dataset",)


class RoleSerializer(serializers.ModelSerializer):

    class Meta:
        model = Role
        exclude = ("dataset",)


class FacilitySerializer(serializers.ModelSerializer):

    class Meta:
        model = Facility
        exclude = ("dataset", "kind", "parent")


class ClassroomSerializer(serializers.ModelSerializer):

    class Meta:
        model = Classroom
        exclude = ("dataset", "kind")


class LearnerGroupSerializer(serializers.ModelSerializer):

    class Meta:
        model = LearnerGroup
        exclude = ("dataset", "kind")<commit_msg>Add serialized list of learner groups to classroom api<commit_after>from rest_framework import serializers

from .models import (
    Classroom, DeviceOwner, Facility, FacilityUser, LearnerGroup, Membership,
    Role
)


class FacilityUserSerializer(serializers.ModelSerializer):

    class Meta:
        model = FacilityUser
        exclude = ("dataset", "last_login")
        extra_kwargs = {'password': {'<PASSWORD>_<PASSWORD>': True}}

    def create(self, validated_data):
        user = FacilityUser(**validated_data)
        user.set_password(validated_data['password'])
        user.save()
        return user


class DeviceOwnerSerializer(serializers.ModelSerializer):

    class Meta:
        model = DeviceOwner
        exclude = ("last_login",)
        extra_kwargs = {'password': {'<PASSWORD>': True}}

    def create(self, validated_data):
        user = DeviceOwner(**validated_data)
        user.set_password(validated_data['password'])
        user.save()
        return user


class MembershipSerializer(serializers.ModelSerializer):

    class Meta:
        model = Membership
        exclude = ("dataset",)


class RoleSerializer(serializers.ModelSerializer):

    class Meta:
        model = Role
        exclude = ("dataset",)


class FacilitySerializer(serializers.ModelSerializer):

    class Meta:
        model = Facility
        exclude = ("dataset", "kind", "parent")


class ClassroomSerializer(serializers.ModelSerializer):

    class Meta:
        model = Classroom
        fields = ('id', 'name', )

    def to_representation(self, instance):
        representation = super(ClassroomSerializer, self).to_representation(instance)
        representation['learnerGroups'] = []
        for lg in instance.get_learner_groups():
            representation['learnerGroups'].append({
                'id': lg.id,
                'name': lg.name,
            })
        return representation


class LearnerGroupSerializer(serializers.ModelSerializer):

    class Meta:
        model = LearnerGroup
        exclude = ("dataset", "kind")
{'fraction_non_alphanumeric': 0.10472056429734129, 'fraction_numerical': 0.0, 'mean_word_length': 3.033916849015317, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1654242', 'n_tokens_mistral': 994, 'n_tokens_neox': 934, 'n_words': 227}