Fix for django 1.10 to replace deprecated code. Keep support for django 1.7
161487
def get_all_related_objects(self, table):
        
        # Django 1.7 method
        if hasattr(table.model._meta, 'get_all_related_objects'):
            return table.model._meta.get_all_related_objects()
        else:
            # Django > 1.7
            return [
                f for f in table.model._meta.get_fields()
                if (f.one_to_many or f.one_to_one) and f.auto_created and not f.concrete
            ]
494307
def patch(self):
        
        from django.db.models.sql import compiler

        self._read_compilers = (
            compiler.SQLCompiler,
            compiler.SQLAggregateCompiler,
            compiler.SQLDateCompiler,
        )
        self._write_compilers = (
            compiler.SQLInsertCompiler,
            compiler.SQLDeleteCompiler,
            compiler.SQLUpdateCompiler,
        )
        if not self._patched:
            self._original = {}
            for reader in self._read_compilers:
                self._original[reader] = reader.execute_sql
                reader.execute_sql = self._monkey_select(reader.execute_sql)
            for updater in self._write_compilers:
                self._original[updater] = updater.execute_sql
                updater.execute_sql = self._monkey_write(updater.execute_sql)
            self._patched = True
            self.cache_backend.patch()
            self._handle_signals()
143931
def prepare_environment(default_settings=_default_settings, **kwargs):
    # pylint: disable=unused-argument
    '''
    
    '''
    for key, value in default_settings.items():
        os.environ.setdefault(key, value)
    os.environ.update(kwargs)
    if six.PY2:  # nocv
        warnings.warn(
            'Python 2.7 is deprecated and will dropped in 2.0, use Python >3.5',
            DeprecationWarning
        )
1326366
def deprecated(reason):
    

    if isinstance(reason, string_types):

        # The @deprecated is used with a 'reason'.
        #
        # .. code-block:: python
        #
        #    @deprecated("please, use another function")
        #    def old_function(x, y):
        #      pass

        def decorator(func1):

            if inspect.isclass(func1):
                fmt1 = "Call to deprecated class {name} ({reason})."
            else:
                fmt1 = "Call to deprecated function {name} ({reason})."

            @functools.wraps(func1)
            def new_func1(*args, **kwargs):
                #warnings.simplefilter('default', DeprecationWarning)
                warnings.warn(
                    fmt1.format(name=func1.__name__, reason=reason),
                    category=FieldDeprecationWarning,
                    stacklevel=2
                )
                #warnings.simplefilter('default', DeprecationWarning)
                return func1(*args, **kwargs)

            return new_func1

        return decorator

    elif inspect.isclass(reason) or inspect.isfunction(reason):

        # The @deprecated is used without any 'reason'.
        #
        # .. code-block:: python
        #
        #    @deprecated
        #    def old_function(x, y):
        #      pass

        func2 = reason

        if inspect.isclass(func2):
            fmt2 = "Call to deprecated class {name}."
        else:
            fmt2 = "Call to deprecated function {name}."

        @functools.wraps(func2)
        def new_func2(*args, **kwargs):
            #warnings.simplefilter('default', DeprecationWarning)
            warnings.warn(
                fmt2.format(name=func2.__name__),
                category=FieldDeprecationWarning,
                stacklevel=2
            )
            #warnings.simplefilter('default', DeprecationWarning)
            return func2(*args, **kwargs)

        return new_func2

    else:
        raise TypeError(repr(type(reason)))
1268751
def _get_fix_my_django_submission_url(self, tb_info, sanitized_tb):
        
        err_post_create_path = '/create/'
        url = '{0}{1}'.format(base_url, err_post_create_path)
        return '{url}?{query}'.format(
            url=url,
            query=urlencode({
                'exception_type': clean_exception_type(tb_info['parsed_traceback']['exc_type']),
                'error_message': tb_info['parsed_traceback']['exc_msg'],
                'django_version': '{0[0]}.{0[1]}'.format(django.VERSION),
                'traceback': sanitized_tb
            }))
805193
def _deprecated(func):
    """"""
    @wraps(func)
    def with_warning(*args, **kwargs):
        warnings.warn(
            ('The %s method is deprecated and will be removed in v2.*.*' %
             func.__name__),
            DeprecationWarning
        )
        return func(*args, **kwargs)
    return with_warning
1190026
def deprecated(func, msg=None):
    

    message = msg or "Use of deprecated function '{}`.".format(func.__name__)

    @functools.wraps(func)
    def wrapper_func(*args, **kwargs):
        warnings.warn(message, DeprecationWarning, stacklevel=2)
        return func(*args, **kwargs)

    return wrapper_func
