From 15265b191456e9afc72d7109b477802fe9e752e7 Mon Sep 17 00:00:00 2001 From: rizwanisready Date: Fri, 7 Jun 2024 17:06:47 +0530 Subject: [PATCH] saving interested and going notifications into database if enabled False --- manage_events/report.py | 6 +-- .../management/commands/interested_going.py | 40 +++++++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/manage_events/report.py b/manage_events/report.py index 7d78216..5f571b4 100644 --- a/manage_events/report.py +++ b/manage_events/report.py @@ -118,15 +118,15 @@ def generate_event_report(user_id): report_data = [] for event in events: # Collecting individual counts for each event - favorites_count = event.favorites_set.count() + favorites_count = event.favorites.count() interested_count = event.interaction_event.filter( status=EventInteractionType.INTERESTED ).count() going_count = event.interaction_event.filter( status=EventInteractionType.GOING ).count() - reviews_count = event.reviews_set.filter(active=True, deleted=False).count() - views_count = event.views_set.count() + reviews_count = event.reviews.filter(active=True, deleted=False).count() + views_count = event.views.count() # Collecting views and locations views = EventView.objects.filter(event=event) diff --git a/manage_notifications/management/commands/interested_going.py b/manage_notifications/management/commands/interested_going.py index 1d8ba6d..bddc788 100644 --- a/manage_notifications/management/commands/interested_going.py +++ b/manage_notifications/management/commands/interested_going.py @@ -29,21 +29,7 @@ class Command(BaseCommand): principal_interaction.event.title ) # Accessing event title correctly message = f"{event_title} is going live tomorrow." - - try: - player_id = ( - principal_interaction.principal.player_id - ) # Correctly access player_id from principal - except AttributeError: - continue - notification_title = "Event Reminder" - notification_payload = { - "headings": {"en": notification_title}, - "contents": {"en": message}, - "include_player_ids": [player_id], - } - response = client.send_notification(notification_payload) in_app_notification = InAppNotification( principal=principal_interaction.principal, @@ -53,6 +39,28 @@ class Command(BaseCommand): ) in_app_notification.save() + notification_settings = IAmPrincipalNotificationSettings.objects.filter( + principal=principal_interaction.principal, + notification_category=NotificationCategoryChoices.EVENT, + is_enabled=True, + ).exists() + + if notification_settings: + try: + player_id = ( + principal_interaction.principal.player_id + ) # Correctly access player_id from principal + if player_id: + notification_payload = { + "headings": {"en": notification_title}, + "contents": {"en": message}, + "include_player_ids": [player_id], + } + response = client.send_notification(notification_payload) + except AttributeError: + # Handle the case where player_id does not exist + continue + self.stdout.write(self.style.SUCCESS("Event reminders sent successfully")) def eligible_event_interactions(self): @@ -64,6 +72,6 @@ class Command(BaseCommand): event__created_by__is_active=True, principal__is_active=True, status__in=[EventInteractionType.GOING, EventInteractionType.INTERESTED], - principal__notifications_principal__notification_category=NotificationCategoryChoices.EVENT, - principal__notifications_principal__is_enabled=True, + # principal__notifications_principal__notification_category=NotificationCategoryChoices.EVENT, + # principal__notifications_principal__is_enabled=True, ).select_related("principal", "event")