diff --git a/README.md b/README.md index 151b278..dc60419 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ +## ** This package is no longer being maintained ** +## Please use [Django REST Swagger](https://github.com/marcgibbons/django-rest-swagger) + =========================== -Rest Framework Docs (0.1.6) +Rest Framework Docs (0.1.7) =========================== Rest Framework Docs is an application built to produce an inventory and documentation for your Django Rest Framework v2 endpoints. + Installation ------------ From pip: @@ -12,7 +16,7 @@ From pip: pip install django-rest-framework-docs From the source: -- Download the tarball: django-rest-framework-docs-0.1.6.tar.gz +- Download the tarball: django-rest-framework-docs-0.1.7.tar.gz - Extract files - Run python setup.py install @@ -133,6 +137,10 @@ Many thanks to Tom Christie for developing the Django Rest Framework - a tool I Release Notes ------------- +### v.0.1.7 (Sept 5, 2013) +- Added filtering & ordering +- URL flattening & custom serializer fixes + ### v.0.1.6 (June 5, 2013) - Bugfix when url patterns property 'name' is None @@ -169,6 +177,8 @@ Contributors - @swistakm - Peter Baumgartner (@ipmb) - Marlon Bailey (@avinash240) +- @filipeximenes +- @pleasedontbelong License -------- diff --git a/cigar_example/cigar_example/restapi/views.py b/cigar_example/cigar_example/restapi/views.py index 2830696..dffc3dd 100644 --- a/cigar_example/cigar_example/restapi/views.py +++ b/cigar_example/cigar_example/restapi/views.py @@ -12,7 +12,9 @@ class CigarList(ListCreateAPIView): model = Cigar """ This is the model """ serializer_class = CigarSerializer - + ordering = ("price", "length") + filter_fields = ("colour",) + search_fields = ("name", "manufacturer",) class CigarDetails(RetrieveUpdateDestroyAPIView): """ diff --git a/dist/django-rest-framework-docs-0.1.7.tar.gz b/dist/django-rest-framework-docs-0.1.7.tar.gz new file mode 100644 index 0000000..7f7f3ce Binary files /dev/null and b/dist/django-rest-framework-docs-0.1.7.tar.gz differ diff --git a/rest_framework_docs/__init__.py b/rest_framework_docs/__init__.py index 2fb2513..124e462 100644 --- a/rest_framework_docs/__init__.py +++ b/rest_framework_docs/__init__.py @@ -1 +1 @@ -__version__ = '0.1.6' +__version__ = '0.1.7' diff --git a/rest_framework_docs/docs.py b/rest_framework_docs/docs.py index d24c65b..b74fb70 100644 --- a/rest_framework_docs/docs.py +++ b/rest_framework_docs/docs.py @@ -7,6 +7,8 @@ from django.core.urlresolvers import RegexURLResolver, RegexURLPattern from rest_framework.views import APIView from itertools import groupby +from django.test.client import RequestFactory +from django.contrib.auth import get_user_model class DocumentationGenerator(): @@ -24,6 +26,8 @@ def __init__(self, urlpatterns=None): """ if urlpatterns is None: urlpatterns = self.get_url_patterns() + else: + urlpatterns = self._flatten_patterns_tree(urlpatterns) self.urlpatterns = urlpatterns @@ -126,6 +130,9 @@ def __process_urlpatterns(self): doc.model = self.__get_model__(callback) doc.allowed_methods = self.__get_allowed_methods__(callback) doc.fields = self.__get_serializer_fields__(callback) + doc.filter_fields = self.__get_filter_fields__(callback) + doc.search_fields = self.__get_search_fields__(callback) + doc.ordering = self.__get_ordering__(callback) docs.append(doc) del(doc) # Clean up @@ -216,10 +223,15 @@ def __get_serializer_fields__(self, callback): if not hasattr(callback, 'get_serializer_class'): return data + factory = RequestFactory() + request = factory.get('') + request.user = get_user_model()() + if hasattr(callback, '__call__'): - serializer = callback().get_serializer_class() - else: - serializer = callback.get_serializer_class() + callback = callback() + + callback.request = request + serializer = callback.get_serializer_class() try: fields = serializer().get_fields() @@ -238,6 +250,18 @@ def __get_serializer_fields__(self, callback): return data + def __get_filter_fields__(self, callback): + """Gets filter fields if described in API view""" + return getattr(callback, 'filter_fields', None) + + def __get_search_fields__(self, callback): + """Gets search fields if described in API view""" + return getattr(callback, 'search_fields', None) + + def __get_ordering__(self, callback): + """Gets ordering fields if described in API view""" + return getattr(callback, 'ordering', None) + def __trim(self, docstring): """ Trims whitespace from docstring @@ -256,3 +280,5 @@ class ApiDocObject(object): params = [] allowed_methods = [] model = None + + diff --git a/rest_framework_docs/templates/rest_framework_docs/docs.html b/rest_framework_docs/templates/rest_framework_docs/docs.html index d761251..bea5ed4 100644 --- a/rest_framework_docs/templates/rest_framework_docs/docs.html +++ b/rest_framework_docs/templates/rest_framework_docs/docs.html @@ -99,7 +99,8 @@ if (details.is(':visible')) { details.hide() - $(this).parent().removeClass('selected') } else { + $(this).parent().removeClass('selected') + } else { $(this).parent().addClass('selected') details.show() } @@ -208,6 +209,40 @@