|
10 | 10 | from datetime import timedelta |
11 | 11 | from typing import Dict, List, Optional |
12 | 12 | from countries.filters import CountryFilter |
13 | | -from django import forms |
14 | 13 | from django.contrib import admin, messages |
15 | 14 | from django.db.models.query import QuerySet |
16 | 15 | from django.utils import timezone |
|
30 | 29 | from django.db.models import Exists, OuterRef |
31 | 30 |
|
32 | 31 | from django.contrib.admin import SimpleListFilter |
| 32 | +from participants.models import Participant |
33 | 33 |
|
34 | 34 | EXPORT_GRANTS_FIELDS = ( |
35 | 35 | "name", |
@@ -351,39 +351,6 @@ def mark_rejected_and_send_email(modeladmin, request, queryset): |
351 | 351 | messages.info(request, f"Sent Rejected reply email to {grant.name}") |
352 | 352 |
|
353 | 353 |
|
354 | | -class GrantAdminForm(forms.ModelForm): |
355 | | - class Meta: |
356 | | - model = Grant |
357 | | - fields = ( |
358 | | - "id", |
359 | | - "name", |
360 | | - "status", |
361 | | - "approved_type", |
362 | | - "ticket_amount", |
363 | | - "travel_amount", |
364 | | - "accommodation_amount", |
365 | | - "total_amount", |
366 | | - "full_name", |
367 | | - "conference", |
368 | | - "user", |
369 | | - "age_group", |
370 | | - "gender", |
371 | | - "occupation", |
372 | | - "grant_type", |
373 | | - "python_usage", |
374 | | - "been_to_other_events", |
375 | | - "needs_funds_for_travel", |
376 | | - "why", |
377 | | - "notes", |
378 | | - "nationality", |
379 | | - "departure_country", |
380 | | - "departure_city", |
381 | | - "country_type", |
382 | | - "applicant_reply_sent_at", |
383 | | - "applicant_reply_deadline", |
384 | | - ) |
385 | | - |
386 | | - |
387 | 354 | class IsProposedSpeakerFilter(SimpleListFilter): |
388 | 355 | title = "Is Proposed Speaker" |
389 | 356 | parameter_name = "is_proposed_speaker" |
@@ -420,7 +387,6 @@ def queryset(self, request, queryset): |
420 | 387 | class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin): |
421 | 388 | change_list_template = "admin/grants/grant/change_list.html" |
422 | 389 | resource_class = GrantResource |
423 | | - form = GrantAdminForm |
424 | 390 | list_display = ( |
425 | 391 | "user_display_name", |
426 | 392 | "country", |
@@ -524,16 +490,27 @@ class GrantAdmin(ExportMixin, ConferencePermissionMixin, admin.ModelAdmin): |
524 | 490 | "been_to_other_events", |
525 | 491 | "community_contribution", |
526 | 492 | "notes", |
527 | | - "website", |
528 | | - "twitter_handle", |
529 | | - "github_handle", |
530 | | - "linkedin_url", |
531 | | - "mastodon_handle", |
532 | 493 | ) |
533 | 494 | }, |
534 | 495 | ), |
535 | 496 | ) |
536 | 497 |
|
| 498 | + def change_view(self, request, object_id, form_url="", extra_context=None): |
| 499 | + extra_context = extra_context or {} |
| 500 | + grant = self.model.objects.get(id=object_id) |
| 501 | + owner_id = grant.user_id |
| 502 | + extra_context["participant"] = Participant.objects.filter( |
| 503 | + user_id=owner_id, |
| 504 | + conference_id=grant.conference_id, |
| 505 | + ).first() |
| 506 | + |
| 507 | + return super().change_view( |
| 508 | + request, |
| 509 | + object_id, |
| 510 | + form_url, |
| 511 | + extra_context=extra_context, |
| 512 | + ) |
| 513 | + |
537 | 514 | @admin.display(description="User", ordering="user__full_name") |
538 | 515 | def user_display_name(self, obj): |
539 | 516 | if obj.user_id: |
|
0 commit comments