Skip to content

Commit

Permalink
Add columns to check user ticket and voucher status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
estyxx committed Feb 9, 2025
1 parent debe3cd commit d45033f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions backend/grants/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from django.db import transaction
from custom_admin.audit import (
create_addition_admin_log_entry,
Expand Down Expand Up @@ -31,12 +32,15 @@
from submissions.models import Submission
from .models import Grant, GrantConfirmPendingStatusProxy
from django.db.models import Exists, OuterRef, F
from pretix import user_has_admission_ticket

from django.contrib.admin import SimpleListFilter
from participants.models import Participant
from django.urls import reverse
from django.utils.safestring import mark_safe

logger = logging.getLogger(__name__)

EXPORT_GRANTS_FIELDS = (
"name",
"full_name",
Expand Down Expand Up @@ -407,6 +411,8 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
"accommodation_amount",
"total_amount",
"country_type",
"user_has_ticket",
"has_voucher",
"applicant_reply_sent_at",
"applicant_reply_deadline",
"created",
Expand Down Expand Up @@ -555,6 +561,29 @@ def emoji_gender(self, obj):
}
return emoji[gender]

@admin.display(
boolean=True,
)
def user_has_ticket(self, obj: Grant) -> bool:
if not obj.user_id:
return None

try:
return user_has_admission_ticket(
email=obj.user.email,
event_organizer=obj.conference.pretix_organizer_id,
event_slug=obj.conference.pretix_event_id,
)
except Exception as e:
logger.error(e)
return None

@admin.display(
boolean=True,
)
def has_voucher(self, obj: Grant) -> bool:
return obj.has_voucher

def get_queryset(self, request):
qs = (
super()
Expand All @@ -572,8 +601,16 @@ def get_queryset(self, request):
submission__speaker_id=OuterRef("user_id"),
)
),
has_voucher=Exists(
ConferenceVoucher.objects.for_conference(
OuterRef("conference_id"),
).filter(
user_id=OuterRef("user_id"),
)
),
)
)

return qs

class Media:
Expand Down

0 comments on commit d45033f

Please sign in to comment.