Skip to content

Commit

Permalink
Closes #13132: Wrap verbose_name and other model text with gettext_la…
Browse files Browse the repository at this point in the history
…zy() (i18n)


---------

Co-authored-by: Jeremy Stretch <[email protected]>
  • Loading branch information
arthanson and jeremystretch authored Jul 31, 2023
1 parent 80376ab commit 83bebc1
Show file tree
Hide file tree
Showing 36 changed files with 899 additions and 431 deletions.
30 changes: 16 additions & 14 deletions netbox/circuits/models/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _

from circuits.choices import *
from dcim.models import CabledObjectModel
Expand Down Expand Up @@ -34,8 +34,8 @@ class Circuit(PrimaryModel):
"""
cid = models.CharField(
max_length=100,
verbose_name='Circuit ID',
help_text=_("Unique circuit ID")
verbose_name=_('circuit ID'),
help_text=_('Unique circuit ID')
)
provider = models.ForeignKey(
to='circuits.Provider',
Expand All @@ -55,6 +55,7 @@ class Circuit(PrimaryModel):
related_name='circuits'
)
status = models.CharField(
verbose_name=_('status'),
max_length=50,
choices=CircuitStatusChoices,
default=CircuitStatusChoices.STATUS_ACTIVE
Expand All @@ -69,17 +70,17 @@ class Circuit(PrimaryModel):
install_date = models.DateField(
blank=True,
null=True,
verbose_name='Installed'
verbose_name=_('installed')
)
termination_date = models.DateField(
blank=True,
null=True,
verbose_name='Terminates'
verbose_name=_('terminates')
)
commit_rate = models.PositiveIntegerField(
blank=True,
null=True,
verbose_name='Commit rate (Kbps)',
verbose_name=_('commit rate (Kbps)'),
help_text=_("Committed rate")
)

Expand Down Expand Up @@ -162,7 +163,7 @@ class CircuitTermination(
term_side = models.CharField(
max_length=1,
choices=CircuitTerminationSideChoices,
verbose_name='Termination'
verbose_name=_('termination')
)
site = models.ForeignKey(
to='dcim.Site',
Expand All @@ -179,30 +180,31 @@ class CircuitTermination(
null=True
)
port_speed = models.PositiveIntegerField(
verbose_name='Port speed (Kbps)',
verbose_name=_('port speed (Kbps)'),
blank=True,
null=True,
help_text=_("Physical circuit speed")
help_text=_('Physical circuit speed')
)
upstream_speed = models.PositiveIntegerField(
blank=True,
null=True,
verbose_name='Upstream speed (Kbps)',
verbose_name=_('upstream speed (Kbps)'),
help_text=_('Upstream speed, if different from port speed')
)
xconnect_id = models.CharField(
max_length=50,
blank=True,
verbose_name='Cross-connect ID',
help_text=_("ID of the local cross-connect")
verbose_name=_('cross-connect ID'),
help_text=_('ID of the local cross-connect')
)
pp_info = models.CharField(
max_length=100,
blank=True,
verbose_name='Patch panel/port(s)',
help_text=_("Patch panel ID and port number(s)")
verbose_name=_('patch panel/port(s)'),
help_text=_('Patch panel ID and port number(s)')
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
Expand Down
12 changes: 8 additions & 4 deletions netbox/circuits/models/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db import models
from django.db.models import Q
from django.urls import reverse
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy as _

from netbox.models import PrimaryModel

Expand All @@ -19,11 +19,13 @@ class Provider(PrimaryModel):
stores information pertinent to the user's relationship with the Provider.
"""
name = models.CharField(
verbose_name=_('name'),
max_length=100,
unique=True,
help_text=_("Full name of the provider")
help_text=_('Full name of the provider')
)
slug = models.SlugField(
verbose_name=_('slug'),
max_length=100,
unique=True
)
Expand Down Expand Up @@ -61,9 +63,10 @@ class ProviderAccount(PrimaryModel):
)
account = models.CharField(
max_length=100,
verbose_name='Account ID'
verbose_name=_('account ID')
)
name = models.CharField(
verbose_name=_('name'),
max_length=100,
blank=True
)
Expand Down Expand Up @@ -104,6 +107,7 @@ class ProviderNetwork(PrimaryModel):
unimportant to the user.
"""
name = models.CharField(
verbose_name=_('name'),
max_length=100
)
provider = models.ForeignKey(
Expand All @@ -114,7 +118,7 @@ class ProviderNetwork(PrimaryModel):
service_id = models.CharField(
max_length=100,
blank=True,
verbose_name='Service ID'
verbose_name=_('service ID')
)

class Meta:
Expand Down
16 changes: 14 additions & 2 deletions netbox/core/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class DataSource(JobsMixin, PrimaryModel):
A remote source, such as a git repository, from which DataFiles are synchronized.
"""
name = models.CharField(
verbose_name=_('name'),
max_length=100,
unique=True
)
type = models.CharField(
verbose_name=_('type'),
max_length=50,
choices=DataSourceTypeChoices,
default=DataSourceTypeChoices.LOCAL
Expand All @@ -52,23 +54,28 @@ class DataSource(JobsMixin, PrimaryModel):
verbose_name=_('URL')
)
status = models.CharField(
verbose_name=_('status'),
max_length=50,
choices=DataSourceStatusChoices,
default=DataSourceStatusChoices.NEW,
editable=False
)
enabled = models.BooleanField(
verbose_name=_('enabled'),
default=True
)
ignore_rules = models.TextField(
verbose_name=_('ignore rules'),
blank=True,
help_text=_("Patterns (one per line) matching files to ignore when syncing")
)
parameters = models.JSONField(
verbose_name=_('parameters'),
blank=True,
null=True
)
last_synced = models.DateTimeField(
verbose_name=_('last synced'),
blank=True,
null=True,
editable=False
Expand Down Expand Up @@ -239,9 +246,11 @@ class DataFile(models.Model):
updated, or deleted only by calling DataSource.sync().
"""
created = models.DateTimeField(
verbose_name=_('created'),
auto_now_add=True
)
last_updated = models.DateTimeField(
verbose_name=_('last updated'),
editable=False
)
source = models.ForeignKey(
Expand All @@ -251,20 +260,23 @@ class DataFile(models.Model):
editable=False
)
path = models.CharField(
verbose_name=_('path'),
max_length=1000,
editable=False,
help_text=_("File path relative to the data source's root")
)
size = models.PositiveIntegerField(
editable=False
editable=False,
verbose_name=_('size')
)
hash = models.CharField(
verbose_name=_('hash'),
max_length=64,
editable=False,
validators=[
RegexValidator(regex='^[0-9a-f]{64}$', message=_("Length must be 64 hexadecimal characters."))
],
help_text=_("SHA256 hash of the file data")
help_text=_('SHA256 hash of the file data')
)
data = models.BinaryField()

Expand Down
6 changes: 5 additions & 1 deletion netbox/core/models/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@ class ManagedFile(SyncedDataMixin, models.Model):
to provide additional functionality.
"""
created = models.DateTimeField(
verbose_name=_('created'),
auto_now_add=True
)
last_updated = models.DateTimeField(
verbose_name=_('last updated'),
editable=False,
blank=True,
null=True
)
file_root = models.CharField(
verbose_name=_('file root'),
max_length=1000,
choices=ManagedFileRootPathChoices
)
file_path = models.FilePathField(
verbose_name=_('file path'),
editable=False,
help_text=_("File path relative to the designated root path")
help_text=_('File path relative to the designated root path')
)

objects = RestrictedQuerySet.as_manager()
Expand Down
11 changes: 10 additions & 1 deletion netbox/core/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,34 @@ class Job(models.Model):
for_concrete_model=False
)
name = models.CharField(
verbose_name=_('name'),
max_length=200
)
created = models.DateTimeField(
verbose_name=_('created'),
auto_now_add=True
)
scheduled = models.DateTimeField(
verbose_name=_('scheduled'),
null=True,
blank=True
)
interval = models.PositiveIntegerField(
verbose_name=_('interval'),
blank=True,
null=True,
validators=(
MinValueValidator(1),
),
help_text=_("Recurrence interval (in minutes)")
help_text=_('Recurrence interval (in minutes)')
)
started = models.DateTimeField(
verbose_name=_('started'),
null=True,
blank=True
)
completed = models.DateTimeField(
verbose_name=_('completed'),
null=True,
blank=True
)
Expand All @@ -76,15 +82,18 @@ class Job(models.Model):
null=True
)
status = models.CharField(
verbose_name=_('status'),
max_length=30,
choices=JobStatusChoices,
default=JobStatusChoices.STATUS_PENDING
)
data = models.JSONField(
verbose_name=_('data'),
null=True,
blank=True
)
job_id = models.UUIDField(
verbose_name=_('job ID'),
unique=True
)

