def accountDetail(username): if userhelper.loggedInAs(username): accountDetailFile = open("accountDetail.html", "r") accountDetail = accountDetailFile.read() accountDetailFile.close() realname = userhelper.getRealName(username) cartResultFile = open("cartResult.html", "r") cartResult = cartResultFile.read() cartResultFile.close() cart = "" for book in userhelper.getCart(username): book["username"] = username cart += cartResult % book cartSuffix = "" if cart == "": cartSuffix = " is empty" else: cartSuffix = "'s price: "+userhelper.getCartPrice(username) orderResultFile = open("orderResult.html", "r") orderResult = orderResultFile.read() orderResultFile.close() orders = "" for book in userhelper.getOrders(username): book["username"] = username orders += orderResult % book orderSuffix = "" if orders == "": orderSuffix = " is empty" else: orderSuffix = "' price: "+userhelper.getOrdersPrice(username) return accountDetail % { "header": getHeader(), "username": username, "realname": realname, "cartsuffix": cartSuffix, "cart": cart, "ordersuffix": orderSuffix, "orders": orders } else: return error()
def checkout(username): if userhelper.loggedInAs(username) and len(userhelper.getCart(username)) > 0: checkoutFile = open("checkout.html", "r") checkout = checkoutFile.read() checkoutFile.close() checkoutResultFile = open("checkoutResult.html", "r") checkoutResult = checkoutResultFile.read() checkoutResultFile.close() cart = "" for book in userhelper.getCart(username): cart += checkoutResult % book return checkout % { "header": getHeader(), "username": username, "cartsuffix": "'s price: "+userhelper.getCartPrice(username), "cart": cart } else: return error()