示例#1
0
def create_default_objects():
    '''
    Creates a list of default users and accounts for testing purposes
    '''
    # Create a default Admin user
    Admin(username="******", password="******", first_name="Jack").save()
    print("Default Admin Created")

    cust1 = Customer(username="******",
                     password="******",
                     first_name="John")
    cust1.save()
    print("Default Customer Created")

    Checking_Account(account_number="1", owner=cust1).save()
    print("Default Checking Account Created")

    Savings_Account(account_number="2", owner=cust1).save()
    print("Default Savings Account Created")

    cust2 = Customer(username="******",
                     password="******",
                     first_name="Clark")
    cust2.save()
    print("Default Customer2 Created")

    Savings_Account(account_number="3", owner=cust2).save()
    print("Default Savings Account Created")

    Brokerage_Account(account_number="4", owner=cust1).save()
    print("Default Brokerage Account Created")
示例#2
0
 def create_account(self, account_type, account_number):
     '''
     Creates and returns a new account object with the given account type and account number
     Takes two strings as parameters
     '''
     # Try to retrieve an account with the same account number and, if it succeeds, we know
     # that number is already in use.
     account_number_exists = False
     try:
         Checking_Account.get(account_number=account_number)
         account_number_exists = True
     except:
         try:
             Savings_Account.get(account_number=account_number)
             account_number_exists = True
         except:
             try:
                 Brokerage_Account.get_account(account_number)
                 acount_number_exists = True
             except:
                 pass
     # Throw exception if account number is already in use
     if account_number_exists:
         raise Exception("Account Number is already in use")
     # Create a checking account if that's the account type
     if account_type == "checking":
         acct = Checking_Account(account_number=account_number).save()
     # Create a savings account if that's the account type
     elif account_type == "savings":
         acct = Savings_Account(account_number=account_number).save()
     # Create a brokerage account if that's the account type
     elif account_type == "brokerage":
         acct = Brokerage_Account(account_number=account_number).save()
     # If we don't have a matching account type, raise an exception
     else:
         raise Exception("Invalid Account Type")
     return acct
 def create_account(self, account_type, account_number):
     '''
     Creates and returns a new account object with the given account type and account number
     Takes two strings as parameters
     '''
     # Try to retrieve an account with the same account number and, if it succeeds, we know
     # that number is already in use.
     account_number_exists = False
     try:
         Checking_Account.get(account_number=account_number)
         account_number_exists = True
     except:
         try:
             Savings_Account.get(account_number=account_number)
             account_number_exists = True
         except:
             try:
                 Brokerage_Account.get_account(account_number)
                 acount_number_exists = True
             except:
                 pass
     # Throw exception if account number is already in use
     if account_number_exists:
         raise Exception("Account Number is already in use")
     # Create a checking account if that's the account type
     if account_type == "checking":
         acct = Checking_Account(account_number=account_number).save()
     # Create a savings account if that's the account type
     elif account_type == "savings":
         acct = Savings_Account(account_number=account_number).save()
     # Create a brokerage account if that's the account type
     elif account_type == "brokerage":
         acct = Brokerage_Account(account_number=account_number).save()
     # If we don't have a matching account type, raise an exception
     else:
         raise Exception("Invalid Account Type")
     return acct
示例#4
0
 def get_all_account_info(self):
     '''
     Retrieves infomration about all of the accounts as an array of accounts
     '''
     # Create the accounts array
     accounts = []
     # Add savings accounts to the accounts array
     for each_account in Savings_Account.select():
         accounts.append(str(each_account))
     # Add Checking accounts to the accounts array
     for each_account in Checking_Account.select():
         accounts.append(str(each_account))
     # Add Brokerage accounts to the account array
     for each_account in Brokerage_Account.select():
         accounts.append(str(each_account))
     # Return the accounts array
     return accounts
 def get_all_account_info(self):
     '''
     Retrieves infomration about all of the accounts as an array of accounts
     '''
     # Create the accounts array
     accounts = []
     # Add savings accounts to the accounts array
     for each_account in Savings_Account.select():
         accounts.append(str(each_account))
     # Add Checking accounts to the accounts array
     for each_account in Checking_Account.select():
         accounts.append(str(each_account))
     # Add Brokerage accounts to the account array
     for each_account in Brokerage_Account.select():
         accounts.append(str(each_account))
     # Return the accounts array
     return accounts
    def get_account(self):
        '''
        Ask the user for an account number, and return a valid account
        '''
        acct = None
        account_number = input("Account Number: ")
        # Check Savings Accounts for a match
        try:
            return Savings_Account.get_account(account_number)
        except Savings_Account.DoesNotExist:
            # Check Checking Accounts for a match
            try:
                return Checking_Account.get_account(account_number)
            except Checking_Account.DoesNotExist:
                # Check Brokerage Accounts for a match
                try:
                    return Brokerage_Account.get_account(account_number)
                except Brokerage_Account.DoesNotExist:
                    print("Account not found")

        return acct
 def set_acct(self, id):
     self.acct = Brokerage_Account.get_account(id)
 def set_acct(self, id):
     self.acct = Brokerage_Account.get_account(id)