Mercurial > public > sg101
comparison gpp/messages/views.py @ 568:7cec8d6f9581
For bitbucket issue #7, provide a bar graph indication of inbox and outbox
usage.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 10 Mar 2012 15:24:46 -0600 |
parents | 4b9970ad0edb |
children |
comparison
equal
deleted
inserted
replaced
567:0a8e6a9ccf53 | 568:7cec8d6f9581 |
---|---|
46 def _quota_check(box_name, count, request): | 46 def _quota_check(box_name, count, request): |
47 """ | 47 """ |
48 Checks the message box count against MSG_BOX_LIMIT. | 48 Checks the message box count against MSG_BOX_LIMIT. |
49 Emits a message to the user if the quota is exceeded. | 49 Emits a message to the user if the quota is exceeded. |
50 | 50 |
51 Returns the percent used as an integer between 0-100. | |
52 | |
51 """ | 53 """ |
52 if count >= MSG_BOX_LIMIT: | 54 if count >= MSG_BOX_LIMIT: |
53 django_messages.warning(request, | 55 django_messages.warning(request, |
54 "Your %s is full. Please delete some messages." % box_name) | 56 "Your %s is full. Please delete some messages." % box_name) |
57 | |
58 return 100 * count / MSG_BOX_LIMIT | |
55 | 59 |
56 | 60 |
57 @login_required | 61 @login_required |
58 def index(request, tab=None): | 62 def index(request, tab=None): |
59 """ | 63 """ |
91 """ | 95 """ |
92 if not request.user.is_authenticated(): | 96 if not request.user.is_authenticated(): |
93 return HttpResponseForbidden() | 97 return HttpResponseForbidden() |
94 | 98 |
95 msg_list = Message.objects.inbox(request.user) | 99 msg_list = Message.objects.inbox(request.user) |
96 _quota_check('inbox', msg_list.count(), request) | 100 msg_count = msg_list.count() |
101 pct_used = _quota_check('inbox', msg_count, request) | |
97 | 102 |
98 paginator = Paginator(msg_list, MSGS_PER_PAGE) | 103 paginator = Paginator(msg_list, MSGS_PER_PAGE) |
99 try: | 104 try: |
100 msgs = paginator.page(_get_page(request)) | 105 msgs = paginator.page(_get_page(request)) |
101 except (EmptyPage, InvalidPage): | 106 except (EmptyPage, InvalidPage): |
102 msgs = paginator.page(paginator.num_pages) | 107 msgs = paginator.page(paginator.num_pages) |
103 | 108 |
104 return render(request, 'messages/inbox_tab.html', { | 109 return render(request, 'messages/inbox_tab.html', { |
105 'msgs': msgs, | 110 'msgs': msgs, |
106 'url': reverse('messages-inbox'), | 111 'url': reverse('messages-inbox'), |
112 'pct_used': pct_used, | |
107 }) | 113 }) |
108 | 114 |
109 | 115 |
110 def outbox(request): | 116 def outbox(request): |
111 """ | 117 """ |
114 """ | 120 """ |
115 if not request.user.is_authenticated(): | 121 if not request.user.is_authenticated(): |
116 return HttpResponseForbidden() | 122 return HttpResponseForbidden() |
117 | 123 |
118 msg_list = Message.objects.outbox(request.user) | 124 msg_list = Message.objects.outbox(request.user) |
119 _quota_check('outbox', msg_list.count(), request) | 125 msg_count = msg_list.count() |
126 pct_used = _quota_check('outbox', msg_count, request) | |
120 | 127 |
121 paginator = Paginator(msg_list, MSGS_PER_PAGE) | 128 paginator = Paginator(msg_list, MSGS_PER_PAGE) |
122 try: | 129 try: |
123 msgs = paginator.page(_get_page(request)) | 130 msgs = paginator.page(_get_page(request)) |
124 except (EmptyPage, InvalidPage): | 131 except (EmptyPage, InvalidPage): |
125 msgs = paginator.page(paginator.num_pages) | 132 msgs = paginator.page(paginator.num_pages) |
126 | 133 |
127 return render(request, 'messages/outbox_tab.html', { | 134 return render(request, 'messages/outbox_tab.html', { |
128 'msgs': msgs, | 135 'msgs': msgs, |
129 'url': reverse('messages-outbox'), | 136 'url': reverse('messages-outbox'), |
137 'pct_used': pct_used, | |
130 }) | 138 }) |
131 | 139 |
132 | 140 |
133 def trash(request): | 141 def trash(request): |
134 """ | 142 """ |