Exemplo n.º 1
0
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
Exemplo n.º 2
0
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']
Exemplo n.º 3
0
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}
Exemplo n.º 4
0
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"]