Mercurial > public > sg101
comparison messages/views.py @ 813:eca0c17ff9c8
Private message refactor: reports should email admins.
Added tests for reporting messages and ensuring emails are sent
when messages are sent (when user options allow it).
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 08 Sep 2014 20:50:37 -0500 |
parents | 42436d674ba8 |
children | cf486a8e8b43 |
comparison
equal
deleted
inserted
replaced
812:42436d674ba8 | 813:eca0c17ff9c8 |
---|---|
14 | 14 |
15 from messages.models import Flag, Message, Options | 15 from messages.models import Flag, Message, Options |
16 from messages.forms import OptionsForm, ComposeForm, ReportForm | 16 from messages.forms import OptionsForm, ComposeForm, ReportForm |
17 from messages.utils import reply_subject | 17 from messages.utils import reply_subject |
18 from messages import MSG_BOX_LIMIT | 18 from messages import MSG_BOX_LIMIT |
19 from core.functions import quote_message | 19 from core.functions import email_admins, quote_message |
20 | 20 |
21 | 21 |
22 MSGS_PER_PAGE = 20 # message pagination value | 22 MSGS_PER_PAGE = 20 # message pagination value |
23 | |
24 REPORT_SUBJECT = 'A user has flagged a private message' | |
25 REPORT_MSG = """Hello, | |
26 | |
27 A user has flagged a private message for review. | |
28 """ | |
23 | 29 |
24 | 30 |
25 def _quota_check(box_name, count, request): | 31 def _quota_check(box_name, count, request): |
26 """ | 32 """ |
27 Checks the message box count against MSG_BOX_LIMIT. | 33 Checks the message box count against MSG_BOX_LIMIT. |
326 form = ReportForm(request.POST) | 332 form = ReportForm(request.POST) |
327 if form.is_valid(): | 333 if form.is_valid(): |
328 flag = form.save(commit=False) | 334 flag = form.save(commit=False) |
329 flag.message = msg | 335 flag.message = msg |
330 flag.save() | 336 flag.save() |
337 email_admins(REPORT_SUBJECT, REPORT_MSG) | |
331 django_messages.success(request, | 338 django_messages.success(request, |
332 'Message reported. An admin will be notified. Thank you.') | 339 'Message reported. An admin will be notified. Thank you.') |
333 return redirect('messages-inbox') | 340 return redirect('messages-inbox') |
334 else: | 341 else: |
335 form = ReportForm() | 342 form = ReportForm() |