urls.py 1.44 KB
Newer Older
1
2
3
4
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.conf.urls import patterns, include, url
5
from django.views.generic import RedirectView
6
# imports from your apps
7
from .views import BuildingList, BuildingRetrieve, FloorRetrieve, RoomRetrieve,\
8
                   MajorList, MajorRetrieve, APIRoot
9

10
# custom routing ftw
11
12

# API v1
13
14
15
# separate out major and building patterns
building_urls = patterns('',
    url(r'^$', BuildingList.as_view(), name='api_list_buildings'),
16
17
18
    url(r'^(?P<building_name>[\w-]+)/$', BuildingRetrieve.as_view(), name='api_detail_building'),
    # the naming here and for floors is a little obnoxious
    url(r'^(?P<building__building_name>[\w-]+)/(?P<floor_num>\d+)/$', FloorRetrieve.as_view(), name='api_detail_floor'),
19
    # list all the floors still?
20
    url(r'^(?P<floor__building__building_name>[\w-]+)/(?P<floor__floor_num>\d+)/(?P<room_num>\d+)/$', RoomRetrieve.as_view(), name='api_detail_room'),
21
22
    # list all the rooms still?
)
23

24
25
major_urls = patterns('',
    url(r'^$', MajorList.as_view(), name='api_list_majors'),
26
    url(r'^(?P<slug>[\w-]+)/$', MajorRetrieve.as_view(), name='api_detail_major'),
27
)
28

29
urlpatterns = patterns('',
30
31
32
33
    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')),
34
)
35
36

# Subsequent API versions below