From 40e167556c9fdfcb1283b0c12609fe9631b437f4 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 31 May 2011 11:04:26 +0100 Subject: [PATCH] Check we have a valid char/corp before doing other checks, fixes bug #64 --- app/hr/forms.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/hr/forms.py b/app/hr/forms.py index 7f9e467..dff0c68 100644 --- a/app/hr/forms.py +++ b/app/hr/forms.py @@ -46,11 +46,15 @@ def CreateApplicationForm(user): def clean(self): - if self.cleaned_data['character'].corporation == self.cleaned_data['corporation']: - raise forms.ValidationError("%s is already a member of %s" % (self.cleaned_data['character'], self.cleaned_data['corporation'])) - if not self.cleaned_data['character'].account.api_keytype >= self.cleaned_data['corporation'].application_config.api_required: - raise forms.ValidationError("%s requires a %s API key for this application" % (self.cleaned_data['corporation'], self.cleaned_data['corporation'].application_config.get_api_required_display())) + char = self.cleaned_data.get('character') + corp = self.cleaned_data.get('corporation') + + if char and corp: + if char.corporation == corp: + raise forms.ValidationError("%s is already a member of %s" % (char, corp)) + if not char.account.api_keytype >= corp.application_config.api_required: + raise forms.ValidationError("%s requires a %s API key for this application" % (corp, corp.application_config.get_api_required_display())) return self.cleaned_data