Skip to content

Commit 2b912e0

Browse files
committed
WIP
1 parent 7397b7a commit 2b912e0

12 files changed

+680
-410
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 5.0.7 on 2024-08-24 16:08
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
(
9+
"conferences",
10+
"0044_remove_conference_slack_new_grant_reply_incoming_incoming_webhook_url_and_more",
11+
),
12+
]
13+
14+
operations = [
15+
migrations.RemoveField(
16+
model_name="conference",
17+
name="grants_default_accommodation_amount",
18+
),
19+
migrations.RemoveField(
20+
model_name="conference",
21+
name="grants_default_ticket_amount",
22+
),
23+
migrations.RemoveField(
24+
model_name="conference",
25+
name="grants_default_travel_from_europe_amount",
26+
),
27+
migrations.RemoveField(
28+
model_name="conference",
29+
name="grants_default_travel_from_extra_eu_amount",
30+
),
31+
migrations.RemoveField(
32+
model_name="conference",
33+
name="grants_default_travel_from_italy_amount",
34+
),
35+
]

backend/conferences/models/conference.py

-41
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,6 @@ class Conference(GeoLocalizedModel, TimeFramedModel, TimeStampedModel):
9494
default="",
9595
)
9696

97-
grants_default_ticket_amount = models.DecimalField(
98-
verbose_name=_("grants default ticket amount"),
99-
null=True,
100-
blank=True,
101-
max_digits=6,
102-
decimal_places=2,
103-
default=None,
104-
)
105-
grants_default_accommodation_amount = models.DecimalField(
106-
verbose_name=_("grants default accommodation amount"),
107-
null=True,
108-
blank=True,
109-
max_digits=6,
110-
decimal_places=2,
111-
default=None,
112-
)
113-
grants_default_travel_from_italy_amount = models.DecimalField(
114-
verbose_name=_("grants default travel from Italy amount"),
115-
null=True,
116-
blank=True,
117-
max_digits=6,
118-
decimal_places=2,
119-
default=None,
120-
)
121-
grants_default_travel_from_europe_amount = models.DecimalField(
122-
verbose_name=_("grants default travel from Europe amount"),
123-
null=True,
124-
blank=True,
125-
max_digits=6,
126-
decimal_places=2,
127-
default=None,
128-
)
129-
grants_default_travel_from_extra_eu_amount = models.DecimalField(
130-
verbose_name=_("grants default travel from Extra EU amount"),
131-
null=True,
132-
blank=True,
133-
max_digits=6,
134-
decimal_places=2,
135-
default=None,
136-
)
137-
13897
video_title_template = models.TextField(
13998
default="",
14099
blank=True,

backend/grants/admin.py

+49-58
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pretix import create_voucher
2828
from schedule.models import ScheduleItem
2929
from submissions.models import Submission
30-
from .models import Grant
30+
from .models import Grant, AidCategory, CountryAidAmount, GrantAllocation
3131
from django.db.models import Exists, OuterRef
3232

3333
from django.contrib.admin import SimpleListFilter
@@ -154,31 +154,6 @@ class Meta:
154154
export_order = EXPORT_GRANTS_FIELDS
155155

156156

157-
def _check_amounts_are_not_empty(grant: Grant, request):
158-
if grant.total_amount is None:
159-
messages.error(
160-
request,
161-
f"Grant for {grant.name} is missing 'Total Amount'!",
162-
)
163-
return False
164-
165-
if grant.has_approved_accommodation() and grant.accommodation_amount is None:
166-
messages.error(
167-
request,
168-
f"Grant for {grant.name} is missing 'Accommodation Amount'!",
169-
)
170-
return False
171-
172-
if grant.has_approved_travel() and grant.travel_amount is None:
173-
messages.error(
174-
request,
175-
f"Grant for {grant.name} is missing 'Travel Amount'!",
176-
)
177-
return False
178-
179-
return True
180-
181-
182157
@admin.action(description="Send Approved/Waiting List/Rejected reply emails")
183158
@validate_single_conference_selection
184159
def send_reply_emails(modeladmin, request, queryset):
@@ -199,16 +174,6 @@ def send_reply_emails(modeladmin, request, queryset):
199174

200175
for grant in queryset:
201176
if grant.status in (Grant.Status.approved,):
202-
if grant.approved_type is None:
203-
messages.error(
204-
request,
205-
f"Grant for {grant.name} is missing 'Grant Approved Type'!",
206-
)
207-
return
208-
209-
if not _check_amounts_are_not_empty(grant, request):
210-
return
211-
212177
now = timezone.now()
213178
grant.applicant_reply_deadline = timezone.datetime(
214179
now.year, now.month, now.day, 23, 59, 59, tzinfo=UTC
@@ -246,8 +211,6 @@ def send_grant_reminder_to_waiting_for_confirmation(modeladmin, request, queryse
246211
)
247212
return
248213

249-
_check_amounts_are_not_empty(grant, request)
250-
251214
send_grant_reply_approved_email.delay(grant_id=grant.id, is_reminder=True)
252215

253216
messages.info(request, f"Grant reminder sent to {grant.name}")
@@ -352,11 +315,6 @@ class Meta:
352315
"id",
353316
"name",
354317
"status",
355-
"approved_type",
356-
"ticket_amount",
357-
"travel_amount",
358-
"accommodation_amount",
359-
"total_amount",
360318
"full_name",
361319
"conference",
362320
"user",
@@ -371,7 +329,6 @@ class Meta:
371329
"why",
372330
"notes",
373331
"travelling_from",
374-
"country_type",
375332
"applicant_reply_sent_at",
376333
"applicant_reply_deadline",
377334
)
@@ -409,6 +366,53 @@ def queryset(self, request, queryset):
409366
return queryset
410367

411368

369+
@admin.register(AidCategory)
370+
class AidCategoryAdmin(admin.ModelAdmin):
371+
list_display = (
372+
"name",
373+
"conference",
374+
"category",
375+
"max_amount",
376+
"included_by_default",
377+
)
378+
379+
list_filter = ("conference", "category")
380+
search_fields = ("name", "description", "conference", "max_amount")
381+
382+
383+
@admin.register(CountryAidAmount)
384+
class CountryAidAmountAdmin(admin.ModelAdmin):
385+
list_display = ("conference", "_country", "max_amount")
386+
387+
def _country(self, obj):
388+
if obj.country:
389+
country = countries.get(code=obj.country)
390+
if country:
391+
return f"{country.name} {country.emoji}"
392+
393+
return ""
394+
395+
396+
class GrantAllocationFormSet:
397+
pass
398+
399+
400+
class GrantAllocationInline(admin.StackedInline):
401+
model = GrantAllocation
402+
403+
def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
404+
if db_field.name == "category":
405+
grant_id = request.resolver_match.kwargs.get("object_id")
406+
if grant_id:
407+
grant = Grant.objects.get(pk=grant_id)
408+
kwargs["queryset"] = AidCategory.objects.filter(
409+
conference=grant.conference
410+
)
411+
else:
412+
kwargs["queryset"] = AidCategory.objects.none()
413+
return super().formfield_for_foreignkey(db_field, request, **kwargs)
414+
415+
412416
@admin.register(Grant)
413417
class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
414418
change_list_template = "admin/grants/grant/change_list.html"
@@ -422,12 +426,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
422426
"emoji_gender",
423427
"conference",
424428
"status",
425-
"approved_type",
426-
"ticket_amount",
427-
"travel_amount",
428-
"accommodation_amount",
429-
"total_amount",
430-
"country_type",
431429
"applicant_reply_sent_at",
432430
"applicant_reply_deadline",
433431
"voucher_code",
@@ -437,9 +435,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
437435
list_filter = (
438436
"conference",
439437
"status",
440-
"country_type",
441438
"occupation",
442-
"approved_type",
443439
"interested_in_volunteering",
444440
"needs_funds_for_travel",
445441
"need_visa",
@@ -474,12 +470,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
474470
{
475471
"fields": (
476472
"status",
477-
"approved_type",
478-
"country_type",
479-
"ticket_amount",
480-
"travel_amount",
481-
"accommodation_amount",
482-
"total_amount",
483473
"applicant_reply_sent_at",
484474
"applicant_reply_deadline",
485475
"pretix_voucher_id",
@@ -527,6 +517,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
527517
},
528518
),
529519
)
520+
inlines = [GrantAllocationInline]
530521

531522
@admin.display(description="User", ordering="user__full_name")
532523
def user_display_name(self, obj):

0 commit comments

Comments
 (0)