mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
Added ngettext to error_handlers and clusters.py
This commit is contained in:
parent
65e40603ff
commit
f0774c912e
@ -7,7 +7,7 @@ from django.db.models import ProtectedError, RestrictedError
|
||||
from django.http import JsonResponse
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _, ngettext
|
||||
from rest_framework import status
|
||||
|
||||
__all__ = (
|
||||
@ -28,7 +28,10 @@ def handle_protectederror(obj_list, request, e):
|
||||
raise e
|
||||
|
||||
# Formulate the error message
|
||||
err_message = _("Unable to delete <strong>{objects}</strong>. {count} dependent objects were found: ").format(
|
||||
err_message = _(ngettext(
|
||||
"Unable to delete <strong>{objects}</strong>. {count} dependent object was found: ",
|
||||
"Unable to delete <strong>{objects}</strong>. {count} dependent objects were found: ",
|
||||
len(protected_objects),)).format(
|
||||
objects=', '.join(str(obj) for obj in obj_list),
|
||||
count=len(protected_objects) if len(protected_objects) <= 50 else _('More than 50')
|
||||
)
|
||||
|
@ -2,7 +2,7 @@ from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _, ngettext
|
||||
|
||||
from dcim.models import Device
|
||||
from netbox.models import OrganizationalModel, PrimaryModel
|
||||
@ -137,7 +137,9 @@ class Cluster(ContactsMixin, PrimaryModel):
|
||||
if self.pk and self.site:
|
||||
if nonsite_devices := Device.objects.filter(cluster=self).exclude(site=self.site).count():
|
||||
raise ValidationError({
|
||||
'site': _(
|
||||
"{count} devices are assigned as hosts for this cluster but are not in site {site}"
|
||||
).format(count=nonsite_devices, site=self.site)
|
||||
'site': _(ngettext(
|
||||
"{count} device is assigned as hosts for this cluster but is not in site {site}",
|
||||
"{count} devices are assigned as hosts for this cluster but are not in site {site}",
|
||||
nonsite_devices,
|
||||
)).format(count=nonsite_devices, site=self.site)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user