コード例 #1
0
 def post(self, customer_id):
   abort_if_customer_doesnt_exist(customer_id)
   parser.add_argument('acct_type')
   args = parser.parse_args()
   acct = AccountModel(customer_id=customer_id, acct_type=args['acct_type'])
   S.add(acct)
   return
コード例 #2
0
def display_accounts(customer_id=None):
  if customer_id == None:
    for account in S.query(Account).all():
      print "  ACCOUNT NUMBER: " + str(account.acct_num) + "\tACCOUNT TYPE: " + str(account.acct_type) + "\tACCOUNT BALANCE: " + str(account.balance) + "\n",
  else:
    for account in S.query(Account).filter(Account.customer_id==customer_id):
      print "  ACCOUNT NUMBER: " + str(account.acct_num) + "\tACCOUNT TYPE: " + str(account.acct_type) + "\tACCOUNT BALANCE: " + str(account.balance) + "\n",
  return
コード例 #3
0
 def do_1(self, args):
   print "Please enter the following:"
   username_input = raw_input('Username: '******'Password: ')
   c = Customer(username=username_input, password=password_input)
   S.add(c)
   S.commit()
   print self.intro
   return
コード例 #4
0
 def do_5(self, args):
   print "Please choose which customer to suspend:"
   display_customers()
   customers = S.query(Customer).all()
   customer_index = int(raw_input(">").strip())
   customer = customers[customer_index]
   customer.suspended = True
   S.commit()
   print self.intro
   return
コード例 #5
0
 def do_2(self, args):
   print "Please enter the account number:"
   display_accounts(customer_id=login_manager.get_customer().customer_id)
   account_num = int(raw_input(">").strip())
   account = S.query(Account).filter(Account.acct_num==account_num).first()
   amount = float(raw_input("Please enter the amount to withdraw: ").strip())
   account.balance -= amount
   S.commit()
   create_transaction(from_acct=account, amount=amount, transaction_type="withdrawal", final_balance=account.balance)
   print self.intro
   return
 def do_1(self, args):
   print "Please enter the account number:"
   display_accounts(customer_id=login_manager.get_customer().customer_id)
   account_num = int(raw_input(">").strip())
   account = S.query(Account).filter(Account.acct_num==account_num).first()
   amount = float(raw_input("Please enter the amount to deposit: ").strip())
   account.balance += amount
   S.commit()
   create_transaction(to_acct=account, amount=amount, transaction_type="deposit")
   print self.intro
   return
コード例 #7
0
 def do_3(self, args):
   print "Please enter the account number to transfer FROM:"
   display_accounts(customer_id=login_manager.get_customer().customer_id)
   account_num_from = int(raw_input(">").strip())
   account_from = S.query(Account).filter(Account.acct_num==account_num_from).first()
   display_accounts(customer_id=login_manager.get_customer().customer_id)
   print "Please enter the account number to transfer TO:"
   account_num_to = int(raw_input(">").strip())
   account_to = S.query(Account).filter(Account.acct_num==account_num_to).first()
   amount = float(raw_input("Please enter the amount to deposit: ").strip())
   account_from.balance -= amount
   account_to.balance += amount
   S.commit()
   create_transaction(from_acct=account_from, to_acct=account_to, amount=amount, transaction_type="transfer", final_balance=None)
   print self.intro
   return
コード例 #8
0
def abort_if_account_doesnt_exist(customer_id, acct_num):
  account = S.query(AccountModel) \
    .filter(AccountModel.customer_id==customer_id) \
    .filter(AccountModel.acct_num==acct_num).first()
  if not account:
    abort(404, error=doesnt_exist_error('account')['error'])
  return
 def do_2(self, args):
   print "Please choose which customer to add the account for:"
   customers = S.query(Customer).all()
   display_customers()
   customer_index = int(raw_input(">").strip())
   customer = customers[customer_index]
   acct_types = {
     0: 'checking',
     1: 'savings'
   }
   acct_type_prompt = "Please pick what type the account is:\n" + \
                      "  0. Checking\n" + \
                      "  1. Savings\n>"
   acct_type = acct_types[int(raw_input(acct_type_prompt).strip())]
   acct = Account(acct_type=acct_type, balance=0.0, customer=customer)
   S.add(acct)
   S.commit()
   print self.intro
   return
コード例 #10
0
 def get(self, customer_id=None):
   if customer_id:
     abort_if_customer_doesnt_exist(customer_id)
     customer = get_customer(customer_id)
     return customer.serialize
   else:
     customers = []
     for c in S.query(CustomerModel).all():
       customers.append(c.serialize)
     return customers
 def login(self):
   try:
     self.customer = S.query(Customer).filter(Customer.username==self.username) \
                                      .filter(Customer.password==self.password) \
                                      .one()
   except:
     return False
   if self.customer.suspended:
     print "Failed to login. Customer is SUSPENDED."
     return False
   return True
コード例 #12
0
 def do_4(self, args):
   global login_manager
   transactions = S.query(Transaction).order_by(Transaction.date).all()
   for t in transactions:
     if t.from_account != None:
       if t.from_account.customer == login_manager.customer:
         display_transaction(t)
     elif t.to_account != None:
       if t.to_account.customer == login_manager.customer:
         display_transaction(t)
   print self.intro
   return
コード例 #13
0
def get_customer(customer_id=None, username=None):
  if username:
    return S.query(CustomerModel) \
          .filter(CustomerModel.username==username).first()
  return S.query(CustomerModel) \
        .filter(CustomerModel.customer_id==customer_id).first()
コード例 #14
0
 def get(self, customer_id):
   abort_if_customer_doesnt_exist(customer_id)
   customer = get_customer(customer_id)
   stocks = S.query(StocksModel).filter(StocksModel.customer_id==customer_id).all()
   return stocks
コード例 #15
0
def abort_if_customer_doesnt_exist(customer_id):
  customer = S.query(CustomerModel) \
    .filter(CustomerModel.customer_id==customer_id).first()
  if not customer:
    abort(404, error=doesnt_exist_error('customer')['error'])
  return
def create_transaction(from_acct=None, to_acct=None, transaction_type=None, amount=0.0):
  t = Transaction(from_account=from_acct, to_account=to_acct, transaction_type=transaction_type, amount=amount)
  S.add(t)
  S.commit()
コード例 #17
0
def create_transaction(from_acct=None, to_acct=None, transaction_type=None, amount=0.0, final_balance=None):
  t = Transaction(from_account=from_acct, to_account=to_acct, transaction_type=transaction_type, amount=amount, final_balance=final_balance, date=datetime.utcnow())
  S.add(t)
  S.commit()
コード例 #18
0
def display_customers():
  for customer in enumerate(S.query(Customer).all()):
    print "  " + str(customer[0]) + ". " + customer[1].username
  return
コード例 #19
0
 def do_3(self, args):
   transactions = S.query(Transaction).order_by(Transaction.date).all()
   for t in transactions:
     display_transaction(t)
   print self.intro
   return
コード例 #20
0
 def post(self):
   args = parser.parse_args()
   c = CustomerModel(username=args['username'], password=args['password'])
   S.add(c)
   S.commit()
   return c.serialize