-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathurls.py
More file actions
253 lines (233 loc) · 8.27 KB
/
urls.py
File metadata and controls
253 lines (233 loc) · 8.27 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
from django.urls import path, resolvers
from django.views.generic import TemplateView
from public_api.metrics_interface.interface import MetricsPublicAPIInterface
from public_api.version_02.views import (
GeographyDetailViewV2,
GeographyListViewV2,
GeographyTypeDetailViewV2,
GeographyTypeListViewV2,
MetricListViewV2,
PublicAPIRootViewV2,
SubThemeDetailViewV2,
SubThemeListViewV2,
ThemeDetailViewV2,
ThemeListViewV2,
TopicDetailViewV2,
TopicListViewV2,
)
from public_api.version_02.views.timeseries_viewset import (
APITimeSeriesViewSetV2,
APITimeSeriesViewSetV3,
)
from public_api.views import (
GeographyDetailView,
GeographyListView,
GeographyTypeDetailView,
GeographyTypeListView,
MetricListView,
PublicAPIRootView,
SubThemeDetailView,
SubThemeListView,
ThemeDetailView,
ThemeListView,
TopicDetailView,
TopicListView,
)
from public_api.views.timeseries_viewset import APITimeSeriesViewSet
def construct_url_patterns_for_public_api(
*,
prefix: str,
) -> list[resolvers.URLResolver]:
"""Returns a set of URLResolvers for `public_api` endpoints
Args:
prefix: The prefix to add to the start of the paths
Returns:
List of `URLResolver` objects each representing a
set of versioned URLS.
"""
urls = []
urls.extend(_construct_version_one_urls(prefix=prefix))
urls.extend(_construct_version_two_urls(prefix=prefix))
urls.extend(_construct_version_three_urls(prefix=prefix))
if MetricsPublicAPIInterface.is_auth_enabled():
urls.append(
path(
"robots.txt",
TemplateView.as_view(
template_name="robots.txt", content_type="text/plain"
),
)
)
return urls
def _construct_version_one_urls(
*,
prefix: str,
) -> list[resolvers.URLResolver]:
"""Returns a list of URLResolvers for the public_api version 1
Args:
prefix: The prefix to add to the start of the url paths
Returns:
List of `URLResolver` objects each representing a
set of versioned URLS.
"""
return [
path(prefix, PublicAPIRootView.as_view(), name="public-api-root-version-1"),
path(f"{prefix}themes/", ThemeListView.as_view(), name="theme-list"),
path(
f"{prefix}themes/<str:theme>",
ThemeDetailView.as_view(),
name="theme-detail",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/",
SubThemeListView.as_view(),
name="sub_theme-list",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>",
SubThemeDetailView.as_view(),
name="sub_theme-detail",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics",
TopicListView.as_view(),
name="topic-list",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>",
TopicDetailView.as_view(),
name="topic-detail",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types",
GeographyTypeListView.as_view(),
name="geography_type-list",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>",
GeographyTypeDetailView.as_view(),
name="geography_type-detail",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies",
GeographyListView.as_view(),
name="geography-list",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies/<str:geography>",
GeographyDetailView.as_view(),
name="geography-detail",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies/<str:geography>/metrics",
MetricListView.as_view(),
name="metric-list",
),
path(
f"{prefix}themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies/<str:geography>/metrics/<str:metric>",
APITimeSeriesViewSet.as_view(
{"get": "list"}, name=APITimeSeriesViewSet.name
),
name="timeseries-list",
),
]
def _construct_version_two_urls(
*,
prefix: str,
) -> list[resolvers.URLResolver]:
"""Returns a list of URLResolvers for the public_api version 2
Args:
prefix: The prefix to add to the start of the url paths
Returns:
List of `URLResolver` objects each representing a
set of versioned URLS.
"""
return [
path(
f"{prefix}v2/",
PublicAPIRootViewV2.as_view(),
name="public-api-v2",
),
path(
f"{prefix}v2/themes/",
ThemeListViewV2.as_view(),
name="theme-list-v2",
),
path(
f"{prefix}v2/themes/<str:theme>",
ThemeDetailViewV2.as_view(),
name="theme-detail-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/",
SubThemeListViewV2.as_view(),
name="sub_theme-list-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>",
SubThemeDetailViewV2.as_view(),
name="sub_theme-detail-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics",
TopicListViewV2.as_view(),
name="topic-list-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>",
TopicDetailViewV2.as_view(),
name="topic-detail-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types",
GeographyTypeListViewV2.as_view(),
name="geography_type-list-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>",
GeographyTypeDetailViewV2.as_view(),
name="geography_type-detail-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies",
GeographyListViewV2.as_view(),
name="geography-list-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies/<str:geography>",
GeographyDetailViewV2.as_view(),
name="geography-detail-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies/<str:geography>/metrics",
MetricListViewV2.as_view(),
name="metric-list-v2",
),
path(
f"{prefix}v2/themes/<str:theme>/sub_themes/<str:sub_theme>/topics/<str:topic>/geography_types/<str:geography_type>/geographies/<str:geography>/metrics/<str:metric>",
APITimeSeriesViewSetV2.as_view(
{"get": "list"}, name=APITimeSeriesViewSet.name
),
name="timeseries-list-v2",
),
]
def _construct_version_three_urls(
*,
prefix: str,
) -> list[resolvers.URLResolver]:
"""Returns a list of URLResolvers for the public_api version 3
Args:
prefix: The prefix to add to the start of the url paths
Returns:
List of `URLResolver` objects each representing a
set of versioned URLS.
"""
return [
path(
f"{prefix}v3/themes/<str:theme>",
APITimeSeriesViewSetV3.as_view(
{"get": "list"}, name=APITimeSeriesViewSetV3.name
),
name="timeseries-list-v3",
),
]