<commit_before># coding: utf-8

from __future__ import unicode_literals
from django.core.exceptions import ValidationError
from django.db.models import CharField, FloatField, BooleanField, ForeignKey, \
                             ManyToManyField, OneToOneField, permalink, Q
from django.utils.html import strip_tags
from django.utils.translation import pgettext, ungettext_lazy, \
                                     ugettext,  ugettext_lazy as _
from tinymce.models import HTMLField
from .common import CustomModel, AutoriteModel, LOWER_MSG, PLURAL_MSG, \
                    calc_pluriel, UniqueSlugModel
from ..templatetags.extras import abbreviate
from .evenement import Evenement
from .functions import str_list, str_list_w_last, href, sc


__all__ = (b'Prenom', b'TypeDeParenteDIndividus', b'ParenteDIndividus',
           b'Individu')


class Prenom(CustomModel):
    prenom = CharField(_('prénom'), max_length=100, db_index=True)
    classement = FloatField(_('classement'), default=1.0, db_index=True)
    favori = BooleanField(_('favori'), default=True, db_index=True)

    class Meta(object):
        verbose_name = ungettext_lazy('prénom', 'prénoms', 1)
        verbose_name_plural = ungettext_lazy('prénom', 'prénoms', 2)
        ordering = ('classement', 'prenom')
        app_label = 'catalogue'

    def has_individu(self):
        return self.individus.exists()
    has_individu.short_description = _('individu(s) lié(s)')
    has_individu.boolean = True

    def __unicode__(self):
        return self.prenom

    @staticmethod
    def autocomplete_search_fields():
        return 'prenom__icontains',


class TypeDeParenteDIndividus(CustomModel):
    nom = CharField(_('nom'), max_length=50, help_text=LOWER_MSG, unique=True,
                    db_index=True)
    nom_pluriel = CharField(_('nom (au pluriel)'), max_length=55, blank=True,
                            help_text=PLURAL_MSG)
    nom_relatif = CharField(_('nom relatif'), max_length=50, db_index=True,
                            help_text=LOWER_MSG)
    nom_relatif_pluriel = CharField(_('nom relatif (au pluriel)'),
                                    max_length=55, help_text=PLURAL_MSG,
                                    blank=True)
    classement = FloatField(_('classement'), default=1.0, db_index=True)

    class Meta(object):
        verbose_name = ungettext_lazy('type de parenté d’individus',
                                      'types de parenté d’individus', 1)
        verbose_name_plural = ungettext_lazy(
            'type de parenté d’individus',
            'types de parenté d’individus',
            2)
        ordering = ('classement',)
        app_label = 'catalogue'

    def pluriel(self):
        return calc_pluriel(self)

    def __unicode__(self):
        return self.nom


class ParenteDIndividus(CustomModel):
    type = ForeignKey('TypeDeParenteDIndividus', related_name='parentes',
                      verbose_name=_('type'), db_index=True)
    parent = ForeignKey('Individu', related_name='enfances',
                        verbose_name=_('individu parent'), db_index=True)
    enfant = ForeignKey('Individu', related_name='parentes',
                        verbose_name=_('individu enfant'), db_index=True)

    class Meta(object):
        verbose_name = ungettext_lazy('parenté d’individus',
                                      'parentés d’individus', 1)
        verbose_name_plural = ungettext_lazy('parenté d’individus',
                                             'parentés d’individus', 2)
        ordering = ('type', 'parent', 'enfant')
        app_label = 'catalogue'

    def clean(self):
        if self.parent == self.enfant:
                raise ValidationError(_('Un individu ne peut avoir une '
                                        'parenté avec lui-même.'))

    def __unicode__(self):
        return _('%s, %s de %s') % (self.parent, self.type.nom,
                                    self.enfant)

    def pluriel(self):
        return calc_pluriel(self)

    def relatif_pluriel(self):
        return calc_pluriel(self, attr_base='nom_relatif')


