From ab3faf6059dfcd4fad89a564b01e6a51f224672a Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 16 Apr 2024 10:47:55 +0200 Subject: [PATCH] fix(history): sort history data directly in model, not in templatetag This way we don't have to parse the timestamp Closes: #784 --- apis_core/history/models.py | 1 + .../history/templatetags/apis_history_templatetags.py | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/apis_core/history/models.py b/apis_core/history/models.py index 53a9d7263..366fce3fa 100644 --- a/apis_core/history/models.py +++ b/apis_core/history/models.py @@ -160,6 +160,7 @@ def get_history_data(self): data.append(entry) prev_entry = entry data += [x for x in self.history.all()] + data = sorted(data, key=lambda x: x.history_date, reverse=True) return data def __init__(self, *args: Any, **kwargs: Any) -> None: diff --git a/apis_core/history/templatetags/apis_history_templatetags.py b/apis_core/history/templatetags/apis_history_templatetags.py index a70fb37a7..20f4af8d7 100644 --- a/apis_core/history/templatetags/apis_history_templatetags.py +++ b/apis_core/history/templatetags/apis_history_templatetags.py @@ -1,6 +1,4 @@ -from datetime import datetime from apis_core.history.serializers import HistoryLogSerializer -from apis_core.history.views import convert_timestamps from django import template from apis_core.history.utils import triple_sidebar_history @@ -18,9 +16,4 @@ def object_relations_history(context, detail=True): @register.filter def get_history_data(obj): data = HistoryLogSerializer(obj.get_history_data(), many=True).data - data = sorted( - [convert_timestamps(x) for x in data], - key=lambda x: datetime.strptime(x["timestamp"], "%d.%m.%Y %H:%M"), - reverse=True, - ) return data