mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Remove Django 1.5 get_model_name fallback
This commit is contained in:
parent
4a1ab3c18c
commit
25de8c960f
|
@ -127,14 +127,6 @@ except ImportError:
|
|||
pass
|
||||
|
||||
|
||||
def get_model_name(model_cls):
|
||||
try:
|
||||
return model_cls._meta.model_name
|
||||
except AttributeError:
|
||||
# < 1.6 used module_name instead of model_name
|
||||
return model_cls._meta.module_name
|
||||
|
||||
|
||||
# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
|
||||
if django.VERSION >= (1, 8):
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
|
|
|
@ -11,9 +11,7 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.db import models
|
||||
from django.utils import six
|
||||
|
||||
from rest_framework.compat import (
|
||||
distinct, django_filters, get_model_name, guardian
|
||||
)
|
||||
from rest_framework.compat import distinct, django_filters, guardian
|
||||
from rest_framework.settings import api_settings
|
||||
|
||||
FilterSet = django_filters and django_filters.FilterSet or None
|
||||
|
@ -202,7 +200,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
|||
model_cls = queryset.model
|
||||
kwargs = {
|
||||
'app_label': model_cls._meta.app_label,
|
||||
'model_name': get_model_name(model_cls)
|
||||
'model_name': model_cls._meta.model_name
|
||||
}
|
||||
permission = self.perm_format % kwargs
|
||||
if guardian.VERSION >= (1, 3):
|
||||
|
|
|
@ -5,8 +5,6 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.http import Http404
|
||||
|
||||
from rest_framework.compat import get_model_name
|
||||
|
||||
SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')
|
||||
|
||||
|
||||
|
@ -104,7 +102,7 @@ class DjangoModelPermissions(BasePermission):
|
|||
"""
|
||||
kwargs = {
|
||||
'app_label': model_cls._meta.app_label,
|
||||
'model_name': get_model_name(model_cls)
|
||||
'model_name': model_cls._meta.model_name
|
||||
}
|
||||
return [perm % kwargs for perm in self.perms_map[method]]
|
||||
|
||||
|
@ -166,7 +164,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
|
|||
def get_required_object_permissions(self, method, model_cls):
|
||||
kwargs = {
|
||||
'app_label': model_cls._meta.app_label,
|
||||
'model_name': get_model_name(model_cls)
|
||||
'model_name': model_cls._meta.model_name
|
||||
}
|
||||
return [perm % kwargs for perm in self.perms_map[method]]
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from rest_framework import (
|
|||
HTTP_HEADER_ENCODING, authentication, generics, permissions, serializers,
|
||||
status
|
||||
)
|
||||
from rest_framework.compat import get_model_name, guardian, unittest
|
||||
from rest_framework.compat import guardian, unittest
|
||||
from rest_framework.filters import DjangoObjectPermissionsFilter
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from rest_framework.test import APIRequestFactory
|
||||
|
@ -278,7 +278,7 @@ class ObjectPermissionsIntegrationTests(TestCase):
|
|||
|
||||
# give everyone model level permissions, as we are not testing those
|
||||
everyone = Group.objects.create(name='everyone')
|
||||
model_name = get_model_name(BasicPermModel)
|
||||
model_name = BasicPermModel._meta.model_name
|
||||
app_label = BasicPermModel._meta.app_label
|
||||
f = '{0}_{1}'.format
|
||||
perms = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user