diff --git a/README.md b/README.md index 49216b3..dc4c80a 100644 --- a/README.md +++ b/README.md @@ -34,5 +34,5 @@ Finally include the `drfdocs` urls in your `urls.py`: urlpatterns = [ ... - url(r'^docs/', include('drfdocs.urls', namespace='drfdocs')), + url(r'^docs/', include('drfdocs.urls', app_name='drfdocs', namespace='drfdocs')), ] diff --git a/drfdocs/api_docs.py b/drfdocs/api_docs.py new file mode 100644 index 0000000..809f214 --- /dev/null +++ b/drfdocs/api_docs.py @@ -0,0 +1,22 @@ +from django.conf import settings +from django.core.urlresolvers import RegexURLResolver, RegexURLPattern + + +class ApiDocumentation(object): + excluded_apps = ["admin", "drfdocs"] + excluded_endpoints = ["serve"] + root_urlconf = __import__(settings.ROOT_URLCONF) + + def __init__(self): + self.view_names = [] + self.get_all_view_names(self.root_urlconf.urls.urlpatterns) + + def get_all_view_names(self, urlpatterns): + for pattern in urlpatterns: + if isinstance(pattern, RegexURLResolver) and (pattern.app_name not in self.excluded_apps): + self.get_all_view_names(pattern.url_patterns) + elif isinstance(pattern, RegexURLPattern) and (pattern.callback.__name__ not in self.excluded_endpoints): + self.view_names.append(pattern.callback.__name__) + + def get_views(self): + return self.view_names diff --git a/drfdocs/api_endpoint.py b/drfdocs/api_endpoint.py new file mode 100644 index 0000000..e69de29 diff --git a/drfdocs/templates/drfdocs/base.html b/drfdocs/templates/drfdocs/base.html index 39f414c..68b55d9 100644 --- a/drfdocs/templates/drfdocs/base.html +++ b/drfdocs/templates/drfdocs/base.html @@ -7,5 +7,7 @@