Agentes del sistema

Los agentes son las personas que ejercen un rol determinado en el sistema y no deben confundirse son los usuarios del mismo.

apps.core.models – Common data to all agents

# -*- coding: utf-8 -*-
"""
===================================================
:mod:`apps.core.models` - Common data to all agents
===================================================

Describes classes that hold common data to all agents and the
abstractions :class:`Person` and :class:`Agent` for inheritance by
classes in other modules.


"""
import datetime

from django.db import models
from django.db.models import permalink
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _

from kelsen.apps.territory.models import Territory

class Address(models.Model):
    place = models.CharField(
        _('place'),
        help_text=_('Home, office, headquarters...'),
        max_length=200,)
    street = models.CharField(_('street'), max_length=200)
    municipality = models.ForeignKey(
        Territory,
        verbose_name=_('Municipality'),
        related_name='municipality_address',
        blank=True,
        null=True)
    province = models.ForeignKey(
        Territory,
        verbose_name=_('Province'),
        related_name='province_address',
        blank=True,
        null=True)
    region_state = models.ForeignKey(
        Territory,
        verbose_name=_('Region or State'),
        related_name='region_state_address',
        blank=True,
        null=True)
    state = models.ForeignKey(
        Territory,
        verbose_name=_('State'))
    zip_code = models.IntegerField(_('zip code'), blank=True, null=True)

    class Meta:
        verbose_name = _('Address')
        verbose_name_plural = _('Addresses')
        ordering = ['state', 'municipality', 'region_state', 'zip_code']

    def __unicode__(self):
        return '%s - %s - %s' % (self.place, self.street, self.municipality.name)


class BankAccount(models.Model):
    bank = models.CharField(_('bank'), max_length=255, blank=True)
    code = models.CharField(_('code'),max_length=255, blank=True)
    number = models.CharField(_('number'),max_length=30)
    iban = models.CharField(_('iban'),max_length=40, blank=True)

    class Meta:
        verbose_name = _('Bank account')
        verbose_name_plural = _('Bank accounts')
        ordering = ['number']

    def __unicode__(self):
        return self.number


class Email(models.Model):
    email = models.EmailField(verbose_name=_('email'))
    category = models.CharField(
        _('category'),
        help_text=_('Personal, office...'),
        max_length=120)

    class Meta:
        ordering = ['email', 'category']

    def __unicode__(self):
        return self.email


class Telephone(models.Model):
    number = models.CharField(_('number'), unique=True, max_length=20)
    place = models.CharField(
        _('place'),
        help_text=_('Home, office, fax, mobile...'),
        max_length=20)

    class Meta:
        verbose_name = _('Telephone')
        verbose_name_plural = _('Telephones')
        ordering = ['number', 'place']

    def __unicode__(self):
        return '%s - %s' % (self.number, self.place)


class Url(models.Model):
    url = models.URLField()
    category = models.CharField(
        _('category'),
        help_text=_('Personal, company, blog...'),
        max_length=200,)

    class Meta:
        ordering = ['url',]

    def __unicode__(self):
        return self.url


class TimeBased(models.Model):
    creation_date = models.DateTimeField(auto_now_add=True)
    modification_date = models.DateTimeField(auto_now=True)
    
    class Meta:
        abstract = True


class Agent(TimeBased):
    title = models.CharField(
        _('title'),
        max_length=250,
        unique=True,
        help_text=_('Use a descriptive title (unique for Agent)'))
    addresses = models.ManyToManyField(
        Address,
        blank=True, null=True,
        verbose_name=_('addresses'))
    telephones = models.ManyToManyField(
        Telephone,
        blank=True, null=True,
        verbose_name=_('telephones'))
    emails = models.ManyToManyField(
        Email, blank=True, null=True,
        verbose_name=_('emails'))
    bank_accounts = models.ManyToManyField(
        BankAccount,
        blank=True, null=True,
        verbose_name=_('bank accounts'))
    urls = models.ManyToManyField(
        Url,
        blank=True, null=True,
        verbose_name=_('urls'))

    class Meta:
        verbose_name = _('Agent')
        verbose_name_plural = _('Agents')
        ordering = ['title']

    def __unicode__(self):
        return self.title

class Person(Agent):
    name = models.CharField(_('name'), max_length=255)
    surname1 = models.CharField(_('surname1'), max_length=255)
    surname2 = models.CharField(
        _('surname2'),
        max_length=255,
        blank=True)
    slug = models.SlugField()
    date_birth = models.DateField(_('date of birth'), blank=True, null=True)
    place_birth = models.ForeignKey(
        Territory,
        blank=True,
        null=True,
        related_name='born_in',
        verbose_name=_('Birth place'))
    gender = models.CharField(
        _('gender'),
        max_length=20,
        blank=True)
    marital_status = models.CharField(
        _('marital status'),
        max_length=100,
        blank=True)
    children = models.PositiveIntegerField(_('children'), blank=True, null=True)
    url_img = models.URLField(_('url image'), blank=True, null=True)
    studies = models.CharField(
        _('studies'),
        max_length=255,
        blank=True)
    job = models.CharField(_('job'), max_length=255, blank=True)
    email = models.EmailField(_('email'), blank=True, null=True)

    class Meta:
        verbose_name = _('Person')
        verbose_name_plural = _('Persons')
        ordering = ['surname1', 'surname2', 'name']

    def save(self):
        slug_str = "%s-%s-%s" % (self.name, self.surname1, self.surname2)
        self.slug = slugify(slug_str)
        super(Person, self).save()

    def __unicode__(self):
        return '%s %s %s' % (self.name, self.surname1, self.surname2)

    @permalink
    def get_absolute_url(self):
        return ('person', (), {'slug': self.slug})

Contenidos

Tema anterior

Módulos

Próximo tema

Instituciones

Esta página