def changeUserBag(userID, newBagStatus, lensID): if newBagStatus in ['wantIt', 'haveIt', 'doNotWant', 'clearStatus']: bagInstance = getBagInstance(userID, lensID) if bagInstance is not None: bagInstance.bagStatus = newBagStatus else: bagInstance = userLensBag( userID = userID, bagStatus = newBagStatus, lensID = lensID) bagInstance.put() cacheKey = userBagCacheKey(userID, lensID) #get the individual lens bag key memcache.set(cacheKey, bagInstance) updateUserBag(userID) getBagInstance(userID, lensID, update = True) getLensStats(lensID, update = True) getTotalLensInstances(refresh = True)
def __init__(self, lensID): currentStats = getLensStats(lensID) self.have = currentStats['haveIt'] self.want = currentStats['wantIt'] self.dont = currentStats['doNotWant'] self.total = getTotalLensInstances() if self.total != 0: self.havePercent = int(100.*self.have/self.total) self.wantPercent = int(100.*self.want/self.total) self.dontPercent = int(100.*self.dont/self.total) else: self.havePercent = 0 self.wantPercent = 0 self.dontPercent = 0