From f7cba6a2bdb010c94817361366b523df3930cec5 Mon Sep 17 00:00:00 2001 From: Mira Date: Fri, 7 Feb 2025 11:53:17 +0100 Subject: [PATCH] Fix log display for checkins and order splits (Z#23181229) (#4818) - Fix link in pretix.event.order.changed.split - Add link to existing order in pretix.event.order.changed.split_from - Fix display of checkin entries without datetime in data - Add additional info for admins (action type, linked content object) --- src/pretix/control/logdisplay.py | 25 ++++++++++++------- src/pretix/control/views/global_settings.py | 2 +- src/pretix/static/pretixcontrol/js/ui/main.js | 10 ++++++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/pretix/control/logdisplay.py b/src/pretix/control/logdisplay.py index dc9d00af3a..b8b70da60b 100644 --- a/src/pretix/control/logdisplay.py +++ b/src/pretix/control/logdisplay.py @@ -72,7 +72,7 @@ class OrderChangeLogEntryType(OrderLogEntryType): prefix = _('The order has been changed:') def display(self, logentry, data): - return self.prefix + ' ' + self.display_prefixed(logentry.event, logentry, data) + return format_html('{} {}', self.prefix, self.display_prefixed(logentry.event, logentry, data)) def display_prefixed(self, event: Event, logentry: LogEntry, data): return super().display(logentry, data) @@ -282,12 +282,13 @@ class OrderChangedSplit(OrderChangeLogEntryType): 'organizer': event.organizer.slug, 'code': data['new_order'] }) - return mark_safe(self.prefix + ' ' + _('Position #{posid} ({old_item}, {old_price}) split into new order: {order}').format( + return format_html( + _('Position #{posid} ({old_item}, {old_price}) split into new order: {order}'), old_item=escape(old_item), posid=data.get('positionid', '?'), - order='{}'.format(url, data['new_order']), + order=format_html(mark_safe('{}'), url, data['new_order']), old_price=money_filter(Decimal(data['old_price']), event.currency), - )) + ) @log_entry_types.new() @@ -295,8 +296,14 @@ class OrderChangedSplitFrom(OrderLogEntryType): action_type = 'pretix.event.order.changed.split_from' def display(self, logentry: LogEntry, data): - return _('This order has been created by splitting the order {order}').format( - order=data['original_order'], + url = reverse('control:event.order', kwargs={ + 'event': logentry.event.slug, + 'organizer': logentry.event.organizer.slug, + 'code': data['original_order'] + }) + return format_html( + _('This order has been created by splitting the order {order}'), + order=format_html(mark_safe('{}'), url, data['original_order']), ) @@ -343,12 +350,12 @@ class CheckinErrorLogEntryType(OrderLogEntryType): if 'datetime' in data: dt = dateutil.parser.parse(data.get('datetime')) - if abs((logentry.datetime - dt).total_seconds()) > 5 or 'forced' in data: + if abs((logentry.datetime - dt).total_seconds()) > 5 or data.get('forced'): tz = event.timezone data['datetime'] = date_format(dt.astimezone(tz), "SHORT_DATETIME_FORMAT") return str(plain_with_dt).format_map(data) - else: - return str(plain_without_dt).format_map(data) + + return str(plain_without_dt).format_map(data) @log_entry_types.new('pretix.event.checkin') diff --git a/src/pretix/control/views/global_settings.py b/src/pretix/control/views/global_settings.py index b6e2978779..362ca449b0 100644 --- a/src/pretix/control/views/global_settings.py +++ b/src/pretix/control/views/global_settings.py @@ -110,7 +110,7 @@ class MessageView(TemplateView): class LogDetailView(AdministratorPermissionRequiredMixin, View): def get(self, request, *args, **kwargs): le = get_object_or_404(LogEntry, pk=request.GET.get('pk')) - return JsonResponse({'data': le.parsed_data}) + return JsonResponse({'action_type': le.action_type, 'content_type': str(le.content_type), 'object_id': le.object_id, 'data': le.parsed_data}) class PaymentDetailView(AdministratorPermissionRequiredMixin, View): diff --git a/src/pretix/static/pretixcontrol/js/ui/main.js b/src/pretix/static/pretixcontrol/js/ui/main.js index 86a5151711..331196c34b 100644 --- a/src/pretix/static/pretixcontrol/js/ui/main.js +++ b/src/pretix/static/pretixcontrol/js/ui/main.js @@ -1065,11 +1065,17 @@ function add_log_expand_handlers(el) { } else if ($a.is("[data-expandpayment]")) { url += 'payment/' } + function format_data(data) { + return Object.entries(data).map(([key, value]) => + $("
").append( + $("").text(key + ': '), + $("").text(JSON.stringify(value, null, 2)))); + } $.getJSON(url + '?pk=' + id, function (data) { if ($a.parent().tagName === "p") { - $("
").text(JSON.stringify(data.data, null, 2)).insertAfter($a.parent());
+                $("
").append(format_data(data)).insertAfter($a.parent());
             } else {
-                $("
").text(JSON.stringify(data.data, null, 2)).appendTo($a.parent());
+                $("
").append(format_data(data)).appendTo($a.parent());
             }
             $a.remove();
         });