Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove Django 1.5 get_model_name fallback
  • Loading branch information
Carlton Gibson committed Sep 21, 2015
commit 25de8c960fcbb79f6d1097da22cab2dfeefb4e6e
8 changes: 0 additions & 8 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ def clean_manytomany_helptext(text):
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
Expand Down
6 changes: 2 additions & 4 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
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
Expand Down Expand Up @@ -202,7 +200,7 @@ def filter_queryset(self, request, queryset, view):
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):
Expand Down
6 changes: 2 additions & 4 deletions rest_framework/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from django.http import Http404

from rest_framework.compat import get_model_name

SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')


Expand Down Expand Up @@ -104,7 +102,7 @@ def get_required_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]]

Expand Down Expand Up @@ -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]]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand Down Expand Up @@ -278,7 +278,7 @@ def setUp(self):

# 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 = {
Expand Down