Imports a field by its dotted class path, prepending "django.db.models"
    to raw class names and raising an exception if the import fails.
2173
def import_field(field_classpath):
    
    if '.' in field_classpath:
        fully_qualified = field_classpath
    else:
        fully_qualified = "django.db.models.%s" % field_classpath
    try:
        return import_dotted_path(fully_qualified)
    except ImportError:
        raise ImproperlyConfigured("The EXTRA_MODEL_FIELDS setting contains "
                                   "the field '%s' which could not be "
                                   "imported." % field_classpath)
1241945
def import_recursive(path):
    
    results = {}
    obj = importlib.import_module(path)
    results[path] = obj
    path = getattr(obj, '__path__', os.path.dirname(obj.__file__))
    for loader, name, is_pkg in pkgutil.walk_packages(path):
        full_name = obj.__name__ + '.' + name
        results[full_name] = importlib.import_module(full_name)
        if is_pkg:
            results.update(import_recursive(full_name))
    return results
913118
def load_model_from_package(name, **overrides):
    """"""
    cls = importlib.import_module(name)
    return cls.load(**overrides)
941251
def django_field_to_index(field, **attr):
    '''
    
    '''

    dj_type = field.get_internal_type()

    if dj_type in ('DateField', 'DateTimeField'):
        return DateField(**attr)
    elif dj_type in ('BooleanField', 'NullBooleanField'):
        return BooleanField(**attr)
    elif dj_type in ('DecimalField', 'FloatField'):
        return NumberField(coretype='float', **attr)
    elif dj_type in ('PositiveSmallIntegerField', 'SmallIntegerField'):
        return NumberField(coretype='short', **attr)
    elif dj_type in ('IntegerField', 'PositiveIntegerField', 'AutoField'):
        return NumberField(coretype='integer', **attr)
    elif dj_type in ('BigIntegerField'):
        return NumberField(coretype='long', **attr)

    return StringField(**attr)
1309468
def get_class_field(cls, field_name):
        
        if not cls.has_field(field_name):
            raise AttributeError('"%s" is not a field for the model "%s"' %
                                 (field_name, cls.__name__))

        field = getattr(cls, '_redis_attr_%s' % field_name)

        return field
1029041
def get_class(import_path=None):
    
    from django.core.exceptions import ImproperlyConfigured
    if import_path is None:
        raise ImproperlyConfigured('No class path specified.')
    try:
        dot = import_path.rindex('.')
    except ValueError:
        raise ImproperlyConfigured("%s isn't a module." % import_path)
    module, classname = import_path[:dot], import_path[dot+1:]
    try:
        mod = import_module(module)
    except ImportError as e:
        raise ImproperlyConfigured('Error importing module %s: "%s"' % (module, e))
    try:
        return getattr(mod, classname)
    except AttributeError:
        raise ImproperlyConfigured('Module "%s" does not define a "%s" class.' % (module, classname))
1044640
def _improve_class_docs(app, cls, lines):
    """"""
    if issubclass(cls, models.Model):
        _add_model_fields_as_params(app, cls, lines)
    elif issubclass(cls, forms.Form):
        _add_form_fields(cls, lines)
542326
def _load_class(class_path):
    """"""
    parts = class_path.rsplit('.', 1)
    module = __import__(parts[0], fromlist=parts[1])
    return getattr(module, parts[1])
30053
def import_class(import_str):
    """"""
    mod_str, _sep, class_str = import_str.rpartition('.')
    try:
        __import__(mod_str)
        return getattr(sys.modules[mod_str], class_str)
    except (ValueError, AttributeError):
        raise ImportError('Class %s cannot be found (%s)' %
                          (class_str,
                           traceback.format_exception(*sys.exc_info())))
201685
def _import_module(module_path, classnames):
    
    try:
        imported_module = __import__(module_path, fromlist=classnames)
        return imported_module
    except ImportError:
        # In case of an ImportError, the module being loaded generally does not exist. But an
        # ImportError can occur if the module being loaded exists and another import located inside
        # it failed.
        #
        # In order to provide a meaningfull traceback, the execution information can be inspected in
        # order to determine which case to consider. If the execution information provides more than
        # a certain amount of frames, this means that an ImportError occured while loading the
        # initial Python module.
        __, __, exc_traceback = sys.exc_info()
        frames = traceback.extract_tb(exc_traceback)
        if len(frames) > 1:
            raise
