mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Reenable flake8 on compat, cleanup style/imports
This commit is contained in:
parent
f8e8381c00
commit
5f8438697a
|
@ -3,7 +3,6 @@ The `compat` module provides support for backwards compatibility with older
|
||||||
versions of Django/Python, and compatibility wrappers around optional packages.
|
versions of Django/Python, and compatibility wrappers around optional packages.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# flake8: noqa
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -11,15 +10,9 @@ import inspect
|
||||||
import django
|
import django
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
from django.core import validators
|
||||||
from django.core.validators import \
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
MaxLengthValidator as DjangoMaxLengthValidator
|
|
||||||
from django.core.validators import MaxValueValidator as DjangoMaxValueValidator
|
|
||||||
from django.core.validators import \
|
|
||||||
MinLengthValidator as DjangoMinLengthValidator
|
|
||||||
from django.core.validators import MinValueValidator as DjangoMinValueValidator
|
|
||||||
from django.db import connection, models, transaction
|
from django.db import connection, models, transaction
|
||||||
from django.template import Context, RequestContext, Template
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
|
|
||||||
|
@ -152,7 +145,7 @@ except ImportError:
|
||||||
guardian = None
|
guardian = None
|
||||||
try:
|
try:
|
||||||
if 'guardian' in settings.INSTALLED_APPS:
|
if 'guardian' in settings.INSTALLED_APPS:
|
||||||
import guardian
|
import guardian # noqa
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -254,7 +247,7 @@ else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pytz
|
import pytz # noqa
|
||||||
from pytz.exceptions import InvalidTimeError
|
from pytz.exceptions import InvalidTimeError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
InvalidTimeError = Exception
|
InvalidTimeError = Exception
|
||||||
|
@ -279,22 +272,28 @@ class CustomValidatorMessage(object):
|
||||||
|
|
||||||
Ref: https://github.com/encode/django-rest-framework/pull/5452
|
Ref: https://github.com/encode/django-rest-framework/pull/5452
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.message = kwargs.pop('message', self.message)
|
self.message = kwargs.pop('message', self.message)
|
||||||
super(CustomValidatorMessage, self).__init__(*args, **kwargs)
|
super(CustomValidatorMessage, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
class MinValueValidator(CustomValidatorMessage, DjangoMinValueValidator):
|
|
||||||
|
class MinValueValidator(CustomValidatorMessage, validators.MinValueValidator):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MaxValueValidator(CustomValidatorMessage, DjangoMaxValueValidator):
|
|
||||||
|
class MaxValueValidator(CustomValidatorMessage, validators.MaxValueValidator):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MinLengthValidator(CustomValidatorMessage, DjangoMinLengthValidator):
|
|
||||||
|
class MinLengthValidator(CustomValidatorMessage, validators.MinLengthValidator):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MaxLengthValidator(CustomValidatorMessage, DjangoMaxLengthValidator):
|
|
||||||
|
class MaxLengthValidator(CustomValidatorMessage, validators.MaxLengthValidator):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def set_rollback():
|
def set_rollback():
|
||||||
if hasattr(transaction, 'set_rollback'):
|
if hasattr(transaction, 'set_rollback'):
|
||||||
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
|
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
|
||||||
|
@ -318,4 +317,3 @@ def authenticate(request=None, **credentials):
|
||||||
return authenticate(**credentials)
|
return authenticate(**credentials)
|
||||||
else:
|
else:
|
||||||
return authenticate(request=request, **credentials)
|
return authenticate(request=request, **credentials)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user