Пример #1
0
    def delUser(selector):

        matches = []

        if (functions.num_there(selector)):
            print("\nNumber Found!!\nID Number or Date....\n\n")

            if ((len(selector) == 8) and (selector[2] == "/")):
                print("\n\n*Date identifier entered")

                for k in range(0, len(User.usersList)):
                    if (User.usersList[k].DOB == selector):

                        print("DOB match found at item # ", k)
                        matches.append(k)

            else:

                print("\nID Number entered.....")

                for k in range(0, len(User.usersList)):

                    if (str(User.usersList[k].id_num) == selector):

                        print("ID Number match found at item # ", k)
                        matches.append(k)

        else:
            print("No Number!!\nname identifier")
            for k in range(0, len(User.usersList)):
                if (User.nameCompare(selector, User.usersList[k].name)):
                    matches.append(k)

        if (len(matches) == 1):

            print("\nOne possible match found\n")
            print("\nMatch Name: \n", User.usersList[matches[0]].name, "\n")
            toRemove = input("\nWould you like to delete a user? [Y/N]\n")

            if (toRemove.lower() == "y"):
                print("Deleting User")
                User.usersList.remove(User.usersList[matches[0]])

            else:
                print("\nContinuing without deletion....")

        elif (len(matches) > 1):

            print("\n\n\nMultiple matches found!\n\nPrinting matches:")
            for match in matches:
                print(User.usersList[match].name)
            toRemove = input("""\n\nWould you like to delete a user?
                             If yes, enter which user
                             ----------------------
                             1 - First Match Shown
                             2 - Second Match Shown
                             n - nth match....\n""")

            try:
                val = int(toRemove)
            except ValueError:

                print(
                    "\n\nPlease enter a valid integer user index to delete...")
                return

            print("\nYou have selected item number", toRemove, "to remove\n")
            print("\nDeleting user number", toRemove, "with name", selector,
                  "\n")
            print("This will delete user #", matches[int(toRemove) - 1],
                  "from master list")
            User.usersList.remove(User.usersList[matches[int(toRemove) - 1]])
            print("\nUser Deleted....\n")

        else:
            print("\nDo Nothing...")
