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
be0c2af4
Commit
be0c2af4
authored
Oct 14, 2014
by
Jason D Yeomans
Browse files
Added Building api query, lists rooms and info
parent
fbc89840
Changes
3
Hide whitespace changes
Inline
Side-by-side
api/models.py
View file @
be0c2af4
...
...
@@ -35,9 +35,9 @@ class Room(models.Model):
number
=
models
.
IntegerField
()
floor
=
models
.
IntegerField
()
bedA
=
models
.
CharField
(
max_length
=
80
)
bedB
=
models
.
CharField
(
max_length
=
80
)
bedC
=
models
.
CharField
(
max_length
=
80
)
bedD
=
models
.
CharField
(
max_length
=
80
)
bedB
=
models
.
CharField
(
max_length
=
80
,
blank
=
True
)
bedC
=
models
.
CharField
(
max_length
=
80
,
blank
=
True
)
bedD
=
models
.
CharField
(
max_length
=
80
,
blank
=
True
)
building
=
models
.
ForeignKey
(
'Building'
)
def
__str__
(
self
):
# __unicode__ on Python 2
...
...
api/urls.py
View file @
be0c2af4
...
...
@@ -5,6 +5,6 @@ from api import views
urlpatterns
=
patterns
(
''
,
url
(
r
'^$'
,
views
.
index
,
name
=
'index'
),
url
(
r
'^building/(?P<building>.+)/(?P<room_number>\d+)$'
,
views
.
room
,
name
=
'room'
),
url
(
r
'^building/(?P<building>[a-zA-Z]+)$'
,
views
.
building
,
name
=
'building'
),
url
(
r
'^building/(?P<building
Name
>[a-zA-Z]+)$'
,
views
.
building
,
name
=
'building'
),
url
(
r
'^buildings/$'
,
views
.
buildings_list
,
name
=
'buildings_list'
),
)
api/views.py
View file @
be0c2af4
from
django.http
import
HttpResponse
from
api.models
import
Building
from
api.models
import
Building
,
Room
# Create your views here.
def
index
(
request
):
...
...
@@ -14,8 +14,21 @@ def buildings_list(request):
json
=
json
[:
-
1
]
+
']}'
return
HttpResponse
(
json
)
def
building
(
request
,
building
):
return
HttpResponse
(
"You are looking up building %s"
%
building
)
def
building
(
request
,
buildingName
):
room_list
=
Room
.
objects
.
filter
(
building__name
=
""
+
buildingName
)
json
=
'{"'
+
buildingName
+
'":['
for
p
in
room_list
:
json
+=
'"'
+
p
.
number
.
__str__
()
+
'":['
json
+=
'"floor":'
+
p
.
floor
.
__str__
()
+
',"bedA":"'
+
p
.
bedA
.
__str__
()
+
'"'
if
p
.
bedB
.
__str__
()
is
not
''
:
json
+=
',"bedB":"'
+
p
.
bedB
.
__str__
()
+
'"'
if
p
.
bedC
.
__str__
()
is
not
''
:
json
+=
',"bedC":"'
+
p
.
bedC
.
__str__
()
+
'"'
if
p
.
bedD
.
__str__
()
is
not
''
:
json
+=
',"bedD":"'
+
p
.
bedD
.
__str__
()
+
'"'
json
+=
'],'
json
=
json
[:
-
1
]
+
']}'
return
HttpResponse
(
json
)
def
room
(
request
,
building
,
room_number
):
return
HttpResponse
(
"You are looking up room number %s in %s"
%
(
room_number
,
building
))
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