Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort news/push notifications #3164

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion integreat_cms/api/v3/push_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from typing import TYPE_CHECKING

from django.conf import settings
from django.db.models import F
from django.db.models.functions import Greatest
from django.http import JsonResponse
from django.utils import timezone

Expand Down Expand Up @@ -42,7 +44,10 @@ def sent_push_notifications(
)
.filter(language__slug=language_slug)
.filter(push_notification__draft=False)
.order_by("-last_updated")
.annotate(
display_date=Greatest(F("last_updated"), F("push_notification__sent_date"))
)
.order_by("-display_date")
)
if channel != "all":
query_result = query_result.filter(push_notification__channel=channel)
Expand All @@ -67,6 +72,7 @@ def transform_notification(pnt: PushNotificationTranslation) -> dict[str, Any]:
"message": pnt.get_text(),
"timestamp": pnt.last_updated, # deprecated field in the future
"last_updated": timezone.localtime(pnt.last_updated),
"display_date": pnt.display_date,
"channel": pnt.push_notification.channel,
"available_languages": available_languages_dict,
}
Loading