forked from arenadata/adcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drf_docs.py
executable file
·59 lines (49 loc) · 2.01 KB
/
drf_docs.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
54
55
56
57
58
59
#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import adcm.init_django # pylint: disable=unused-import
import api.urls
def fix_ordering(field, view):
fix = field.replace('prototype__', 'prototype_')
fix = fix.replace('provider__', 'provider_')
fix = fix.replace('cluster__', 'cluster_')
fix = fix.replace('version_order', 'version')
if view.__name__ == 'ClusterServiceList':
if 'display_name' in fix:
fix = fix.replace('prototype_display_name', 'display_name')
elif view.__name__ == 'ServiceComponentList':
if 'display_name' in fix:
fix = fix.replace('component__display_name', 'display_name')
return fix
def drf_docs():
for p in api.urls.urlpatterns:
if not p.callback:
continue
if not hasattr(p.callback, 'view_class'):
continue
order = filtr = None
if hasattr(p.callback.view_class, 'ordering_fields'):
order = p.callback.view_class.ordering_fields
if hasattr(p.callback.view_class, 'filterset_fields'):
filtr = p.callback.view_class.filterset_fields
if not (order or filtr):
continue
print("{}".format(p.pattern))
if order:
print(" ORDERING: {}".format([
fix_ordering(ord, p.callback.view_class) for ord in order
]))
if filtr:
print(" FILTERING: {}".format([
fix_ordering(flt, p.callback.view_class) for flt in filtr
]))
drf_docs()