Expand Down
13 changes: 12 additions & 1 deletion netbox/dcim/models/cables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.db.models import Sum
from django.dispatch import Signal
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from dcim.choices import *
from dcim.constants import *
Expand Down Expand Up @@ -40,11 +41,13 @@ class Cable(PrimaryModel):
A physical connection between two endpoints.
"""
type = models.CharField(
verbose_name=_('type'),
max_length=50,
choices=CableTypeChoices,
blank=True
)
status = models.CharField(
verbose_name=_('status'),
max_length=50,
choices=LinkStatusChoices,
default=LinkStatusChoices.STATUS_CONNECTED
Expand All @@ -57,19 +60,23 @@ class Cable(PrimaryModel):
null=True
)
label = models.CharField(
verbose_name=_('label'),
max_length=100,
blank=True
)
color = ColorField(
verbose_name=_('color'),
blank=True
)
length = models.DecimalField(
verbose_name=_('length'),
max_digits=8,
decimal_places=2,
blank=True,
null=True
)
length_unit = models.CharField(
verbose_name=_('length unit'),
max_length=50,
choices=CableLengthUnitChoices,
blank=True,
Expand Down Expand Up @@ -235,7 +242,7 @@ class CableTermination(ChangeLoggedModel):
cable_end = models.CharField(
max_length=1,
choices=CableEndChoices,
verbose_name='End'
verbose_name=_('end')
)
termination_type = models.ForeignKey(
to=ContentType,
Expand Down Expand Up @@ -403,15 +410,19 @@ class CablePath(models.Model):
`_nodes` retains a flattened list of all nodes within the path to enable simple filtering.
"""
path = models.JSONField(
verbose_name=_('path'),
default=list
)
is_active = models.BooleanField(
verbose_name=_('is active'),
default=False
)
is_complete = models.BooleanField(
verbose_name=_('is complete'),
default=False
)
is_split = models.BooleanField(
verbose_name=_('is split'),
default=False
)
_nodes = PathField()
Expand Down
Loading

0 comments on commit 83bebc1

Please sign in to comment.