Example #1
0
    def d__borrower(self):
        self.print_submenu('Delete a borrower')

        cardNo = None
        while True:
            cardNo = input(
                'Enter the card number for the\nborrower you want to delete: ')

            if len(cardNo) > 0 and cardNo.isdigit():
                cardNo = int(cardNo)
                break
            else:
                print(constants.INCORRECT_INPUT)

        borrower_info = get_borrower(self.cursor,
                                     cardNo)  # {id: [name, address, phone]}

        old_id = None
        old_name = None
        old_address = None
        old_phone = None
        if borrower_info:
            for b in borrower_info:
                old_id = b
                old_name = borrower_info[b][0]
                old_address = borrower_info[b][1]
                old_phone = borrower_info[b][2]
        else:
            print(
                'No such user with that card number exists.\nReturning to previous menu.'
            )
            return True

        borrower_string = 'Deleting borrower ' + old_name + '\n' + old_address + '\n' + old_phone
        self.print_submenu(borrower_string)

        print('Are you sure you wish to delete this borrower?')
        delete_options = ['Yes', 'No']

        delete_selection = self.prompt_options(delete_options)

        if isinstance(delete_selection, bool):
            if delete_selection == True:
                return True
            elif delete_selection == False:
                return False

        if int(delete_selection) == 1:
            print('Deleting borrower', old_name)

            existing_loans = check_existing_loans(self.cursor, old_id)
            if existing_loans:
                print('Failed to delete borrower with existing book loans.\n')
            else:
                modify_borrower(self.cursor, self.connection, 'D', old_id,
                                old_name, old_address, old_phone)
        else:
            print('Not deleting borrower.')

        return True
Example #2
0
    def u__borrower(self):
        self.print_submenu('Update a Borrower')

        cardNo = None
        while True:
            cardNo = input(
                'Enter the card number for the\nborrower you want to update: ')

            if len(cardNo) > 0 and cardNo.isdigit():
                cardNo = int(cardNo)
                break
            else:
                print(constants.INCORRECT_INPUT)

        borrower_info = get_borrower(self.cursor,
                                     cardNo)  # {id: [name, address, phone]}

        old_id = None
        old_name = None
        old_address = None
        old_phone = None
        if borrower_info:
            for b in borrower_info:
                old_id = b
                old_name = borrower_info[b][0]
                old_address = borrower_info[b][1]
                old_phone = borrower_info[b][2]
        else:
            print(
                'No such user with that card number exists.\nReturning to previous menu.'
            )
            return True

        borrower_string = 'Editing borrower ' + old_name + '\n' + old_address + '\n' + old_phone
        self.print_submenu(borrower_string)

        new_name = input('Enter a new name or leave blank to continue: ')
        new_address = input('Enter new address or leave blank to continue: ')
        new_phone = input(
            'Enter a new phone number or leave blank to continue: ')

        if len(new_name) > 0:
            old_name = new_name
        if len(new_address) > 0:
            old_address = new_address
        if len(new_phone) > 0:
            old_phone = new_phone

        modify_borrower(self.cursor, self.connection, 'U', old_id, old_name,
                        old_address, old_phone)

        return True
Example #3
0
    def a__borrower(self):
        self.print_submenu('Add a Borrower')

        name = ''
        address = ''
        phone = ''
        while True:
            name = input('Enter Borrower Name: ')
            if len(name) == 0:
                print(
                    'ERROR: You must enter a name. Type \'quit\' to quit program.'
                )
            elif name == 'quit':
                return False
            elif len(name) > 0:
                break
        while True:
            address = input('Enter Borrower Address: ')
            if len(address) == 0:
                print(
                    'ERROR: You must enter an address. Type \'quit\' to quit program.'
                )
            elif address == 'quit':
                return False
            elif len(address) > 0:
                break

        while True:
            phone = input('Enter Borrower Phone Number: ')
            if len(phone) == 0:
                print(
                    'ERROR: You must enter an phone number. Type \'quit\' to quit program.'
                )
            elif phone == 'quit':
                return False
            elif len(phone) > 0:
                break

        modify_borrower(self.cursor, self.connection, 'A', 0, name, address,
                        phone)

        return True