Mercurial > public > sg101
diff gpp/messages/forms.py @ 436:241c80ff16c5
For #211, added message quotas; can't send or receive private messages if your outbox/inbox quota has been exceeded.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 13 May 2011 02:06:53 +0000 |
parents | ca744075e7b7 |
children | 33d0c55e57a9 |
line wrap: on
line diff
--- a/gpp/messages/forms.py Fri May 13 00:12:53 2011 +0000 +++ b/gpp/messages/forms.py Fri May 13 02:06:53 2011 +0000 @@ -14,6 +14,7 @@ from core.widgets import AutoCompleteUserInput from messages.models import Message from messages.models import Options +from messages import MSG_BOX_LIMIT # Maximum size of a private message in characters @@ -53,6 +54,21 @@ raise forms.ValidationError("Your message is too long. Please trim some text.") return msg + def clean(self): + # Can we send a message? Is our outbox full? + + 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 + def save(self, parent_msg=None): sender = self.user receiver = self.rcvr_user