class Individu(AutoriteModel, UniqueSlugModel):
    particule_nom = CharField(
        _('particule du nom d’usage'), max_length=10, blank=True,
        db_index=True)
    # TODO: rendre le champ nom 'blank'
    nom = CharField(_('nom d’usage'), max_length=200, db_index=True)
    particule_nom_naissance = CharField(
        _('particule du nom de naissance'), max_length=10, blank=True,<commit_msg>Corrige un bug d'enregistrement.<commit_after># coding: utf-8

from __future__ import unicode_literals
from django.core.exceptions import ValidationError
from django.db.models import CharField, FloatField, BooleanField, ForeignKey, \
                             ManyToManyField, OneToOneField, permalink, Q
from django.utils.html import strip_tags
from django.utils.translation import pgettext, ungettext_lazy, \
                                     ugettext,  ugettext_lazy as _
from tinymce.models import HTMLField
from .common import CustomModel, AutoriteModel, LOWER_MSG, PLURAL_MSG, \
                    calc_pluriel, UniqueSlugModel
from ..templatetags.extras import abbreviate
from .evenement import Evenement
from .functions import str_list, str_list_w_last, href, sc


__all__ = (b'Prenom', b'TypeDeParenteDIndividus', b'ParenteDIndividus',
           b'Individu')


class Prenom(CustomModel):
    prenom = CharField(_('prénom'), max_length=100, db_index=True)
    classement = FloatField(_('classement'), default=1.0, db_index=True)
    favori = BooleanField(_('favori'), default=True, db_index=True)

    class Meta(object):
        verbose_name = ungettext_lazy('prénom', 'prénoms', 1)
        verbose_name_plural = ungettext_lazy('prénom', 'prénoms', 2)
        ordering = ('classement', 'prenom')
        app_label = 'catalogue'

    def has_individu(self):
        return self.individus.exists()
    has_individu.short_description = _('individu(s) lié(s)')
    has_individu.boolean = True

    def __unicode__(self):
        return self.prenom

    @staticmethod
    def autocomplete_search_fields():
        return 'prenom__icontains',


class TypeDeParenteDIndividus(CustomModel):
    nom = CharField(_('nom'), max_length=50, help_text=LOWER_MSG, unique=True,
                    db_index=True)
    nom_pluriel = CharField(_('nom (au pluriel)'), max_length=55, blank=True,
                            help_text=PLURAL_MSG)
    nom_relatif = CharField(_('nom relatif'), max_length=50, db_index=True,
                            help_text=LOWER_MSG)
    nom_relatif_pluriel = CharField(_('nom relatif (au pluriel)'),
                                    max_length=55, help_text=PLURAL_MSG,
                                    blank=True)
    classement = FloatField(_('classement'), default=1.0, db_index=True)

    class Meta(object):
        verbose_name = ungettext_lazy('type de parenté d’individus',
                                      'types de parenté d’individus', 1)
        verbose_name_plural = ungettext_lazy(
            'type de parenté d’individus',
            'types de parenté d’individus',
            2)
        ordering = ('classement',)
        app_label = 'catalogue'

    def pluriel(self):
        return calc_pluriel(self)

    def __unicode__(self):
        return self.nom


class ParenteDIndividus(CustomModel):
    type = ForeignKey('TypeDeParenteDIndividus', related_name='parentes',
                      verbose_name=_('type'), db_index=True)
    parent = ForeignKey('Individu', related_name='enfances',
                        verbose_name=_('individu parent'), db_index=True)
    enfant = ForeignKey('Individu', related_name='parentes',
                        verbose_name=_('individu enfant'), db_index=True)

    class Meta(object):
        verbose_name = ungettext_lazy('parenté d’individus',
                                      'parentés d’individus', 1)
        verbose_name_plural = ungettext_lazy('parenté d’individus',
                                             'parentés d’individus', 2)
        ordering = ('type', 'parent', 'enfant')
        app_label = 'catalogue'

    def clean(self):
        try:
            parent, enfant = self.parent, self.enfant
        except Individu.DoesNotExist:
            return
        if parent and enfant and parent == enfant:
            raise ValidationError(_('Un individu ne peut avoir une '
                                    'parenté avec lui-même.'))

    def __unicode__(self):
        return _('%s, %s de %s') % (self.parent, self.type.nom,
                                    self.enfant)

    def pluriel(self):
        return calc_pluriel(self)

    def relatif_pluriel(self):
        return calc_pluriel(self, attr_base='nom_relatif')


class Individu(AutoriteModel, UniqueSlugModel):
    particule_nom = CharField(
        _('particule du nom d’usage'), max_length=10, blank=True,
        db_index=True)
    # TODO: rendre le champ nom 'blank'
    nom = CharField(_('nom d’usage'), max_length=200, db_index=True)
    particule_nom_naissance = CharField(
        _('particule du nom de naissance'), max_length=10, blank=True,
{'fraction_non_alphanumeric': 0.10171716066936454, 'fraction_numerical': 0.006343650880454993, 'mean_word_length': 2.5621347876899105, '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': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4199679', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2818, 'n_words': 588}