19
19
)
20
20
from sponsors import use_cases
21
21
from sponsors .forms import SponsorshipReviewAdminForm
22
+ from sponsors .exceptions import SponsorshipInvalidStatusException
22
23
from cms .admin import ContentManageableModelAdmin
23
24
24
25
@@ -101,16 +102,19 @@ class SponsorBenefitInline(admin.TabularInline):
101
102
102
103
@admin .register (Sponsorship )
103
104
class SponsorshipAdmin (admin .ModelAdmin ):
105
+ change_form_template = "sponsors/admin/sponsorship_change_form.html"
104
106
form = SponsorshipReviewAdminForm
105
107
inlines = [SponsorBenefitInline ]
106
108
list_display = [
107
109
"sponsor" ,
110
+ "status" ,
108
111
"applied_on" ,
109
112
"approved_on" ,
110
113
"start_date" ,
111
114
"end_date" ,
112
115
"display_sponsorship_link" ,
113
116
]
117
+ list_filter = ["status" ]
114
118
readonly_fields = [
115
119
"for_modified_package" ,
116
120
"sponsor" ,
@@ -260,7 +264,19 @@ def get_sponsor_primary_phone(self, obj):
260
264
get_sponsor_primary_phone .short_description = "Primary Phone"
261
265
262
266
def get_sponsor_mailing_address (self , obj ):
263
- return obj .sponsor .mailing_address
267
+ sponsor = obj .sponsor
268
+ city_row = f'{ sponsor .city } - { sponsor .get_country_display ()} ({ sponsor .country } )'
269
+ if sponsor .state :
270
+ city_row = f'{ sponsor .city } - { sponsor .state } - { sponsor .get_country_display ()} ({ sponsor .country } )'
271
+
272
+ mail_row = sponsor .mailing_address_line_1
273
+ if sponsor .mailing_address_line_2 :
274
+ mail_row += f' - { sponsor .mailing_address_line_2 } '
275
+
276
+ html = f'<p>{ city_row } </p>'
277
+ html += f'<p>{ mail_row } </p>'
278
+ html += f'<p>{ sponsor .postal_code } </p>'
279
+ return mark_safe (html )
264
280
265
281
get_sponsor_mailing_address .short_description = "Mailing/Billing Address"
266
282
@@ -276,7 +292,7 @@ def get_sponsor_contacts(self, obj):
276
292
)
277
293
html += "</ul>"
278
294
if not_primary :
279
- html = "<b>Other contacts</b><ul>"
295
+ html + = "<b>Other contacts</b><ul>"
280
296
html += "" .join (
281
297
[f"<li>{ c .name } : { c .email } / { c .phone } </li>" for c in not_primary ]
282
298
)
@@ -289,12 +305,18 @@ def reject_sponsorship_view(self, request, pk):
289
305
sponsorship = get_object_or_404 (self .get_queryset (request ), pk = pk )
290
306
291
307
if request .method .upper () == "POST" and request .POST .get ("confirm" ) == "yes" :
292
- use_case = use_cases .RejectSponsorshipApplicationUseCase .build ()
293
- use_case .execute (sponsorship )
308
+ try :
309
+ use_case = use_cases .RejectSponsorshipApplicationUseCase .build ()
310
+ use_case .execute (sponsorship )
311
+ self .message_user (
312
+ request , "Sponsorship was rejected!" , messages .SUCCESS
313
+ )
314
+ except SponsorshipInvalidStatusException as e :
315
+ self .message_user (request , str (e ), messages .ERROR )
316
+
294
317
redirect_url = reverse (
295
318
"admin:sponsors_sponsorship_change" , args = [sponsorship .pk ]
296
319
)
297
- self .message_user (request , "Sponsorship was rejected!" , messages .SUCCESS )
298
320
return redirect (redirect_url )
299
321
300
322
context = {"sponsorship" : sponsorship }
@@ -306,12 +328,18 @@ def approve_sponsorship_view(self, request, pk):
306
328
sponsorship = get_object_or_404 (self .get_queryset (request ), pk = pk )
307
329
308
330
if request .method .upper () == "POST" and request .POST .get ("confirm" ) == "yes" :
309
- sponsorship .approve ()
310
- sponsorship .save ()
331
+ try :
332
+ sponsorship .approve ()
333
+ sponsorship .save ()
334
+ self .message_user (
335
+ request , "Sponsorship was approved!" , messages .SUCCESS
336
+ )
337
+ except SponsorshipInvalidStatusException as e :
338
+ self .message_user (request , str (e ), messages .ERROR )
339
+
311
340
redirect_url = reverse (
312
341
"admin:sponsors_sponsorship_change" , args = [sponsorship .pk ]
313
342
)
314
- self .message_user (request , "Sponsorship was approved!" , messages .SUCCESS )
315
343
return redirect (redirect_url )
316
344
317
345
context = {"sponsorship" : sponsorship }
0 commit comments