Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
 def find_email_contact(self, email):
     return self.contacts.filter(
         db.or_(EmailContact.email == email, GoogleContact.email == email)
     ).first()
Beispiel #6
0
 def find_email_contact(self, email):
     return self.contacts.filter(
         db.or_(EmailContact.email == email,
                GoogleContact.email == email)).first()