Mercurial > public > sg101
comparison shoutbox/views.py @ 1032:e932f2ecd4a7
Django 1.8 warnings / tech debt cleanup.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 26 Dec 2015 15:10:55 -0600 |
parents | 0ca691cccf8d |
children |
comparison
equal
deleted
inserted
replaced
1031:e1c03da72818 | 1032:e932f2ecd4a7 |
---|---|
1 """ | 1 """ |
2 Views for the Shoutbox application. | 2 Views for the Shoutbox application. |
3 """ | 3 """ |
4 | 4 |
5 import re | 5 import re |
6 from django.shortcuts import render_to_response | 6 from django.shortcuts import render |
7 from django.template import RequestContext | |
8 from django.core.paginator import InvalidPage | 7 from django.core.paginator import InvalidPage |
9 from django.http import HttpResponse | 8 from django.http import HttpResponse |
10 from django.http import HttpResponseBadRequest | 9 from django.http import HttpResponseBadRequest |
11 from django.http import HttpResponseForbidden | 10 from django.http import HttpResponseForbidden |
12 from django.http import HttpResponseRedirect | |
13 from django.http import Http404 | 11 from django.http import Http404 |
14 from django.contrib.auth.decorators import login_required | 12 from django.contrib.auth.decorators import login_required |
15 from django.views.decorators.http import require_POST | 13 from django.views.decorators.http import require_POST |
16 | 14 |
17 from core.paginator import DiggPaginator | 15 from core.paginator import DiggPaginator |
18 from core.functions import email_admins | 16 from core.functions import email_admins |
19 from core.functions import get_page | 17 from core.functions import get_page |
20 from shoutbox.forms import ShoutBoxForm | |
21 from shoutbox.models import Shout | 18 from shoutbox.models import Shout |
22 from shoutbox.models import ShoutFlag | 19 from shoutbox.models import ShoutFlag |
23 | 20 |
24 SHOUTS_PER_PAGE = 10 | 21 SHOUTS_PER_PAGE = 10 |
25 | 22 |
30 if msg == '': | 27 if msg == '': |
31 return HttpResponse('') | 28 return HttpResponse('') |
32 | 29 |
33 shout = Shout(user=request.user, shout=msg) | 30 shout = Shout(user=request.user, shout=msg) |
34 shout.save() | 31 shout.save() |
35 return render_to_response('shoutbox/shout.html', { | 32 return render(request, 'shoutbox/shout.html', { |
36 'shout': shout, | 33 'shout': shout, |
37 }, | 34 }) |
38 context_instance = RequestContext(request)) | |
39 | 35 |
40 | 36 |
41 def view_shout(request, id): | 37 def view_shout(request, id): |
42 """This view is for viewing an individual shout.""" | 38 """This view is for viewing an individual shout.""" |
43 try: | 39 try: |
44 shout = Shout.objects.get(pk=id) | 40 shout = Shout.objects.get(pk=id) |
45 except Shout.DoesNotExist: | 41 except Shout.DoesNotExist: |
46 return render_to_response('shoutbox/missing_shout.html', {}, | 42 return render(request, 'shoutbox/missing_shout.html') |
47 context_instance = RequestContext(request)) | |
48 | 43 |
49 return render_to_response('shoutbox/view_shout.html', { | 44 return render(request, 'shoutbox/view_shout.html', { |
50 'shout': shout, | 45 'shout': shout, |
51 }, | 46 }) |
52 context_instance = RequestContext(request)) | |
53 | 47 |
54 | 48 |
55 def view_history(request): | 49 def view_history(request): |
56 """This view allows one to view the shoutbox history.""" | 50 """This view allows one to view the shoutbox history.""" |
57 qs = Shout.objects.select_related('user', 'user__profile') | 51 qs = Shout.objects.select_related('user', 'user__profile') |
61 try: | 55 try: |
62 the_page = paginator.page(page) | 56 the_page = paginator.page(page) |
63 except InvalidPage: | 57 except InvalidPage: |
64 raise Http404 | 58 raise Http404 |
65 | 59 |
66 return render_to_response('shoutbox/view.html', { | 60 return render(request, 'shoutbox/view.html', { |
67 'page': the_page, | 61 'page': the_page, |
68 }, | 62 }) |
69 context_instance = RequestContext(request)) | |
70 | 63 |
71 | 64 |
72 shout_id_re = re.compile(r'shout-(\d+)') | 65 shout_id_re = re.compile(r'shout-(\d+)') |
73 | 66 |
74 def text(request): | 67 def text(request): |
151 | 144 |
152 A user has flagged a shout for review. | 145 A user has flagged a shout for review. |
153 """) | 146 """) |
154 return HttpResponse('The shout was flagged. A moderator will review the shout shortly. ' \ | 147 return HttpResponse('The shout was flagged. A moderator will review the shout shortly. ' \ |
155 'Thanks for helping to improve the quality of this site.') | 148 'Thanks for helping to improve the quality of this site.') |
156 | |
157 # vim: ts=4 sw=4 |