add index views
diff --git a/xos/api/import_methods.py b/xos/api/import_methods.py
index d53556c..1b5e3ca 100644
--- a/xos/api/import_methods.py
+++ b/xos/api/import_methods.py
@@ -1,6 +1,7 @@
from django.views.generic import View
from django.conf.urls import patterns, url, include
from rest_framework.routers import DefaultRouter
+from xosapi_helpers import XOSIndexViewSet
import os, sys
import inspect
import importlib
@@ -35,6 +36,7 @@
return module
def import_api_methods(dirname=None, api_path="api", api_module="api"):
+ has_index_view = False
subdirs=[]
urlpatterns=[]
@@ -61,10 +63,12 @@
method_name = os.path.join(api_path, method_name)
else:
method_name = api_path
+ has_index_view = True
view_urls.append( (method_kind, method_name, classname, c) )
elif os.path.isdir(pathname):
urlpatterns.extend(import_api_methods(pathname, os.path.join(api_path, fn), api_module+"." + fn))
+ subdirs.append(fn)
for view_url in view_urls:
if view_url[0] == "list":
@@ -75,6 +79,9 @@
viewset = view_url[3]
urlpatterns.extend(viewset.get_urlpatterns(api_path="^"+api_path+"/"))
+ if not has_index_view:
+ urlpatterns.append(url('^' + api_path + '/$', XOSIndexViewSet.as_view({'get': 'list'}, view_urls=view_urls, subdirs=subdirs), name="api_path"+"_index"))
+
return urlpatterns
urlpatterns = import_api_methods()
diff --git a/xos/api/xosapi_helpers.py b/xos/api/xosapi_helpers.py
index ee3ed00..df405e5 100644
--- a/xos/api/xosapi_helpers.py
+++ b/xos/api/xosapi_helpers.py
@@ -97,3 +97,24 @@
patterns.append(url(self.get_api_method_path() + '(?P<pk>[a-zA-Z0-9\-]+)/$', self.as_view({'get': 'retrieve', 'put': 'update', 'post': 'update', 'delete': 'destroy', 'patch': 'partial_update'}), name=self.base_name+'_detail'))
return patterns
+
+class XOSIndexViewSet(viewsets.ViewSet):
+ view_urls=[]
+ subdirs=[]
+
+ def __init__(self, view_urls, subdirs):
+ self.view_urls = view_urls
+ self.subdirs = subdirs
+ super(XOSIndexViewSet, self).__init__()
+
+ def list(self, request):
+ endpoints = []
+ for view_url in self.view_urls:
+ method_name = view_url[1].split("/")[-1]
+ endpoints.append(method_name)
+
+ for subdir in self.subdirs:
+ endpoints.append(subdir)
+
+ return Response({"endpoints": endpoints})
+