def getHeader(query="", category="all"): # returns the raw html for the fixed header # at the top of the page # if user is logged in. # then use the logged-in header # comment in haiku username = userhelper.getCurrentUser() user = "" if username != None: realname = userhelper.getRealName(username) userFile = open("userLoggedIn.html", "r") user = userFile.read() user = user % { "username": username, "realname": realname } userFile.close() else: userFile = open("userLoggedOut.html", "r") user = userFile.read() userFile.close() headerFile = open("header.html", "r") header = headerFile.read() headerFile.close() return header % { "user": user, "query": query, "category": category }
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()