Пример #1
0
    def _load_module(self):
        spec = self.default_module_spec
        module_identifier = self.module_identifier
        if module_identifier:
            impls = self.get_module_implementation_map()
            if module_identifier not in impls:
                raise ModuleNotFound(
                    "Invalid module identifier %r in %s" % (module_identifier, force_ascii(repr(self)))
                )
            spec = impls[module_identifier]

        cls = load(spec, context_explanation="Loading module for %s" % force_ascii(repr(self)))

        options = getattr(self, self.module_options_field, None) or {}
        return cls(self, options)
Пример #2
0
    def _load_module(self):
        spec = self.default_module_spec
        module_identifier = self.module_identifier
        if module_identifier:
            impls = self.get_module_implementation_map()
            if module_identifier not in impls:
                raise ModuleNotFound(
                    "Invalid module identifier %r in %s" % (module_identifier, force_ascii(repr(self)))
                )
            spec = impls[module_identifier]

        cls = load(spec, context_explanation="Loading module for %s" % force_ascii(repr(self)))

        options = getattr(self, self.module_options_field, None) or {}
        return cls(self, options)
Пример #3
0
 def __repr__(self):
     identifier = getattr(self, self.identifier_attr, None)
     if identifier:
         identifier_suf = '-{}'.format(text.force_ascii(identifier))
     else:
         identifier_suf = ''
     return '<{}:{}{}>'.format(type(self).__name__, self.pk, identifier_suf)
Пример #4
0
 def __repr__(self):
     identifier = getattr(self, self.identifier_attr, None)
     if identifier:
         identifier_suf = '-{}'.format(text.force_ascii(identifier))
     else:
         identifier_suf = ''
     return '<{}:{}{}>'.format(type(self).__name__, self.pk, identifier_suf)
Пример #5
0
    def _load_modules(self):
        enabled_supplier_modules = self.supplier_modules.all()
        loaded_modules = []
        options = getattr(self, self.module_options_field, None) or {}

        for supplier_module in enabled_supplier_modules:
            impls = self.get_module_implementation_map()
            if supplier_module.module_identifier not in impls:
                raise ModuleNotFound(
                    "Invalid module identifier %r in %s" %
                    (supplier_module.name, force_ascii(repr(self))))
            spec = impls[supplier_module.module_identifier]
            module = load(spec,
                          context_explanation="Loading module for %s" %
                          force_ascii(repr(self)))
            loaded_modules.append(module(self, options))

        return loaded_modules
Пример #6
0
def map_relation_type(relation_type):
    """
    Map relation type to enum value.

    :type relation_type: ProductCrossSellType|str
    :rtype: ProductCrossSellType
    :raises: `LookupError` if unknown string is given
    """
    if isinstance(relation_type, ProductCrossSellType):
        return relation_type
    attr_name = force_ascii(relation_type).upper()
    try:
        return getattr(ProductCrossSellType, attr_name)
    except AttributeError:
        raise LookupError('Unknown ProductCrossSellType %r' % (relation_type,))
Пример #7
0
def map_relation_type(relation_type):
    """
    Map relation type to enum value.

    :type relation_type: ProductCrossSellType|str
    :rtype: ProductCrossSellType
    :raises: `LookupError` if unknown string is given
    """
    if isinstance(relation_type, ProductCrossSellType):
        return relation_type
    attr_name = force_ascii(relation_type).upper()
    try:
        return getattr(ProductCrossSellType, attr_name)
    except AttributeError:
        raise LookupError('Unknown ProductCrossSellType %r' % (relation_type,))