Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
roomlist
Commits
92e6bc6b
Commit
92e6bc6b
authored
Oct 28, 2016
by
Daniel W Bond
Browse files
404 handling for object dne on housing views
parent
7ed85fe0
Changes
1
Hide whitespace changes
Inline
Side-by-side
roomlist/housing/views.py
View file @
92e6bc6b
...
...
@@ -3,6 +3,8 @@ from __future__ import absolute_import, print_function
from
collections
import
OrderedDict
# core django imports
from
django.views.generic
import
DetailView
,
ListView
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.http
import
Http404
# third party imports
from
braces.views
import
LoginRequiredMixin
# imports from your apps
...
...
@@ -63,7 +65,10 @@ class DetailBuilding(DetailView):
url_parts
=
self
.
request
.
get_full_path
().
split
(
'/'
)
# [u'', u'housing', u'building',]
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
def
get_context_data
(
self
,
**
kwargs
):
...
...
@@ -85,9 +90,12 @@ class DetailFloor(LoginRequiredMixin, DetailView):
# [u'', u'housing', u'building', u'floor', ]
building_name
=
url_parts
[
2
].
replace
(
'-'
,
' '
).
title
()
floor_number
=
url_parts
[
3
]
building
=
Building
.
objects
.
get
(
name
=
building_name
)
floor
=
Floor
.
objects
.
get
(
number
=
floor_number
,
building
=
building
)
try
:
building
=
Building
.
objects
.
get
(
name
=
building_name
)
floor
=
Floor
.
objects
.
get
(
number
=
floor_number
,
building
=
building
)
except
ObjectDoesNotExist
:
raise
Http404
return
floor
def
get_context_data
(
self
,
**
kwargs
):
...
...
@@ -117,11 +125,14 @@ class DetailRoom(LoginRequiredMixin, DetailView):
building_name
=
url_parts
[
2
].
replace
(
'-'
,
' '
).
title
()
floor_number
=
url_parts
[
3
]
room_number
=
url_parts
[
4
].
upper
()
building
=
Building
.
objects
.
get
(
name
=
building_name
)
floor
=
Floor
.
objects
.
get
(
number
=
floor_number
,
building
=
building
)
room
=
Room
.
objects
.
get
(
floor
=
floor
,
number
=
room_number
)
try
:
building
=
Building
.
objects
.
get
(
name
=
building_name
)
floor
=
Floor
.
objects
.
get
(
number
=
floor_number
,
building
=
building
)
room
=
Room
.
objects
.
get
(
floor
=
floor
,
number
=
room_number
)
except
ObjectDoesNotExist
:
raise
Http404
return
room
def
get_context_data
(
self
,
**
kwargs
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment