Skip to content
Open
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
12 changes: 11 additions & 1 deletion backend/submissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class SubmissionAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
"speaker_display_name",
"type",
"status",
"is_scheduled",
"conference",
"open_submission",
"inline_tags",
Expand Down Expand Up @@ -306,6 +307,15 @@ def speaker_display_name(self, obj):
def inline_tags(self, obj):
return ", ".join([tag.name for tag in obj.tags.all()])

@admin.display(
description="Scheduled",
boolean=True,
)
def is_scheduled(self, obj):
# Use bool() on all() to utilize prefetch_related data instead of exists()
# which would issue an additional query
return bool(obj.schedule_items.all())

@admin.display(
description="Open",
)
Expand All @@ -318,7 +328,7 @@ def open_submission(self, obj): # pragma: no cover
)

def get_queryset(self, request):
return super().get_queryset(request).prefetch_related("tags")
return super().get_queryset(request).prefetch_related("tags", "schedule_items")

class Media:
js = ["admin/js/jquery.init.js"]
Expand Down
21 changes: 21 additions & 0 deletions backend/submissions/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from notifications.tests.factories import EmailTemplateFactory
from notifications.models import EmailTemplateIdentifier, SentEmail
import pytest
from schedule.tests.factories import ScheduleItemFactory
from submissions.admin import (
SubmissionAdmin,
apply_and_notify_status_change,
send_proposal_in_waiting_list_email_action,
send_proposal_rejected_email_action,
Expand All @@ -14,6 +16,25 @@
pytestmark = pytest.mark.django_db


def test_is_scheduled_returns_true_when_submission_has_schedule_items():
submission = SubmissionFactory()
ScheduleItemFactory(
submission=submission,
conference=submission.conference,
type="submission",
)

admin = SubmissionAdmin(model=Submission, admin_site=None)
assert admin.is_scheduled(submission) is True


def test_is_scheduled_returns_false_when_submission_has_no_schedule_items():
submission = SubmissionFactory()

admin = SubmissionAdmin(model=Submission, admin_site=None)
assert admin.is_scheduled(submission) is False


def test_send_proposal_rejected_email_action(rf, mocker):
mock_task = mocker.patch("submissions.admin.send_proposal_rejected_email")
mocker.patch("submissions.admin.messages")
Expand Down
Loading