Пример #2
0
    def deleteUser(selector):
        matches = []

        if (functions.num_there(selector)):

            print("\n\n*Number identified in the selector\n")
            if ((len(selector) > 2) and (selector[2] == "/")):

                print("\n\n*Date identifier entered")
                if (len(selector) == 8):

                    print("Correct Date Format entered")

                    for k in range(0, len(User.usersList)):
                        if (User.usersList[k].DOB == selector):

                            print("DOB match found at item # ", k)
                            print("Deleting user with DOB: ", selector)
                            User.usersList.remove(User.usersList[k])
                else:

                    print("Incorrect Date Format....")

            else:
                print("\n*ID Number identifier entered")

                for k in range(0, len(User.usersList)):
                    if (User.usersList[k].id_num == int(selector)):

                        print("ID Number match found at item # ", k)
                        print("Deleting user with id number: ", selector)
                        User.usersList.remove(User.usersList[k])
                        return
                print(
                    "\n\nNo matching ID number found in database.....\n\nReturning to program....\n"
                )

        else:

            print("\n\nName identifier entered")
            selector = selector.lower()

            for k in range(0, len(User.usersList)):
                if (User.usersList[k].name.lower() == selector):
                    print("\nExact name match found!\nMatch at index: ", k)
                    matches.append(k)

            if (len(matches) > 0):

                print("\n\n\nPerfect matches found!\n\nPrinting matches:")
                for match in matches:
                    print(User.usersList[match].name)
                toRemove = input("""\n\nWould you like to delete a user?
                                 If yes, enter which user
                                 ----------------------
                                 1 - First Match Shown
                                 2 - Second Match Shown
                                 n - nth match....\n""")
                print("\nYou have selected item number", toRemove,
                      "to remove\n")
                print("\nDeleting user number", toRemove, "with name",
                      selector, "\n")
                print("This will delete user #", matches[int(toRemove) - 1],
                      "from master list")
                User.usersList.remove(User.usersList[matches[int(toRemove) -
                                                             1]])
                print("\nUser Deleted....\n")

            else:

                print("\nNo perfect name match found!")

                if (selector.find(" ") != -1):

                    print("\nFirst and last name entered..")

                    sel = selector[0:selector.find(" ")]
                    ector = selector[selector.find(" ") + 1:]
                    print("""\nNo user found with exact name match.
                          Selector entered with a first and last name.""")
                    print("After splitting the selector, \nsel = ", sel,
                          "\nector = ", ector, "\n")
                    print("------------------------------------------------$$")

                    print(
                        "\nChecking the list of users for possible matches..")
                    for k in range(0, len(User.usersList)):

                        first = User.usersList[k].name[0:User.usersList[k].
                                                       name.find(" ")]
                        last = User.usersList[k].name[User.usersList[k].name.
                                                      find(" "):]
                        first = first.replace(" ", "").lower()
                        last = last.replace(" ", "").lower()

                        if (first == sel):
                            matches.append(k)
                        elif (last == ector):

                            matches.append(k)

                    if (len(matches) > 0):
                        print(
                            "\n\nNo direct matches, here are some similar results:\n"
                        )
                        for match in matches:
                            print(User.usersList[match].name)

                        toRemove = input("""\nWould you like to delete a user?
                                         If yes, enter which user
                                         ----------------------
                                          0 - Delete No Matches
                                          1 - First Match Shown
                                          2 - Second Match Shown
                                          n - nth match....\n""")

                        try:
                            val = int(toRemove)
                        except ValueError:

                            print(
                                "\n\nPlease enter a valid integer user index to delete..."
                            )
                            return

                        if (int(toRemove) - 1 < len(matches)
                                and (matches[int(toRemove) - 1] < len(
                                    User.usersList))):
                            print("\n\nDeleting User: "******"\n\n\nNumber outside range.\nExiting....\n\n\n"
                            )
                            return

                        if (toRemove == "0"):
                            print("\nDeleting no matches and continuing..\n\n")
                        else:
                            User.usersList.remove(
                                User.usersList[matches[int(toRemove) - 1]])
                            print("\n\nUserDeleted...\n\n")

                    else:
                        print("\nNo near matches found...")
                else:
                    print("\nPlease enter a first and last name\n\n")
