15094 Add missing gettext to error strings for internationalization (#15155)

* 15049 add missing gettext to error strings

* 15049 add missing gettext to error strings

* 15094 review change

* 15094 review change

* Formatting cleanup

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Arthur Hanson
2024-02-20 06:44:02 -08:00
committed by GitHub
parent 29f029d480
commit af27bf5eff
47 changed files with 275 additions and 133 deletions

View File

@@ -2,6 +2,7 @@ from django.contrib.auth.mixins import AccessMixin
from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch
from django.utils.translation import gettext_lazy as _
from netbox.registry import registry
from .permissions import resolve_permission
@@ -34,7 +35,9 @@ class ContentTypePermissionRequiredMixin(AccessMixin):
"""
Return the specific permission necessary to perform the requested action on an object.
"""
raise NotImplementedError(f"{self.__class__.__name__} must implement get_required_permission()")
raise NotImplementedError(_("{self.__class__.__name__} must implement get_required_permission()").format(
class_name=self.__class__.__name__
))
def has_permission(self):
user = self.request.user
@@ -68,7 +71,9 @@ class ObjectPermissionRequiredMixin(AccessMixin):
"""
Return the specific permission necessary to perform the requested action on an object.
"""
raise NotImplementedError(f"{self.__class__.__name__} must implement get_required_permission()")
raise NotImplementedError(_("{class_name} must implement get_required_permission()").format(
class_name=self.__class__.__name__
))
def has_permission(self):
user = self.request.user
@@ -89,8 +94,10 @@ class ObjectPermissionRequiredMixin(AccessMixin):
if not hasattr(self, 'queryset'):
raise ImproperlyConfigured(
'{} has no queryset defined. ObjectPermissionRequiredMixin may only be used on views which define '
'a base queryset'.format(self.__class__.__name__)
_(
'{class_name} has no queryset defined. ObjectPermissionRequiredMixin may only be used on views '
'which define a base queryset'
).format(class_name=self.__class__.__name__)
)
if not self.has_permission():