comparison downloads/views.py @ 1031:e1c03da72818

Get rid of some warnings in Django 1.8.
author Brian Neal <bgneal@gmail.com>
date Sun, 20 Dec 2015 22:18:59 -0600
parents a5ebc74dc3f3
children 0e0cd152b86d
comparison
equal deleted inserted replaced
1030:d9610b1e2a3d 1031:e1c03da72818
1 """ 1 """
2 Views for the downloads application. 2 Views for the downloads application.
3 """ 3 """
4 import json 4 import json
5 5
6 from django.shortcuts import render_to_response, get_object_or_404 6 from django.shortcuts import render, get_object_or_404
7 from django.template import RequestContext
8 from django.contrib.auth.decorators import login_required 7 from django.contrib.auth.decorators import login_required
9 from django.http import Http404 8 from django.http import Http404
10 from django.http import HttpResponse 9 from django.http import HttpResponse
11 from django.http import HttpResponseRedirect 10 from django.http import HttpResponseRedirect
12 from django.http import HttpResponseForbidden 11 from django.http import HttpResponseForbidden
35 34
36 @login_required 35 @login_required
37 def index(request): 36 def index(request):
38 categories = Category.objects.all() 37 categories = Category.objects.all()
39 total_dls = Download.public_objects.all().count() 38 total_dls = Download.public_objects.all().count()
40 return render_to_response('downloads/index.html', { 39 return render(request, 'downloads/index.html', {
41 'categories': categories, 40 'categories': categories,
42 'total_dls': total_dls, 41 'total_dls': total_dls,
43 }, 42 })
44 context_instance = RequestContext(request))
45 43
46 ####################################################################### 44 #######################################################################
47 # Maps URL component to database field name for the Download table: 45 # Maps URL component to database field name for the Download table:
48 46
49 DOWNLOAD_FIELD_MAP = { 47 DOWNLOAD_FIELD_MAP = {
69 try: 67 try:
70 the_page = paginator.page(page) 68 the_page = paginator.page(page)
71 except InvalidPage: 69 except InvalidPage:
72 raise Http404 70 raise Http404
73 71
74 return render_to_response('downloads/download_list.html', { 72 return render(request, 'downloads/download_list.html', {
75 's' : sort, 73 's' : sort,
76 'category' : cat, 74 'category' : cat,
77 'page' : the_page, 75 'page' : the_page,
78 }, 76 })
79 context_instance = RequestContext(request))
80 77
81 ####################################################################### 78 #######################################################################
82 79
83 @login_required 80 @login_required
84 def new(request): 81 def new(request):
91 try: 88 try:
92 the_page = paginator.page(page) 89 the_page = paginator.page(page)
93 except InvalidPage: 90 except InvalidPage:
94 raise Http404 91 raise Http404
95 92
96 return render_to_response('downloads/download_summary.html', { 93 return render(request, 'downloads/download_summary.html', {
97 'page': the_page, 94 'page': the_page,
98 'title': 'Newest Downloads', 95 'title': 'Newest Downloads',
99 }, 96 })
100 context_instance = RequestContext(request))
101 97
102 ####################################################################### 98 #######################################################################
103 99
104 @login_required 100 @login_required
105 def popular(request): 101 def popular(request):
112 try: 108 try:
113 the_page = paginator.page(page) 109 the_page = paginator.page(page)
114 except InvalidPage: 110 except InvalidPage:
115 raise Http404 111 raise Http404
116 112
117 return render_to_response('downloads/download_summary.html', { 113 return render(request, 'downloads/download_summary.html', {
118 'page': the_page, 114 'page': the_page,
119 'title': 'Popular Downloads', 115 'title': 'Popular Downloads',
120 }, 116 })
121 context_instance = RequestContext(request))
122 117
123 ####################################################################### 118 #######################################################################
124 119
125 @login_required 120 @login_required
126 def rating(request): 121 def rating(request):
132 try: 127 try:
133 the_page = paginator.page(page) 128 the_page = paginator.page(page)
134 except InvalidPage: 129 except InvalidPage:
135 raise Http404 130 raise Http404
136 131
137 return render_to_response('downloads/download_summary.html', { 132 return render(request, 'downloads/download_summary.html', {
138 'page': the_page, 133 'page': the_page,
139 'title': 'Highest Rated Downloads', 134 'title': 'Highest Rated Downloads',
140 }, 135 })
141 context_instance = RequestContext(request))
142 136
143 ####################################################################### 137 #######################################################################
144 138
145 @login_required 139 @login_required
146 def details(request, id): 140 def details(request, id):
147 download = get_object_or_404(Download.public_objects, pk=id) 141 download = get_object_or_404(Download.public_objects, pk=id)
148 if not download.is_public: 142 if not download.is_public:
149 raise Http404 143 raise Http404
150 return render_to_response('downloads/download_detail.html', { 144 return render(request, 'downloads/download_detail.html', {
151 'download' : download, 145 'download' : download,
152 }, 146 })
153 context_instance = RequestContext(request))
154 147
155 ####################################################################### 148 #######################################################################
156 149
157 @login_required 150 @login_required
158 def add(request): 151 def add(request):
169 """) 162 """)
170 return HttpResponseRedirect(reverse('downloads-add_thanks')) 163 return HttpResponseRedirect(reverse('downloads-add_thanks'))
171 else: 164 else:
172 form = AddDownloadForm() 165 form = AddDownloadForm()
173 166
174 return render_to_response('downloads/add.html', { 167 return render(request, 'downloads/add.html', {
175 'add_form': form, 168 'add_form': form,
176 }, 169 })
177 context_instance=RequestContext(request))
178 170
179 ####################################################################### 171 #######################################################################
180 172
181 @login_required 173 @login_required
182 def thanks(request): 174 def thanks(request):
183 return render_to_response('downloads/thanks.html', { 175 return render(request, 'downloads/thanks.html', {
184 }, 176 })
185 context_instance=RequestContext(request))
186 177
187 ####################################################################### 178 #######################################################################
188 179
189 @require_POST 180 @require_POST
190 def rate_download(request): 181 def rate_download(request):