Skip to content

Commit

Permalink
fix(history): sort history data directly in model, not in templatetag
Browse files Browse the repository at this point in the history
This way we don't have to parse the timestamp

Closes: #784
  • Loading branch information
b1rger committed Apr 16, 2024
1 parent 59792b6 commit ab3faf6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
1 change: 1 addition & 0 deletions apis_core/history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 0 additions & 7 deletions apis_core/history/templatetags/apis_history_templatetags.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

0 comments on commit ab3faf6

Please sign in to comment.