def getTerm(self, value, brain=None): # Contacts if ActorLookup(value).is_contact() and brain is None: catalog = api.portal.get_tool('portal_catalog') brain = catalog.unrestrictedSearchResults( portal_type=CONTACT_TYPE, contactid=value)[0] if brain and ActorLookup(value).is_contact(): actor = Actor.contact(brain.contactid, contact=brain) token = value title = actor.get_label() return SimpleTerm(value, token, title) # Inboxes if ActorLookup(value).is_inbox(): orgunit_id = value.split(':', 1)[1] orgunit = OrgUnit.query.filter(OrgUnit.unit_id == orgunit_id).one() value = token = orgunit.inbox().id() title = translate(_(u'inbox_label', default=u'Inbox: ${client}', mapping=dict(client=orgunit.label())), context=getRequest()) return SimpleTerm(value, token, title) user = self.base_query.filter(User.userid == value).one() token = value title = u'{} ({})'.format(user.fullname(), user.userid) return SimpleTerm(value, token, title)
def getTerm(self, value, brain=None): if not ActorLookup(value).is_contact(): raise ValueError('Value is not a contact token') catalog = api.portal.get_tool('portal_catalog') brain = catalog.unrestrictedSearchResults(portal_type=CONTACT_TYPE, contactid=value)[0] actor = Actor.contact(brain.contactid, contact=brain) token = value title = actor.get_label() return SimpleTerm(value, token, title)
def getTerm(self, value, brain=None): if not ActorLookup(value).is_contact(): raise ValueError('Value is not a contact token') catalog = api.portal.get_tool('portal_catalog') brain = catalog.unrestrictedSearchResults( portal_type=CONTACT_TYPE, contactid=value)[0] actor = Actor.contact(brain.contactid, contact=brain) token = value title = actor.get_label() return SimpleTerm(value, token, title)
def key_value_provider(self): # Reset hidden_terms every time cache key changed self.hidden_terms = [] items, hidden_terms = self._get_users() # copy lists to prevent cache modification items = items[:] self.hidden_terms = hidden_terms[:] for contact in contact_service().all_contact_brains(): actor = Actor.contact(contact.contactid, contact=contact) items.append((contact.contactid, actor.get_label())) return items
def getTerm(self, value=None, brain=None, solr_doc=None): if solr_doc is not None: value = u'contact:{}'.format(solr_doc[u'id']) title = solr_doc[u'Title'] return SimpleTerm(value, title=title) # Contacts if ActorLookup(value).is_contact() and brain is None: catalog = api.portal.get_tool('portal_catalog') brain = catalog.unrestrictedSearchResults( portal_type=CONTACT_TYPE, contactid=value)[0] if brain and ActorLookup(value).is_contact(): actor = Actor.contact(brain.contactid, contact=brain) token = value title = actor.get_label() return SimpleTerm(value, token, title) # Inboxes if ActorLookup(value).is_inbox(): orgunit_id = value.split(':', 1)[1] orgunit = OrgUnit.query.filter(OrgUnit.unit_id == orgunit_id).one() value = token = orgunit.inbox().id() title = translate(_(u'inbox_label', default=u'Inbox: ${client}', mapping=dict(client=orgunit.label())), context=getRequest()) return SimpleTerm(value, token, title) user = self.base_query.filter(User.userid == value).one() token = value title = u'{} ({})'.format(user.fullname(), user.userid) return SimpleTerm(value, token, title)
def key_value_provider(self): for contact in contact_service().all_contact_brains(): yield (contact.contactid, Actor.contact(contact.contactid, contact=contact).get_label())