added translations
This commit is contained in:
+13
-12
@@ -6,12 +6,13 @@ from django.core.exceptions import ValidationError
|
||||
from django.core.files.storage import default_storage
|
||||
from django.db import models, transaction
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class Sensor(models.Model):
|
||||
"""A physical recorder authorised to submit audio to the device API."""
|
||||
|
||||
name = models.CharField(max_length=100, unique=True, help_text="A recognisable device name, e.g. Garden ESP32.")
|
||||
name = models.CharField(max_length=100, unique=True, help_text=_("A recognisable device name, e.g. Garden ESP32."))
|
||||
is_active = models.BooleanField(default=True)
|
||||
token_prefix = models.CharField(max_length=15, blank=True, editable=False)
|
||||
token_hash = models.CharField(max_length=256, blank=True, editable=False)
|
||||
@@ -50,8 +51,8 @@ class ClassificationRule(models.Model):
|
||||
"""A configurable inclusion or exclusion rule for a classification label."""
|
||||
|
||||
class RuleType(models.TextChoices):
|
||||
WHITELIST = "whitelist", "Whitelist"
|
||||
BLACKLIST = "blacklist", "Blacklist"
|
||||
WHITELIST = "whitelist", _("Whitelist")
|
||||
BLACKLIST = "blacklist", _("Blacklist")
|
||||
|
||||
value = models.CharField(max_length=255)
|
||||
rule_type = models.CharField(max_length=10, choices=RuleType.choices)
|
||||
@@ -71,8 +72,8 @@ class ClassifiedAudio(models.Model):
|
||||
"""Shared fields for a classifier response and its original audio upload."""
|
||||
|
||||
class SourceType(models.TextChoices):
|
||||
SENSOR = "sensor", "Sensor"
|
||||
MANUAL = "manual", "Manual report"
|
||||
SENSOR = "sensor", _("Sensor")
|
||||
MANUAL = "manual", _("Manual report")
|
||||
|
||||
audio_file = models.FileField(upload_to="fireworks_audio/%Y/%m/%d", blank=True)
|
||||
sensor = models.ForeignKey(Sensor, null=True, blank=True, on_delete=models.SET_NULL, related_name="%(class)s_records")
|
||||
@@ -103,11 +104,11 @@ class ClassifiedAudio(models.Model):
|
||||
if self.direction_degrees is not None and (
|
||||
not math.isfinite(self.direction_degrees) or not 0 <= self.direction_degrees < 360
|
||||
):
|
||||
errors["direction_degrees"] = "Direction must be a finite value from 0 up to, but not including, 360 degrees."
|
||||
errors["direction_degrees"] = _("Direction must be a finite value from 0 up to, but not including, 360 degrees.")
|
||||
if self.direction_accuracy_degrees is not None and (
|
||||
not math.isfinite(self.direction_accuracy_degrees) or self.direction_accuracy_degrees < 0
|
||||
):
|
||||
errors["direction_accuracy_degrees"] = "Compass accuracy must be a finite, non-negative value."
|
||||
errors["direction_accuracy_degrees"] = _("Compass accuracy must be a finite, non-negative value.")
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
@@ -138,7 +139,7 @@ class ClassifiedAudio(models.Model):
|
||||
|
||||
@property
|
||||
def primary_label(self):
|
||||
return self.primary_prediction.get("class", "No prediction")
|
||||
return self.primary_prediction.get("class", _("No prediction"))
|
||||
|
||||
@property
|
||||
def primary_score(self):
|
||||
@@ -177,8 +178,8 @@ class PendingEvent(ClassifiedAudio):
|
||||
"""A submitted classification awaiting a human review in Django admin."""
|
||||
|
||||
class Meta(ClassifiedAudio.Meta):
|
||||
verbose_name = "Pending event"
|
||||
verbose_name_plural = "Pending"
|
||||
verbose_name = _("Pending event")
|
||||
verbose_name_plural = _("Pending")
|
||||
|
||||
@transaction.atomic
|
||||
def approve(self):
|
||||
@@ -214,5 +215,5 @@ class Event(ClassifiedAudio):
|
||||
approved_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta(ClassifiedAudio.Meta):
|
||||
verbose_name = "Event"
|
||||
verbose_name_plural = "Events"
|
||||
verbose_name = _("Event")
|
||||
verbose_name_plural = _("Events")
|
||||
|
||||
Reference in New Issue
Block a user