From 5d98e300eabe6cd56662dcc9647ae361b627b03c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 9 Sep 2024 20:17:45 -0400 Subject: [PATCH] membershipworks: Indicate in admin events with meeting times not matching event start/end --- membershipworks/admin.py | 15 +++++++++++++++ membershipworks/models.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/membershipworks/admin.py b/membershipworks/admin.py index 192c535..2463562 100644 --- a/membershipworks/admin.py +++ b/membershipworks/admin.py @@ -169,6 +169,7 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin): "count", "cap", "category", + "meeting_times_match_event", ] list_filter = [ "category", @@ -196,6 +197,7 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin): "instructor_flat_rate", ("should_survey", "survey_email_sent"), "links", + "meeting_times_match_event", ] }, ), @@ -234,6 +236,9 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin): ) ] + def get_queryset(self, request): + return EventExt.objects.with_meeting_times_match_event() + @property def refresh_membershipworks_data(self): return run_task_action(self, "Refresh Data", scrape_events) @@ -251,6 +256,7 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin): "details_timestamp", "details", "registrations", + "meeting_times_match_event", ] return fields @@ -262,6 +268,15 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin): def duration(self, obj): return obj.duration + @admin.display( + boolean=True, + description="Meeting times match event start/end", + ordering="meeting_times_match_event", + ) + def meeting_times_match_event(self, obj) -> bool: + print(obj.meeting_times_match_event) + return obj.meeting_times_match_event + @admin.display(description="MembershipWorks links") def links(self, obj): return format_html( diff --git a/membershipworks/models.py b/membershipworks/models.py index 8502061..5e7a681 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -503,6 +503,28 @@ class EventExtQuerySet(models.QuerySet["EventExtAnnotated"]): net_revenue=F("gross_revenue") - F("total_due_to_instructor"), ) + def with_meeting_times_match_event(self): + return self.annotate( + meeting_times_match_event=( + Q( + start=Subquery( + EventMeetingTime.objects.filter(event=OuterRef("pk")) + .order_by("start") + .values("start")[:1], + output_field=models.DateTimeField(), + ) + ) + & Q( + end=Subquery( + EventMeetingTime.objects.filter(event=OuterRef("pk")) + .order_by("-end") + .values("end")[:1], + output_field=models.DateTimeField(), + ) + ) + ), + ) + class EventExtManager(models.Manager): def get_queryset(self) -> EventExtQuerySet: