comparison gpp/messages/views.py @ 566:4b9970ad0edb

For bitbucket issue #6, try to improve quoting messages.
author Brian Neal <bgneal@gmail.com>
date Sun, 04 Mar 2012 14:52:24 -0600
parents 33d0c55e57a9
children 7cec8d6f9581
comparison
equal deleted inserted replaced
565:6a265b5768ca 566:4b9970ad0edb
10 from django.core.paginator import Paginator, EmptyPage, InvalidPage 10 from django.core.paginator import Paginator, EmptyPage, InvalidPage
11 from django.core.urlresolvers import reverse 11 from django.core.urlresolvers import reverse
12 from django.http import HttpResponse 12 from django.http import HttpResponse
13 from django.http import HttpResponseForbidden 13 from django.http import HttpResponseForbidden
14 from django.http import HttpResponseNotAllowed 14 from django.http import HttpResponseNotAllowed
15 from django.http import HttpResponseRedirect
16 from django.shortcuts import get_object_or_404 15 from django.shortcuts import get_object_or_404
17 from django.shortcuts import render 16 from django.shortcuts import render
18 import django.utils.simplejson as json 17 import django.utils.simplejson as json
19 18
20 from messages.models import Message, Options 19 from messages.models import Message, Options
21 from messages.forms import OptionsForm, ComposeForm 20 from messages.forms import OptionsForm, ComposeForm
22 from messages.utils import reply_subject, quote_message 21 from messages.utils import reply_subject
23 from messages import MSG_BOX_LIMIT 22 from messages import MSG_BOX_LIMIT
23 from core.functions import quote_message
24 24
25 25
26 MSGS_PER_PAGE = 20 # message pagination value 26 MSGS_PER_PAGE = 20 # message pagination value
27 27
28 # This must match the jQuery UI tab control 28 # This must match the jQuery UI tab control
96 _quota_check('inbox', msg_list.count(), request) 96 _quota_check('inbox', msg_list.count(), request)
97 97
98 paginator = Paginator(msg_list, MSGS_PER_PAGE) 98 paginator = Paginator(msg_list, MSGS_PER_PAGE)
99 try: 99 try:
100 msgs = paginator.page(_get_page(request)) 100 msgs = paginator.page(_get_page(request))
101 except EmptyPage, InvalidPage: 101 except (EmptyPage, InvalidPage):
102 msgs = paginator.page(paginator.num_pages) 102 msgs = paginator.page(paginator.num_pages)
103 103
104 return render(request, 'messages/inbox_tab.html', { 104 return render(request, 'messages/inbox_tab.html', {
105 'msgs': msgs, 105 'msgs': msgs,
106 'url': reverse('messages-inbox'), 106 'url': reverse('messages-inbox'),
119 _quota_check('outbox', msg_list.count(), request) 119 _quota_check('outbox', msg_list.count(), request)
120 120
121 paginator = Paginator(msg_list, MSGS_PER_PAGE) 121 paginator = Paginator(msg_list, MSGS_PER_PAGE)
122 try: 122 try:
123 msgs = paginator.page(_get_page(request)) 123 msgs = paginator.page(_get_page(request))
124 except EmptyPage, InvalidPage: 124 except (EmptyPage, InvalidPage):
125 msgs = paginator.page(paginator.num_pages) 125 msgs = paginator.page(paginator.num_pages)
126 126
127 return render(request, 'messages/outbox_tab.html', { 127 return render(request, 'messages/outbox_tab.html', {
128 'msgs': msgs, 128 'msgs': msgs,
129 'url': reverse('messages-outbox'), 129 'url': reverse('messages-outbox'),
140 140
141 msg_list = Message.objects.trash(request.user) 141 msg_list = Message.objects.trash(request.user)
142 paginator = Paginator(msg_list, MSGS_PER_PAGE) 142 paginator = Paginator(msg_list, MSGS_PER_PAGE)
143 try: 143 try:
144 msgs = paginator.page(_get_page(request)) 144 msgs = paginator.page(_get_page(request))
145 except EmptyPage, InvalidPage: 145 except (EmptyPage, InvalidPage):
146 msgs = paginator.page(paginator.num_pages) 146 msgs = paginator.page(paginator.num_pages)
147 147
148 return render(request, 'messages/trash_tab.html', { 148 return render(request, 'messages/trash_tab.html', {
149 'msgs': msgs, 149 'msgs': msgs,
150 'url': reverse('messages-trash'), 150 'url': reverse('messages-trash'),
173 msg_dict = dict(subject=msg.subject, 173 msg_dict = dict(subject=msg.subject,
174 sender=msg.sender.username, 174 sender=msg.sender.username,
175 receiver=msg.receiver.username, 175 receiver=msg.receiver.username,
176 content=msg.html, 176 content=msg.html,
177 re_subject=reply_subject(msg.subject), 177 re_subject=reply_subject(msg.subject),
178 re_content=quote_message(msg.sender.username, msg.send_date, 178 re_content=quote_message(msg.sender.username, msg.message))
179 msg.message))
180 179
181 result = json.dumps(msg_dict, ensure_ascii=False) 180 result = json.dumps(msg_dict, ensure_ascii=False)
182 return HttpResponse(result, content_type='application/json') 181 return HttpResponse(result, content_type='application/json')
183 182
184 183