def GetContext(self): tContext = {} typeOfGold = self.GOLDTYPE tCurrentPrice = Price() tPriceQuery = Price().all() tPriceQuery.order("-priceDateCreated") tPriceQuery.filter("priceType", typeOfGold) tCurrentPrice = tPriceQuery.fetch(limit=1)[0] tPriceDictionary = _data.PriceContainer.GetBasePriceDictionary() typeOfGold = self.GOLDTYPE if typeOfGold is 'regular': tCurrentPrice.priceType = 'regular' tContext['post_location'] = '/price' elif typeOfGold is '07': tCurrentPrice.priceType = '07' tContext['post_location'] = '/price07' tSortedProperties = sorted(tCurrentPrice.properties().keys()) for tCurrentProperty in tSortedProperties: try: tMatches = re.match(r'price(?P<number>[0-9]{4}m)', str(tCurrentProperty)) tMatchedKey = str(tMatches.group('number')) tPriceDictionary[tMatchedKey] = tCurrentPrice.__getattribute__( tCurrentProperty) except: logging.debug('Could not find a key in: ' + str(tCurrentProperty)) tPriceList = [] tSortedPriceKeys = sorted(tPriceDictionary.keys()) for tCurrentKey in tSortedPriceKeys: if (tCurrentKey[:3] == '000'): tKey = tCurrentKey[3:] elif (tCurrentKey[:2] == '00'): tKey = tCurrentKey[2:] elif (tCurrentKey[0] == '0'): tKey = tCurrentKey[1:] else: tKey = tCurrentKey tTuple = (tKey, tPriceDictionary[tCurrentKey]) tPriceList.append(tTuple) #logging.debug(tPriceList) tContext['prices'] = tPriceList return tContext
def GetContext(self): tContext = {} typeOfGold = self.GOLDTYPE tCurrentPrice = Price() tPriceQuery = Price().all() tPriceQuery.order("-priceDateCreated") tPriceQuery.filter("priceType", typeOfGold) tCurrentPrice = tPriceQuery.fetch(limit=1)[0] tPriceDictionary = _data.PriceContainer.GetBasePriceDictionary() typeOfGold = self.GOLDTYPE if typeOfGold is "regular": tCurrentPrice.priceType = "regular" tContext["post_location"] = "/price" elif typeOfGold is "07": tCurrentPrice.priceType = "07" tContext["post_location"] = "/price07" tSortedProperties = sorted(tCurrentPrice.properties().keys()) for tCurrentProperty in tSortedProperties: try: tMatches = re.match(r"price(?P<number>[0-9]{4}m)", str(tCurrentProperty)) tMatchedKey = str(tMatches.group("number")) tPriceDictionary[tMatchedKey] = tCurrentPrice.__getattribute__(tCurrentProperty) except: logging.debug("Could not find a key in: " + str(tCurrentProperty)) tPriceList = [] tSortedPriceKeys = sorted(tPriceDictionary.keys()) for tCurrentKey in tSortedPriceKeys: if tCurrentKey[:3] == "000": tKey = tCurrentKey[3:] elif tCurrentKey[:2] == "00": tKey = tCurrentKey[2:] elif tCurrentKey[0] == "0": tKey = tCurrentKey[1:] else: tKey = tCurrentKey tTuple = (tKey, tPriceDictionary[tCurrentKey]) tPriceList.append(tTuple) # logging.debug(tPriceList) tContext["prices"] = tPriceList return tContext
def GetCurrentPriceDic(): tCurrentPrice = Price() tPriceQuery = Price().all() tPriceQuery.order("-priceDateCreated") tPriceQuery.filter("priceType", 'regular') tCurrentPrice = tPriceQuery.fetch(limit=1)[0] tPriceDictionary = PriceContainer.GetBasePriceDictionary() tSortedProperties = sorted(tCurrentPrice.properties().keys()) for tCurrentProperty in tSortedProperties: try: tMatches = re.match(r'price(?P<number>[0-9]{4}m)', str(tCurrentProperty)) tMatchedKey = str(tMatches.group('number')) tPriceDictionary[tMatchedKey] = tCurrentPrice.__getattribute__(tCurrentProperty) except: logging.debug('Could not find a key in: ' + str(tCurrentProperty)) tPriceList = [] tSortedPriceKeys = sorted(tPriceDictionary.keys()) tCleanPriceDictionary = {} for tCurrentKey in tSortedPriceKeys: if(tCurrentKey[:3] == '000'): tKey = tCurrentKey[3:] elif(tCurrentKey[:2] == '00'): tKey = tCurrentKey[2:] elif(tCurrentKey[:1] == '0'): tKey = tCurrentKey[1:] else: tKey = tCurrentKey tCleanPriceDictionary[tKey] = str(tPriceDictionary[tCurrentKey]) tCleanPriceDictionary[tKey.upper()] = str(tPriceDictionary[tCurrentKey]) return tCleanPriceDictionary