comparison messages/views.py @ 812:42436d674ba8

Private message refactor: add unit tests for message cycle.
author Brian Neal <bgneal@gmail.com>
date Sun, 07 Sep 2014 16:53:05 -0500
parents 4a4fa174a0ec
children eca0c17ff9c8
comparison
equal deleted inserted replaced
811:56b30c79f10e 812:42436d674ba8
108 options = Options.objects.for_user(request.user) 108 options = Options.objects.for_user(request.user)
109 form = OptionsForm(request.POST, instance=options, prefix='opts') 109 form = OptionsForm(request.POST, instance=options, prefix='opts')
110 if form.is_valid(): 110 if form.is_valid():
111 form.save() 111 form.save()
112 django_messages.success(request, 'Options saved.') 112 django_messages.success(request, 'Options saved.')
113 return redirect('messages-options')
113 else: 114 else:
114 options = Options.objects.for_user(request.user) 115 options = Options.objects.for_user(request.user)
115 form = OptionsForm(instance=options, prefix='opts') 116 form = OptionsForm(instance=options, prefix='opts')
116 117
117 return render(request, 'messages/options.html', { 118 return render(request, 'messages/options.html', {
153 """ 154 """
154 This view function displays a private message for reading to the user. If 155 This view function displays a private message for reading to the user. If
155 the user is a recipient of the message, a reply can be composed and sent. 156 the user is a recipient of the message, a reply can be composed and sent.
156 157
157 """ 158 """
159 msg = get_object_or_404(Message.objects.select_related(), pk=msg_id)
160
158 if request.method == 'POST': 161 if request.method == 'POST':
159 form = ComposeForm(request.user, request.POST) 162 form = ComposeForm(request.user, request.POST)
160 if form.is_valid(): 163 if form.is_valid():
161 form.save() 164 form.save()
162 django_messages.success(request, 'Reply sent.') 165 django_messages.success(request, 'Reply sent.')
163 return redirect('messages-inbox') 166 return redirect('messages-inbox')
164 else: 167 else:
165 msg = get_object_or_404(Message.objects.select_related(), pk=msg_id)
166 if msg.sender != request.user and msg.receiver != request.user: 168 if msg.sender != request.user and msg.receiver != request.user:
167 django_messages.error(request, 169 django_messages.error(request,
168 "You don't have permission to read that message.") 170 "You don't have permission to read that message.")
169 return redirect('messages-inbox') 171 return redirect('messages-inbox')
170 172