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): if hasattr(self, self.identifier_attr): identifier = getattr(self, self.identifier_attr) or '' identifier_suf = '-{}'.format(text.force_ascii(identifier)) else: identifier_suf = '' return '<{}:{}{}>'.format(type(self).__name__, self.pk, identifier_suf)
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_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 _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,))
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,))
def __repr__(self): identifier = force_ascii(getattr(self, 'identifier', '')) return '<%s: %s "%s">' % (type(self).__name__, self.pk, identifier)