Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
435:b2f02766cc72 | 436:241c80ff16c5 |
---|---|
12 from core.functions import send_mail | 12 from core.functions import send_mail |
13 from core.functions import get_full_name | 13 from core.functions import get_full_name |
14 from core.widgets import AutoCompleteUserInput | 14 from core.widgets import AutoCompleteUserInput |
15 from messages.models import Message | 15 from messages.models import Message |
16 from messages.models import Options | 16 from messages.models import Options |
17 from messages import MSG_BOX_LIMIT | |
17 | 18 |
18 | 19 |
19 # Maximum size of a private message in characters | 20 # Maximum size of a private message in characters |
20 MESSAGE_MAX = getattr(settings, 'MESSAGES_MAX_SIZE', 8192) | 21 MESSAGE_MAX = getattr(settings, 'MESSAGES_MAX_SIZE', 8192) |
21 | 22 |
50 def clean_message(self): | 51 def clean_message(self): |
51 msg = self.cleaned_data['message'] | 52 msg = self.cleaned_data['message'] |
52 if len(msg) > MESSAGE_MAX: | 53 if len(msg) > MESSAGE_MAX: |
53 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.") |
54 return msg | 55 return msg |
56 | |
57 def clean(self): | |
58 # Can we send a message? Is our outbox full? | |
59 | |
60 count = Message.objects.outbox(self.user).count() | |
61 if count >= MSG_BOX_LIMIT: | |
62 raise forms.ValidationError("Your outbox is full. Please delete some messages.") | |
63 | |
64 # Is the receiver's inbox full? | |
65 count = Message.objects.inbox(self.rcvr_user).count() | |
66 if count >= MSG_BOX_LIMIT: | |
67 raise forms.ValidationError( | |
68 "Sorry, %s's inbox is full. This message cannot be sent." % self.rcvr_user.username) | |
69 | |
70 return self.cleaned_data | |
55 | 71 |
56 def save(self, parent_msg=None): | 72 def save(self, parent_msg=None): |
57 sender = self.user | 73 sender = self.user |
58 receiver = self.rcvr_user | 74 receiver = self.rcvr_user |
59 subject = self.cleaned_data['subject'] | 75 subject = self.cleaned_data['subject'] |