Mercurial > public > sg101
diff gpp/messages/forms.py @ 461:2d96d9bcf0de
Fixing #222. Verified all the fields have been validated before trying to use them in the form.clean() method.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 05 Jul 2011 19:24:18 +0000 |
parents | 33d0c55e57a9 |
children | 4b9970ad0edb |
line wrap: on
line diff
--- 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