Python django.utils.deprecation 模块,RemovedInDjango19Warning() 实例源码

我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用django.utils.deprecation.RemovedInDjango19Warning()

项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def handle(self, **options):
        warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
        call_command("migrate", **options)

        try:
            apps.get_model('auth', 'Permission')
        except LookupError:
            return

        UserModel = get_user_model()

        if not UserModel._default_manager.exists() and options.get('interactive'):
            msg = ("\nYou have installed Django's auth system, and "
                "don't have any superusers defined.\nWould you like to create one "
                "now? (yes/no): ")
            confirm = input(msg)
            while 1:
                if confirm not in ('yes', 'no'):
                    confirm = input('Please enter either "yes" or "no": ')
                    continue
                if confirm == 'yes':
                    call_command("createsuperuser", interactive=True, database=options['database'])
                break
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def check(cls, model, **kwargs):
        if cls.validator_class:
            warnings.warn(
                'ModelAdmin.validator_class is deprecated. '
                'ModelAdmin validators must be converted to use '
                'the system check framework.',
                RemovedInDjango19Warning)
            validator = cls.validator_class()
            try:
                validator.validate(cls, model)
            except ImproperlyConfigured as e:
                return [checks.Error(e.args[0], hint=None, obj=cls)]
            else:
                return []
        else:
            return cls.checks_class().check(cls, model, **kwargs)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def get_formsets_with_inlines(self, request, obj=None):
        """
        Yields formsets and the corresponding inlines.
        """
        # We call get_formsets() [deprecated] and check if it triggers a
        # warning. If it does, then it's ours and we can safely ignore it, but
        # if it doesn't then it has been overridden so we must warn about the
        # deprecation.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            formsets = self.get_formsets(request, obj)

        if len(w) != 1 or not issubclass(w[0].category, RemovedInDjango19Warning):
            warnings.warn(
                "ModelAdmin.get_formsets() is deprecated and will be removed in "
                "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
                RemovedInDjango19Warning, stacklevel=2
            )
            if formsets:
                zipped = zip(formsets, self.get_inline_instances(request, None))
                for formset, inline in zipped:
                    yield formset, inline
        else:
            for inline in self.get_inline_instances(request, obj):
                yield inline.get_formset(request, obj), inline
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def handle(self, **options):
        warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
        call_command("migrate", **options)

        try:
            apps.get_model('auth', 'Permission')
        except LookupError:
            return

        UserModel = get_user_model()

        if not UserModel._default_manager.exists() and options.get('interactive'):
            msg = ("\nYou have installed Django's auth system, and "
                "don't have any superusers defined.\nWould you like to create one "
                "now? (yes/no): ")
            confirm = input(msg)
            while 1:
                if confirm not in ('yes', 'no'):
                    confirm = input('Please enter either "yes" or "no": ')
                    continue
                if confirm == 'yes':
                    call_command("createsuperuser", interactive=True, database=options['database'])
                break
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def check(cls, model, **kwargs):
        if cls.validator_class:
            warnings.warn(
                'ModelAdmin.validator_class is deprecated. '
                'ModelAdmin validators must be converted to use '
                'the system check framework.',
                RemovedInDjango19Warning)
            validator = cls.validator_class()
            try:
                validator.validate(cls, model)
            except ImproperlyConfigured as e:
                return [checks.Error(e.args[0], hint=None, obj=cls)]
            else:
                return []
        else:
            return cls.checks_class().check(cls, model, **kwargs)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def get_formsets_with_inlines(self, request, obj=None):
        """
        Yields formsets and the corresponding inlines.
        """
        # We call get_formsets() [deprecated] and check if it triggers a
        # warning. If it does, then it's ours and we can safely ignore it, but
        # if it doesn't then it has been overridden so we must warn about the
        # deprecation.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            formsets = self.get_formsets(request, obj)

        if len(w) != 1 or not issubclass(w[0].category, RemovedInDjango19Warning):
            warnings.warn(
                "ModelAdmin.get_formsets() is deprecated and will be removed in "
                "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
                RemovedInDjango19Warning, stacklevel=2
            )
            if formsets:
                zipped = zip(formsets, self.get_inline_instances(request, None))
                for formset, inline in zipped:
                    yield formset, inline
        else:
            for inline in self.get_inline_instances(request, obj):
                yield inline.get_formset(request, obj), inline
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def handle(self, **options):
        warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
        call_command("migrate", **options)

        try:
            apps.get_model('auth', 'Permission')
        except LookupError:
            return

        UserModel = get_user_model()

        if not UserModel._default_manager.exists() and options.get('interactive'):
            msg = ("\nYou have installed Django's auth system, and "
                "don't have any superusers defined.\nWould you like to create one "
                "now? (yes/no): ")
            confirm = input(msg)
            while 1:
                if confirm not in ('yes', 'no'):
                    confirm = input('Please enter either "yes" or "no": ')
                    continue
                if confirm == 'yes':
                    call_command("createsuperuser", interactive=True, database=options['database'])
                break
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def check(cls, model, **kwargs):
        if cls.validator_class:
            warnings.warn(
                'ModelAdmin.validator_class is deprecated. '
                'ModelAdmin validators must be converted to use '
                'the system check framework.',
                RemovedInDjango19Warning)
            validator = cls.validator_class()
            try:
                validator.validate(cls, model)
            except ImproperlyConfigured as e:
                return [checks.Error(e.args[0], hint=None, obj=cls)]
            else:
                return []
        else:
            return cls.checks_class().check(cls, model, **kwargs)
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def get_formsets_with_inlines(self, request, obj=None):
        """
        Yields formsets and the corresponding inlines.
        """
        # We call get_formsets() [deprecated] and check if it triggers a
        # warning. If it does, then it's ours and we can safely ignore it, but
        # if it doesn't then it has been overridden so we must warn about the
        # deprecation.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            formsets = self.get_formsets(request, obj)

        if len(w) != 1 or not issubclass(w[0].category, RemovedInDjango19Warning):
            warnings.warn(
                "ModelAdmin.get_formsets() is deprecated and will be removed in "
                "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
                RemovedInDjango19Warning, stacklevel=2
            )
            if formsets:
                zipped = zip(formsets, self.get_inline_instances(request, None))
                for formset, inline in zipped:
                    yield formset, inline
        else:
            for inline in self.get_inline_instances(request, obj):
                yield inline.get_formset(request, obj), inline
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def handle(self, **options):
        warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
        call_command("migrate", **options)

        try:
            apps.get_model('auth', 'Permission')
        except LookupError:
            return

        UserModel = get_user_model()

        if not UserModel._default_manager.exists() and options.get('interactive'):
            msg = ("\nYou have installed Django's auth system, and "
                "don't have any superusers defined.\nWould you like to create one "
                "now? (yes/no): ")
            confirm = input(msg)
            while 1:
                if confirm not in ('yes', 'no'):
                    confirm = input('Please enter either "yes" or "no": ')
                    continue
                if confirm == 'yes':
                    call_command("createsuperuser", interactive=True, database=options['database'])
                break
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def check(cls, model, **kwargs):
        if cls.validator_class:
            warnings.warn(
                'ModelAdmin.validator_class is deprecated. '
                'ModelAdmin validators must be converted to use '
                'the system check framework.',
                RemovedInDjango19Warning)
            validator = cls.validator_class()
            try:
                validator.validate(cls, model)
            except ImproperlyConfigured as e:
                return [checks.Error(e.args[0], hint=None, obj=cls)]
            else:
                return []
        else:
            return cls.checks_class().check(cls, model, **kwargs)
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def get_formsets_with_inlines(self, request, obj=None):
        """
        Yields formsets and the corresponding inlines.
        """
        # We call get_formsets() [deprecated] and check if it triggers a
        # warning. If it does, then it's ours and we can safely ignore it, but
        # if it doesn't then it has been overridden so we must warn about the
        # deprecation.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            formsets = self.get_formsets(request, obj)

        if len(w) != 1 or not issubclass(w[0].category, RemovedInDjango19Warning):
            warnings.warn(
                "ModelAdmin.get_formsets() is deprecated and will be removed in "
                "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
                RemovedInDjango19Warning, stacklevel=2
            )
            if formsets:
                zipped = zip(formsets, self.get_inline_instances(request, None))
                for formset, inline in zipped:
                    yield formset, inline
        else:
            for inline in self.get_inline_instances(request, obj):
                yield inline.get_formset(request, obj), inline
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def handle(self, **options):
        warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
        call_command("migrate", **options)

        try:
            apps.get_model('auth', 'Permission')
        except LookupError:
            return

        UserModel = get_user_model()

        if not UserModel._default_manager.exists() and options.get('interactive'):
            msg = ("\nYou have installed Django's auth system, and "
                "don't have any superusers defined.\nWould you like to create one "
                "now? (yes/no): ")
            confirm = input(msg)
            while 1:
                if confirm not in ('yes', 'no'):
                    confirm = input('Please enter either "yes" or "no": ')
                    continue
                if confirm == 'yes':
                    call_command("createsuperuser", interactive=True, database=options['database'])
                break
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def check(cls, model, **kwargs):
        if cls.validator_class:
            warnings.warn(
                'ModelAdmin.validator_class is deprecated. '
                'ModelAdmin validators must be converted to use '
                'the system check framework.',
                RemovedInDjango19Warning)
            validator = cls.validator_class()
            try:
                validator.validate(cls, model)
            except ImproperlyConfigured as e:
                return [checks.Error(e.args[0], hint=None, obj=cls)]
            else:
                return []
        else:
            return cls.checks_class().check(cls, model, **kwargs)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def get_formsets_with_inlines(self, request, obj=None):
        """
        Yields formsets and the corresponding inlines.
        """
        # We call get_formsets() [deprecated] and check if it triggers a
        # warning. If it does, then it's ours and we can safely ignore it, but
        # if it doesn't then it has been overridden so we must warn about the
        # deprecation.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            formsets = self.get_formsets(request, obj)

        if len(w) != 1 or not issubclass(w[0].category, RemovedInDjango19Warning):
            warnings.warn(
                "ModelAdmin.get_formsets() is deprecated and will be removed in "
                "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
                RemovedInDjango19Warning, stacklevel=2
            )
            if formsets:
                zipped = zip(formsets, self.get_inline_instances(request, None))
                for formset, inline in zipped:
                    yield formset, inline
        else:
            for inline in self.get_inline_instances(request, obj):
                yield inline.get_formset(request, obj), inline
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def __init__(self, data=None):
        warnings.warn(
            "SortedDict is deprecated and will be removed in Django 1.9.",
            RemovedInDjango19Warning, stacklevel=2
        )
        if data is None or isinstance(data, dict):
            data = data or []
            super(SortedDict, self).__init__(data)
            self.keyOrder = list(data) if data else []
        else:
            super(SortedDict, self).__init__()
            super_set = super(SortedDict, self).__setitem__
            for key, value in data:
                # Take the ordering from first key
                if key not in self:
                    self.keyOrder.append(key)
                # But override with last value in data (dict() does this)
                super_set(key, value)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def javascript_quote(s, quote_double_quotes=False):
    msg = (
        "django.utils.text.javascript_quote() is deprecated. "
        "Use django.utils.html.escapejs() instead."
    )
    warnings.warn(msg, RemovedInDjango19Warning, stacklevel=2)

    def fix(match):
        return "\\u%04x" % ord(match.group(1))

    if type(s) == bytes:
        s = s.decode('utf-8')
    elif type(s) != six.text_type:
        raise TypeError(s)
    s = s.replace('\\', '\\\\')
    s = s.replace('\r', '\\r')
    s = s.replace('\n', '\\n')
    s = s.replace('\t', '\\t')
    s = s.replace("'", "\\'")
    s = s.replace('</', '<\\/')
    if quote_double_quotes:
        s = s.replace('"', '&quot;')
    return ustring_re.sub(fix, s)
