Commit 92e6bc6b authored by Daniel W Bond's avatar Daniel W Bond
Browse files

404 handling for object dne on housing views

parent 7ed85fe0
...@@ -3,6 +3,8 @@ from __future__ import absolute_import, print_function ...@@ -3,6 +3,8 @@ from __future__ import absolute_import, print_function
from collections import OrderedDict from collections import OrderedDict
# core django imports # core django imports
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from django.core.exceptions import ObjectDoesNotExist
from django.http import Http404
# third party imports # third party imports
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin
# imports from your apps # imports from your apps
...@@ -63,7 +65,10 @@ class DetailBuilding(DetailView): ...@@ -63,7 +65,10 @@ class DetailBuilding(DetailView):
url_parts = self.request.get_full_path().split('/') url_parts = self.request.get_full_path().split('/')
# [u'', u'housing', u'building',] # [u'', u'housing', u'building',]
building_name = url_parts[2].replace('-', ' ').title() building_name = url_parts[2].replace('-', ' ').title()
building = Building.objects.get(name=building_name) try:
building = Building.objects.get(name=building_name)
except ObjectDoesNotExist:
raise Http404
return building return building
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
...@@ -85,9 +90,12 @@ class DetailFloor(LoginRequiredMixin, DetailView): ...@@ -85,9 +90,12 @@ class DetailFloor(LoginRequiredMixin, DetailView):
# [u'', u'housing', u'building', u'floor', ] # [u'', u'housing', u'building', u'floor', ]
building_name = url_parts[2].replace('-', ' ').title() building_name = url_parts[2].replace('-', ' ').title()
floor_number = url_parts[3] floor_number = url_parts[3]
building = Building.objects.get(name=building_name) try:
floor = Floor.objects.get(number=floor_number, building = Building.objects.get(name=building_name)
building=building) floor = Floor.objects.get(number=floor_number,
building=building)
except ObjectDoesNotExist:
raise Http404
return floor return floor
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
...@@ -117,11 +125,14 @@ class DetailRoom(LoginRequiredMixin, DetailView): ...@@ -117,11 +125,14 @@ class DetailRoom(LoginRequiredMixin, DetailView):
building_name = url_parts[2].replace('-', ' ').title() building_name = url_parts[2].replace('-', ' ').title()
floor_number = url_parts[3] floor_number = url_parts[3]
room_number = url_parts[4].upper() room_number = url_parts[4].upper()
building = Building.objects.get(name=building_name) try:
floor = Floor.objects.get(number=floor_number, building = Building.objects.get(name=building_name)
building=building) floor = Floor.objects.get(number=floor_number,
room = Room.objects.get(floor=floor, building=building)
number=room_number) room = Room.objects.get(floor=floor,
number=room_number)
except ObjectDoesNotExist:
raise Http404
return room return room
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment