27
27
from pretix import create_voucher
28
28
from schedule .models import ScheduleItem
29
29
from submissions .models import Submission
30
- from .models import Grant
30
+ from .models import Grant , AidCategory , CountryAidAmount , GrantAllocation
31
31
from django .db .models import Exists , OuterRef
32
32
33
33
from django .contrib .admin import SimpleListFilter
@@ -154,31 +154,6 @@ class Meta:
154
154
export_order = EXPORT_GRANTS_FIELDS
155
155
156
156
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
-
182
157
@admin .action (description = "Send Approved/Waiting List/Rejected reply emails" )
183
158
@validate_single_conference_selection
184
159
def send_reply_emails (modeladmin , request , queryset ):
@@ -199,16 +174,6 @@ def send_reply_emails(modeladmin, request, queryset):
199
174
200
175
for grant in queryset :
201
176
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
-
212
177
now = timezone .now ()
213
178
grant .applicant_reply_deadline = timezone .datetime (
214
179
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
246
211
)
247
212
return
248
213
249
- _check_amounts_are_not_empty (grant , request )
250
-
251
214
send_grant_reply_approved_email .delay (grant_id = grant .id , is_reminder = True )
252
215
253
216
messages .info (request , f"Grant reminder sent to { grant .name } " )
@@ -352,11 +315,6 @@ class Meta:
352
315
"id" ,
353
316
"name" ,
354
317
"status" ,
355
- "approved_type" ,
356
- "ticket_amount" ,
357
- "travel_amount" ,
358
- "accommodation_amount" ,
359
- "total_amount" ,
360
318
"full_name" ,
361
319
"conference" ,
362
320
"user" ,
@@ -371,7 +329,6 @@ class Meta:
371
329
"why" ,
372
330
"notes" ,
373
331
"travelling_from" ,
374
- "country_type" ,
375
332
"applicant_reply_sent_at" ,
376
333
"applicant_reply_deadline" ,
377
334
)
@@ -409,6 +366,53 @@ def queryset(self, request, queryset):
409
366
return queryset
410
367
411
368
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
+
412
416
@admin .register (Grant )
413
417
class GrantAdmin (ExportMixin , ConferencePermissionMixin , admin .ModelAdmin ):
414
418
change_list_template = "admin/grants/grant/change_list.html"
@@ -422,12 +426,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
422
426
"emoji_gender" ,
423
427
"conference" ,
424
428
"status" ,
425
- "approved_type" ,
426
- "ticket_amount" ,
427
- "travel_amount" ,
428
- "accommodation_amount" ,
429
- "total_amount" ,
430
- "country_type" ,
431
429
"applicant_reply_sent_at" ,
432
430
"applicant_reply_deadline" ,
433
431
"voucher_code" ,
@@ -437,9 +435,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
437
435
list_filter = (
438
436
"conference" ,
439
437
"status" ,
440
- "country_type" ,
441
438
"occupation" ,
442
- "approved_type" ,
443
439
"interested_in_volunteering" ,
444
440
"needs_funds_for_travel" ,
445
441
"need_visa" ,
@@ -474,12 +470,6 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
474
470
{
475
471
"fields" : (
476
472
"status" ,
477
- "approved_type" ,
478
- "country_type" ,
479
- "ticket_amount" ,
480
- "travel_amount" ,
481
- "accommodation_amount" ,
482
- "total_amount" ,
483
473
"applicant_reply_sent_at" ,
484
474
"applicant_reply_deadline" ,
485
475
"pretix_voucher_id" ,
@@ -527,6 +517,7 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin):
527
517
},
528
518
),
529
519
)
520
+ inlines = [GrantAllocationInline ]
530
521
531
522
@admin .display (description = "User" , ordering = "user__full_name" )
532
523
def user_display_name (self , obj ):
0 commit comments