def update(self): organization = self.context othercontacts = [] held_positions = organization.get_held_positions() for hp in held_positions: contact = {} person = hp.get_person() contact['title'] = person.Title() contact['held_position'] = hp.Title() contact['label'] = hp.label contact['obj'] = hp if IContactDetails.providedBy(hp): contactable = hp elif IContactDetails.providedBy(person): contactable = person contact['email'] = contactable.email contact['phone'] = contactable.phone contact['cell_phone'] = contactable.cell_phone contact['fax'] = contactable.fax contact['im_handle'] = contactable.im_handle contact['website'] = contactable.website othercontacts.append(contact) self.othercontacts = othercontacts
def update(self): organization = self.context othercontacts = [] held_positions = organization.get_held_positions() held_positions.sort(key=lambda x: held_position_sortable_title(x)()) for hp in held_positions: contact = {} person = hp.get_person() contact['title'] = person.Title() contact['held_position'] = hp.Title() contact['label'] = hp.label contact['obj'] = hp if IContactDetails.providedBy(hp): contactable = hp elif IContactDetails.providedBy(person): contactable = person contact['email'] = contactable.email contact['phone'] = contactable.phone contact['cell_phone'] = contactable.cell_phone contact['fax'] = contactable.fax contact['im_handle'] = contactable.im_handle contact['website'] = get_valid_url(contactable.website) othercontacts.append(contact) self.othercontacts = othercontacts
def update(self): organization = self.context othercontacts = [] held_positions = organization.get_held_positions() held_positions.sort(key=lambda x: x.get_sortable_title()) for hp in held_positions: contact = {} person = hp.get_person() contact['person'] = person contact['title'] = person.Title() contact['held_position'] = hp.Title() contact['label'] = hp.get_label() contact['obj'] = hp contact['display_photo'] = api.portal.get_registry_record( name='display_contact_photo_on_organization_view', interface=IContactCoreParameters) contact['has_photo'] = contact['display_photo'] and hp.photo or None if IContactDetails.providedBy(hp): contactable = hp elif IContactDetails.providedBy(person): contactable = person contact['email'] = contactable.email contact['phone'] = contactable.phone contact['cell_phone'] = contactable.cell_phone contact['fax'] = contactable.fax contact['im_handle'] = contactable.im_handle contact['website'] = get_valid_url(contactable.website) othercontacts.append(contact) self.othercontacts = othercontacts
def update(self): super(Person, self).update() # Do not show person contact details # if they are the same as the main held position contactable_held_position = IContactable(self.context).held_position if IContactDetails.providedBy(contactable_held_position) and not IContactDetails.providedBy(self.context): self.show_contact_details = False else: self.show_contact_details = True
def get_address(obj): """Returns a dictionary which contains address fields""" if aq_base(obj).use_parent_address is True: related = None priv = api.portal.get_registry_record( name='person_contact_details_private', interface=IContactCoreParameters) if IHeldPosition.providedBy(obj) and priv: # For a held position, we use the related element: a position or an organization related = (obj.get_position() or obj.get_organization()) elif hasattr(obj, 'aq_parent'): related = obj.aq_parent if related and IContactDetails.providedBy(related): return get_address(related) else: return {} address = {} address_fields = ADDRESS_FIELDS obj = aq_base(obj) for field in address_fields: value = getattr(obj, field, '') or '' address[field] = value if not [v for v in address.values() if v]: # no value in address fields return {} return address
def get_address(obj): """Returns a dictionary which contains address fields""" if aq_base(obj).use_parent_address is True: related = None priv = api.portal.get_registry_record(name='person_contact_details_private', interface=IContactCoreParameters) if IHeldPosition.providedBy(obj) and priv: # For a held position, we use the related element: a position or an organization related = (obj.get_position() or obj.get_organization()) elif hasattr(obj, 'aq_parent'): related = obj.aq_parent if related and IContactDetails.providedBy(related): return get_address(related) else: return {} address = {} address_fields = ADDRESS_FIELDS obj = aq_base(obj) for field in address_fields: value = getattr(obj, field, '') or '' address[field] = value if not [v for v in address.values() if v]: # no value in address fields return {} return address
def setPropertiesForUser(self, user, propertysheet): """ Set the property to the person object if it implements IContactDetails else, try to update main held position. """ if IContactDetails.providedBy(self.context): storage = self.context else: main_position = IPersonHeldPositions(self.context).get_main_position() if main_position: storage = main_position else: return changed = False properties = dict(propertysheet.propertyItems()) for prop_name, field_name in self.property_map.items(): value = properties.get(prop_name, '').strip() if value != getattr(storage, field_name, ''): setattr(storage, field_name, value) changed = True if changed: storage.reindexObject() notify(ObjectModifiedEvent(storage))
def get_contact_details(self, keys=(), fallback=True): if not IContactDetails.providedBy(self.context): raise TypeError( "Your contactable content must provide IContactDetails " "if it doesn't have a more specific contactable adapter") contact_details = {} if keys: contact_details_fields = [k for k in keys if k != 'address'] else: contact_details_fields = CONTACT_DETAILS_FIELDS context = aq_base(self.context) for field in contact_details_fields: # search the object that carries the field value = getattr(context, field, '') or '' contact_details[field] = value if (not keys) or ('address' in keys): contact_details['address'] = get_address(context) if 'website' in contact_details: contact_details['website'] = get_valid_url( contact_details['website']) return contact_details
def get_contact_details(self, keys=(), fallback=True): if not IContactDetails.providedBy(self.context): raise TypeError("Your contactable content must provide IContactDetails " "if it doesn't have a more specific contactable adapter") contact_details = {} if keys: contact_details_fields = [k for k in keys if k != 'address'] else: contact_details_fields = CONTACT_DETAILS_FIELDS context = aq_base(self.context) for field in contact_details_fields: # search the object that carries the field value = getattr(context, field, '') or '' contact_details[field] = value if (not keys) or ('address' in keys): contact_details['address'] = get_address(context) if 'website' in contact_details: contact_details['website'] = get_valid_url( contact_details['website']) return contact_details
def get_contact_details(self): if not IContactDetails.providedBy(self.context): raise TypeError("Your contactable content must provide IContactDetails " "if it doesn't have a more specific contactable adapter") contact_details = {} contact_details_fields = ['email', 'phone', 'cell_phone', 'fax', 'website', 'im_handle'] context = aq_base(self.context) for field in contact_details_fields: # search the object that carries the field value = getattr(context, field, '') or '' contact_details[field] = value contact_details['address'] = get_address(context) return contact_details
def __call__(self): cd = IContactDetails(self.context) if not cd.email: return None if self.context.firstname: return formataddr(( "%s %s" % (self.context.firstname, self.context.lastname), cd.email, )) else: return formataddr(( self.context.lastname, cd.email, ))
def _get_contactables(self): """ Build a list of objects which have the IContactDetails behavior for each contact information (email, phone, ...) we use the one of the first object in this list which have this information """ contactables = [] related_items = [self.context, self.person, self.position] + list(reversed(self.organizations)) for related_item in related_items: if related_item is not None \ and IContactDetails.providedBy(related_item) \ and related_item not in contactables: contactables.append(related_item) return contactables
def _get_contactables(self): """ Build a list of objects which have the IContactDetails behavior for each contact information (email, phone, ...) we use the one of the first object in this list which have this information """ contactables = [] related_items = [self.context, self.person, self.position] + list( reversed(self.organizations)) for related_item in related_items: if related_item is not None \ and IContactDetails.providedBy(related_item) \ and related_item not in contactables: contactables.append(related_item) return contactables
def _get_contactables(self): """ Build a list of objects which have the IContactDetails behavior for each contact information (email, phone, ...) we use the one of the first object in this list which have this information """ contactables = [] related_items = [self.context, self.held_position, self.position] + list(reversed(self.organizations)) if not api.portal.get_registry_record(name='person_contact_details_private', interface=IContactCoreParameters): related_items.insert(2, self.person) for related_item in related_items: if related_item is not None \ and IContactDetails.providedBy(related_item) \ and related_item not in contactables: contactables.append(related_item) return contactables
def get_address(obj): """Returns a dictionary which contains address fields""" address = {} if (aq_base(obj).use_parent_address is True and hasattr(obj, 'aq_parent') and IContactDetails.providedBy(obj.aq_parent)): address = get_address(obj.aq_parent) if address: return address address_fields = ADDRESS_FIELDS obj = aq_base(obj) for field in address_fields: value = getattr(obj, field, '') or '' address[field] = value if not [v for v in address.values() if v]: # no value in address fields return {} return address
def get_address(obj): """Returns a dictionary which contains address fields""" address = {} if aq_base(obj).use_parent_address is True and IContactDetails.providedBy(obj.aq_parent): address = get_address(obj.aq_parent) if address: return address address_fields = ['country', 'region', 'zip_code', 'city', 'street', 'number', 'additional_address_details'] obj = aq_base(obj) for field in address_fields: value = getattr(obj, field, '') or '' address[field] = value if not [v for v in address.values() if v]: # no value in address fields return {} return address