From bc6ecea15ddfdbdd19b0c125639f97840b5d113d Mon Sep 17 00:00:00 2001 From: yasinrawther Date: Thu, 20 Jul 2017 16:47:53 +0530 Subject: [PATCH 1/8] additionally fetch the max_length field to render in table --- rest_framework_docs/api_endpoint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework_docs/api_endpoint.py b/rest_framework_docs/api_endpoint.py index 953f9a0..1cbf53e 100644 --- a/rest_framework_docs/api_endpoint.py +++ b/rest_framework_docs/api_endpoint.py @@ -122,7 +122,8 @@ def __get_serializer_fields__(self, serializer): "type": str(field.__class__.__name__), "sub_fields": sub_fields, "required": field.required, - "to_many_relation": to_many_relation + "to_many_relation": to_many_relation, + "max_length": (field.__dict__.get('max_length', '-') if field.__dict__.get('max_length', '-') != None else '-') }) # FIXME: # Show more attibutes of `field`? From aa1cf3dedc9d8b2159d184aa5ebfffd0c472d2e3 Mon Sep 17 00:00:00 2001 From: yasinrawther Date: Thu, 20 Jul 2017 16:48:23 +0530 Subject: [PATCH 2/8] add additional settings 'DESC_TABLE' for the reference to render the field as ul or table --- rest_framework_docs/settings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework_docs/settings.py b/rest_framework_docs/settings.py index 2853a7b..50b230b 100644 --- a/rest_framework_docs/settings.py +++ b/rest_framework_docs/settings.py @@ -5,7 +5,8 @@ class DRFSettings(object): def __init__(self): self.drf_settings = { - "HIDE_DOCS": self.get_setting("HIDE_DOCS") or False + "HIDE_DOCS": self.get_setting("HIDE_DOCS") or False, + "DESC_TABLE": self.get_setting("DESC_TABLE") or False } def get_setting(self, name): From b4558a0336704fc1b27ffd557ada10fa9d8f6eb5 Mon Sep 17 00:00:00 2001 From: yasinrawther Date: Thu, 20 Jul 2017 16:48:49 +0530 Subject: [PATCH 3/8] add desc_table column for to reference in home.html --- rest_framework_docs/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rest_framework_docs/views.py b/rest_framework_docs/views.py index 50400d4..fb837f4 100644 --- a/rest_framework_docs/views.py +++ b/rest_framework_docs/views.py @@ -24,4 +24,5 @@ def get_context_data(self, **kwargs): context['query'] = query context['endpoints'] = endpoints + context['desc_table'] = settings['DESC_TABLE'] return context From 91a65676a07d767433240785eaf615e21654f877 Mon Sep 17 00:00:00 2001 From: yasinrawther Date: Thu, 20 Jul 2017 16:49:17 +0530 Subject: [PATCH 4/8] template update with table, Based on 'DESC_TABLE' condition to render the fields in table --- .../templates/rest_framework_docs/home.html | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/rest_framework_docs/templates/rest_framework_docs/home.html b/rest_framework_docs/templates/rest_framework_docs/home.html index e13e5a5..11f2b1c 100644 --- a/rest_framework_docs/templates/rest_framework_docs/home.html +++ b/rest_framework_docs/templates/rest_framework_docs/home.html @@ -1,3 +1,24 @@ + + + + + {% extends "rest_framework_docs/docs.html" %} {% load drfdocs_filters %} @@ -65,8 +86,29 @@

{% endif %} {% if endpoint.fields %} + {% if desc_table %} +

Fields details:

+ + + + + + + + {% for field in endpoint.fields %} + + + + + + + {% endfor %} +
Field Name Field Type Max Length Is Required
{{ field.name }} {{ field.type }} {{ field.max_length }} {{ field.required }}
+ {% else %} +

Fields:

{%include "rest_framework_docs/components/fields_list.html" with fields=endpoint.fields %} + {% endif %} {% elif not endpoint.errors %}

No fields.

{% endif %} @@ -99,3 +141,4 @@