Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
estyxx committed Aug 30, 2024
1 parent 7397b7a commit 2b912e0
Show file tree
Hide file tree
Showing 12 changed files with 680 additions and 410 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.0.7 on 2024-08-24 16:08

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
(
"conferences",
"0044_remove_conference_slack_new_grant_reply_incoming_incoming_webhook_url_and_more",
),
]

operations = [
migrations.RemoveField(
model_name="conference",
name="grants_default_accommodation_amount",
),
migrations.RemoveField(
model_name="conference",
name="grants_default_ticket_amount",
),
migrations.RemoveField(
model_name="conference",
name="grants_default_travel_from_europe_amount",
),
migrations.RemoveField(
model_name="conference",
name="grants_default_travel_from_extra_eu_amount",
),
migrations.RemoveField(
model_name="conference",
name="grants_default_travel_from_italy_amount",
),
]
41 changes: 0 additions & 41 deletions backend/conferences/models/conference.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,47 +94,6 @@ class Conference(GeoLocalizedModel, TimeFramedModel, TimeStampedModel):
default="",
)

grants_default_ticket_amount = models.DecimalField(
verbose_name=_("grants default ticket amount"),
null=True,
blank=True,
max_digits=6,
decimal_places=2,
default=None,
)
grants_default_accommodation_amount = models.DecimalField(
verbose_name=_("grants default accommodation amount"),
null=True,
blank=True,
max_digits=6,
decimal_places=2,
default=None,
)
grants_default_travel_from_italy_amount = models.DecimalField(
verbose_name=_("grants default travel from Italy amount"),
null=True,
blank=True,
max_digits=6,
decimal_places=2,
default=None,
)
grants_default_travel_from_europe_amount = models.DecimalField(
verbose_name=_("grants default travel from Europe amount"),
null=True,
blank=True,
max_digits=6,
decimal_places=2,
default=None,
)
grants_default_travel_from_extra_eu_amount = models.DecimalField(
verbose_name=_("grants default travel from Extra EU amount"),
null=True,
blank=True,
max_digits=6,
decimal_places=2,
default=None,
)

video_title_template = models.TextField(
default="",
blank=True,
Expand Down
107 changes: 49 additions & 58 deletions backend/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pretix import create_voucher
from schedule.models import ScheduleItem
from submissions.models import Submission
from .models import Grant
from .models import Grant, AidCategory, CountryAidAmount, GrantAllocation
from django.db.models import Exists, OuterRef

from django.contrib.admin import SimpleListFilter
Expand Down Expand Up @@ -154,31 +154,6 @@ class Meta:
export_order = EXPORT_GRANTS_FIELDS


def _check_amounts_are_not_empty(grant: Grant, request):
if grant.total_amount is None:
messages.error(
request,
f"Grant for {grant.name} is missing 'Total Amount'!",
)
return False

if grant.has_approved_accommodation() and grant.accommodation_amount is None:
messages.error(
request,
f"Grant for {grant.name} is missing 'Accommodation Amount'!",
)
return False

if grant.has_approved_travel() and grant.travel_amount is None:
messages.error(
request,
f"Grant for {grant.name} is missing 'Travel Amount'!",
)
return False

return True


@admin.action(description="Send Approved/Waiting List/Rejected reply emails")
@validate_single_conference_selection
def send_reply_emails(modeladmin, request, queryset):
Expand All @@ -199,16 +174,6 @@ def send_reply_emails(modeladmin, request, queryset):

for grant in queryset:
if grant.status in (Grant.Status.approved,):
if grant.approved_type is None:
messages.error(
request,
f"Grant for {grant.name} is missing 'Grant Approved Type'!",
)
return

if not _check_amounts_are_not_empty(grant, request):
return

now = timezone.now()
grant.applicant_reply_deadline = timezone.datetime(
now.year, now.month, now.day, 23, 59, 59, tzinfo=UTC
Expand Down Expand Up @@ -246,8 +211,6 @@ def send_grant_reminder_to_waiting_for_confirmation(modeladmin, request, queryse
)
return

_check_amounts_are_not_empty(grant, request)

send_grant_reply_approved_email.delay(grant_id=grant.id, is_reminder=True)

messages.info(request, f"Grant reminder sent to {grant.name}")
Expand Down Expand Up @@ -352,11 +315,6 @@ class Meta:
"id",
"name",
"status",
"approved_type",
"ticket_amount",
"travel_amount",
"accommodation_amount",
"total_amount",
"full_name",
"conference",
"user",
Expand All @@ -371,7 +329,6 @@ class Meta:
"why",
"notes",
"travelling_from",
"country_type",
"applicant_reply_sent_at",
"applicant_reply_deadline",
)
Expand Down Expand Up @@ -409,6 +366,53 @@ def queryset(self, request, queryset):
return queryset


@admin.register(AidCategory)
class AidCategoryAdmin(admin.ModelAdmin):
list_display = (
"name",
"conference",
"category",
"max_amount",
"included_by_default",
)

list_filter = ("conference", "category")
search_fields = ("name", "description", "conference", "max_amount")


@admin.register(CountryAidAmount)
class CountryAidAmountAdmin(admin.ModelAdmin):
list_display = ("conference", "_country", "max_amount")

def _country(self, obj):
if obj.country:
country = countries.get(code=obj.country)
if country:
return f"{country.name} {country.emoji}"

return ""


class GrantAllocationFormSet:
pass


class GrantAllocationInline(admin.StackedInline):
model = GrantAllocation

def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
if db_field.name == "category":
grant_id = request.resolver_match.kwargs.get("object_id")
if grant_id:
grant = Grant.objects.get(pk=grant_id)
kwargs["queryset"] = AidCategory.objects.filter(
conference=grant.conference
)
else:
kwargs["queryset"] = AidCategory.objects.none()
return super().formfield_for_foreignkey(db_field, request, **kwargs)


@admin.register(Grant)
class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
change_list_template = "admin/grants/grant/change_list.html"
Expand All @@ -422,12 +426,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
"emoji_gender",
"conference",
"status",
"approved_type",
"ticket_amount",
"travel_amount",
"accommodation_amount",
"total_amount",
"country_type",
"applicant_reply_sent_at",
"applicant_reply_deadline",
"voucher_code",
Expand All @@ -437,9 +435,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
list_filter = (
"conference",
"status",
"country_type",
"occupation",
"approved_type",
"interested_in_volunteering",
"needs_funds_for_travel",
"need_visa",
Expand Down Expand Up @@ -474,12 +470,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
{
"fields": (
"status",
"approved_type",
"country_type",
"ticket_amount",
"travel_amount",
"accommodation_amount",
"total_amount",
"applicant_reply_sent_at",
"applicant_reply_deadline",
"pretix_voucher_id",
Expand Down Expand Up @@ -527,6 +517,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
},
),
)
inlines = [GrantAllocationInline]

@admin.display(description="User", ordering="user__full_name")
def user_display_name(self, obj):
Expand Down
Loading

0 comments on commit 2b912e0

Please sign in to comment.