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

send_push_notifications: 1–based counting, improve messages #3404

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def get_repr(self) -> str:

:return: The canonical string representation of the push notification
"""
return f"<PushNotification (id: {self.id}, channel: {self.channel}, regions: {self.regions.values_list('slug', flat=True)})>"
return f"<PushNotification (id: {self.id}, channel: {self.channel!r}, regions: {self.regions.values_list('slug', flat=True)})>"

class Meta:
#: The verbose name of the model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_repr(self) -> str:

:return: The canonical string representation of the event
"""
return f"<PushNotificationTranslation (id: {self.id}, push_notification_id: {self.push_notification.id}, title: {self.title})>"
return f"<PushNotificationTranslation (id: {self.id}, push_notification_id: {self.push_notification.id}, title: {self.title!r})>"

class Meta:
#: The verbose name of the model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def handle(self, *args: Any, **options: Any) -> None:
)

if total := len(pending_push_notifications):
for counter, push_notification in enumerate(pending_push_notifications):
for counter, push_notification in enumerate(pending_push_notifications, 1):
self.send_push_notification(counter, total, push_notification)
logger.success( # type: ignore[attr-defined]
"✔ All %d scheduled push notifications have been processed.",
Expand Down Expand Up @@ -102,14 +102,14 @@ def send_push_notification(
push_sender = FirebaseApiClient(push_notification)
if not push_sender.is_valid():
logger.error(
"Push notification %d/%d %r cannot be sent because required texts are missing",
"Push notification %d/%d cannot be sent because required texts are missing: %r",
counter,
total,
push_notification,
)
elif push_sender.send_all():
logger.success( # type: ignore[attr-defined]
"Successfully sent %d/%d %r",
"Successfully sent %d/%d: %r",
counter,
total,
push_notification,
Expand All @@ -118,14 +118,14 @@ def send_push_notification(
push_notification.save()
else:
logger.error(
"Push notification %d/%d %r could not be sent",
"Push notification %d/%d could not be sent: %r",
counter,
total,
push_notification,
)
except ImproperlyConfigured:
logger.exception(
"Push notification %d/%d %r could not be sent due to a configuration error",
"Push notification %d/%d could not be sent due to a configuration error: %r",
counter,
total,
push_notification,
Expand Down
8 changes: 4 additions & 4 deletions integreat_cms/firebase_api/firebase_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def send_pn(self, pnt: PushNotificationTranslation, region: Region) -> bool:
"topic": f"{region.slug}-{pnt.language.slug}-{self.push_notification.channel}",
"notification": {"title": pnt.title, "body": pnt.text},
"data": {
"news_id": pnt.id,
"city_code": region.slug,
"language_code": pnt.language.slug,
"group": self.push_notification.channel,
"news_id": str(pnt.id),
"city_code": str(region.slug),
"language_code": str(pnt.language.slug),
"group": str(self.push_notification.channel),
},
"apns": {
"headers": {"apns-priority": "5"},
Expand Down
Loading