mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 13:30:12 +03:00
Initial components for documentation
This commit is contained in:
parent
abc62afddb
commit
c1707548d9
8
rest_framework/documentation.py
Normal file
8
rest_framework/documentation.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from rest_framework.renderers import DocumentationRenderer, CoreJSONRenderer
|
||||||
|
from rest_framework.schemas import get_schema_view
|
||||||
|
|
||||||
|
|
||||||
|
def get_docs_view(title=None, url=None, renderer_classes=None):
|
||||||
|
if renderer_classes is None:
|
||||||
|
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
|
||||||
|
return get_schema_view(title, url, renderer_classes)
|
|
@ -794,6 +794,16 @@ class AdminRenderer(BrowsableAPIRenderer):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentationRenderer(BaseRenderer):
|
||||||
|
media_type = 'text/html'
|
||||||
|
format = 'html'
|
||||||
|
charset = 'utf-8'
|
||||||
|
|
||||||
|
def render(self, data, accepted_media_type=None, renderer_context=None):
|
||||||
|
from coredocs.main import render as render_docs
|
||||||
|
return render_docs(data, theme='cerulean', highlight='emacs', static=lambda path: '/static/rest_framework/docs/' + path)
|
||||||
|
|
||||||
|
|
||||||
class MultiPartRenderer(BaseRenderer):
|
class MultiPartRenderer(BaseRenderer):
|
||||||
media_type = 'multipart/form-data; boundary=BoUnDaRyStRiNg'
|
media_type = 'multipart/form-data; boundary=BoUnDaRyStRiNg'
|
||||||
format = 'multipart'
|
format = 'multipart'
|
||||||
|
|
|
@ -242,7 +242,12 @@ class SchemaGenerator(object):
|
||||||
links = self.get_links(request)
|
links = self.get_links(request)
|
||||||
if not links:
|
if not links:
|
||||||
return None
|
return None
|
||||||
return coreapi.Document(title=self.title, url=self.url, content=links)
|
|
||||||
|
url = self.url
|
||||||
|
if not url and request is not None:
|
||||||
|
url = request.build_absolute_uri()
|
||||||
|
|
||||||
|
return coreapi.Document(title=self.title, url=url, content=links)
|
||||||
|
|
||||||
def get_links(self, request=None):
|
def get_links(self, request=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user