mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
feat(operations): a job's error and warning show in the reader's language
A job stored its error and its result's warning as English text, much of it built with the values in it (volume paths, a disk, libvirt's error), so no catalog could translate it, and the job pages and panel showed English whatever the language. A job now stores them as messages: our English text, marked for translation, and its values; libvirt's own text is a message without values and is shown as it is. The jobs API and pages put them in the reader's language. OperationError keeps its text and values apart for the same reason, so a refusal raised while a job is submitted is shown translated too. Messages one after another still read as sentences. Errors stored before are kept as one message each, shown as they were.
This commit is contained in:
parent
0eab09e19d
commit
1e66367bb4
29 changed files with 927 additions and 333 deletions
|
|
@ -6,12 +6,14 @@ from rest_framework import serializers
|
|||
|
||||
from operations.jobs import KINDS, label_of
|
||||
from operations.models import Operation
|
||||
from operations.utils import shown_label
|
||||
from operations.utils import shown_label, words
|
||||
|
||||
|
||||
class OperationSerializer(serializers.ModelSerializer):
|
||||
label = serializers.SerializerMethodField()
|
||||
phase = serializers.SerializerMethodField()
|
||||
error = serializers.SerializerMethodField()
|
||||
result = serializers.SerializerMethodField()
|
||||
resource_label = serializers.SerializerMethodField()
|
||||
cancellable = serializers.SerializerMethodField()
|
||||
in_request = serializers.SerializerMethodField()
|
||||
|
|
@ -35,6 +37,15 @@ class OperationSerializer(serializers.ModelSerializer):
|
|||
return (_("%(phase)s (over its time limit)") % {"phase": phase}).strip()
|
||||
return phase
|
||||
|
||||
def get_error(self, op) -> str:
|
||||
return words(op.error)
|
||||
|
||||
def get_result(self, op) -> dict:
|
||||
"""What the job made; its warning in the viewer's language."""
|
||||
if op.result.get("warning"):
|
||||
return {**op.result, "warning": words(op.result["warning"])}
|
||||
return op.result
|
||||
|
||||
def get_resource_label(self, op) -> str:
|
||||
return shown_label(op, self.context["request"].user)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue