forked from mozilla/zamboni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urls.py
53 lines (40 loc) · 1.65 KB
/
urls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
API URL versioning goes here.
The "current" version should be marked via the empty pattern. Each other
version's URLs should be loaded in this way, with the most recent versions
first:
url('^v2/', include('mkt.api.v2.urls')),
url('^v1/', include('mkt.api.v1.urls')),
Each version's URLs should live in its own submodule, and should inherit from
the previous version's patterns. Example:
from mkt.api.v1.urls import urlpatterns as v1_urls
router = SimpleRouter()
router.register(r'widgets', WidgetViewSet, base_name='widget')
urlpatterns = patterns('',
url(r'^widgets/', include(feed.urls)),
) + v1_urls
Strategies for deprecating and removing endpoints are currently being discussed
in bug 942934.
"""
from django.conf import settings
from django.conf.urls import include, patterns, url
def include_version(version):
"""
Returns an include statement containing URL patterns for the passed API
version. Adds a namespace if that version does not match
`settings.API_CURRENT_VERSION`, to ensure that reversed URLs always use the
current version.
"""
kwargs = {}
if version != settings.API_CURRENT_VERSION:
kwargs['namespace'] = 'api-v%d' % version
return include('mkt.api.v%d.urls' % version, **kwargs)
urlpatterns = patterns(
'',
url('^v2/', include_version(2)),
url('^v1/', include_version(1)),
# Necessary for backwards-compatibility. We assume that this always means
# API version 1. The namespace ensures that no URLS are ever reversed to
# this pattern. Yummycake because we already ate the tastypie.
url('', include('mkt.api.v1.urls', namespace='yummycake')),
)