421538
def formfield_for_dbfield(self, db_field, **kwargs):
        ''' '''
        if db_field.name == "gradings":
            request=kwargs['request']
            try:
                #TODO:  MockRequst object from unit test does not contain path information, so an exception occurs during test.
                #       Find a test-suite compatible solution here.
                obj=resolve(request.path).args[0]
                filterexpr=Q(schemes=obj) | Q(schemes=None)
                kwargs['queryset'] = Grading.objects.filter(filterexpr).distinct()
            except:
                pass
        return super(GradingSchemeAdmin, self).formfield_for_dbfield(db_field, **kwargs)
977345
def load_path(self, path):
        '''
        
        '''
        containing_module, _, last_item = path.rpartition('.')
        if last_item[0].isupper():
            # Is a class definition, should do an "import from"
            path = containing_module
        imported_obj = importlib.import_module(path)
        if last_item[0].isupper():
            try:
                imported_obj = getattr(imported_obj, last_item)
            except AttributeError:
                msg = 'Cannot import "%s". ' \
                    '(Hint: CamelCase is only for classes)' % last_item
                raise ConfigurationError(msg)
        return imported_obj
528765
def helper_import(module_name, class_name=None):
    
    try:
        module = __import__(module_name, globals(), locals(), [class_name])
    except (BlackbirdError, ImportError) as error:
        raise BlackbirdError(
            'can not load {0} module [{1}]'
            ''.format(module_name, str(error))
        )

    if not class_name:
        return module
    else:
        try:
            return getattr(module, class_name)
        except:
            return False
1056374
def parse_field_path(field_path):
    
    model_path, field_name = field_path.rsplit(".", 1)
    app_name, model_name = model_path.split('.models.')
    _, app_label = app_name.rsplit('.', 1)
    return (app_label, model_name.lower()), field_name
23862
def load_class(class_path, setting_name=None):
    
    if not isinstance(class_path, six.string_types):
        try:
            class_path, app_label = class_path
        except:
            if setting_name:
                raise exceptions.ImproperlyConfigured(
                    CLASS_PATH_ERROR % (setting_name, setting_name)
                )
            else:
                raise exceptions.ImproperlyConfigured(
                    CLASS_PATH_ERROR % ("this setting", "It")
                )

    try:
        class_module, class_name = class_path.rsplit(".", 1)
    except ValueError:
        if setting_name:
            txt = "%s isn't a valid module. Check your %s setting" % (
                class_path,
                setting_name,
            )
        else:
            txt = "%s isn't a valid module." % class_path
        raise exceptions.ImproperlyConfigured(txt)

    try:
        mod = import_module(class_module)
    except ImportError as e:
        if setting_name:
            txt = 'Error importing backend %s: "%s". Check your %s setting' % (
                class_module,
                e,
                setting_name,
            )
        else:
            txt = 'Error importing backend %s: "%s".' % (class_module, e)
        raise exceptions.ImproperlyConfigured(txt)

    try:
        clazz = getattr(mod, class_name)
    except AttributeError:
        if setting_name:
            txt = (
                'Backend module "%s" does not define a "%s" class. Check'
                " your %s setting" % (class_module, class_name, setting_name)
            )
        else:
            txt = 'Backend module "%s" does not define a "%s" class.' % (
                class_module,
                class_name,
            )
        raise exceptions.ImproperlyConfigured(txt)
    return clazz
103101
def import_string(dotted_path):
    
    try:
        module_path, class_name = dotted_path.rsplit('.', 1)
    except ValueError:
        raise ImportError('%s doesn\'t look like a valid path' % dotted_path)

    module = __import__(module_path, fromlist=[class_name])

    try:
        return getattr(module, class_name)
    except AttributeError:
        msg = 'Module "%s" does not define a "%s" attribute/class' % (
            dotted_path, class_name)
        raise ImportError(msg)
315555
def import_class(class_path):
    '''
        
    '''
    module_name, class_name = class_path.rsplit(".", 1)
    module = import_module(module_name)
    claz = getattr(module, class_name)
    return claz