Skip to content

Commit d45033f

Browse files
committed
Add columns to check user ticket and voucher status
Added `has_ticket` and `has_voucher` columns to the GrantAdmin model to determine if a user has a voucher or has redeemed a ticket. The `has_ticket` data is fetched from Pretix via the API, while the `has_voucher` data is retrieved from the `ConferenceVoucher` table.
1 parent debe3cd commit d45033f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

backend/grants/admin.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from django.db import transaction
23
from custom_admin.audit import (
34
create_addition_admin_log_entry,
@@ -31,12 +32,15 @@
3132
from submissions.models import Submission
3233
from .models import Grant, GrantConfirmPendingStatusProxy
3334
from django.db.models import Exists, OuterRef, F
35+
from pretix import user_has_admission_ticket
3436

3537
from django.contrib.admin import SimpleListFilter
3638
from participants.models import Participant
3739
from django.urls import reverse
3840
from django.utils.safestring import mark_safe
3941

42+
logger = logging.getLogger(__name__)
43+
4044
EXPORT_GRANTS_FIELDS = (
4145
"name",
4246
"full_name",
@@ -407,6 +411,8 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
407411
"accommodation_amount",
408412
"total_amount",
409413
"country_type",
414+
"user_has_ticket",
415+
"has_voucher",
410416
"applicant_reply_sent_at",
411417
"applicant_reply_deadline",
412418
"created",
@@ -555,6 +561,29 @@ def emoji_gender(self, obj):
555561
}
556562
return emoji[gender]
557563

564+
@admin.display(
565+
boolean=True,
566+
)
567+
def user_has_ticket(self, obj: Grant) -> bool:
568+
if not obj.user_id:
569+
return None
570+
571+
try:
572+
return user_has_admission_ticket(
573+
email=obj.user.email,
574+
event_organizer=obj.conference.pretix_organizer_id,
575+
event_slug=obj.conference.pretix_event_id,
576+
)
577+
except Exception as e:
578+
logger.error(e)
579+
return None
580+
581+
@admin.display(
582+
boolean=True,
583+
)
584+
def has_voucher(self, obj: Grant) -> bool:
585+
return obj.has_voucher
586+
558587
def get_queryset(self, request):
559588
qs = (
560589
super()
@@ -572,8 +601,16 @@ def get_queryset(self, request):
572601
submission__speaker_id=OuterRef("user_id"),
573602
)
574603
),
604+
has_voucher=Exists(
605+
ConferenceVoucher.objects.for_conference(
606+
OuterRef("conference_id"),
607+
).filter(
608+
user_id=OuterRef("user_id"),
609+
)
610+
),
575611
)
576612
)
613+
577614
return qs
578615

579616
class Media:

0 commit comments

Comments
 (0)