def get_rate(self, taxclass=None, get_object=False, **kwargs): if not taxclass: taxclass = "Default" rate = None if is_string_like(taxclass): try: taxclass = TaxClass.objects.get(title__iexact=taxclass) except TaxClass.DoesNotExist: raise ImproperlyConfigured("Can't find a '%s' Tax Class", taxclass) try: rate = TaxRate.objects.get(taxClass=taxclass) except TaxRate.DoesNotExist: rate = None log.debug("Got rate [%s] = %s", taxclass, rate) if get_object: return rate else: if rate: return rate.percentage else: return Decimal("0.00")
def cache_key(*keys, **pairs): """Smart key maker, returns the object itself if a key, else a list delimited by ':', automatically hashing any non-scalar objects.""" if is_string_like(keys): keys = [keys] if is_list_or_tuple(keys): if len(keys) == 1 and is_list_or_tuple(keys[0]): keys = keys[0] else: keys = [md5_hash(keys)] if pairs: keys = list(keys) klist = pairs.keys() klist.sort() for k in klist: keys.append(k) keys.append(pairs[k]) key = KEY_DELIM.join([_hash_or_string(x) for x in keys]) prefix = CACHE_PREFIX + KEY_DELIM if not key.startswith(prefix): key = prefix+key return key.replace(" ", ".")
def get_rate(self, taxclass=None, area=None, country=None, get_object=False, **kwargs): if not taxclass: taxclass = "Default" # initialize the rates array, allow for more than one rate rates = [] # get the area/country if not (area or country): area, country = self._get_location() # get the taxclass object if is_string_like(taxclass): try: taxclass = TaxClass.objects.get(title__iexact=taxclass) except TaxClass.DoesNotExist: raise ImproperlyConfigured("Can't find a '%s' Tax Class", taxclass) # get all the rates for the given area if area: rates += list(TaxRate.objects.filter(taxClass=taxclass, taxZone=area)) # get all rates for the given country if country: rates += list(TaxRate.objects.filter(taxClass=taxclass, taxCountry=country)) log.debug("Got rates for taxclass: %s, area: %s, country: %s = [%s]", taxclass, area, country, rates) if get_object: return self.tax_rate_list(rates) else: return self.tax_rate_list(rates)[0]
def _hash_or_string(key): if is_string_like(key) or isinstance(key, (types.IntType, types.LongType, types.FloatType)): return smart_str(key) else: try: #if it has a PK, use it. return str(key._get_pk_val()) except AttributeError: return md5_hash(key)
def _checkorder(request, template=template, min_order=min_order, *args, **kwargs): # resolve the min order if is_string_like(min_order): from livesettings.functions import config_value min_order = config_value(*min_order.split('.')) cart = Cart.objects.from_request(request) if cart.total >= min_order: return view_func(request, *args, **kwargs) else: ctx = RequestContext(request, {'minimum_order' : min_order}) return render_to_response(template, context_instance=ctx)
def gateway_live(settings): if is_string_like(settings): settings = config_get_group(settings) try: if config_value('PAYMENT', 'LIVE'): return settings['LIVE'].value except SettingNotSet: pass return False
def _resolve_key(self, raw): if is_string_like(raw): key = raw elif isinstance(raw, values.ConfigurationGroup): key = raw.key else: group = self.groups()[raw] key = group.key return key
def to_python(self, value): if not value or value == NOTSET: return [] if is_list_or_tuple(value): return value else: try: return simplejson.loads(value) except: if is_string_like(value): return [value] else: log.warning('Could not decode returning empty list: %s', value) return []
def _checkorder(request, template=template, min_order=min_order, *args, **kwargs): # resolve the min order if is_string_like(min_order): from livesettings.functions import config_value min_order = config_value(*min_order.split('.')) cart = Cart.objects.from_request(request) if cart.total >= min_order: return view_func(request, *args, **kwargs) else: return render(request, template, {'minimum_order': min_order})
def get_rate(self, taxclass=None, area=None, country=None, get_object=False, **kwargs): if not taxclass: taxclass = "Default" rate = None #if not (area or country): location = self._get_location() state = location['area'] country = location['country'] if is_string_like(taxclass): try: taxclass = TaxClass.objects.get(title__iexact=taxclass) except TaxClass.DoesNotExist: raise ImproperlyConfigured("Can't find a '%s' Tax Class", taxclass) # This module only works in the USA. if country.iso2_code != 'US': rate = None else: try: taxable = Taxable.objects.get(taxClass=taxclass, taxZone=state) if taxable.isTaxable is False: rate = None else: rate = self.get_boundry(taxable, location) rate.useIntrastate = taxable.useIntrastate rate.useFood = taxable.useFood except Taxable.DoesNotExist: rate = None log.debug("Got rate [%s] = %s", taxclass, rate) if get_object: return rate else: if rate: return rate.percentage else: return Decimal("0.00")
def get_db_prep_save(self, value): if is_string_like(value): value = [value] return simplejson.dumps(value)