def polymorphic_by_searchable_text(self, text_filters=[]): """Query all Contacts by searchable text. If the function of a Persons OrgRole matches, only the matching OrgRoles will be returned. """ # we need to join manually instead of using `options.joinedload` to be # able to filter by OrgRole.function below. query = self.outerjoin(Person.organizations) query = query.options(contains_eager(Person.organizations)) return extend_query_with_textfilter( query, [Person.firstname, Person.lastname, Organization.name, OrgRole.function, Contact.former_contact_id], text_filters, )
def search(self, query_string): self.terms = [] text_filters = query_string.split(' ') query = extend_query_with_textfilter( self.base_query, [User.userid, User.firstname, User.lastname, User.email], text_filters) if self.search_only_active_users: query = query.filter_by(active=True) query = query.order_by(asc(func.lower(User.lastname)), asc(func.lower(User.firstname))) for user in query: self.terms.append(self.getTerm(u'{}'.format(user.userid))) return self.terms
def polymorphic_by_searchable_text(self, text_filters=[]): """Query all Contacts by searchable text. If the function of a Persons OrgRole matches, only the matching OrgRoles will be returned. """ # we need to join manually instead of using `options.joinedload` to be # able to filter by OrgRole.function below. query = self.outerjoin(Person.organizations) query = query.options(contains_eager(Person.organizations)) return extend_query_with_textfilter( query, [ Person.firstname, Person.lastname, Organization.name, OrgRole.function, Contact.former_contact_id ], text_filters, )
def search(self, query_string): self.terms = [] text_filters = query_string.split(' ') query = extend_query_with_textfilter( self.base_query, [User.userid, User.firstname, User.lastname, User.email], text_filters) query = query.filter_by(active=True) query = query.order_by(asc(func.lower(User.lastname)), asc(func.lower(User.firstname))) for user in query.all(): self.terms.append( self.getTerm(u'{}'.format(user.userid))) self._extend_terms_with_contacts(query_string) self._extend_terms_with_inboxes(text_filters) return self.terms
def _extend_terms_with_inboxes(self, text_filters): inbox_text = translate(_(u'inbox_label', default=u'Inbox: ${client}', mapping=dict(client='')), context=getRequest()).strip().lower() text_filters = filter(lambda text: text.lower() not in inbox_text, text_filters) query = OrgUnit.query if self.only_current_inbox: query = query.filter(OrgUnit.unit_id == self.client_id) query = extend_query_with_textfilter( query, [OrgUnit.title, OrgUnit.unit_id], text_filters) for orgunit in query.all(): self.terms.insert(0, self.getTerm(orgunit.inbox().id()))
def search(self, query_string): self.terms = [] text_filters = query_string.split(' ') query = extend_query_with_textfilter(self.base_query, [ OrgUnit.title, OrgUnit.unit_id, User.userid, User.firstname, User.lastname, User.email ], text_filters) query = query.filter_by(active=True) query = query.order_by(asc(func.lower(User.lastname)), asc(func.lower(User.firstname))) for user, orgunit in query: self.terms.append( self.getTerm(u'{}:{}'.format(orgunit.id(), user.userid))) self._extend_terms_with_inboxes(text_filters) if self.include_teams: self._extend_terms_with_teams(text_filters) return self.terms
def _extend_terms_with_teams(self, text_filters): query = Team.query.filter(Team.active == True) # noqa query = extend_query_with_textfilter(query, [Team.title], text_filters) for team in query: self.terms.insert(0, self.getTerm(team.actor_id()))