mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
fix #4965
This commit is contained in:
parent
7b0689a67f
commit
9c18c38da6
|
@ -0,0 +1,15 @@
|
|||
{% for section_key, section in items %}
|
||||
{% if section_key %}
|
||||
<h{{level}} id="{{prefix}}-{{ section_key }}" class="coredocs-section-title">{{ section_key }} <a href="#{{ section_key }}"><i class="fa fa-link" aria-hidden="true"></i>
|
||||
</a></h{{level}}>
|
||||
{% endif %}
|
||||
|
||||
{% if section.links.items %}
|
||||
{% for link_key, link in section.links.items %}
|
||||
{% include "rest_framework/docs/link.html" with prefix=prefix level=level|add:1%}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% include 'rest_framework/docs/_recursive_document.html' with items=section.items prefix=prefix|add:section_key|add:'/' level=level|add:1 %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<ul id="{% if prefix %}{{prefix}}-dropdown{% else %}menu-content{% endif %}" class="menu-content collapse out">
|
||||
{% for section_key, section in items %}
|
||||
<li data-toggle="collapse" data-target="#{{prefix}}{{ section_key }}-dropdown" class="collapsed">
|
||||
<a><i class="fa fa-dot-circle-o fa-lg"></i> {% if prefix %}{{prefix}}/{% endif %}{% if section_key %}{{ section_key }}{% else %}API Endpoints{% endif %} <span class="arrow"></span></a>
|
||||
</li>
|
||||
{% if section.links.items %}
|
||||
<ul class="sub-menu {% if section_key %}collapse{% endif %}" id="{{prefix}}{{ section_key }}-dropdown">
|
||||
{% for link_key, link in section.links.items %}
|
||||
<li><a href="#{{prefix}}-{{ section_key }}-{{ link_key }}">{{ link.title|default:link_key }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
{% include 'rest_framework/docs/_recursive_menu.html' with items=section.items prefix=prefix|add:section_key %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
@ -14,16 +14,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% for section_key, section in document.data|items %}
|
||||
{% if section_key %}
|
||||
<h2 id="{{ section_key }}" class="coredocs-section-title">{{ section_key }} <a href="#{{ section_key }}"><i class="fa fa-link" aria-hidden="true"></i>
|
||||
</a></h2>
|
||||
{% endif %}
|
||||
|
||||
{% for link_key, link in section.links|items %}
|
||||
{% include "rest_framework/docs/link.html" %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% include 'rest_framework/docs/_recursive_document.html' with items=document.data|items level=2 %}
|
||||
|
||||
{% for link_key, link in document.links|items %}
|
||||
{% include "rest_framework/docs/link.html" %}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
</div>
|
||||
|
||||
<form data-key='["{{ section_key }}", "{{ link_key }}"]' class="api-interaction">
|
||||
<form data-key='[{{ prefix|split_keys }} "{{ section_key }}", "{{ link_key }}"]' class="api-interaction">
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 request">
|
||||
|
|
|
@ -6,7 +6,7 @@ var schema = window.schema // Loaded by `schema.js`
|
|||
var client = new coreapi.Client()
|
||||
|
||||
// Interact with the API endpoint
|
||||
var action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
|
||||
var action = [{% if prefix %}{{ prefix|split_keys }} {% endif %}{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
|
||||
{% if link.fields %}var params = {
|
||||
{% for field in link.fields %} {{ field.name }}: ...{% if not loop.last %},{% endif %}
|
||||
{% endfor %}}
|
||||
|
|
|
@ -6,7 +6,7 @@ client = coreapi.Client()
|
|||
schema = client.get("{{ document.url }}"{% if schema_format %}, format="{{ schema_format }}"{% endif %})
|
||||
|
||||
# Interact with the API endpoint
|
||||
action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
|
||||
action = [{% if prefix %}{{ prefix|split_keys }} {% endif %}{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
|
||||
{% if link.fields %}params = {
|
||||
{% for field in link.fields %} "{{ field.name }}": ...{% if not loop.last %},{% endif %}
|
||||
{% endfor %}}
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
$ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
|
||||
|
||||
# Interact with the API endpoint
|
||||
$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</code></pre>
|
||||
$ coreapi action {% if prefix %}{{ prefix|split_keys:'cmd' }} {% endif %}{% if section_key %}{{ section_key }} {% endif %}{{ link_key }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</code></pre>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<i class="fa fa-exchange"></i> Interact
|
||||
</button>
|
||||
|
||||
<h3 id="{{ section_key }}-{{ link_key }}" class="coredocs-link-title">{{ link.title|default:link_key }} <a href="#{{ section_key }}-{{ link_key }}"><i class="fa fa-link" aria-hidden="true"></i>
|
||||
<h3 id="{{prefix}}-{{ section_key }}-{{ link_key }}" class="coredocs-link-title">{{ link.title|default:link_key }} <a href="#{{prefix}}-{{ section_key }}-{{ link_key }}"><i class="fa fa-link" aria-hidden="true"></i>
|
||||
</a></h3>
|
||||
|
||||
<div class="meta">
|
||||
|
|
|
@ -4,18 +4,7 @@
|
|||
|
||||
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
|
||||
<div class="menu-list">
|
||||
<ul id="menu-content" class="menu-content collapse out">
|
||||
{% for section_key, section in document.data|items %}
|
||||
<li data-toggle="collapse" data-target="#{{ section_key }}-dropdown" class="collapsed">
|
||||
<a><i class="fa fa-dot-circle-o fa-lg"></i> {% if section_key %}{{ section_key }}{% else %}API Endpoints{% endif %} <span class="arrow"></span></a>
|
||||
</li>
|
||||
<ul class="sub-menu {% if section_key %}collapse{% endif %}" id="{{ section_key }}-dropdown">
|
||||
{% for link_key, link in section.links|items %}
|
||||
<li><a href="#{{ section_key }}-{{ link_key }}">{{ link.title|default:link_key }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% include 'rest_framework/docs/_recursive_menu.html' with items=document.data|items %}
|
||||
|
||||
<ul class="menu-list menu-list-bottom">
|
||||
<li data-toggle="collapse" data-target="#auth-control" class="collapsed">
|
||||
|
|
|
@ -362,3 +362,22 @@ def break_long_headers(header):
|
|||
if len(header) > 160 and ',' in header:
|
||||
header = mark_safe('<br> ' + ', <br>'.join(header.split(',')))
|
||||
return header
|
||||
|
||||
|
||||
@register.filter
|
||||
def split_keys(keys, cmd_type='script'):
|
||||
if not keys:
|
||||
return ''
|
||||
|
||||
if cmd_type == 'script':
|
||||
joiner = ', '
|
||||
wrapper = '"'
|
||||
else:
|
||||
joiner = ' '
|
||||
wrapper = ''
|
||||
|
||||
return joiner.join([
|
||||
'{wrapper}{k}{wrapper}'.format(k=k, wrapper=wrapper)
|
||||
if k != '' else ''
|
||||
for k in keys.split('/')
|
||||
])
|
||||
|
|
Loading…
Reference in New Issue
Block a user