<commit_before># -*- coding: utf-8 -*-
# Copyright (c) 2016 Aladom SAS & Hosting Dvpt SAS
from django.db.models import CharField
from django.utils.translation import ugettext_lazy as _

from ..phone import Phone


class PhoneField(CharField):
    description = _("Phone number")

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('max_length', 20)
        super().__init__(*args, **kwargs)

    def from_db_value(self, value, expression, connection, context):
        if value is None:
            return value
        return Phone(value)

    def to_python(self, value):
        if isinstance(value, Phone) or value is None:
            return value
        return Phone(value)

    def get_prep_value(self, value):
        return str(value)<commit_msg>Implemented get_FOO_display() for PhoneField<commit_after># -*- coding: utf-8 -*-
# Copyright (c) 2016 Aladom SAS & Hosting Dvpt SAS
from django.db.models import CharField
from django.utils.translation import ugettext_lazy as _

from ..phone import Phone


class PhoneField(CharField):
    description = _("Phone number")

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('max_length', 20)
        super().__init__(*args, **kwargs)

    def from_db_value(self, value, expression, connection, context):
        if value is None:
            return value
        return Phone(value)

    def to_python(self, value):
        if isinstance(value, Phone) or value is None:
            return value
        return Phone(value)

    def get_prep_value(self, value):
        return str(value)

    def contribute_to_class(self, cls, name, *args, **kwargs):
        super().contribute_to_class(self, cls, name, *args, **kwargs)

        def get_FOO_display(s):
            field = getattr(s, name)
            return field.format() if field else '-'

        setattr(cls, 'get_{}_display'.format(self.name), get_FOO_display)
{'fraction_non_alphanumeric': 0.10871848739495799, 'fraction_numerical': 0.007352941176470588, 'mean_word_length': 2.96875, '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': '481781', 'n_tokens_mistral': 584, 'n_tokens_neox': 553, 'n_words': 166}