mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
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.
27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
"""A job's error and its result's warning are lists of messages
|
|
(operations.utils.say), so that they are shown in the language of whoever
|
|
reads them. Those stored before are one message each, without values: shown
|
|
as they were."""
|
|
|
|
from django.db import migrations, models
|
|
|
|
|
|
def to_messages(apps, schema_editor):
|
|
Operation = apps.get_model("operations", "Operation")
|
|
for op in Operation.objects.exclude(error_text="").only("pk", "error_text"):
|
|
Operation.objects.filter(pk=op.pk).update(error=[{"text": op.error_text, "values": {}}])
|
|
for op in Operation.objects.only("pk", "result"):
|
|
if isinstance(op.result.get("warning"), str):
|
|
Operation.objects.filter(pk=op.pk).update(
|
|
result={**op.result, "warning": [{"text": op.result["warning"], "values": {}}]})
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [("operations", "0001_initial")]
|
|
|
|
operations = [
|
|
migrations.RenameField("operation", "error", "error_text"),
|
|
migrations.AddField("operation", "error", models.JSONField(default=list)),
|
|
migrations.RunPython(to_messages, migrations.RunPython.noop),
|
|
migrations.RemoveField("operation", "error_text"),
|
|
]
|