1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 11:46:49 +00:00

feat(operations): the job panel and job pages speak the page's language

The job panel on VM and storage pages wrote its buttons and notes in
English (Cancel, Open, Refresh, Dismiss, Finishing..., Files not
removed, Worker unavailable, Cancel failed) and its state badge as the
state's code, and the jobs API gave the phase untranslated. The panel
now takes its texts and the state labels from the page's settings, and
the API gives the phase in the viewer's language, as it gives the
label; the job pages show that phase.

A job that cannot be cancelled and ran past its time limit had
"(over its time limit)" written into its phase, which then matched no
translation. The phase stays as the job sets it, and the pages say the
job is past its limit.
This commit is contained in:
catborise 2026-11-02 23:33:34 +03:00
parent 9d57adc097
commit 0eab09e19d
13 changed files with 178 additions and 42 deletions

View file

@ -1,3 +1,6 @@
from datetime import timedelta
from django.utils import timezone
from django.utils.translation import gettext as _
from rest_framework import serializers
@ -8,6 +11,7 @@ from operations.utils import shown_label
class OperationSerializer(serializers.ModelSerializer):
label = serializers.SerializerMethodField()
phase = serializers.SerializerMethodField()
resource_label = serializers.SerializerMethodField()
cancellable = serializers.SerializerMethodField()
in_request = serializers.SerializerMethodField()
@ -22,6 +26,15 @@ class OperationSerializer(serializers.ModelSerializer):
def get_label(self, op) -> str:
return str(_(label_of(op.kind)))
def get_phase(self, op) -> str:
"""The phase in the viewer's language; a job running past its time
limit says so (one that can be cancelled is cancelled instead)."""
phase = _(op.phase) if op.phase else ""
if op.state == Operation.RUNNING and op.time_limit and op.started_at \
and timezone.now() - op.started_at > timedelta(seconds=op.time_limit):
return (_("%(phase)s (over its time limit)") % {"phase": phase}).strip()
return phase
def get_resource_label(self, op) -> str:
return shown_label(op, self.context["request"].user)