Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove voucher columns from Grant model #4335

Merged
merged 2 commits into from
Feb 18, 2025
Merged
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
42 changes: 37 additions & 5 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,10 +411,10 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
"accommodation_amount",
"total_amount",
"country_type",
"user_has_ticket",
"has_voucher",
"applicant_reply_sent_at",
"applicant_reply_deadline",
"voucher_code",
"voucher_email_sent_at",
"created",
)
list_filter = (
Expand Down Expand Up @@ -461,9 +465,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
"total_amount",
"applicant_reply_sent_at",
"applicant_reply_deadline",
"pretix_voucher_id",
Copy link
Member

@marcoacierno marcoacierno Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be beneficial to expose in this admin something that checks if a ConferenceVoucher exists for this grant user, so we don't need to go to a different UI to check if this grant has the voucher or not. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah was thinking about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the columns has_voucher and has_ticket

"voucher_code",
"voucher_email_sent_at",
"internal_notes",
)
},
Expand Down Expand Up @@ -560,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 @@ -577,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2025-01-28 16:45

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('grants', '0027_grantconfirmpendingstatusproxy'),
]

operations = [
migrations.RemoveField(
model_name='grant',
name='pretix_voucher_id',
),
migrations.RemoveField(
model_name='grant',
name='voucher_code',
),
migrations.RemoveField(
model_name='grant',
name='voucher_email_sent_at',
),
]
13 changes: 0 additions & 13 deletions backend/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,6 @@ class ApprovedType(models.TextChoices):
)

# Voucher Management
voucher_code = models.TextField(
help_text=_("Voucher code generated for this grant."),
blank=True,
null=True,
)
pretix_voucher_id = models.IntegerField(
help_text=_("ID of the voucher in the Pretix database"),
blank=True,
null=True,
)
voucher_email_sent_at = models.DateTimeField(
help_text=_("When the email was last sent"), blank=True, null=True
)
internal_notes = models.TextField(
_("Internal Notes"),
help_text=_("Internal notes only available to the Financial Aid Commettie"),
Expand Down