Coverage for /home/tribaal/workspace/django-shop/shop/cart/modifiers_pool: 100.00%

# Coverage for /home/tribaal/workspace/django-shop/shop/cart/modifiers_pool : 100.00%

## 32 statements 32 run 0 missing 0 excluded 0 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #-*- coding: utf-8 -*- from django.conf import settings from django.core import exceptions from django.utils.importlib import import_module class CartModifiersPool(object): USE_CACHE = True def __init__(self): self._modifiers_list = [] def get_modifiers_list(self): if not self.USE_CACHE or not self._modifiers_list: self._modifiers_list = self._load_modifiers_list() return self._modifiers_list def _load_modifiers_list(self): """ Heavily inspired by django.core.handlers.base... """ result = [] if not getattr(settings, 'SHOP_CART_MODIFIERS', None): return result for modifier_path in settings.SHOP_CART_MODIFIERS: try: mod_module, mod_classname = modifier_path.rsplit('.', 1) except ValueError: raise exceptions.ImproperlyConfigured( '%s isn\'t a price modifier module' % modifier_path) try: mod = import_module(mod_module) except ImportError, e: raise exceptions.ImproperlyConfigured( 'Error importing modifier %s: "%s"' % (mod_module, e)) try: mod_class = getattr(mod, mod_classname) except AttributeError: raise exceptions.ImproperlyConfigured( 'Price modifier module "%s" does not define a "%s" class' % (mod_module, mod_classname)) mod_instance = mod_class() result.append(mod_instance) return result cart_modifiers_pool = CartModifiersPool()