1+ import logging
12from django .db import transaction
23from custom_admin .audit import (
34 create_addition_admin_log_entry ,
3132from submissions .models import Submission
3233from .models import Grant , GrantConfirmPendingStatusProxy
3334from django .db .models import Exists , OuterRef , F
35+ from pretix import user_has_admission_ticket
3436
3537from django .contrib .admin import SimpleListFilter
3638from participants .models import Participant
3739from django .urls import reverse
3840from django .utils .safestring import mark_safe
3941
42+ logger = logging .getLogger (__name__ )
43+
4044EXPORT_GRANTS_FIELDS = (
4145 "name" ,
4246 "full_name" ,
@@ -407,10 +411,10 @@ 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" ,
412- "voucher_code" ,
413- "voucher_email_sent_at" ,
414418 "created" ,
415419 )
416420 list_filter = (
@@ -461,9 +465,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
461465 "total_amount" ,
462466 "applicant_reply_sent_at" ,
463467 "applicant_reply_deadline" ,
464- "pretix_voucher_id" ,
465- "voucher_code" ,
466- "voucher_email_sent_at" ,
467468 "internal_notes" ,
468469 )
469470 },
@@ -560,6 +561,29 @@ def emoji_gender(self, obj):
560561 }
561562 return emoji [gender ]
562563
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+
563587 def get_queryset (self , request ):
564588 qs = (
565589 super ()
@@ -577,8 +601,16 @@ def get_queryset(self, request):
577601 submission__speaker_id = OuterRef ("user_id" ),
578602 )
579603 ),
604+ has_voucher = Exists (
605+ ConferenceVoucher .objects .for_conference (
606+ OuterRef ("conference_id" ),
607+ ).filter (
608+ user_id = OuterRef ("user_id" ),
609+ )
610+ ),
580611 )
581612 )
613+
582614 return qs
583615
584616 class Media :
0 commit comments