mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
Added ngettext to device_components.py, devices.py, device_component_templates.py, and views.py
This commit is contained in:
parent
44c78b0844
commit
15a7746b29
@ -2,7 +2,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _, ngettext
|
||||
from mptt.models import MPTTModel, TreeForeignKey
|
||||
|
||||
from dcim.choices import *
|
||||
@ -539,7 +539,11 @@ class FrontPortTemplate(ModularComponentTemplateModel):
|
||||
# Validate rear port position assignment
|
||||
if self.rear_port_position > self.rear_port.positions:
|
||||
raise ValidationError(
|
||||
_("Invalid rear port position ({position}); rear port {name} has only {count} positions").format(
|
||||
_(ngettext(
|
||||
"Invalid rear port position ({position}); rear port {name} has only {count} position",
|
||||
"Invalid rear port position ({position}); rear port {name} has only {count} positions",
|
||||
self.rear_port.positions,
|
||||
)).format(
|
||||
position=self.rear_port_position,
|
||||
name=self.rear_port.name,
|
||||
count=self.rear_port.positions
|
||||
|
@ -6,7 +6,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.db import models
|
||||
from django.db.models import Sum
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _, ngettext
|
||||
from mptt.models import MPTTModel, TreeForeignKey
|
||||
|
||||
from dcim.choices import *
|
||||
@ -1026,10 +1026,13 @@ class FrontPort(ModularComponentModel, CabledObjectModel, TrackingModelMixin):
|
||||
# Validate rear port position assignment
|
||||
if self.rear_port_position > self.rear_port.positions:
|
||||
raise ValidationError({
|
||||
"rear_port_position": _(
|
||||
"rear_port_position": _(ngettext(
|
||||
"Invalid rear port position ({rear_port_position}): Rear port {name} has only {positions} "
|
||||
"positions."
|
||||
).format(
|
||||
"position.",
|
||||
"Invalid rear port position ({rear_port_position}): Rear port {name} has only {positions} "
|
||||
"positions.",
|
||||
self.rear_port.positions
|
||||
)).format(
|
||||
rear_port_position=self.rear_port_position,
|
||||
name=self.rear_port.name,
|
||||
positions=self.rear_port.positions
|
||||
|
@ -12,7 +12,7 @@ from django.db.models.functions import Lower
|
||||
from django.db.models.signals import post_save
|
||||
from django.urls import reverse
|
||||
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 dcim.choices import *
|
||||
from dcim.constants import *
|
||||
@ -318,10 +318,13 @@ class DeviceType(ImageAttachmentsMixin, PrimaryModel, WeightMixin):
|
||||
if racked_instance_count:
|
||||
url = f"{reverse('dcim:device_list')}?manufactuer_id={self.manufacturer_id}&device_type_id={self.pk}"
|
||||
raise ValidationError({
|
||||
'u_height': mark_safe(_(
|
||||
'u_height': mark_safe(_(ngettext(
|
||||
'Unable to set 0U height: Found <a href="{url}">{racked_instance_count} instance</a> already '
|
||||
'mounted within racks.',
|
||||
'Unable to set 0U height: Found <a href="{url}">{racked_instance_count} instances</a> already '
|
||||
'mounted within racks.'
|
||||
).format(url=url, racked_instance_count=racked_instance_count))
|
||||
'mounted within racks.',
|
||||
racked_instance_count,
|
||||
)).format(url=url, racked_instance_count=racked_instance_count))
|
||||
})
|
||||
|
||||
if (
|
||||
|
@ -11,7 +11,7 @@ from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext as _, ngettext
|
||||
from django.views.generic import View
|
||||
from jinja2.exceptions import TemplateError
|
||||
|
||||
@ -136,7 +136,11 @@ class BulkDisconnectView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View)
|
||||
for cable in Cable.objects.filter(pk__in=cable_ids):
|
||||
cable.delete()
|
||||
|
||||
messages.success(request, _("Disconnected {count} {type}").format(
|
||||
messages.success(request, _(ngettext(
|
||||
"Disconnected 1 {type}",
|
||||
"Disconnected {count} {type}",
|
||||
count,
|
||||
)).format(
|
||||
count=count,
|
||||
type=self.queryset.model._meta.verbose_name_plural
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user