changeset 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 2ff5f4c1476d
children 53fdaf0da539
files gpp/messages/forms.py
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
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