Пример #1
0
class RelatedContact(ContactAssociation):
    """Related contact model class.

    Capture related contact attributes.  A contact may be associated
    with 0 or more contact instances:
        Contact(1) ------> Contact(0..*)
    """
    from_contact = fields.foreign_key_field(
        Contact,
        on_delete=CASCADE,
        related_name="%(app_label)s_%(class)s_related_from_contact")
    to_contact = fields.foreign_key_field(
        Contact,
        on_delete=CASCADE,
        related_name="%(app_label)s_%(class)s_related_to_contact")
    contact_relationship_type = fields.foreign_key_field(
        ContactRelationshipType)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _related_contact)
        verbose_name = _(_related_contact_verbose)
        verbose_name_plural = _(pluralize(_related_contact_verbose))
        unique_together = ("from_contact", "to_contact",
                           "contact_relationship_type")

    def clean(self):
        super(RelatedContact, self).clean()
        validation.related_contact_validation(self)
Пример #2
0
class ContactCategory(ContactAssociation):
    """Contact category model class.

    Capture contact category attributes.  A contact may be associated
    with 0 or more contact categories:
        Contact(1) ------> Category(0..*)
    """
    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_category)
        verbose_name = _(_contact_category_verbose)
        verbose_name_plural = _(pluralize(_contact_category_verbose))
        unique_together = ("contact", "category")

    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    category = fields.foreign_key_field(Category, on_delete=CASCADE)
Пример #3
0
class ContactGroup(ContactAssociation):
    """ContactGroup model class.

    Capture contact group attributes.  A contact may be associated
    with 0 or more groups :
        Contact(1) ------> Group(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    group = fields.foreign_key_field(Group, on_delete=CASCADE)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_group)
        verbose_name = _(_contact_group_verbose)
        verbose_name_plural = _(pluralize(_contact_group_verbose))
        unique_together = ("contact", "group")
Пример #4
0
class ContactAnnotation(ContactAssociation):
    """Contact annotation model class.

    Capture contact annotation/notes attributes.  A contact may be associated
    with 0 or more  annotations:
        Contact(1) ------> Annotation(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    annotation = fields.foreign_key_field(Annotation, on_delete=CASCADE)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_annotation)
        verbose_name = _(_contact_annotation_verbose)
        verbose_name_plural = _(pluralize(_contact_annotation_verbose))
        unique_together = ("contact", "annotation")
Пример #5
0
class ContactAddress(ContactAssociation):
    """Contact address model class.

    Capture the attributes of contact address(s).
    A contact may be associated with 0 or more addresses as follows:
    Contact(1)  -------> ContactAddress(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    address = fields.foreign_key_field(Address, on_delete=CASCADE)
    address_type = fields.foreign_key_field(AddressType, null=True, blank=True)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_address)
        verbose_name = _(_contact_address_verbose)
        verbose_name_plural = _(pluralize(_contact_address_verbose))
        unique_together = ("contact", "address", "address_type")
Пример #6
0
class ContactNickname(ContactAssociation):
    """Contact nickname model class.

    Allow a association of contact with a nickname.
    A Contact may be associated with 0 or more Nickname instances:
        Contact(1) ------> Nickname(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    name = fields.foreign_key_field(Nickname, on_delete=CASCADE)
    nickname_type = fields.foreign_key_field(NicknameType,
                                             null=True,
                                             blank=True)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_nickname)
        verbose_name = _(_contact_nickname_verbose)
        verbose_name_plural = _(pluralize(_contact_nickname_verbose))
        unique_together = ("contact", "name", "nickname_type")
