mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
The Logs tab of a VM's Stats showed each row's time in UTC, formatted by
the process locale ("11/10/26 08:43:08" whatever the page's language),
while the Logs page shows the same row in the panel's time zone
("2026-11-10 11:43:08" with TIME_ZONE=Europe/Istanbul). The tab now
shows the panel's time in the Logs page's format, and its Date heading
names the zone as the Logs page's does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
from django.http import JsonResponse
|
|
from django.shortcuts import get_object_or_404
|
|
from django.utils import timezone
|
|
from django.utils.translation import gettext as _
|
|
|
|
from admin.decorators import superuser_only
|
|
from instances.models import Instance
|
|
from logs.models import Logs
|
|
|
|
# the rows of a VM on its Stats tab; the Logs page has them all
|
|
VM_LOG_ROWS = 50
|
|
|
|
|
|
@superuser_only
|
|
def vm_logs(request, pk):
|
|
"""The rows of a VM, found by its UUID: a rename keeps them, and a VM on two computes is one VM."""
|
|
vm = get_object_or_404(Instance, pk=pk)
|
|
results = {None: _("Unknown"), True: _("Done"), False: _("Failed")}
|
|
logs = []
|
|
for log in Logs.objects.filter(instance_uuid=vm.uuid).order_by("-date", "-id")[:VM_LOG_ROWS]:
|
|
logs.append({
|
|
"user": log.user,
|
|
"host": log.host,
|
|
"instance": log.instance,
|
|
"message": log.message,
|
|
"result": results[log.success],
|
|
# as the Logs page shows it: in the panel's time zone, which the tab's heading names
|
|
"date": timezone.localtime(log.date).strftime("%Y-%m-%d %H:%M:%S"),
|
|
})
|
|
return JsonResponse(logs, safe=False)
|