# HG changeset patch # User Brian Neal # Date 1309893858 0 # Node ID 2d96d9bcf0defb2bdc4f907b96996d9fff89542d # Parent 2ff5f4c1476d6a6cfdd1e8e446152c368dddb61a Fixing #222. Verified all the fields have been validated before trying to use them in the form.clean() method. diff -r 2ff5f4c1476d -r 2d96d9bcf0de gpp/messages/forms.py --- a/gpp/messages/forms.py Sun Jul 03 19:35:09 2011 +0000 +++ b/gpp/messages/forms.py Tue Jul 05 19:24:18 2011 +0000 @@ -55,17 +55,24 @@ return msg def clean(self): - # Can we send a message? Is our outbox full? + rcvr = self.cleaned_data.get('receiver') + subject = self.cleaned_data.get('subject') + message = self.cleaned_data.get('message') - count = Message.objects.outbox(self.user).count() - if count >= MSG_BOX_LIMIT: - raise forms.ValidationError("Your outbox is full. Please delete some messages.") + if rcvr and subject and message: + # Can we send a message? Is our outbox full? - # Is the receiver's inbox full? - count = Message.objects.inbox(self.rcvr_user).count() - if count >= MSG_BOX_LIMIT: - raise forms.ValidationError( - "Sorry, %s's inbox is full. This message cannot be sent." % self.rcvr_user.username) + count = Message.objects.outbox(self.user).count() + if count >= MSG_BOX_LIMIT: + raise forms.ValidationError( + "Your outbox is full. Please delete some messages.") + + # Is the receiver's inbox full? + count = Message.objects.inbox(self.rcvr_user).count() + if count >= MSG_BOX_LIMIT: + raise forms.ValidationError( + "Sorry, %s's inbox is full. This message cannot be sent." % + self.rcvr_user.username) return self.cleaned_data