Skip to content

Commit 863d7f6

Browse files
authored
Remove voucher columns from Grant model (#4335)
1 parent 644f3fd commit 863d7f6

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

backend/grants/admin.py

Lines changed: 37 additions & 5 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,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:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.1.4 on 2025-01-28 16:45
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('grants', '0027_grantconfirmpendingstatusproxy'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='grant',
15+
name='pretix_voucher_id',
16+
),
17+
migrations.RemoveField(
18+
model_name='grant',
19+
name='voucher_code',
20+
),
21+
migrations.RemoveField(
22+
model_name='grant',
23+
name='voucher_email_sent_at',
24+
),
25+
]

backend/grants/models.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,6 @@ class ApprovedType(models.TextChoices):
207207
)
208208

209209
# Voucher Management
210-
voucher_code = models.TextField(
211-
help_text=_("Voucher code generated for this grant."),
212-
blank=True,
213-
null=True,
214-
)
215-
pretix_voucher_id = models.IntegerField(
216-
help_text=_("ID of the voucher in the Pretix database"),
217-
blank=True,
218-
null=True,
219-
)
220-
voucher_email_sent_at = models.DateTimeField(
221-
help_text=_("When the email was last sent"), blank=True, null=True
222-
)
223210
internal_notes = models.TextField(
224211
_("Internal Notes"),
225212
help_text=_("Internal notes only available to the Financial Aid Commettie"),

0 commit comments

Comments
 (0)