Skip to content

Commit b153985

Browse files
feat: add is_scheduled column to submission admin
Add a new column in the submission admin that shows whether a submission is scheduled in the conference. The column displays a boolean checkmark using Django's admin.display decorator with boolean=True. - Add `is_scheduled` to list_display in SubmissionAdmin - Implement `is_scheduled` method that checks if submission has schedule items - Optimize queryset with prefetch_related for schedule_items to avoid N+1 - Add tests for the new is_scheduled method Closes #4585 Co-authored-by: Marco Acierno <marcoacierno@users.noreply.github.com>
1 parent 62a0f4e commit b153985

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

backend/submissions/admin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class SubmissionAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
222222
"speaker_display_name",
223223
"type",
224224
"status",
225+
"is_scheduled",
225226
"conference",
226227
"open_submission",
227228
"inline_tags",
@@ -306,6 +307,15 @@ def speaker_display_name(self, obj):
306307
def inline_tags(self, obj):
307308
return ", ".join([tag.name for tag in obj.tags.all()])
308309

310+
@admin.display(
311+
description="Scheduled",
312+
boolean=True,
313+
)
314+
def is_scheduled(self, obj):
315+
# Use bool() on all() to utilize prefetch_related data instead of exists()
316+
# which would issue an additional query
317+
return bool(obj.schedule_items.all())
318+
309319
@admin.display(
310320
description="Open",
311321
)
@@ -318,7 +328,7 @@ def open_submission(self, obj): # pragma: no cover
318328
)
319329

320330
def get_queryset(self, request):
321-
return super().get_queryset(request).prefetch_related("tags")
331+
return super().get_queryset(request).prefetch_related("tags", "schedule_items")
322332

323333
class Media:
324334
js = ["admin/js/jquery.init.js"]

backend/submissions/tests/test_admin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from notifications.tests.factories import EmailTemplateFactory
44
from notifications.models import EmailTemplateIdentifier, SentEmail
55
import pytest
6+
from schedule.tests.factories import ScheduleItemFactory
67
from submissions.admin import (
8+
SubmissionAdmin,
79
apply_and_notify_status_change,
810
send_proposal_in_waiting_list_email_action,
911
send_proposal_rejected_email_action,
@@ -14,6 +16,25 @@
1416
pytestmark = pytest.mark.django_db
1517

1618

19+
def test_is_scheduled_returns_true_when_submission_has_schedule_items():
20+
submission = SubmissionFactory()
21+
ScheduleItemFactory(
22+
submission=submission,
23+
conference=submission.conference,
24+
type="submission",
25+
)
26+
27+
admin = SubmissionAdmin(model=Submission, admin_site=None)
28+
assert admin.is_scheduled(submission) is True
29+
30+
31+
def test_is_scheduled_returns_false_when_submission_has_no_schedule_items():
32+
submission = SubmissionFactory()
33+
34+
admin = SubmissionAdmin(model=Submission, admin_site=None)
35+
assert admin.is_scheduled(submission) is False
36+
37+
1738
def test_send_proposal_rejected_email_action(rf, mocker):
1839
mock_task = mocker.patch("submissions.admin.send_proposal_rejected_email")
1940
mocker.patch("submissions.admin.messages")

0 commit comments

Comments
 (0)