Ejemplo n.º 1
0
    def findUsers(self, name=None, number=None, id=None):
        """Finds users matching specified name/alias, number, or UID."""

        names = utils.toCleanList(name)
        numbers = utils.toCleanList(number)
        ids = utils.toCleanList(id)

        matches = []

        for user in self.users:
            test_name = len(
                names
            ) == 0  #If this argument is not supplied, its test passes automatically.
            test_num = len(numbers) == 0
            test_id = len(ids) == 0

            for name in names:
                for userName in user.names:
                    if userName.lower().find(name.lower()) > -1:
                        test_name = True
            for num in numbers:
                for userNum in user.numbers:
                    if userNum.find(num) > -1:
                        test_num = True
            for id in ids:
                if str(id) == str(user.id):
                    test_id = True

            if test_name and test_num and test_id:
                matches.append(user)

        return len(matches) > 0, matches
Ejemplo n.º 2
0
 def addAlias(self, args):
     """Adds one or several names to the user."""
     l = utils.toCleanList(args)
     t = len(self.names)
     for arg in l:
         self.names.append(arg)
     return t != len(self.names)
Ejemplo n.º 3
0
 def addNumber(self, args):
     """Adds one or several numbers to the user."""
     l = utils.toCleanList(args)
     t = len(self.numbers)
     for arg in l:
         self.numbers.append(arg)
     return t != len(self.numbers)
Ejemplo n.º 4
0
    def addUser(self, name, number=None):
        """Adds a new user to the phonebook and returns the User object."""

        names = utils.toCleanList(
            name
        )  #Convert input to a list, which helps when doing batch operations.
        numbers = utils.toCleanList(number)

        for num in numbers:
            test = self.findUsers(number=num)
            if test[0]:
                return False, test[1]

        new = User(name, number)
        self.users.append(new)
        return True, new
Ejemplo n.º 5
0
 def removeAlias(self, args):
     """Removes one or several names from the user."""
     l = utils.toCleanList(args)
     t = len(self.names)
     for arg in l:
         if arg in self.names and arg != self.names[0]:
             self.names.remove(arg)
     return t != len(self.names)
Ejemplo n.º 6
0
 def removeNumber(self, args):
     """Removes one or several numbers from the user."""
     l = utils.toCleanList(args)
     t = len(self.numbers)
     for arg in l:
         if arg in self.numbers:
             self.numbers.remove(arg)
     return t != len(self.numbers)
Ejemplo n.º 7
0
 def removeUser(self, user=None, name=None, number=None, id=None):
     """Removes users matching specified name (+ alias) and numbers."""
     l = len(self.users)
     if user:
         r = utils.toCleanList(user)
     else:
         r = self.findUsers(name, number, id)[1]
     self.users = [user for user in self.users if user not in r
                   ]  #Strip users list of users present in 'r'.
     return l != len(self.users)
Ejemplo n.º 8
0
 def __init__(self, name, number=None):
     self.id = User.numUsers
     self.names = utils.toCleanList(name)
     self.numbers = utils.toCleanList(number)
     User.numUsers += 1