Пример #7
0
class ContactLanguage(ContactAssociation):
    """Contact language model class.

    Specify the language(s) that may be used for communicating with
    a contact.  A contact may be associated 0 or more languages:
        Contact(1) -------> ContactLanguage(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    language = fields.foreign_key_field(Language, on_delete=CASCADE)
    language_type = fields.foreign_key_field(LanguageType,
                                             blank=True,
                                             null=True)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_language)
        verbose_name = _(_contact_language_verbose)
        verbose_name_plural = _(pluralize(_contact_language_verbose))
        unique_together = ("contact", "language", "language_type")
Пример #8
0
class ContactImage(ContactAssociation):
    """Contact image abstract model base class.

    Capture contact  photograph information.
    A contact may be associated with 0 or more images:
        Contact(1) -------> Image(0..*).

    An image may be associated with one or more contacts.
    """
    contact = fields.foreign_key_field(
        Contact,
        on_delete=CASCADE,
        related_name="%(app_label)s_%(class)s_related_contact")
    image_reference = fields.foreign_key_field(ImageReference,
                                               on_delete=CASCADE)

    class Meta(ContactAssociation.Meta):
        abstract = True
Пример #9
0
class ContactFormattedName(ContactAssociation):
    """Contact formatted name model class.

    Specifies the formatted contact name.
    A Contact must be associated with at least one FormatedName instance:
        Contact(1) ------> FormattedName(1..*)
    """

    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    name = fields.foreign_key_field(FormattedName, on_delete=CASCADE)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _formatted_name)
        verbose_name = _(_formatted_name_verbose)
        verbose_name_plural = _(pluralize(_formatted_name_verbose))
        unique_together = ('contact', 'name')

    def clean(self):
        super(ContactFormattedName, self).clean()
        validation.contact_formatted_name_validation(self)
Пример #10
0
class ContactName(ContactAssociation):
    """Contact name model class.

    Defines the contact name components.
    While the RFC specifies that a contact may be associated with at most one
    Name instance, this implementation supports many such instances:
        Contact(1) --------> Name(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    name = fields.foreign_key_field(Name, on_delete=CASCADE)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_name)
        verbose_name = _(_contact_name_verbose)
        verbose_name_plural = _(pluralize(_contact_name_verbose))
        unique_together = ('contact', 'name')

    def clean(self):
        super(ContactName, self).clean()
        validation.contact_name_validation(self)
Пример #11
0
class ContactEmail(ContactAssociation):
    """Contact email address model class.

    Captures contact email address(s).  Contact may be associated with
    0 or more email addresses:
        Contact (1) ------> Email(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    email = fields.foreign_key_field(Email, on_delete=CASCADE)
    email_type = fields.foreign_key_field(EmailType, null=True, blank=True)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_email)
        verbose_name = _(_contact_email_verbose)
        verbose_name_plural = _(pluralize(_contact_email_verbose))
        unique_together = (
            "contact",
            "email",
            "email_type",
        )
Пример #12
0
class ContactGeographicLocation(ContactAssociation):
    """
    Contact geographic location model class.

    Capture contact geographic location(s) information.  A contact may be
    associated with 0 or more geographic locations:
        Contact ------> GeographicLocation(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    geographic_location = fields.foreign_key_field(GeographicLocation,
                                                   on_delete=CASCADE)
    geographic_location_type = fields.foreign_key_field(GeographicLocationType,
                                                        blank=True,
                                                        null=True)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_geographic_location)
        verbose_name = _(_contact_geographic_location_verbose)
        verbose_name_plural = _(
            pluralize(_contact_geographic_location_verbose))
        unique_together = ("contact", "geographic_location",
                           "geographic_location_type")
Пример #13
0
class ContactLogo(ContactImage):
    """Contact logo class.

    Capture contact logo information.
    A contact may be associated with 0 or more logos:
        Contact(1) -------> Logo(0..*).
    """
    logo_type = fields.foreign_key_field(LogoType, null=True, blank=True)

    class Meta(ContactImage.Meta):
        db_table = db_table(_app_label, _contact_logo)
        verbose_name = _(_contact_logo_verbose)
        verbose_name_plural = _(pluralize(_contact_logo_verbose))
        unique_together = ("contact", "image_reference", "logo_type")
