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)
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)
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
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,))