# Path: apps/contacts/mixins.py
# class ContactMixin(object):
#     """
#     Would be used for adding contacts functionality to Employee model.
#     """
# 
#     def get_contacts(self, is_primary=False):
#         """
#         Returns dict with all contacts.
#         Example:
#         >> obj.get_contacts()
#         << {'email': [], 'skype': []}
# 
#         :param is_primary: bool Return only primary contacts.
#         :return: dict
#         """
#         subclasses = BaseContact.__subclasses__()
#         results = {}
#         for cls in subclasses:
#             queryset = cls.objects.filter(employee_id=self.id, is_active=True)
#             key, verbose = cls.CONTACT_EXTRA_DATA
#             if is_primary:
#                 queryset = queryset.filter(is_primary=True)
#             results.setdefault(key, queryset)
#         return results


from django.conf import settings
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from apps.contacts.mixins import ContactMixin

__all__ = [
    'Employee'
]


def current_date():
    return timezone.now().date()


class Employee(ContactMixin, models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='employee')
    first_name = models.CharField(_('first name'), max_length=128)
    last_name = models.CharField(_('last name'), max_length=128)
    middle_name = models.CharField(
        _('middle name'), default='', max_length=128, blank=True
    )
    notes = models.TextField(_('notes'), default='', blank=True)
    birthday = models.DateField(
        _('birthday'), default=None, null=True, blank=True
    )
    specializations = models.ManyToManyField(
        'employees.Specialization', verbose_name=_('specializations'),
        related_name='employees', blank=True
    )
    position = models.ForeignKey(
        'employees.Position', related_name='employees',
        verbose_name=_('position'),
    )

# Path: apps/contacts/mixins.py
# class ContactMixin(object):
#     """
#     Would be used for adding contacts functionality to Employee model.
#     """
# 
#     def get_contacts(self, is_primary=False):
#         """
#         Returns dict with all contacts.
#         Example:
#         >> obj.get_contacts()
#         << {'email': [], 'skype': []}
# 
#         :param is_primary: bool Return only primary contacts.
#         :return: dict
#         """
#         subclasses = BaseContact.__subclasses__()
#         results = {}
#         for cls in subclasses:
#             queryset = cls.objects.filter(employee_id=self.id, is_active=True)
#             key, verbose = cls.CONTACT_EXTRA_DATA
#             if is_primary:
#                 queryset = queryset.filter(is_primary=True)
#             results.setdefault(key, queryset)
#         return results


# Path: apps/employees/models/employee.py
from django.conf import settings
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from apps.contacts.mixins import ContactMixin


__all__ = [
    'Employee'
]


def current_date():
    return timezone.now().date()


class Employee(ContactMixin, models.Model):

    user = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='employee')
    first_name = models.CharField(_('first name'), max_length=128)
    last_name = models.CharField(_('last name'), max_length=128)
    middle_name = models.CharField(
        _('middle name'), default='', max_length=128, blank=True
    )
    notes = models.TextField(_('notes'), default='', blank=True)
    birthday = models.DateField(
        _('birthday'), default=None, null=True, blank=True
    )
    specializations = models.ManyToManyField(
        'employees.Specialization', verbose_name=_('specializations'),
        related_name='employees', blank=True
    )
    position = models.ForeignKey(
        'employees.Position', related_name='employees',
        verbose_name=_('position'),
    )

    work_started = models.DateField(_('work started'), default=current_date)