from rest_framework permissions import IsAuthenticated class ViewPermi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from rest_framework.permissions import IsAuthenticated
class ViewPermission(IsAuthenticated):
default_detail = ('My message ')
permission_denied_class = PermissionDenied
def has_permission(self, request, view):
if request.user and request.user.is_authenticated():
return True
else:
raise self.permission_denied_class
class MyViewSet(TemporalViewMixin, ContextUserMixin, FilteredSchoolMixin,
TransactionManagementMixin, mixins.UpdateModelMixin,
viewsets.ReadOnlyModelViewSet):
model = Model
permission_classes = (ViewPermission, )
def __init__(self, *args, **kwargs):
super(MyViewSet, self).__init__(*args, **kwargs)
Не переопределяется default_detail
Я по api получаю
{
"detail": "You do not have permission to perform this action."
}
а по идее должен
{
"detail": "My message."
}
класс PermissionDenied
https://github.com/tomchristie/django-rest-framework/blob/426547c61c725ca7dc47671c084d1a2805c92305/rest_framework/exceptions.py
class PermissionDenied(APIException):
status_code = status.HTTP_403_FORBIDDEN
default_detail = _('You do not have permission to perform this action.')