def default_use_parent_address(adapter):
    """We don't use parent address by default for contacts and level-0 organizations
    """
    from collective.contact.core.content.organization import IOrganization
    from collective.contact.core.content.position import IPosition

    try:
        parent = adapter.view._parent
    except AttributeError:
        return False

    try:
        parent_type = parent.portal_type
    except:
        # in schema editor
        return False

    if parent_type == 'person':
        return False
    elif parent_type == 'organization' \
      and not IOrganization.providedBy(adapter.context) \
      and not IPosition.providedBy(adapter.context):
        return False
    else:
        return True
Exemple #2
0
def default_use_parent_address(adapter):
    """We don't use parent address by default for contacts and level-0 organizations
    """
    from collective.contact.core.content.organization import IOrganization
    from collective.contact.core.content.position import IPosition

    try:
        parent = adapter.view._parent
    except AttributeError:
        return False

    try:
        parent_type = parent.portal_type
    except:
        # in schema editor
        return False

    if parent_type == 'person':
        return False
    elif parent_type == 'organization' \
      and not IOrganization.providedBy(adapter.context) \
      and not IPosition.providedBy(adapter.context):
        return False
    else:
        return True
Exemple #3
0
 def available(self):
     """
     Condition on the content types wanted for the gallery viewlet
     (it was first meant only for Organizations), now it is also used for
     folderish content types (collective.folderish)
     """
     context = self.context
     return IOrganization.providedBy(context) or IFolderishType.providedBy(context)
Exemple #4
0
 def get_full_title(self, contact, **kwargs):
     if IPerson.providedBy(contact):
         return contact.get_title()
     elif IOrganization.providedBy(contact):
         return contact.get_full_title(**kwargs)
     elif IHeldPosition.providedBy(contact):
         return contact.get_full_title()
     else:
         return ''
Exemple #5
0
 def get_separate_titles(self, contact, **kwargs):
     """ Return a list with separate title for organization and person """
     ret = [u'', u'']  # org, pers
     if IPerson.providedBy(contact):
         ret[1] = contact.get_title()
     elif IOrganization.providedBy(contact):
         ret[0] = contact.get_full_title(**kwargs)  # separator=u' / ', first_index=0
     elif IHeldPosition.providedBy(contact):
         ret[1] = contact.get_person_title()
         org = contact.get_organization()
         if org:
             ret[0] = org.get_full_title(**kwargs)
     return ret
 def contentValue(self, item):
     """Display get_full_title instead title."""
     if IOrganization.providedBy(item):
         # find first_index relative to PLONEGROUP_ORG organization
         path = item.getPhysicalPath()
         if item.getId() == PLONEGROUP_ORG or PLONEGROUP_ORG not in path:
             first_index = 0
         else:
             # 1 considering that PLONEGROUP is at 1st level.
             # Otherwise must use get_organizations_chain
             first_index = 1
         return item.get_full_title(first_index=first_index)
     else:
         return item.get_full_title()
Exemple #7
0
    def getCSSClasses(self, item):
        """Returns a CSS class specific to current content."""
        cssClasses = super(ContactPrettyLinkColumn, self).getCSSClasses(item)

        current_org_css_class = None
        obj = self._getObject(item)
        if HAS_CONTACT_CORE and IOrganization.providedBy(obj):
            current_org_css_class = '___'.join(
                [org.id for org in obj.get_organizations_chain()])

        if current_org_css_class:
            cssClasses['td'] = '{0} {1}'.format(cssClasses['td'],
                                                current_org_css_class)

        return cssClasses
Exemple #8
0
def update_related_with_organization(obj, event=None):
    if isinstance(event, ContainerModifiedEvent):
        return

    for held_position in obj.get_held_positions():
        held_position.reindexObject(idxs=indexes_to_update)
        update_related_with_held_position(held_position)

    for position in obj.get_positions():
        position.reindexObject(idxs=indexes_to_update)
        for held_position in position.get_held_positions():
            held_position.reindexObject(idxs=indexes_to_update)
            update_related_with_held_position(held_position)

    for child in obj.values():
        if IOrganization.providedBy(child):
            child.reindexObject(idxs=indexes_to_update)
            update_related_with_organization(child)
Exemple #9
0
def update_related_with_organization(obj, event=None):
    if isinstance(event, ContainerModifiedEvent):
        return

    for held_position in obj.get_held_positions():
        held_position.reindexObject(idxs=indexes_to_update)
        update_related_with_held_position(held_position)

    for position in obj.get_positions():
        position.reindexObject(idxs=indexes_to_update)
        for held_position in position.get_held_positions():
            held_position.reindexObject(idxs=indexes_to_update)
            update_related_with_held_position(held_position)

    for child in obj.values():
        if IOrganization.providedBy(child):
            child.reindexObject(idxs=indexes_to_update)
            update_related_with_organization(child)
Exemple #10
0
 def get_separate_contacts(self, contact, **kwargs):
     """ Return a list with separate organization and person """
     ret = {'pers': None, 'org': None, 'root': None, 'chain': None, 'levels': False}
     if IPerson.providedBy(contact):
         ret['pers'] = contact
     elif IOrganization.providedBy(contact):
         ret['org'] = contact
     elif IHeldPosition.providedBy(contact):
         if contact.label:
             ret['label'] = contact.label
         ret['pers'] = contact.get_person()
         org = contact.get_organization()
         if org:
             ret['org'] = org
     if ret['org']:
         ret['chain'] = ret['org'].get_organizations_chain()
         ret['root'] = ret['chain'][0]
         ret['levels'] = len(ret['chain']) > 1 and True
     return ret
Exemple #11
0
    def person_title(self, contact, pers_dft=u'Monsieur', org_dft=u'Madame, Monsieur', with_name=False,
                     upper_name=False):

        def pers_title(pers):
            title = contact.person_title
            if not title:
                title = pers_dft
            if with_name and pers.lastname:
                return u'{} {}'.format(title, upper_name and pers.lastname.upper() or pers.lastname)
            else:
                return title

        if IPerson.providedBy(contact):
            return pers_title(contact)
        elif IOrganization.providedBy(contact):
            return org_dft
        elif IHeldPosition.providedBy(contact):
            return pers_title(contact.get_person())
        else:
            return u''