726328
def python(code, show=True):
    
    setup = "import os;" \
            "os.environ[\'DJANGO_SETTINGS_MODULE\']=\'%s.settings\';" \
            "import django;" \
            "django.setup();" % env.proj_app
    full_code = 'python -c "%s%s"' % (setup, code.replace("`", "\\\`"))
    with project():
        if show:
            print_command(code)
        result = run(full_code, show=False)
    return result
980485
def handle_deprecated_args(tokens, args, kwargs):
    
    num_args = len(args)
    pattern = args[0] if num_args else kwargs.get('pattern', None)
    regex = args[1] if num_args > 1 else kwargs.get('r', None)

    if pattern is not None:
        tokens = tools.filter_wildcard(tokens, pattern)
        sys.stderr.write(
            'Please use see().match() now. The "pattern" argument is '
            'deprecated and will be removed in a later release. \n')

    if regex is not None:
        tokens = tools.filter_regex(tokens, re.compile(regex))
        sys.stderr.write(
            'Please use see().match() now. The "r" argument is '
            'deprecated and will be removed in a later release. \n')

    return tokens
720979
def _raise_deprecation_note(deprecated, replacement, soft=False):
    
    error_msg = ("`{deprecated}` is deprecated. Please use `{replacement}`. "
                 "`{deprecated}` will be removed in future versions of "
                 "Ray.".format(deprecated=deprecated, replacement=replacement))
    if soft:
        logger.warning(error_msg)
    else:
        raise DeprecationWarning(error_msg)
1067090
def _remove_deprecated_options(self, old_version):
        
        old_defaults = self._load_old_defaults(old_version)
        for section in old_defaults.sections():
            for option, _ in old_defaults.items(section, raw=self.raw):
                if self.get_default(section, option) is NoDefault:
                    try:
                        self.remove_option(section, option)
                        if len(self.items(section, raw=self.raw)) == 0:
                            self.remove_section(section)
                    except cp.NoSectionError:
                        self.remove_section(section)
272142
function patchMakeErrFromCode() {
  const func = errors.makeErrFromCode;
  function makeErrFromCodeHook() {
    const err = func.apply(null, arguments);
    patchErrorBody(err, {});
    return err;
  }
  errors.makeErrFromCode = makeErrFromCodeHook;

  // Deprecated.
  // See https://github.com/restify/errors/blob/master/lib/index.js#L126
  errors.codeToHttpError = makeErrFromCodeHook;
}
874970
def deprecated (func):
    """"""
    def newfunc (*args, **kwargs):
        """Print deprecated warning and execute original function."""
        warnings.warn("Call to deprecated function %s." % func.__name__,
                      category=DeprecationWarning)
        return func(*args, **kwargs)
    return update_func_meta(newfunc, func)
123650
function checkEnv() {
        async.series([
            function(cb) {
                childProcess.exec(
                    'python -c "import django; print(django.get_version())"',
                    function(err, version) {
                        if (err || !/^1\.7/.test(version)) {
                            return cb(new Error(
                                'Django 1.7 environment is not working'
                            ));
                        }
                        cb();
                    });
            }
        ], function(err) {
            if (err) {
                console.error(chalk.red('\nFATAL: ' + err.message +
                    '\n'));
            }
        });
    }
59318
def fail_on_template_errors(f, *args, **kwargs):
    
    decorators = [
        _fail_template_string_if_invalid,
        _always_strict_resolve,
        _disallow_catching_UnicodeDecodeError,
    ]
    if django.VERSION < (1, 8):
        decorators.append(_patch_invalid_var_format_string)

    return reduce(__apply, decorators, f)(*args, **kwargs)
508458
def import_and_wrap_deprecated(module_name, module_dict, warn_import=True):
    
    if warn_import:
        deprecated_import(module_name)

    from importlib import import_module
    module = import_module(module_name)
    for attr in module.__all__:
        module_dict[attr] = deprecated(getattr(module, attr))
802649
def deprecated(func: Callable) -> Callable:
    """"""
    @functools.wraps(func)
    def _new_func(*args: Any, **kwargs: Any) -> Any:
        warnings.simplefilter('always', DeprecationWarning)  # turn off filter
        warnings.warn("Call to deprecated function {}.".format(func.__name__),
                      category=DeprecationWarning,
                      stacklevel=2)
        warnings.simplefilter('default', DeprecationWarning)  # reset filter
        return func(*args, **kwargs)
    return _new_func