Пример #3
0
    def deleteUser(selector):
        matches = []

        if (functions.num_there(selector)):
            #either id number or date
            #works for exactly matched id numbers
            print("\n\n*Number identified in the selector\n")
            if ((len(selector) > 2) and (selector[2] == "/")):
                # DATE
                #control for dates entered incorectly: "1/1/94, 12/3/89"
                print("\n\n*Date identifier entered")
                if (len(selector) == 8):
                    #scan objects for date match.....
                    print("Correct Date Format entered")
                    #match dates
                    for k in range(0, len(User.usersList)):
                        if (User.usersList[k].DOB == selector):
                            #found date match
                            print("DOB match found at item # ", k)
                            print("Deleting user with DOB: ", selector)
                            User.usersList.remove(User.usersList[k])
                else:
                    #include code to check if "/" is in the string somewhere? 9/12 chance this error could happen 4/13/21, etc
                    print("Incorrect Date Format....")

            else:
                print("\n*ID Number identifier entered")
                #match id numbers
                for k in range(0, len(User.usersList)):
                    if (User.usersList[k].id_num == int(selector)):
                        #found id number match
                        print("ID Number match found at item # ", k)
                        print("Deleting user with id number: ", selector)
                        User.usersList.remove(User.usersList[k])
                        return
                print(
                    "\n\nNo matching ID number found in database.....\n\nReturning to program....\n"
                )

        else:
            # NAME - there are no numbers
            # for exactly matched names - if two by same name then gives option to delete either
            print("\n\nName identifier entered")
            selector = selector.lower()
            #search for direct match
            for k in range(0, len(User.usersList)):
                if (User.usersList[k].name.lower() == selector):
                    print("\nExact name match found!\nMatch at index: ", k)
                    matches.append(k)  # to allow for multiple matches

            if (len(matches) > 0):
                #show one or more matches
                #need to add more info on entries name1 = name2....
                print("\n\n\nPerfect matches found!\n\nPrinting matches:")
                for match in matches:
                    print(User.usersList[match].name)
                toRemove = input("""\n\nWould you like to delete a user?
                                 If yes, enter which user
                                 ----------------------
                                 1 - First Match Shown
                                 2 - Second Match Shown
                                 n - nth match....\n""")
                print("\nYou have selected item number", toRemove,
                      "to remove\n")
                print("\nDeleting user number", toRemove, "with name",
                      selector, "\n")
                print("This will delete user #", matches[int(toRemove) - 1],
                      "from master list")
                User.usersList.remove(User.usersList[matches[
                    int(toRemove) -
                    1]])  #the second match will really be @ index n-1 in array
                print("\nUser Deleted....\n")

            else:
                #no exact matches found yet!
                print("\nNo perfect name match found!")

                #search for just first name or last name
                #there is a space in the name entered (first and last entered)
                if (selector.find(" ") != -1):

                    print("\nFirst and last name entered..")
                    #get the first name and last name
                    sel = selector[0:selector.find(" ")]
                    ector = selector[selector.find(" ") + 1:]
                    print("""\nNo user found with exact name match.
                          Selector entered with a first and last name.""")
                    print("After splitting the selector, \nsel = ", sel,
                          "\nector = ", ector, "\n")
                    print("------------------------------------------------$$")
                    #checking for first/last name matches only...
                    print(
                        "\nChecking the list of users for possible matches..")
                    for k in range(0, len(User.usersList)):
                        #print("\nChecking for the same first/last names..")
                        first = User.usersList[k].name[0:User.usersList[k].
                                                       name.find(" ")]
                        last = User.usersList[k].name[User.usersList[k].name.
                                                      find(" "):]
                        first = first.replace(" ",
                                              "").lower()  #strips any spaces
                        last = last.replace(" ", "").lower()
                        ##                        print("\nFirst name is: \n",first)
                        ##                        print("\nLast name is: \n",last)

                        #check if first names match, or last name....
                        if (first == sel):
                            ##                            print("First name match @ k = ",k)
                            ##                            print("Selector entered: ", selector)
                            ##                            print("Matched User: "******"User with same first name found: /nUser: "******"\n user id: ",User.usersList[k].id_num,"\n\n"))
                            matches.append(k)
                        elif (last == ector):
                            ##                            print("\n\nLast name match @ k = ",k)
                            ##                            print("Selector entered: ", selector)
                            ##                            print("Matched User: "******"User with same last name found: /nUser: "******"\n user id: ",User.usersList[k].id_num,"\n\n"))
                            matches.append(k)

############                        #need to replace alot of the code above with
############                        elif( selector.find(User.usersList[k].name) == User.usersList[k].name ):
############################## THIS CODE NEEDS TO BE REDONE....
############################# ------ ALSO USE .find( first_three_letters_of_first) and  .find( first_three_letters_of_last)

##Code works as intended
#--------------- CAN ONLY ALLOW FOR ONE DELETION AT A TIME
                    if (len(matches) > 0):
                        print(
                            "\n\nNo direct matches, here are some similar results:\n"
                        )
                        for match in matches:
                            print(User.usersList[match].name)

                        #allow user to select from ~matches and delete....
                        toRemove = input("""\nWould you like to delete a user?
                                         If yes, enter which user
                                         ----------------------
                                          0 - Delete No Matches
                                          1 - First Match Shown
                                          2 - Second Match Shown
                                          n - nth match....\n""")

                        #catch non integer input
                        try:
                            val = int(toRemove)  #make sure its an integer
                        except ValueError:
                            #not an int entered
                            print(
                                "\n\nPlease enter a valid integer user index to delete..."
                            )
                            return

                        #make sure integer that is entered is within valid ranges
                        if (int(toRemove) - 1 < len(matches)
                                and (matches[int(toRemove) - 1] < len(
                                    User.usersList))):
                            print("\n\nDeleting User: "******"\n\n\nNumber outside range.\nExiting....\n\n\n"
                            )
                            return

                        #for debugging
