def decodeEntity(request, dbsession, entity, leagueObj): numShares = dbsession.query(func.sum(Shares.quantity)).filter(Shares.entity_id == entity.id).scalar() numFreeShares = dbsession.query(func.sum(Shares.quantity)).filter(Shares.entity_id == entity.id).filter(Shares.user_id == None).scalar() priceChanges = dbsession.query(PriceChange).filter(PriceChange.entity_id == entity.id).all() priceChangeDict = {} for priceChange in priceChanges: priceChangeDict[priceChange.term] = float(priceChange.value) leagueDict = {'name':leagueObj.name, 'uri':sm_url.formLeagueURI(request, leagueObj.name)} data = { 'id':entity.id, 'name':entity.name, 'uri':sm_url.formPlayerURI(request, entity.name), 'league':leagueDict, 'numShares':numShares, 'numFreeShares':numFreeShares, 'price':entity.price, 'priceChanges':priceChangeDict} return data
def decodeGroup(request, dbsession, group): url = sm_url.formLeagueURI(request, group.name) return {'id': group.id, 'name': group.name, 'url': url}