Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
460:2ff5f4c1476d | 461:2d96d9bcf0de |
---|---|
53 if len(msg) > MESSAGE_MAX: | 53 if len(msg) > MESSAGE_MAX: |
54 raise forms.ValidationError("Your message is too long. Please trim some text.") | 54 raise forms.ValidationError("Your message is too long. Please trim some text.") |
55 return msg | 55 return msg |
56 | 56 |
57 def clean(self): | 57 def clean(self): |
58 # Can we send a message? Is our outbox full? | 58 rcvr = self.cleaned_data.get('receiver') |
59 subject = self.cleaned_data.get('subject') | |
60 message = self.cleaned_data.get('message') | |
59 | 61 |
60 count = Message.objects.outbox(self.user).count() | 62 if rcvr and subject and message: |
61 if count >= MSG_BOX_LIMIT: | 63 # Can we send a message? Is our outbox full? |
62 raise forms.ValidationError("Your outbox is full. Please delete some messages.") | |
63 | 64 |
64 # Is the receiver's inbox full? | 65 count = Message.objects.outbox(self.user).count() |
65 count = Message.objects.inbox(self.rcvr_user).count() | 66 if count >= MSG_BOX_LIMIT: |
66 if count >= MSG_BOX_LIMIT: | 67 raise forms.ValidationError( |
67 raise forms.ValidationError( | 68 "Your outbox is full. Please delete some messages.") |
68 "Sorry, %s's inbox is full. This message cannot be sent." % self.rcvr_user.username) | 69 |
70 # Is the receiver's inbox full? | |
71 count = Message.objects.inbox(self.rcvr_user).count() | |
72 if count >= MSG_BOX_LIMIT: | |
73 raise forms.ValidationError( | |
74 "Sorry, %s's inbox is full. This message cannot be sent." % | |
75 self.rcvr_user.username) | |
69 | 76 |
70 return self.cleaned_data | 77 return self.cleaned_data |
71 | 78 |
72 def save(self, parent_msg=None): | 79 def save(self, parent_msg=None): |
73 sender = self.user | 80 sender = self.user |