From ddeedf3e153c8b63fa1569a33d382fb48f7404bb Mon Sep 17 00:00:00 2001 From: Martey Dodoo Date: Tue, 20 Dec 2016 23:39:22 -0500 Subject: [PATCH] Fix sponsor applicant edge cases. Since the applicant field of the Sponsor model is optional, we cannot be sure that all Sponsors have applicants, or that their applicants have names. If they don't, we need to return different text. --- symposion/sponsorship/admin.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/symposion/sponsorship/admin.py b/symposion/sponsorship/admin.py index 15b09439..3be94a80 100644 --- a/symposion/sponsorship/admin.py +++ b/symposion/sponsorship/admin.py @@ -62,9 +62,17 @@ def contact(self, sponsor): return mark_safe('%s' % (escape(sponsor.contact_email), escape(sponsor.contact_name))) def applicant_field(self, sponsor): - name = sponsor.applicant.get_full_name() - email = sponsor.applicant.email - return mark_safe('%s' % (escape(email), escape(name))) + if sponsor.applicant: + name = sponsor.applicant.get_full_name() + email = sponsor.applicant.email + # If applicants do not have a name set, we print + # the email address. + if not name: + name = email + return mark_safe("{}".format( + escape(email), escape(name))) + else: + return mark_safe("") applicant_field.short_description = _(u"Applicant") def get_form(self, *args, **kwargs):