<commit_before># -*- coding: UTF-8 -*-
# Copyright 2013-2017 Rumma & Ko Ltd
# License: BSD (see file COPYING for details)

"""
The `models` module for `lino.projects.min2.modlib.contacts`.
"""

from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _
from django.utils.text import format_lazy

from lino.api import dd, rt

from lino_xl.lib.contacts.models import *
from lino.modlib.comments.mixins import Commentable
from lino_xl.lib.cal.workflows import feedback

# from lino_xl.lib.addresses.mixins import AddressOwner
from lino_xl.lib.dupable_partners.mixins import DupablePartner, DupablePerson


class Partner(Partner, mixins.CreatedModified, DupablePartner, Commentable):
    """A Partner as seen in `lino.projects.min2`.  It does not define any
    specific field but inherits from a specific set of mixins.

    """

    hidden_columns = 'created modified'

    # def get_overview_elems(self, ar):
    #     # In the base classes, Partner must come first because
    #     # otherwise Django won't inherit `meta.verbose_name`. OTOH we
    #     # want to get the `get_overview_elems` from AddressOwner, not
    #     # from Partner (i.e. AddressLocation).
    #     elems = super(Partner, self).get_overview_elems(ar)
    #     elems += AddressOwner.get_overview_elems(self, ar)
    #     return elems


class PartnerDetail(PartnerDetail):

    main = "general contact misc"

    general = dd.Panel("""
    overview:20 general2:20 general3:40
    reception.AppointmentsByPartner comments.CommentsByRFC
    """, label=_("General"))

    general2 = """
    id language
    url
    """

    general3 = """
    email:40
    phone
    gsm
    fax
    """

    contact = dd.Panel("""
    address_box
    remarks:30
    """, label=_("Contact"))

    address_box = """
    country region city zip_code:10
    addr1
    street_prefix street:25 street_no street_box
    addr2
    """

    misc = dd.Panel("""
    created modified
    changes.ChangesByMaster
    """, label=_("Miscellaneous"))


class Person(Person, Partner, DupablePerson):
    """
    Represents a physical person.
    """

    class Meta(Person.Meta):
        verbose_name = _("Person")
        verbose_name_plural = _("Persons")
        #~ ordering = ['last_name','first_name']

    def get_queryset(self, ar):
        return self.model.objects.select_related('country', 'city')

    def get_print_language(self):
        "Used by DirectPrintAction"
        return self.language

dd.update_field(Person, 'first_name', blank=False)
dd.update_field(Person, 'last_name', blank=False)
<commit_msg>Update get_queryset method<commit_after># -*- coding: UTF-8 -*-
# Copyright 2013-2017 Rumma & Ko Ltd
# License: BSD (see file COPYING for details)

"""
The `models` module for `lino.projects.min2.modlib.contacts`.
"""

from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _
from django.utils.text import format_lazy

from lino.api import dd, rt

from lino_xl.lib.contacts.models import *
from lino.modlib.comments.mixins import Commentable
from lino_xl.lib.cal.workflows import feedback

# from lino_xl.lib.addresses.mixins import AddressOwner
from lino_xl.lib.dupable_partners.mixins import DupablePartner, DupablePerson


class Partner(Partner, mixins.CreatedModified, DupablePartner, Commentable):
    """A Partner as seen in `lino.projects.min2`.  It does not define any
    specific field but inherits from a specific set of mixins.

    """

    hidden_columns = 'created modified'

    # def get_overview_elems(self, ar):
    #     # In the base classes, Partner must come first because
    #     # otherwise Django won't inherit `meta.verbose_name`. OTOH we
    #     # want to get the `get_overview_elems` from AddressOwner, not
    #     # from Partner (i.e. AddressLocation).
    #     elems = super(Partner, self).get_overview_elems(ar)
    #     elems += AddressOwner.get_overview_elems(self, ar)
    #     return elems


class PartnerDetail(PartnerDetail):

    main = "general contact misc"

    general = dd.Panel("""
    overview:20 general2:20 general3:40
    reception.AppointmentsByPartner comments.CommentsByRFC
    """, label=_("General"))

    general2 = """
    id language
    url
    """

    general3 = """
    email:40
    phone
    gsm
    fax
    """

    contact = dd.Panel("""
    address_box
    remarks:30
    """, label=_("Contact"))

    address_box = """
    country region city zip_code:10
    addr1
    street_prefix street:25 street_no street_box
    addr2
    """

    misc = dd.Panel("""
    created modified
    changes.ChangesByMaster
    """, label=_("Miscellaneous"))


class Person(Person, Partner, DupablePerson):
    """
    Represents a physical person.
    """

    class Meta(Person.Meta):
        verbose_name = _("Person")
        verbose_name_plural = _("Persons")
        #~ ordering = ['last_name','first_name']

    @classmethod
    def get_queryset(cls, user):
        qs = super(Person, cls).get_queryset(user)
        return qs.select_related('country', 'city')

    def get_print_language(self):
        "Used by DirectPrintAction"
        return self.language

dd.update_field(Person, 'first_name', blank=False)
dd.update_field(Person, 'last_name', blank=False)

{'fraction_non_alphanumeric': 0.10744115413819286, 'fraction_numerical': 0.011769172361427487, 'mean_word_length': 3.3082583810302535, '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': '4932885', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1631, 'n_words': 418}