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_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(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 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(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_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_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_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): 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 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 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(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): contactable = IContactable(self.context) self.contact_details = contactable.get_contact_details(fallback=False)
def update(self): contactable = IContactable(self.context) self.contact_details = contactable.get_contact_details()
def update(self): contactable = IContactable(self.context) self.contact_details = contactable.get_contact_details(fallback=False)
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)