コード例 #1
0
ファイル: __init__.py プロジェクト: ToeKnee/jelly-roll
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(" ", ".")
コード例 #2
0
ファイル: __init__.py プロジェクト: ToeKnee/jelly-roll
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(" ", ".")
コード例 #3
0
ファイル: __init__.py プロジェクト: ToeKnee/jelly-roll
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)
コード例 #4
0
ファイル: __init__.py プロジェクト: ToeKnee/jelly-roll
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)
コード例 #5
0
ファイル: __init__.py プロジェクト: sankroh/satchmo
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)
コード例 #6
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)
コード例 #7
0
ファイル: functions.py プロジェクト: jimmcgaw/levicci
        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
コード例 #8
0
ファイル: functions.py プロジェクト: ToeKnee/jelly-roll
        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
コード例 #9
0
ファイル: config.py プロジェクト: jimmcgaw/levicci
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
コード例 #10
0
ファイル: decorators.py プロジェクト: jimmcgaw/levicci
 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
         }))
コード例 #11
0
ファイル: values.py プロジェクト: jimmcgaw/levicci
 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 []
コード例 #12
0
ファイル: decorators.py プロジェクト: ToeKnee/jelly-roll
        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})
コード例 #13
0
 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 []
コード例 #14
0
        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})
コード例 #15
0
        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}))
コード例 #16
0
    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")
コード例 #17
0
ファイル: tax.py プロジェクト: ToeKnee/jelly-roll
    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")
コード例 #18
0
ファイル: values.py プロジェクト: ToeKnee/jelly-roll
 def get_db_prep_save(self, value):
     if is_string_like(value):
         value = [value]
     return json.dumps(value)
コード例 #19
0
ファイル: values.py プロジェクト: jimmcgaw/levicci
 def get_db_prep_save(self, value):
     if is_string_like(value):
         value = [value]
     return simplejson.dumps(value)