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 = sorted(list(pairs.keys())) for k in klist: keys.append(k) keys.append(pairs[k]) key = KEY_DELIM.join([_hash_or_string(x) for x in keys]) prefix = KEY_DELIM if not key.startswith(prefix): key = prefix + key return key.replace(" ", ".")
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 = sorted(list(pairs.keys())) 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 _hash_or_string(key): if is_string_like(key) or isinstance(key, (int, float)): 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 _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 _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 _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 payment_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 _checkorder(request, template=template, min_order=min_order, *args, **kwargs): # resolve the min order if is_string_like(min_order): from satchmo.configuration 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_to_response(template, RequestContext(request, { 'minimum_order' : min_order }))
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 satchmo.configuration.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 to_python(self, value): if not value or value == NOTSET: return [] if is_list_or_tuple(value): return value else: try: return json.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 satchmo.configuration.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 _checkorder(request, template=template, min_order=min_order, *args, **kwargs): # resolve the min order if is_string_like(min_order): from satchmo.configuration 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_to_response( template, RequestContext(request, {'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): area, country = self._get_location() 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) if area: try: rate = TaxRate.objects.get(taxClass=taxclass, taxZone=area) except TaxRate.DoesNotExist: rate = None if not rate: try: rate = TaxRate.objects.get(taxClass=taxclass, taxCountry=country) 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 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): area, country = self._get_location() 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) if area: try: rate = TaxRate.objects.get(taxClass=taxclass, taxZone=area) except TaxRate.DoesNotExist: rate = None if not rate: try: rate = TaxRate.objects.get(taxClass=taxclass, taxCountry=country) 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 get_db_prep_save(self, value): if is_string_like(value): value = [value] return json.dumps(value)
def get_db_prep_save(self, value): if is_string_like(value): value = [value] return simplejson.dumps(value)