def update(self): super(Organization, self).update() self.organization = self.context organization = self.organization self.name = organization.Title() factory = getUtility(IVocabularyFactory, "OrganizationTypesOrLevels") vocabulary = factory(self.context) self.type = vocabulary.getTerm(organization.organization_type).title self.activity = self.context.activity contactable = IContactable(organization) organizations = contactable.organizations self.parent_organizations = [org for org in organizations] self.parent_organizations.remove(organization) self.organizations = organizations catalog = getToolByName(self.context, 'portal_catalog') context_path = '/'.join(organization.getPhysicalPath()) self.sub_organizations = catalog.searchResults(portal_type="organization", path={'query': context_path, 'depth': 1}) self.positions = self.context.get_positions() self.contact_details = contactable.get_contact_details() # also show fields that were added TTW self.ttw_fields = get_ttw_fields(organization) held_positions = organization.get_held_positions() self.othercontacts = [hp.get_person() for hp in held_positions] sm = getSecurityManager() self.can_add = sm.checkPermission('Add portal content', self.context) self.addnew_script = ADDNEW_OVERLAY
def get(self, field): if field.__name__ in ADDRESS_FIELDS: address = IContactable(self.context).get_contact_details( ('address', ))['address'] return address.get(field.__name__, None) return getattr(self.context, field.__name__, None)
def get_recipient_emails(self): """Returns recipient email addresses :return: an email address :rtype: unicode """ emails = [] uniques = [] if self.orig_sender_email: uniques.append(validate_email_address(self.orig_sender_email)[1]) emails.append(self.orig_sender_email) # we don't use directly relation object to be sure to use the real object uids = [rel.to_object.UID() for rel in self.recipients or []] brains = uuidsToCatalogBrains(uids, unrestricted=True) # selection order not kept ! for brain in brains: contact = brain._unrestrictedGetObject() contactable = IContactable(contact) email = contactable.get_contact_details(keys=['email']).get( 'email', u'') if email and email not in uniques: uniques.append(email) if hasattr(contact, 'firstname'): # for person or held_position emails.append(u'"{} {}" <{}>'.format( contact.firstname, contact.lastname, email)) else: emails.append(email) return u', '.join(emails)
def update(self): super(Person, self).update() self.person = self.context person = self.person self.name = person.Title() if IBirthday.providedBy(person): birthday = person.birthday if birthday is not None: birthday = date_to_DateTime(birthday) self.birthday = self.context.toLocalizedTime(birthday) else: self.birthday = "" self.person_title = person.person_title self.gender = person.gender or '' catalog = getToolByName(self.context, 'portal_catalog') context_path = '/'.join(person.getPhysicalPath()) results = catalog.searchResults(path={'query': context_path, 'depth': 1}) self.held_positions = results contactable = IContactable(person) contact_details = contactable.get_contact_details() self.email = contact_details['email'] self.phone = contact_details['phone'] self.fax = contact_details['fax'] self.cell_phone = contact_details['cell_phone'] self.im_handle = contact_details['im_handle'] self.website = contact_details['website'] self.address = contact_details['address'] # also show fields that were added TTW self.ttw_fields = get_ttw_fields(person)
def update(self): super(Position, self).update() self.position = self.context position = self.position self.name = position.get_full_title() factory = getUtility(IVocabularyFactory, "PositionTypes") vocabulary = factory(self.context) self.type = vocabulary.getTerm(position.position_type).title contactable = IContactable(position) self.organizations = contactable.organizations contact_details = contactable.get_contact_details() self.email = contact_details['email'] self.phone = contact_details['phone'] self.cell_phone = contact_details['cell_phone'] self.fax = contact_details['fax'] self.im_handle = contact_details['im_handle'] self.address = contact_details['address'] self.website = contact_details['website'] # also show fields that were added TTW self.ttw_fields = get_ttw_fields(position) sm = getSecurityManager() self.can_add = sm.checkPermission('Add portal content', self.context) self.addnew_script = ADDNEW_OVERLAY
def get_ctct_det(self, obj, fallback=True): try: contactable = IContactable(obj) return contactable.get_contact_details(fallback=fallback) # {'website': '', 'fax': '', 'phone': '', 'address': {'city': u'Eghez\xe9e', 'country': '', 'region': '', # 'additional_address_details': '', 'number': u'8', 'street': u'Grande Ruelle', 'zip_code': u'5310'}, # 'im_handle': '', 'cell_phone': '', 'email': ''} except Exception: return {}
def get_vcard(context): vcard = vobject.vCard() contactable = IContactable(context) contact_details = contactable.get_contact_details() email = contact_details['email'] if email: vcard.add('email') vcard.email.type_param = 'INTERNET' vcard.email.value = email phones = contact_details['phone'] if not isinstance(phones, list): phones = [phones] for phone in phones: if phone: vcard.add('tel') vcard.tel.type_param = 'WORK' vcard.tel.value = phone cell_phones = contact_details['cell_phone'] if not isinstance(cell_phones, list): cell_phones = [cell_phones] for cell_phone in cell_phones: if cell_phone: vcard.add('tel') last_item = len(vcard.tel_list) - 1 vcard.tel_list[last_item].type_param = 'CELL' vcard.tel_list[last_item].value = cell_phone im_handle = contact_details['im_handle'] if im_handle: vcard.add('impp') vcard.impp.value = im_handle address = contact_details['address'] # if we don't have relevant address information, we don't need address if address: vcard.add('adr') country = safe_unicode(address['country'], encoding='utf8') region = safe_unicode(address['region'], encoding='utf8') zip_code = safe_unicode(address['zip_code'], encoding='utf8') city = safe_unicode(address['city'], encoding='utf8') street = safe_unicode(address['street'], encoding='utf8') number = safe_unicode(address['number'], encoding='utf8') additional = safe_unicode(address['additional_address_details'], encoding='utf8') vcard.adr.value = vobject.vcard.Address(street=street, city=city, region=region, code=zip_code, country=country, box=number, extended=additional) return vcard
def get_parent_address(adapter): """Gets the address of the first parent in hierarchy""" if adapter.context.portal_type == "directory": return u'' elif type(aq_base(adapter.context)) == TypeSchemaContext: return u"" try: contactable = IContactable(adapter.context) return contactable.get_parent_address() except TypeError: return u""
def update(self): super(Contact, self).update() held_position = self.context self.portal_url = api.portal.get().absolute_url() start_date = held_position.start_date if start_date is not None: start_date = date_to_DateTime(start_date) self.start_date = self.context.toLocalizedTime(start_date) end_date = held_position.end_date if end_date is not None: end_date = date_to_DateTime(end_date) self.end_date = self.context.toLocalizedTime(end_date) person = held_position.get_person() self.person = person self.fullname = person.Title() self.title = held_position.Title() if IBirthday.providedBy(person): birthday = person.birthday if birthday is not None: birthday = date_to_DateTime(birthday) self.birthday = self.context.toLocalizedTime(birthday) else: self.birthday = None self.gender = person.gender or '' self.position = held_position.get_position() organization = held_position.get_organization() self.organizations = organization and organization.get_organizations_chain() or [] contactable = IContactable(held_position) contact_details = contactable.get_contact_details() self.email = contact_details['email'] self.phone = contact_details['phone'] self.cell_phone = contact_details['cell_phone'] self.fax = contact_details['fax'] self.im_handle = contact_details['im_handle'] self.website = contact_details['website'] self.address = contact_details['address'] # also show fields that were added TTW self.ttw_fields = get_ttw_fields(held_position)
def test_contact_details(self): details = IContactable(self.degaulle).get_contact_details() self.assertEqual(details['website'], 'http://www.charles-de-gaulle.org') self.assertEqual(details['email'], '*****@*****.**') self.assertEqual(details['address'], {'city': u'Colombey les deux \xe9glises', 'country': u'France', 'region': '', 'additional_address_details': u'b\xe2timent D', 'number': u'6bis', 'street': u'rue Jean Moulin', 'zip_code': u'52330'}) details = IContactable(self.degaulle).get_contact_details(keys=('email',)) self.assertEqual(details, {'email': '*****@*****.**'}) details = IContactable(self.pepper).get_contact_details() self.assertEqual(details['website'], 'http://www.sergent-pepper.org')
def get_vcard(self): vcard = vobject.vCard() contactable = IContactable(self.context) contact_details = contactable.get_contact_details() email = contact_details["email"] if email: vcard.add("email") vcard.email.type_param = "INTERNET" vcard.email.value = email phone = contact_details["phone"] if phone: vcard.add("tel") vcard.tel.type_param = "WORK" vcard.tel.value = phone cell_phone = contact_details["cell_phone"] if cell_phone: vcard.add("tel") last_item = len(vcard.tel_list) - 1 vcard.tel_list[last_item].type_param = "CELL" vcard.tel_list[last_item].value = cell_phone im_handle = contact_details["im_handle"] if im_handle: vcard.add("impp") vcard.impp.value = im_handle address = contact_details["address"] # if we don't have relevant address information, we don't need address if address: vcard.add("adr") country = safe_unicode(address["country"], encoding="utf8") region = safe_unicode(address["region"], encoding="utf8") zip_code = safe_unicode(address["zip_code"], encoding="utf8") city = safe_unicode(address["city"], encoding="utf8") street = safe_unicode(address["street"], encoding="utf8") number = safe_unicode(address["number"], encoding="utf8") additional = safe_unicode(address["additional_address_details"], encoding="utf8") vcard.adr.value = vobject.vcard.Address( street=street, city=city, region=region, code=zip_code, country=country, box=number, extended=additional ) return vcard
def getPropertiesForUser(self, user, request=None): """Get properties for this user. Get property from the contactable, which fall backs to organization, position, held_position, etc """ properties = dict( fullname=self.fullname, ) contactable = IContactable(self.context) details = contactable.get_contact_details(keys=self.property_map.values() + ['address']) for prop_name, field_name in self.property_map.items(): properties[prop_name] = details.get(field_name, details['address'].get(field_name, None) ) or u"" return MutablePropertySheet(self.context.getId(), **properties)
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_field(self, contact, field_name): if field_name is "id": return getattr(contact, field_name, "") if field_name not in self.selected_fields: return "" if field_name in self.address_fields: contactable = IContactable(contact) details = contactable.get_contact_details() return details["address"].get(field_name) # field = getattr(contact, field_name, '') # find way to check if field is richetext or image or simple field if getattr(getattr(contact, field_name, ""), "raw", None): if getattr(contact, field_name, ""): text = getattr(contact, field_name).raw text = text.replace("http://resolveuid/", "resolveuid/") parser = ResolveUIDAndCaptionFilter(contact) transform_text = parser(text) return transform_text if transform_text else "" if field_name in ["logo", "photo"]: if getattr(contact, field_name, ""): img = contact.unrestrictedTraverse("@@images") logo = img.scale(field_name) return logo.tag() if logo.tag() else "" if field_name == "schedule": from plone.directives import dexterity display = dexterity.DisplayForm(contact, self.request) display.update() if display.w.get("IScheduledContent.schedule", None): return display.w.get("IScheduledContent.schedule").render() else: return "" if field_name in ["phone", "cell_phone", "fax"]: phones = getattr(contact, field_name, "") if not phones: return False if not isinstance(phones, list): phones = [getattr(contact, field_name)] return [format_phone(phone) for phone in phones] if field_name in ["position"]: positions = [pos.title.strip() for pos in contact.get_held_positions()] return ", ".join(positions) return getattr(contact, field_name, "")
def get_field(self, contact, field_name): if field_name is 'id': return getattr(contact, field_name, '') if field_name not in self.selected_fields: return '' if field_name in self.address_fields: contactable = IContactable(contact) details = contactable.get_contact_details() return details['address'].get(field_name) # field = getattr(contact, field_name, '') # find way to check if field is richetext or image or simple field if getattr(getattr(contact, field_name, ''), 'raw', None): if getattr(contact, field_name, ''): text = getattr(contact, field_name).raw text = text.replace('http://resolveuid/', 'resolveuid/') parser = ResolveUIDAndCaptionFilter(contact) transform_text = parser(text) return transform_text if transform_text else '' if field_name in ['logo', 'photo']: if getattr(contact, field_name, ''): img = contact.unrestrictedTraverse('@@images') logo = img.scale(field_name) return logo.tag() if logo.tag() else '' if field_name == 'schedule': from plone.directives import dexterity display = dexterity.DisplayForm(contact, self.request) display.update() if display.w.get('IScheduledContent.schedule', None): return display.w.get('IScheduledContent.schedule').render() else: return '' if field_name in ['phone', 'cell_phone', 'fax']: phones = getattr(contact, field_name, '') if not phones: return False if not isinstance(phones, list): phones = [getattr(contact, field_name)] return [format_phone(phone) for phone in phones] if field_name in ['position']: positions = [pos.title.strip() for pos in contact.get_held_positions()] return ', '.join(positions) return getattr(contact, field_name, '')
def update(self): super(Position, self).update() self.position = self.context position = self.position factory = getUtility(IVocabularyFactory, "PositionTypes") vocabulary = factory(self.context) self.type = vocabulary.getTerm(position.position_type).title contactable = IContactable(position) self.organizations = contactable.organizations sm = getSecurityManager() self.can_add = sm.checkPermission('Add portal content', self.context) self.addnew_script = ADDNEW_OVERLAY
def update(self): super(Person, self).update() self.person = self.context person = self.person self.name = person.Title() if IBirthday.providedBy(person): birthday = person.birthday if birthday is not None: birthday = date_to_DateTime(birthday) self.birthday = self.context.toLocalizedTime(birthday) else: self.birthday = "" self.person_title = person.person_title self.gender = person.gender or '' catalog = getToolByName(self.context, 'portal_catalog') context_path = '/'.join(person.getPhysicalPath()) results = catalog.searchResults(path={ 'query': context_path, 'depth': 1 }) self.held_positions = results contactable = IContactable(person) contact_details = contactable.get_contact_details() self.email = contact_details['email'] self.phone = contact_details['phone'] self.fax = contact_details['fax'] self.cell_phone = contact_details['cell_phone'] self.im_handle = contact_details['im_handle'] self.website = contact_details['website'] self.address = contact_details['address'] # also show fields that were added TTW self.ttw_fields = get_ttw_fields(person)
def get_vcard(self): vcard = ContactableVCard.get_vcard(self) vcard.add('kind') vcard.kind.value = "individual" held_position = self.context contactable = IContactable(held_position) person = contactable.person position = contactable.position organizations = contactable.organizations vcard.add('n') firstname = safe_unicode(person.firstname or '', encoding='utf8') lastname = safe_unicode(person.lastname or '', encoding='utf8') person_title = safe_unicode(person.person_title or '', encoding='utf8') vcard.n.value = vobject.vcard.Name(prefix=person_title, family=lastname, given=firstname) vcard.add('fn') vcard.fn.value = ' '.join([e for e in (firstname, lastname) if e]) if IBirthday.providedBy(person) and person.birthday is not None: vcard.add('bday') vcard.bday.value = person.birthday.isoformat() if position is not None: position_name = safe_unicode(position.Title(), encoding='utf8') vcard.add('role') vcard.role.value = position_name vcard.add('title') vcard.title.value = position_name vcard.add('org') vcard.org.value = [ safe_unicode(org.Title(), encoding='utf8') for org in organizations ] # TODO ? # vcard.add('photo') # vcard.photo.value = person.photo # if person.latitude is not None and \ # person.longitude is not None: # vcard.add('geo') # vcard.geo.value = "%.2f;%.2f" % (person.latitude, person.longitude) return vcard
def update(self): super(Organization, self).update() self.organization = self.context organization = self.organization contactable = IContactable(organization) organizations = contactable.organizations self.parent_organizations = [org for org in organizations] self.parent_organizations.remove(organization) catalog = getToolByName(self.context, 'portal_catalog') context_path = '/'.join(organization.getPhysicalPath()) self.sub_organizations = catalog.searchResults( portal_type="organization", path={ 'query': context_path, 'depth': 1 }) self.positions = self.context.get_positions() sm = getSecurityManager() self.can_add = sm.checkPermission('Add portal content', self.context) self.addnew_script = ADDNEW_OVERLAY
def get_sender_email(self, sender_i={}): """Returns a sender email address :param sender_i: a dict containing sender information (as returned by `get_sender_info`) :return: an email address :rtype: unicode """ if not sender_i: sender_i = self.get_sender_info() replyto_key = 'imio.dms.mail.browser.settings.IImioDmsMailConfig.omail_sender_email_default' rtv = api.portal.get_registry_record(replyto_key, default=u'agent_email') if rtv == 'agent_email': hpc = IContactable(sender_i['hp']) email = hpc.get_contact_details(keys=['email']).get('email', u'') if email: return u'"{} {}" <{}>'.format(sender_i['hp'].firstname, sender_i['hp'].lastname, email) elif rtv == 'service_email': orgc = IContactable(sender_i['org']) email = orgc.get_contact_details(keys=['email']).get('email', u'') return email return u''
def update(self): contactable = IContactable(self.context) self.contact_details = contactable.get_contact_details()
def update(self): fallback = self.is_contact_core_fallback() contactable = IContactable(self.context) #noFallbackContactDetails or fallback. self.contact_details = contactable.get_contact_details( fallback=fallback)
def test_contact_details(self): # # person contact details are private api.portal.set_registry_record(name='person_contact_details_private', value=True, interface=IContactCoreParameters) # test a person details = IContactable(self.degaulle).get_contact_details() self.assertEqual(details['website'], 'http://www.charles-de-gaulle.org') self.assertEqual(details['email'], '*****@*****.**') self.assertEqual(details['address'], {'city': u'Colombey les deux \xe9glises', 'country': u'France', 'region': '', 'additional_address_details': u'b\xe2timent D', 'number': u'6bis', 'street': u'rue Jean Moulin', 'zip_code': u'52330'}) details = IContactable(self.degaulle).get_contact_details(keys=('email',)) self.assertEqual(details, {'email': '*****@*****.**'}) # test an held position using parent address and related to an organization details = IContactable(self.degaulle['adt']).get_contact_details() self.assertEqual(details['email'], u'*****@*****.**') # phone from org self.assertEqual(details['phone'], u'01000000001') # phone from org self.assertDictEqual(details['address'], {'additional_address_details': '', 'city': u'Paris', 'country': u'France', 'number': u'1', 'region': '', 'street': u'Avenue des Champs-\xc9lys\xe9es', 'zip_code': u'75008'}) # test an held position using parent address and related to a position self.assertFalse(self.directory['armeedeterre']['general_adt'].use_parent_address) details = IContactable(self.degaulle['gadt']).get_contact_details() self.assertEqual(details['email'], u'*****@*****.**') self.assertEqual(details['phone'], u'0987654321') self.assertDictEqual(details['address'], {'additional_address_details': '', 'city': u'Lille', 'country': u'France', 'number': u'1', 'region': '', 'street': u"Rue de la Porte d'Ypres", 'zip_code': u'59800'}) # test an held position using parent address and related to a position using parent address self.directory['armeedeterre']['general_adt'].use_parent_address = True details = IContactable(self.degaulle['gadt']).get_contact_details() self.directory['armeedeterre']['general_adt'].use_parent_address = False self.assertEqual(details['email'], u'*****@*****.**') self.assertEqual(details['phone'], u'0987654321') self.assertDictEqual(details['address'], {'additional_address_details': '', 'city': u'Paris', 'country': u'France', 'number': u'1', 'region': '', 'street': u'Avenue des Champs-\xc9lys\xe9es', 'zip_code': u'75008'}) # test an held position not using parent address details = IContactable(self.pepper['sergent_pepper']).get_contact_details() self.assertEqual(details['email'], u'*****@*****.**') self.assertEqual(details['phone'], u'0288552211') self.assertDictEqual(details['address'], {'additional_address_details': '', 'city': u'Liverpool', 'country': u'England', 'number': u'1', 'region': '', 'street': u'Water Street', 'zip_code': u'L3 4FP'}) # # person contact details are not private api.portal.set_registry_record(name='person_contact_details_private', value=False, interface=IContactCoreParameters) # test an held position using parent address and related to an organization details = IContactable(self.degaulle['adt']).get_contact_details() self.assertEqual(details['email'], u'*****@*****.**') # phone from person self.assertEqual(details['phone'], u'01000000001') # phone from org self.assertDictEqual(details['address'], {'additional_address_details': u'b\xe2timent D', 'city': u'Colombey les deux \xe9glises', 'country': u'France', 'number': u'6bis', 'region': '', 'street': u'rue Jean Moulin', 'zip_code': u'52330'}) # test an held position using parent address and related to a position self.assertFalse(self.directory['armeedeterre']['general_adt'].use_parent_address) details = IContactable(self.degaulle['gadt']).get_contact_details() self.assertEqual(details['email'], u'*****@*****.**') self.assertEqual(details['phone'], u'0987654321') self.assertDictEqual(details['address'], {'additional_address_details': u'b\xe2timent D', 'city': u'Colombey les deux \xe9glises', 'country': u'France', 'number': u'6bis', 'region': '', 'street': u'rue Jean Moulin', 'zip_code': u'52330'}) # test an held position using parent address and related to a position using parent address self.directory['armeedeterre']['general_adt'].use_parent_address = True details = IContactable(self.degaulle['gadt']).get_contact_details() self.directory['armeedeterre']['general_adt'].use_parent_address = False self.assertEqual(details['email'], u'*****@*****.**') self.assertEqual(details['phone'], u'0987654321') self.assertDictEqual(details['address'], {'additional_address_details': u'b\xe2timent D', 'city': u'Colombey les deux \xe9glises', 'country': u'France', 'number': u'6bis', 'region': '', 'street': u'rue Jean Moulin', 'zip_code': u'52330'}) # test an held position not using parent address details = IContactable(self.pepper['sergent_pepper']).get_contact_details() self.assertEqual(details['email'], u'*****@*****.**') self.assertEqual(details['phone'], u'0288552211') self.assertDictEqual(details['address'], {'additional_address_details': '', 'city': u'Liverpool', 'country': u'England', 'number': u'1', 'region': '', 'street': u'Water Street', 'zip_code': u'L3 4FP'})
def update(self): contactable = IContactable(self.context) self.contact_details = contactable.get_contact_details(fallback=False)
def position(self): held_position = self.held_position if held_position: return IContactable(held_position).position
def get(self, field): if field.__name__ in ADDRESS_FIELDS: address = IContactable(self.context).get_contact_details(('address',))['address'] return address.get(field.__name__, None) return getattr(self.context, field.__name__, None)
def organizations(self): held_position = self.held_position if held_position: return IContactable(held_position).organizations else: return ()