Mercurial > public > sg101
comparison gpp/messages/views.py @ 178:d51743322bb2
#56 - Cut over to Django 1.2 messaging system.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 17 Mar 2010 03:12:05 +0000 |
parents | 7ad1f3e77cd9 |
children | c8c0fa817a05 |
comparison
equal
deleted
inserted
replaced
177:9b63ad1f2ad2 | 178:d51743322bb2 |
---|---|
3 import datetime | 3 import datetime |
4 from django.shortcuts import render_to_response | 4 from django.shortcuts import render_to_response |
5 from django.template import RequestContext | 5 from django.template import RequestContext |
6 from django.http import HttpResponseRedirect | 6 from django.http import HttpResponseRedirect |
7 from django.contrib.auth.decorators import login_required | 7 from django.contrib.auth.decorators import login_required |
8 from django.contrib import messages | |
8 from django.shortcuts import get_object_or_404 | 9 from django.shortcuts import get_object_or_404 |
9 from django.core.urlresolvers import reverse | 10 from django.core.urlresolvers import reverse |
10 from django.http import Http404 | 11 from django.http import Http404 |
11 from django.views.decorators.http import require_POST | 12 from django.views.decorators.http import require_POST |
12 | 13 |
107 if request.POST.get('submit_button', 'Cancel') == 'Cancel': | 108 if request.POST.get('submit_button', 'Cancel') == 'Cancel': |
108 return box_redirect(request) | 109 return box_redirect(request) |
109 compose_form = ComposeForm(request.user, request.POST) | 110 compose_form = ComposeForm(request.user, request.POST) |
110 if compose_form.is_valid(): | 111 if compose_form.is_valid(): |
111 compose_form.save(sender=request.user, parent_msg=msg) | 112 compose_form.save(sender=request.user, parent_msg=msg) |
112 request.user.message_set.create(message='Reply sent.') | 113 messages.success(request, 'Reply sent.') |
113 return box_redirect(request) | 114 return box_redirect(request) |
114 else: | 115 else: |
115 if msg.receiver == request.user: | 116 if msg.receiver == request.user: |
116 receiver_name = msg.sender.username | 117 receiver_name = msg.sender.username |
117 else: | 118 else: |
143 if request.POST.get('submit_button', 'Cancel') == 'Cancel': | 144 if request.POST.get('submit_button', 'Cancel') == 'Cancel': |
144 return HttpResponseRedirect(reverse('messages-inbox')) | 145 return HttpResponseRedirect(reverse('messages-inbox')) |
145 compose_form = ComposeForm(request.user, request.POST) | 146 compose_form = ComposeForm(request.user, request.POST) |
146 if compose_form.is_valid(): | 147 if compose_form.is_valid(): |
147 compose_form.save(sender=request.user) | 148 compose_form.save(sender=request.user) |
148 request.user.message_set.create(message='Message sent.') | 149 messages.success(request, 'Message sent.') |
149 return HttpResponseRedirect(reverse('messages-inbox')) | 150 return HttpResponseRedirect(reverse('messages-inbox')) |
150 else: | 151 else: |
151 if receiver is not None: | 152 if receiver is not None: |
152 form_data = { | 153 form_data = { |
153 'receiver': receiver, | 154 'receiver': receiver, |
175 elif msg.receiver == request.user: | 176 elif msg.receiver == request.user: |
176 msg.receiver_delete_date = datetime.datetime.now() | 177 msg.receiver_delete_date = datetime.datetime.now() |
177 else: | 178 else: |
178 raise Http404 | 179 raise Http404 |
179 msg.save() | 180 msg.save() |
180 request.user.message_set.create(message='Message sent to trash.') | 181 messages.success(request, 'Message sent to trash.') |
181 | 182 |
182 return box_redirect(request) | 183 return box_redirect(request) |
183 | 184 |
184 | 185 |
185 @login_required | 186 @login_required |
202 msg.sender_delete_date = now | 203 msg.sender_delete_date = now |
203 msg.save() | 204 msg.save() |
204 elif msg.receiver == request.user: | 205 elif msg.receiver == request.user: |
205 msg.receiver_delete_date = now | 206 msg.receiver_delete_date = now |
206 msg.save() | 207 msg.save() |
207 request.user.message_set.create(message='Messages sent to the trash.') | 208 messages.success(request, 'Messages sent to the trash.') |
208 | 209 |
209 return box_redirect(request) | 210 return box_redirect(request) |
210 | 211 |
211 | 212 |
212 @login_required | 213 @login_required |
222 elif msg.receiver == request.user: | 223 elif msg.receiver == request.user: |
223 msg.receiver_delete_date = None | 224 msg.receiver_delete_date = None |
224 else: | 225 else: |
225 raise Http404 | 226 raise Http404 |
226 msg.save() | 227 msg.save() |
227 request.user.message_set.create(message='Message retrieved from the trash.') | 228 messages.success(request, 'Message retrieved from the trash.') |
228 | 229 |
229 return box_redirect(request) | 230 return box_redirect(request) |
230 | 231 |
231 | 232 |
232 @login_required | 233 @login_required |
248 msg.sender_delete_date = None | 249 msg.sender_delete_date = None |
249 msg.save() | 250 msg.save() |
250 elif msg.receiver == request.user: | 251 elif msg.receiver == request.user: |
251 msg.receiver_delete_date = None | 252 msg.receiver_delete_date = None |
252 msg.save() | 253 msg.save() |
253 request.user.message_set.create(message='Messages retrieved from the trash.') | 254 messages.success(request, 'Messages retrieved from the trash.') |
254 | 255 |
255 return box_redirect(request) | 256 return box_redirect(request) |
256 | 257 |
257 | 258 |
258 @login_required | 259 @login_required |
265 return HttpResponseRedirect(reverse('messages-inbox')) | 266 return HttpResponseRedirect(reverse('messages-inbox')) |
266 options = Options.objects.for_user(request.user) | 267 options = Options.objects.for_user(request.user) |
267 form = OptionsForm(request.POST, instance=options) | 268 form = OptionsForm(request.POST, instance=options) |
268 if form.is_valid(): | 269 if form.is_valid(): |
269 form.save() | 270 form.save() |
270 request.user.message_set.create(message='Options saved.') | 271 messages.success(request, 'Options saved.') |
271 return HttpResponseRedirect(reverse('messages-inbox')) | 272 return HttpResponseRedirect(reverse('messages-inbox')) |
272 else: | 273 else: |
273 try: | 274 try: |
274 options = Options.objects.for_user(request.user) | 275 options = Options.objects.for_user(request.user) |
275 except: | 276 except: |