add a 404 when notice are not found when displaying their page
authorymh <ymh.work@gmail.com>
Fri, 03 Jul 2015 10:39:11 +0200
changeset 636 cc2f7294f1d2
parent 635 73d195640287
child 637 210d4d752a62
add a 404 when notice are not found when displaying their page
src/hdalab/views/pages.py
--- a/src/hdalab/views/pages.py	Fri Jul 03 00:20:27 2015 +0200
+++ b/src/hdalab/views/pages.py	Fri Jul 03 10:39:11 2015 +0200
@@ -8,13 +8,18 @@
 import user_agents
 
 from hdabo.models import Datasheet, TaggedSheet
+from django.http.response import Http404
 
 
 def datasheet(request, hda_id=None):
     MAX_TAG = 15
     MAX_RELATED = 50
     
-    datasheet = Datasheet.objects.select_related("organisation").get(hda_id=hda_id)
+    datasheet = None
+    try:
+        datasheet = Datasheet.objects.select_related("organisation").get(hda_id=hda_id)
+    except Datasheet.DoesNotExist:
+        raise Http404("The datasheet %s is not found."%hda_id)
     
     domain = re.findall(r"^https?://(www\.)?([^/]+)",datasheet.url)
     ordered_tags = TaggedSheet.objects.filter(datasheet=datasheet,order__lte=MAX_TAG).select_related("tag").order_by('order')