<commit_before>from data_france.models import Commune, CirconscriptionConsulaire
from phonenumber_field.serializerfields import PhoneNumberField
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from agir.people.serializers import PersonNewsletterListField
from agir.voting_proxies.actions import (
    create_or_update_voting_proxy,
    create_or_update_voting_proxy_request,
    update_voting_proxy,
)
from agir.voting_proxies.models import VotingProxyRequest, VotingProxy


class CommuneOrConsulateSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    type = serializers.SerializerMethodField()
    value = serializers.IntegerField(read_only=True, source="id")
    label = serializers.SerializerMethodField(read_only=True)

    def get_label(self, instance):
        if isinstance(instance, Commune):
            return f"{instance.code_departement} - {instance.nom}"
        if isinstance(instance, CirconscriptionConsulaire):
            return str(instance)

    def get_type(self, instance):
        if isinstance(instance, Commune):
            return "commune"
        if isinstance(instance, CirconscriptionConsulaire):
            return "consulate"


class VoterSerializerMixin(serializers.ModelSerializer):
    firstName = serializers.CharField(
        required=True, source="first_name", label="Prénom"
    )
    lastName = serializers.CharField(required=True, source="last_name", label="Nom")
    email = serializers.EmailField(required=True, label="Adresse e-mail")
    phone = PhoneNumberField(
        required=True, source="contact_phone", label="Numéro de téléphone"
    )
    commune = serializers.PrimaryKeyRelatedField(<commit_msg>fix: CommuneOrConsulateSerializer commune type label<commit_after>from data_france.models import Commune, CirconscriptionConsulaire
from phonenumber_field.serializerfields import PhoneNumberField
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from agir.people.serializers import PersonNewsletterListField
from agir.voting_proxies.actions import (
    create_or_update_voting_proxy,
    create_or_update_voting_proxy_request,
    update_voting_proxy,
)
from agir.voting_proxies.models import VotingProxyRequest, VotingProxy


class CommuneOrConsulateSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    type = serializers.SerializerMethodField()
    value = serializers.IntegerField(read_only=True, source="id")
    label = serializers.SerializerMethodField(read_only=True)

    def get_label(self, instance):
        if isinstance(instance, Commune):
            return f"{instance.code_departement} - {instance.nom_complet}"
        if isinstance(instance, CirconscriptionConsulaire):
            return str(instance)

    def get_type(self, instance):
        if isinstance(instance, Commune):
            return "commune"
        if isinstance(instance, CirconscriptionConsulaire):
            return "consulate"


class VoterSerializerMixin(serializers.ModelSerializer):
    firstName = serializers.CharField(
        required=True, source="first_name", label="Prénom"
    )
    lastName = serializers.CharField(required=True, source="last_name", label="Nom")
    email = serializers.EmailField(required=True, label="Adresse e-mail")
    phone = PhoneNumberField(
        required=True, source="contact_phone", label="Numéro de téléphone"
    )
    commune = serializers.PrimaryKeyRelatedField(
{'fraction_non_alphanumeric': 0.07989764003411999, 'fraction_numerical': 0.0, 'mean_word_length': 4.873121869782971, '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': '4991592', 'n_tokens_mistral': 984, 'n_tokens_neox': 975, 'n_words': 191}