项目:django-field-history    作者:grantmcconnaughey    | 项目源码 | 文件源码
def serialize(self, queryset, **options):
        """
        Serialize a queryset.
        """
        self.options = options

        self.stream = options.pop("stream", six.StringIO())
        self.selected_fields = options.pop("fields", None)
        self.use_natural_keys = options.pop("use_natural_keys", False)
        if self.use_natural_keys and RemovedInDjango19Warning is not None:
            warnings.warn("``use_natural_keys`` is deprecated; use ``use_natural_foreign_keys`` instead.",
                          RemovedInDjango19Warning)
        self.use_natural_foreign_keys = options.pop('use_natural_foreign_keys', False) or self.use_natural_keys
        self.use_natural_primary_keys = options.pop('use_natural_primary_keys', False)

        self.start_serialization()
        self.first = True
        for obj in queryset:
            self.start_object(obj)
            # Use the concrete parent class' _meta instead of the object's _meta
            # This is to avoid local_fields problems for proxy models. Refs #17717.
            concrete_model = obj._meta.concrete_model
            # only one change local_fields -> fields for supporting nested models
            for field in concrete_model._meta.fields:
                if field.serialize:
                    if field.rel is None:
                        if self.selected_fields is None or field.attname in self.selected_fields:
                            self.handle_field(obj, field)
                    else:
                        if self.selected_fields is None or field.attname[:-3] in self.selected_fields:
                            self.handle_fk_field(obj, field)
            for field in concrete_model._meta.many_to_many:
                if field.serialize:
                    if self.selected_fields is None or field.attname in self.selected_fields:
                        self.handle_m2m_field(obj, field)
            self.end_object(obj)
            if self.first:
                self.first = False
        self.end_serialization()
        return self.getvalue()
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def _get_request(self):
        warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or '
                      '`request.POST` instead.', RemovedInDjango19Warning, 2)
        if not hasattr(self, '_request'):
            self._request = datastructures.MergeDict(self.POST, self.GET)
        return self._request
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def validate(cls, model):
        warnings.warn(
            'ModelAdmin.validate() is deprecated. Use "check()" instead.',
            RemovedInDjango19Warning)
        if cls.validator_class:
            validator = cls.validator_class()
        else:
            validator = cls.default_validator_class()
        validator.validate(cls, model)
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def declared_fieldsets(self):
        warnings.warn(
            "ModelAdmin.declared_fieldsets is deprecated and "
            "will be removed in Django 1.9.",
            RemovedInDjango19Warning, stacklevel=2
        )

        if self.fieldsets:
            return self.fieldsets
        elif self.fields:
            return [(None, {'fields': self.fields})]
        return None
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def get_formsets(self, request, obj=None):
        warnings.warn(
            "ModelAdmin.get_formsets() is deprecated and will be removed in "
            "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
            RemovedInDjango19Warning, stacklevel=2
        )
        return self._get_formsets(request, obj)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def _get_request(self):
        warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or '
                      '`request.POST` instead.', RemovedInDjango19Warning, 2)
        if not hasattr(self, '_request'):
            self._request = datastructures.MergeDict(self.POST, self.GET)
        return self._request
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def validate(cls, model):
        warnings.warn(
            'ModelAdmin.validate() is deprecated. Use "check()" instead.',
            RemovedInDjango19Warning)
        if cls.validator_class:
            validator = cls.validator_class()
        else:
            validator = cls.default_validator_class()
        validator.validate(cls, model)
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def declared_fieldsets(self):
        warnings.warn(
            "ModelAdmin.declared_fieldsets is deprecated and "
            "will be removed in Django 1.9.",
            RemovedInDjango19Warning, stacklevel=2
        )

        if self.fieldsets:
            return self.fieldsets
        elif self.fields:
            return [(None, {'fields': self.fields})]
        return None
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def get_formsets(self, request, obj=None):
        warnings.warn(
            "ModelAdmin.get_formsets() is deprecated and will be removed in "
            "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
            RemovedInDjango19Warning, stacklevel=2
        )
        return self._get_formsets(request, obj)
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def _get_request(self):
        warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or '
                      '`request.POST` instead.', RemovedInDjango19Warning, 2)
        if not hasattr(self, '_request'):
            self._request = datastructures.MergeDict(self.POST, self.GET)
        return self._request
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def validate(cls, model):
        warnings.warn(
            'ModelAdmin.validate() is deprecated. Use "check()" instead.',
            RemovedInDjango19Warning)
        if cls.validator_class:
            validator = cls.validator_class()
        else:
            validator = cls.default_validator_class()
        validator.validate(cls, model)
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def declared_fieldsets(self):
        warnings.warn(
            "ModelAdmin.declared_fieldsets is deprecated and "
            "will be removed in Django 1.9.",
            RemovedInDjango19Warning, stacklevel=2
        )

        if self.fieldsets:
            return self.fieldsets
        elif self.fields:
            return [(None, {'fields': self.fields})]
        return None
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def get_formsets(self, request, obj=None):
        warnings.warn(
            "ModelAdmin.get_formsets() is deprecated and will be removed in "
            "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
            RemovedInDjango19Warning, stacklevel=2
        )
        return self._get_formsets(request, obj)
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def _get_request(self):
        warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or '
                      '`request.POST` instead.', RemovedInDjango19Warning, 2)
        if not hasattr(self, '_request'):
            self._request = datastructures.MergeDict(self.POST, self.GET)
        return self._request
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def validate(cls, model):
        warnings.warn(
            'ModelAdmin.validate() is deprecated. Use "check()" instead.',
            RemovedInDjango19Warning)
        if cls.validator_class:
            validator = cls.validator_class()
        else:
            validator = cls.default_validator_class()
        validator.validate(cls, model)
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def declared_fieldsets(self):
        warnings.warn(
            "ModelAdmin.declared_fieldsets is deprecated and "
            "will be removed in Django 1.9.",
            RemovedInDjango19Warning, stacklevel=2
        )

        if self.fieldsets:
            return self.fieldsets
        elif self.fields:
            return [(None, {'fields': self.fields})]
        return None
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def get_formsets(self, request, obj=None):
        warnings.warn(
            "ModelAdmin.get_formsets() is deprecated and will be removed in "
            "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
            RemovedInDjango19Warning, stacklevel=2
        )
        return self._get_formsets(request, obj)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def _get_request(self):
        warnings.warn('`request.REQUEST` is deprecated, use `request.GET` or '
                      '`request.POST` instead.', RemovedInDjango19Warning, 2)
        if not hasattr(self, '_request'):
            self._request = datastructures.MergeDict(self.POST, self.GET)
        return self._request
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def validate(cls, model):
        warnings.warn(
            'ModelAdmin.validate() is deprecated. Use "check()" instead.',
            RemovedInDjango19Warning)
        if cls.validator_class:
            validator = cls.validator_class()
        else:
            validator = cls.default_validator_class()
        validator.validate(cls, model)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def declared_fieldsets(self):
        warnings.warn(
            "ModelAdmin.declared_fieldsets is deprecated and "
            "will be removed in Django 1.9.",
            RemovedInDjango19Warning, stacklevel=2
        )

        if self.fieldsets:
            return self.fieldsets
        elif self.fields:
            return [(None, {'fields': self.fields})]
        return None
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def get_formsets(self, request, obj=None):
        warnings.warn(
            "ModelAdmin.get_formsets() is deprecated and will be removed in "
            "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.",
            RemovedInDjango19Warning, stacklevel=2
        )
        return self._get_formsets(request, obj)
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def __init__(self, *dicts):
        warnings.warn('`MergeDict` is deprecated, use `dict.update()` '
                      'instead.', RemovedInDjango19Warning, 2)
        self.dicts = dicts