def fetch_by_email(self, email): contact = Contact.query.filter( db.or_( EmailContact.email == email, GoogleContact.email == email ) )\ .filter(Contact.belongs_to_user == True)\ .first() return contact.user if contact else None
def search_contacts(self, term, limit=5): """Searches contacts by a given term.""" pattern = term + '%' # basic name search by_name = self.contacts.filter(Contact.name.ilike(pattern)) # by special attributes by_email = self.contacts.filter( db.or_(EmailContact.email.ilike(pattern), GoogleContact.email.ilike(pattern))) by_id_or_username = self.contacts.filter( db.or_( db.cast(FacebookContact.user_id, db.String).ilike(pattern), FacebookContact.username.ilike(pattern))) # union of results return by_name.union(by_email, by_id_or_username).order_by( Contact.name).limit(limit)
def search_contacts(self, term, limit=5): """Searches contacts by a given term.""" pattern = term + '%' # basic name search by_name = self.contacts.filter(Contact.name.ilike(pattern)) # by special attributes by_email = self.contacts.filter( db.or_( EmailContact.email.ilike(pattern), GoogleContact.email.ilike(pattern) ) ) by_id_or_username = self.contacts.filter( db.or_( db.cast(FacebookContact.user_id, db.String).ilike(pattern), FacebookContact.username.ilike(pattern) ) ) # union of results return by_name.union(by_email, by_id_or_username).order_by(Contact.name).limit(limit)
def find_email_contact(self, email): return self.contacts.filter( db.or_(EmailContact.email == email, GoogleContact.email == email) ).first()
def find_email_contact(self, email): return self.contacts.filter( db.or_(EmailContact.email == email, GoogleContact.email == email)).first()