def getInterestedBuyers(db, sessionID): '''Gets the buyer objects that are buying what the tenant plots are producing''' buyerList = [] # get user from sessionID userObject = data.getSession(db, sessionID) if(userObject == []): return None # get username from sessionID into variable uname = userObject[0]['uname'] # get tenant object from username tenantObject = data.getTableEntry(db, data.COLLECTION_TENANTS, {"uname": uname}) # if the user is a tenant if(tenantObject == []): return None # get the specific produce of the tenant sellingObject = tenantObject[0]['produce'] if(sellingObject == []): return None # get all buyers buyersObject = data.getAllFromTable(db, data.COLLECTION_BUYERS) if(buyersObject == []): return None # for every buyer, compare buying product with tenants sold items for buyer in buyersObject: produceList = [] for produce in sellingObject: if produce[0] in buyer['buying']: produceList.append(produce[0]) if(produceList != []): buyerList.append([buyer['uname'], produceList]) return buyerList
def getPlots(db, sessionID): '''Returns the plot data for every plot associated to a user''' # use session ID to get the uname of the tenant from USERS uname = data.getSession(db, sessionID)[0]['uname'] # use uname to get plots array from TENANTS plotData = data.getTenantData(db, uname) if(plotData == []): return [["No Plots Found", "", ""]] else: return plotData[0]['plots']
def authSession(db, sessionID): '''Used to verify a sessionID is valid, gives user role if sessionID exists''' # verify cookie exists on server # if exists, return true / else return false sessionStatus = data.getSession(db, sessionID) returnObject = {} if(len(sessionStatus) > 0): return {"status": True, "role": sessionStatus[0]['role']} else: return {"status": False}
def getBills(db, sessionID): '''Gets the bills for the tenant based on sessionID''' # use session ID to get the uname of the tenant from USERS uname = data.getSession(db, sessionID)[0]['uname'] # use uname to get plots array from TENANTS plotData = data.getTenantData(db, uname) if(len(plotData) > 0): # return the total bill amount return plotData[0]['totalBillAmt'] else: return ["No Bills Found"]