Merge pull request #46 from WDI-Ideas/development
saving interested and going notifications into database if enabled False
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user