##                        print("\n\nYou have selected: ",toRemove)
##                        print("The 'matches' entry assocuated with to remove is: \n int(toRemove) - 1 = ", int(toRemove) - 1)
##                        print("matches = ",matches)
##                        print("len(User.usersList) = ",len(User.usersList))

                        if (toRemove == "0"):
                            print("\nDeleting no matches and continuing..\n\n")
                        else:
                            User.usersList.remove(
                                User.usersList[matches[int(toRemove) - 1]])
                            print("\n\nUserDeleted...\n\n")

                    #if there is no space in the selector/identifier
                    #just one word, so look at first/last name
                    else:
                        print("\nNo near matches found...")
                else:
                    print("\nPlease enter a first and last name\n\n")
   def deleteUser(selector):
       matches=[]
 
       if(functions.num_there(selector)):
Пример #5
0
    def delUser(selector):

        matches = []

        #names/dates/ids are given raw from user
        #could put in anything '2311 trent'
        #if this happens there will simply be no match and continue

        #-id number or date
        if (functions.num_there(selector)):
            print("\nNumber Found!!\nID Number or Date....\n\n")

            #if date in right format - if not exit
            if ((len(selector) == 8) and (selector[2] == "/")):
                print("\n\n*Date identifier entered")

                for k in range(0, len(User.usersList)):
                    if (User.usersList[k].DOB == selector):
                        #found date match
                        print("DOB match found at item # ", k)
                        matches.append(k)

            #for id number
            #doesssssnt work. gets to "Do Nothing"
            #number found in string, not in date format..
            #just scanning for a match works, if no match/id format then ok
##            elif( selector == id_num ):
            else:

                print("\nID Number entered.....")
                # print("\n\nSelector = ",selector)
                for k in range(0, len(User.usersList)):
                    # print("\n\nUser.usersList[k].id_num = ",User.usersList[k].id_num)
                    if (str(User.usersList[k].id_num) == selector):
                        #found ID Number match
                        print("ID Number match found at item # ", k)
                        matches.append(k)
        #-name
        #----------------- Seems to work fine
        else:
            print("No Number!!\nname identifier")
            for k in range(0, len(User.usersList)):
                if (User.nameCompare(selector, User.usersList[k].name)
                    ):  #returns true if direct match or close match
                    matches.append(k)

#-all matches gathered to array
#-now determine which to delete
#-should use:
        if (len(matches) == 1):
            #only one match...
            #present options to delete this one y/n
            print("\nOne possible match found\n")
            print("\nMatch Name: \n", User.usersList[matches[0]].name, "\n")
            toRemove = input("\nWould you like to delete a user? [Y/N]\n")

            #catch non integer input
            try:
                val = int(toRemove)  #make sure its an integer
            except ValueError:
                #not an int entered
                print(
                    "\n\nPlease enter a valid integer user index to delete...")
                return

            if (toRemove.lower() == "y"):
                print("Deleting User")
                User.usersList.remove(User.usersList[matches[0]])
                #breaks for multiple same names? (wouldnt be in this block then right>
                #is there a better way to delete?
                #usersList.remove( index )??
            else:
                print("\nContinuing without deletion....")

        elif (len(matches) > 1):
            #multiple matches
            #present options for multiple matches..
            print("\n\n\nMultiple matches found!\n\nPrinting matches:")
            for match in matches:
                print(User.usersList[match].name)
            toRemove = input("""\n\nWould you like to delete a user?
                             If yes, enter which user
                             ----------------------
                             1 - First Match Shown
                             2 - Second Match Shown
                             n - nth match....\n""")

            #NEED TO CLEANSE INPUT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            #breaks when pressing <Enter>

            #catch non integer input
            try:
                val = int(toRemove)  #make sure its an integer
            except ValueError:
                #not an int entered
                print(
                    "\n\nPlease enter a valid integer user index to delete...")
                return

            print("\nYou have selected item number", toRemove, "to remove\n")
            print("\nDeleting user number", toRemove, "with name", selector,
                  "\n")
            print("This will delete user #", matches[int(toRemove) - 1],
                  "from master list")
            User.usersList.remove(User.usersList[matches[
                int(toRemove) -
                1]])  #the second match will really be @ index n-1 in array
            print("\nUser Deleted....\n")

        #no matches
        #can really delete this code below..
        else:
            print("\nDo Nothing...")