Mercurial > public > sg101
comparison messages/forms.py @ 814:999a71b81111
Private messages refactor: test inbox/outbox limits.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 09 Sep 2014 20:07:55 -0500 |
parents | 4a4fa174a0ec |
children | 21c592cac71c |
comparison
equal
deleted
inserted
replaced
813:eca0c17ff9c8 | 814:999a71b81111 |
---|---|
9 from django.core.urlresolvers import reverse | 9 from django.core.urlresolvers import reverse |
10 from django.template.loader import render_to_string | 10 from django.template.loader import render_to_string |
11 | 11 |
12 from core.functions import send_mail | 12 from core.functions import send_mail |
13 from core.widgets import AutoCompleteUserInput | 13 from core.widgets import AutoCompleteUserInput |
14 import messages | |
14 from messages.models import Flag, Message, Options | 15 from messages.models import Flag, Message, Options |
15 from messages import MSG_BOX_LIMIT | |
16 | 16 |
17 | 17 |
18 # Maximum size of a private message in characters | 18 # Maximum size of a private message in characters |
19 MESSAGE_MAX = getattr(settings, 'MESSAGES_MAX_SIZE', 8192) | 19 MESSAGE_MAX = getattr(settings, 'MESSAGES_MAX_SIZE', 8192) |
20 | 20 |
60 | 60 |
61 if rcvr and subject and message: | 61 if rcvr and subject and message: |
62 # Can we send a message? Is our outbox full? | 62 # Can we send a message? Is our outbox full? |
63 | 63 |
64 count = Message.objects.outbox(self.user).count() | 64 count = Message.objects.outbox(self.user).count() |
65 if count >= MSG_BOX_LIMIT: | 65 if count >= messages.MSG_BOX_LIMIT: |
66 raise forms.ValidationError( | 66 raise forms.ValidationError( |
67 "Your outbox is full. Please delete some messages.") | 67 "Your outbox is full. Please delete some messages.") |
68 | 68 |
69 # Is the receiver's inbox full? | 69 # Is the receiver's inbox full? |
70 count = Message.objects.inbox(self.rcvr_user).count() | 70 count = Message.objects.inbox(self.rcvr_user).count() |
71 if count >= MSG_BOX_LIMIT: | 71 if count >= messages.MSG_BOX_LIMIT: |
72 raise forms.ValidationError( | 72 raise forms.ValidationError( |
73 "Sorry, %s's inbox is full. This message cannot be sent." % | 73 "Sorry, %s's inbox is full. This message cannot be sent." % |
74 self.rcvr_user.username) | 74 self.rcvr_user.username) |
75 | 75 |
76 return self.cleaned_data | 76 return self.cleaned_data |