Пример #14
0
class ContactInstantMessaging(ContactAssociation):
    """Contact instant messaging model class.

    Capture the URI(s) for contact instant messaging.
    A contact may be associated with  0 or more instance messaging uri's:
        Contact(1) -------> InstantMessaging(0..*)
    """
    contact = fields.foreign_key_field(Contact, on_delete=CASCADE)
    instant_messaging = fields.foreign_key_field(InstantMessaging,
                                                 on_delete=CASCADE)
    instant_messaging_type = fields.foreign_key_field(InstantMessagingType,
                                                      blank=True,
                                                      null=True)

    class Meta(ContactAssociation.Meta):
        db_table = db_table(_app_label, _contact_instant_messaging)
        verbose_name = _(_contact_instant_messaging_verbose)
        verbose_name_plural = _(pluralize(_contact_instant_messaging_verbose))
        unique_together = (
            "contact",
            "instant_messaging",
            "instant_messaging_type",
        )
Пример #15
0
class ContactGroupObjectPermission(GroupObjectPermissionBase):
    """Group contact permission class."""
    content_object = fields.foreign_key_field(Contact, on_delete=CASCADE)
Пример #16
0
class ContactObjectPermission(UserObjectPermissionBase):
    """User contact permission class."""
    content_object = fields.foreign_key_field(Contact, on_delete=CASCADE)
Пример #17
0
class Contact(ContactsModel):
    """Contact model class.

    Capture contact attributes.  Designed to allow having multiple contact
    instances per person, organization, etc.

    Either name or formatted name have to be set on an instance.
    """
    formatted_name = fields.foreign_key_field(FormattedName,
                                              blank=True,
                                              null=True)
    name = fields.foreign_key_field(Name, blank=True, null=True)

    # 'simple fields'
    anniversary = fields.date_field(blank=True, null=True)
    birth_date = fields.date_field(blank=True, null=True)
    contact_type = fields.foreign_key_field(ContactType, blank=True, null=True)
    gender = fields.foreign_key_field(Gender, blank=True, null=True)

    # many-2-many fields
    addresses = fields.many_to_many_field(Address, through="ContactAddress")
    annotations = fields.many_to_many_field(Annotation,
                                            through="ContactAnnotation")
    categories = fields.many_to_many_field(Category, through="ContactCategory")
    emails = fields.many_to_many_field(Email, through="ContactEmail")
    formatted_names = fields.many_to_many_field(FormattedName,
                                                through="ContactFormattedName")
    geographic_locations = fields.many_to_many_field(
        GeographicLocation, through="ContactGeographicLocation")
    groups = fields.many_to_many_field(Group, through="ContactGroup")
    instant_messaging = fields.many_to_many_field(
        InstantMessaging, through="ContactInstantMessaging")
    languages = fields.many_to_many_field(Language, through="ContactLanguage")
    logos = fields.many_to_many_field(ImageReference,
                                      through="ContactLogo",
                                      related_name=related_name_base +
                                      "contact_logo")
    names = fields.many_to_many_field(Name, through="ContactName")
    nicknames = fields.many_to_many_field(Nickname, through="ContactNickname")
    organizations = fields.many_to_many_field(Organization,
                                              through="ContactOrganization")
    phones = fields.many_to_many_field(Phone, through="ContactPhone")
    photos = fields.many_to_many_field(ImageReference,
                                       through="ContactPhoto",
                                       related_name=related_name_base +
                                       "contact_photo")
    related_contacts = fields.many_to_many_field("self",
                                                 through="RelatedContact",
                                                 symmetrical=False)
    roles = fields.many_to_many_field(Role, through="ContactRole")
    timezones = fields.many_to_many_field(Timezone, through="ContactTimezone")
    titles = fields.many_to_many_field(Title, through="ContactTitle")
    urls = fields.many_to_many_field(Url, through="ContactUrl")

    objects = ContactManager()

    class Meta(ContactsModel.Meta):
        db_table = db_table(_app_label, _contact)
        verbose_name = _(_contact_verbose)
        verbose_name_plural = _(pluralize(_contact_verbose))
        permissions = (
            ("read_contact", "Can read contacts"),
            ("write_contact", "Can write contacts"),
        )

    def clean(self):
        super(Contact, self).clean()
        validation.contact_validation(self)

    @property
    def display_name(self):
        return self.name if self.name else self.formatted_name

    def __str__(self):
        return str(self.display_name)