From 230c31a1b68b91f541070195d0383caabfd3eab3 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 19 Jan 2011 10:01:05 +0000 Subject: [PATCH] Switch validation from form level to field level. --- hr/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hr/forms.py b/hr/forms.py index 51e5144..a349400 100644 --- a/hr/forms.py +++ b/hr/forms.py @@ -30,12 +30,12 @@ def CreateApplicationForm(user): character = forms.ModelChoiceField(queryset=characters, required=True, empty_label=None) corporation = forms.ModelChoiceField(queryset=corporations, required=True, empty_label=None) - def clean(self): + def clean_character(self): if not 'character' in self.cleaned_data or not self.cleaned_data['character']: raise forms.ValidationError("Please select a character to apply with") - if len(Application.objects.filter(character=self.cleaned_data['character'], status__in=[APPLICATION_STATUS_NOTSUBMITTED, APPLICATION_STATUS_AWAITINGREVIEW, APPLICATION_STATUS_QUERY])): + if Application.objects.filter(character=self.cleaned_data['character']).exclude(status__in=[APPLICATION_STATUS_COMPLETED, APPLICATION_STATUS_REJECTED]).count(): raise forms.ValidationError("This character already has a open application") return self.cleaned_data