Mercurial > public > sg101
changeset 480:1a7ca5fa494f
Fixing #229: Download details view with a bogus download ID produces internal server error isntead of a 404.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 05 Oct 2011 00:09:30 +0000 |
parents | 32cec6cd8808 |
children | 9f888dbe61ce |
files | gpp/downloads/views.py |
diffstat | 1 files changed, 5 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/downloads/views.py Sun Sep 25 00:49:05 2011 +0000 +++ b/gpp/downloads/views.py Wed Oct 05 00:09:30 2011 +0000 @@ -3,7 +3,7 @@ """ import random -from django.shortcuts import render_to_response +from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext from django.contrib.auth.decorators import login_required from django.http import Http404 @@ -57,10 +57,8 @@ @login_required def category(request, slug, sort='title'): - try: - cat = Category.objects.get(slug=slug) - except Category.DoesNotExist: - raise Http404 + + cat = get_object_or_404(Category, slug=slug) if sort not in DOWNLOAD_FIELD_MAP: sort = 'title' @@ -148,9 +146,7 @@ @login_required def details(request, id): - download = Download.public_objects.get(pk=id) - if download is None: - raise Http404 + download = get_object_or_404(Download.public_objects, pk=id) return render_to_response('downloads/download_detail.html', { 'download' : download, }, @@ -207,10 +203,7 @@ # rating will be from 0-4 rating = min(5, max(1, rating)) - try: - download = Download.public_objects.get(pk=id) - except Download.DoesNotExist: - return HttpResponseBadRequest('Invalid download id.') + download = get_object_or_404(Download.public_objects, pk=id) # prevent multiple votes from the same user vote_record, created = VoteRecord.objects.get_or_create(