urls.py 1.67 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
Eyad Hasan's avatar
Eyad Hasan committed
6
from django.views.decorators.cache import cache_page
7
# imports from your apps
8
from .views import BuildingList, BuildingRetrieve, FloorRetrieve, RoomRetrieve,\
9
                   MajorList, MajorRetrieve, APIRoot
10

11
# custom routing ftw
12 13

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

28
major_urls = patterns('',
Eyad Hasan's avatar
Spacing  
Eyad Hasan committed
29 30 31 32
    url(r'^$', cache_page(60*60)(MajorList.as_view()),
    name='api_list_majors'),
    url(r'^(?P<slug>[\w-]+)/$',  cache_page(60*60)(MajorRetrieve.as_view()),
    name='api_detail_major'),
33
)
34

35
# Added API Caching
36
urlpatterns = patterns('',
37 38
    url(r'^v1/housing/', include(building_urls)),
    url(r'^v1/majors/', include(major_urls)),
Eyad Hasan's avatar
Spacing  
Eyad Hasan committed
39 40
    url(r'^v1/$', cache_page(60*60)(APIRoot.as_view()),
    name='api_root'),
41
    url(r'^$',  RedirectView.as_view(pattern_name='api_root')),
42
)
43 44

# Subsequent API versions below