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
fc5ec423
Commit
fc5ec423
authored
Aug 02, 2016
by
Daniel W Bond
Browse files
added api versioning and api root
parent
8565caae
Changes
2
Hide whitespace changes
Inline
Side-by-side
roomlist/api/urls.py
View file @
fc5ec423
...
...
@@ -2,11 +2,14 @@
from
__future__
import
absolute_import
,
print_function
# core django imports
from
django.conf.urls
import
patterns
,
include
,
url
from
django.views.generic
import
RedirectView
# imports from your apps
from
.views
import
BuildingList
,
BuildingRetrieve
,
FloorRetrieve
,
RoomRetrieve
,
\
MajorList
,
MajorRetrieve
MajorList
,
MajorRetrieve
,
APIRoot
# custom routing ftw
# API v1
# separate out major and building patterns
building_urls
=
patterns
(
''
,
url
(
r
'^$'
,
BuildingList
.
as_view
(),
name
=
'api_list_buildings'
),
...
...
@@ -20,10 +23,14 @@ building_urls = patterns('',
major_urls
=
patterns
(
''
,
url
(
r
'^$'
,
MajorList
.
as_view
(),
name
=
'api_list_majors'
),
url
(
r
'^(?P<slug>[\w-]+)/$'
,
MajorRetrieve
.
as_view
(),
name
=
'api_detail_
building
'
),
url
(
r
'^(?P<slug>[\w-]+)/$'
,
MajorRetrieve
.
as_view
(),
name
=
'api_detail_
major
'
),
)
urlpatterns
=
patterns
(
''
,
url
(
r
'^housing/'
,
include
(
building_urls
)),
url
(
r
'^majors/'
,
include
(
major_urls
)),
url
(
r
'^v1/housing/'
,
include
(
building_urls
)),
url
(
r
'^v1/majors/'
,
include
(
major_urls
)),
url
(
r
'^v1/$'
,
APIRoot
.
as_view
(),
name
=
'api_root'
),
url
(
r
'^$'
,
RedirectView
.
as_view
(
pattern_name
=
'api_root'
)),
)
# Subsequent API versions below
roomlist/api/views.py
View file @
fc5ec423
...
...
@@ -5,6 +5,9 @@ from django.shortcuts import get_object_or_404
# third party imports
from
rest_framework.pagination
import
PageNumberPagination
from
rest_framework.generics
import
ListAPIView
,
RetrieveAPIView
from
rest_framework.views
import
APIView
from
rest_framework.reverse
import
reverse
from
rest_framework.response
import
Response
# imports from your apps
from
housing.models
import
Building
,
Floor
,
Room
from
accounts.models
import
Major
...
...
@@ -84,3 +87,12 @@ class MajorRetrieve(RetrieveAPIView):
queryset
=
Major
.
objects
.
all
()
serializer_class
=
MajorSerializer
lookup_field
=
'slug'
# root urls
class
APIRoot
(
APIView
):
def
get
(
self
,
request
):
return
Response
({
'housing'
:
reverse
(
'api_list_buildings'
,
request
=
request
),
'majors'
:
reverse
(
'api_list_majors'
,
request
=
request
),
})
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