added translations
This commit is contained in:
+18
-17
@@ -3,6 +3,7 @@ import json
|
||||
from django.contrib import admin, messages
|
||||
from django.utils import timezone
|
||||
from django.utils.html import format_html
|
||||
from django.utils.translation import gettext as _, gettext_lazy, ngettext
|
||||
|
||||
from .models import ClassificationRule, Event, PendingEvent, Sensor
|
||||
|
||||
@@ -22,11 +23,11 @@ class ClassificationAdmin(admin.ModelAdmin):
|
||||
fields = ("audio_file", "sensor", "source_type", "occurrences", "location", "latitude", "longitude", "h3_cell", "direction_display", "direction_accuracy_degrees", "visually_confirmed", "original_filename", "created_at")
|
||||
change_form_template = "admin/fireworks_detect/classification_audio_change_form.html"
|
||||
|
||||
@admin.display(description="Direction")
|
||||
@admin.display(description=gettext_lazy("Direction"))
|
||||
def direction_display(self, obj):
|
||||
return obj.direction_display
|
||||
|
||||
@admin.display(description="Classifier response")
|
||||
@admin.display(description=gettext_lazy("Classifier response"))
|
||||
def pretty_classifier_response(self, obj):
|
||||
return format_html("<pre>{}</pre>", json.dumps(obj.classifier_response, indent=2, sort_keys=True))
|
||||
|
||||
@@ -38,21 +39,21 @@ class PendingEventAdmin(ClassificationAdmin):
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
@admin.action(description="Approve selected samples and move them to Events")
|
||||
@admin.action(description=gettext_lazy("Approve selected samples and move them to Events"))
|
||||
def approve_selected(self, request, queryset):
|
||||
approved = 0
|
||||
for pending in queryset:
|
||||
pending.approve()
|
||||
approved += 1
|
||||
self.message_user(request, f"{approved} sample(s) approved and moved to Events.", messages.SUCCESS)
|
||||
self.message_user(request, ngettext("%(count)d sample approved and moved to Events.", "%(count)d samples approved and moved to Events.", approved) % {"count": approved}, messages.SUCCESS)
|
||||
|
||||
@admin.action(description="Deny selected samples and delete their uploaded audio")
|
||||
@admin.action(description=gettext_lazy("Deny selected samples and delete their uploaded audio"))
|
||||
def deny_selected(self, request, queryset):
|
||||
denied = 0
|
||||
for pending in queryset:
|
||||
pending.deny()
|
||||
denied += 1
|
||||
self.message_user(request, f"{denied} sample(s) denied and removed.", messages.WARNING)
|
||||
self.message_user(request, ngettext("%(count)d sample denied and removed.", "%(count)d samples denied and removed.", denied) % {"count": denied}, messages.WARNING)
|
||||
|
||||
|
||||
@admin.register(Event)
|
||||
@@ -72,30 +73,30 @@ class SensorAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("token_prefix", "last_heartbeat", "last_submission", "created_at")
|
||||
actions = ("issue_api_token",)
|
||||
fieldsets = (
|
||||
("Sensor", {"fields": ("name", "is_active", "created_at")}),
|
||||
("API token", {"fields": ("token_prefix",), "description": "Save the sensor first, select it in the list, then choose ‘Issue or rotate API token’. The complete token is shown once only; its salted hash is the only value stored."}),
|
||||
("Heartbeat", {"fields": ("last_heartbeat", "last_submission"), "description": "Devices should POST to /fireworks/heartbeat/ with Authorization: Bearer <token>. Green means seen within 5 minutes; amber within 15; red is older or never seen."}),
|
||||
(gettext_lazy("Sensor"), {"fields": ("name", "is_active", "created_at")}),
|
||||
(gettext_lazy("API token"), {"fields": ("token_prefix",), "description": gettext_lazy("Save the sensor first, select it in the list, then choose ‘Issue or rotate API token’. The complete token is shown once only; its salted hash is the only value stored.")}),
|
||||
(gettext_lazy("Heartbeat"), {"fields": ("last_heartbeat", "last_submission"), "description": gettext_lazy("Devices should POST to /fireworks/heartbeat/ with Authorization: Bearer <token>. Green means seen within 5 minutes; amber within 15; red is older or never seen.")}),
|
||||
)
|
||||
|
||||
@admin.display(description="Heartbeat")
|
||||
@admin.display(description=gettext_lazy("Heartbeat"))
|
||||
def heartbeat_light(self, obj):
|
||||
if not obj.last_heartbeat:
|
||||
colour, label = "#ef4444", "Never seen"
|
||||
colour, label = "#ef4444", _("Never seen")
|
||||
else:
|
||||
age = timezone.now() - obj.last_heartbeat
|
||||
if age.total_seconds() <= 300:
|
||||
colour, label = "#22c55e", "Online"
|
||||
colour, label = "#22c55e", _("Online")
|
||||
elif age.total_seconds() <= 900:
|
||||
colour, label = "#f59e0b", "Delayed"
|
||||
colour, label = "#f59e0b", _("Delayed")
|
||||
else:
|
||||
colour, label = "#ef4444", "Offline"
|
||||
colour, label = "#ef4444", _("Offline")
|
||||
return format_html('<span style="display:inline-flex;align-items:center;gap:6px"><span style="width:10px;height:10px;border-radius:50%;background:{}"></span>{}</span>', colour, label)
|
||||
|
||||
@admin.action(description="Issue or rotate API token (shown once)")
|
||||
@admin.action(description=gettext_lazy("Issue or rotate API token (shown once)"))
|
||||
def issue_api_token(self, request, queryset):
|
||||
if queryset.count() != 1:
|
||||
self.message_user(request, "Select exactly one sensor to issue a token.", messages.ERROR)
|
||||
self.message_user(request, _("Select exactly one sensor to issue a token."), messages.ERROR)
|
||||
return
|
||||
sensor = queryset.get()
|
||||
token = sensor.issue_token()
|
||||
self.message_user(request, format_html('Copy this token now; it is not stored and will not be shown again: <code>{}</code>', token), messages.WARNING)
|
||||
self.message_user(request, format_html(_("Copy this token now; it is not stored and will not be shown again: <code>{}</code>"), token), messages.WARNING)
|
||||
|
||||
Reference in New Issue
Block a user