From 1ed82aa104cd3c4fb6471293e7cb429c75affab6 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Mon, 27 Feb 2017 19:24:21 +0000 Subject: [PATCH] Docs Authentication (#4926) * Authentication token modal & licenses * `none` menu item & Fix clear response * Pass authorisation header to coreapi client * Session Authentication * Fix bug with data/raw response both being displayed * Bump coreapi & remove it from static files * Default to session authentication if logged in * Basic Authentication & Favicon * Rename token to header authentication --- licenses/bootstrap.md | 22 +++ licenses/jquery.json-view.md | 22 +++ rest_framework/renderers.py | 7 +- rest_framework/schemas.py | 4 +- .../static/rest_framework/docs/css/base.css | 37 ++--- .../docs/css/jquery.json-view.min.css | 11 ++ .../rest_framework/docs/img/favicon.ico | Bin 1150 -> 5430 bytes .../docs/js/jquery.json-view.min.js | 7 + .../rest_framework/docs/auth/basic.html | 38 +++++ .../rest_framework/docs/auth/session.html | 35 +++++ .../rest_framework/docs/auth/token.html | 31 +++++ .../templates/rest_framework/docs/index.html | 130 ++++++++++++++++-- .../rest_framework/docs/interact.html | 2 +- .../rest_framework/docs/sidebar.html | 15 +- rest_framework/templatetags/rest_framework.py | 16 +++ 15 files changed, 340 insertions(+), 37 deletions(-) create mode 100644 licenses/bootstrap.md create mode 100644 licenses/jquery.json-view.md create mode 100755 rest_framework/static/rest_framework/docs/css/jquery.json-view.min.css create mode 100755 rest_framework/static/rest_framework/docs/js/jquery.json-view.min.js create mode 100644 rest_framework/templates/rest_framework/docs/auth/basic.html create mode 100644 rest_framework/templates/rest_framework/docs/auth/session.html create mode 100644 rest_framework/templates/rest_framework/docs/auth/token.html diff --git a/licenses/bootstrap.md b/licenses/bootstrap.md new file mode 100644 index 000000000..17fb503e7 --- /dev/null +++ b/licenses/bootstrap.md @@ -0,0 +1,22 @@ +https://github.com/twbs/bootstrap/ + +The MIT License (MIT) + +Copyright (c) 2011-2016 Twitter, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN diff --git a/licenses/jquery.json-view.md b/licenses/jquery.json-view.md new file mode 100644 index 000000000..146db3aa9 --- /dev/null +++ b/licenses/jquery.json-view.md @@ -0,0 +1,22 @@ +https://github.com/bazh/jquery.json-view/ + +The MIT License (MIT) + +Copyright (c) 2014 bazh. (http://github.com/bazh) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index ac0f49e5b..e456d1dac 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -801,7 +801,7 @@ class DocumentationRenderer(BaseRenderer): template = 'rest_framework/docs/index.html' code_style = 'emacs' - def get_context(self, data): + def get_context(self, data, request): from pygments.formatters import HtmlFormatter from django.utils.html import mark_safe formatter = HtmlFormatter(style=self.code_style) @@ -813,12 +813,13 @@ class DocumentationRenderer(BaseRenderer): 'document': data, 'langs': langs, 'code_style': code_style, - 'schema': schema + 'schema': schema, + 'request': request } def render(self, data, accepted_media_type=None, renderer_context=None): template = loader.get_template(self.template) - context = self.get_context(data) + context = self.get_context(data, renderer_context['request']) return template_render(template, context, request=renderer_context['request']) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index 1b3df23af..844bcc5da 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -57,13 +57,13 @@ def field_to_schema(field): return coreschema.String(title=title, description=description) elif isinstance(field, serializers.MultipleChoiceField): return coreschema.Array( - items=coreschema.Enum(enum=list(field.choices.values())), + items=coreschema.Enum(enum=list(field.choices.keys())), title=title, description=description ) elif isinstance(field, serializers.ChoiceField): return coreschema.Enum( - enum=list(field.choices.values()), + enum=list(field.choices.keys()), title=title, description=description ) diff --git a/rest_framework/static/rest_framework/docs/css/base.css b/rest_framework/static/rest_framework/docs/css/base.css index c1acaadc7..aa9550287 100644 --- a/rest_framework/static/rest_framework/docs/css/base.css +++ b/rest_framework/static/rest_framework/docs/css/base.css @@ -30,30 +30,28 @@ margin-bottom: 0; } +.sidebar .brand a { + color: #FFF; +} + +.sidebar .brand a:hover, +.sidebar .brand a:active, +.sidebar .brand a:focus { + text-decoration: none; +} + .sidebar .toggle-btn { display: none; } .sidebar .menu-list ul, .sidebar .menu-list li { + background: #2e353d; list-style: none; padding: 0px; margin: 0px; line-height: 35px; cursor: pointer; - /* - .collapsed{ - .arrow:before{ - font-family: FontAwesome; - content: "\f053"; - display: inline-block; - padding-left:10px; - padding-right: 10px; - vertical-align: middle; - float:right; - } - } -*/ } .sidebar .menu-list ul :not(collapsed) .arrow:before, @@ -97,8 +95,14 @@ background-color: #020203; } -.sidebar .menu-list ul .sub-menu li:before, -.sidebar .menu-list li .sub-menu li:before { + +.sidebar .menu-list ul .sub-menu li a, +.sidebar .menu-list li .sub-menu li a { + display: block; +} + +.sidebar .menu-list ul .sub-menu li a:before, +.sidebar .menu-list li .sub-menu li a:before { font-family: FontAwesome; content: "\f105"; display: inline-block; @@ -273,8 +277,9 @@ body { } .api-modal .modal-body .request-awaiting { - text-align: center; padding: 35px 10px; + color: #7F8177; + text-align: center; } .api-modal .modal-body .meta { diff --git a/rest_framework/static/rest_framework/docs/css/jquery.json-view.min.css b/rest_framework/static/rest_framework/docs/css/jquery.json-view.min.css new file mode 100755 index 000000000..a07568136 --- /dev/null +++ b/rest_framework/static/rest_framework/docs/css/jquery.json-view.min.css @@ -0,0 +1,11 @@ +.json-view{position:relative} +.json-view .collapser{width:20px;height:18px;display:block;position:absolute;left:-1.7em;top:-.2em;z-index:5;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAD1JREFUeNpiYGBgOADE%2F3Hgw0DM4IRHgSsDFOzFInmMAQnY49ONzZRjDFiADT7dMLALiE8y4AGW6LoBAgwAuIkf%2F%2FB7O9sAAAAASUVORK5CYII%3D);background-repeat:no-repeat;background-position:center center;opacity:.5;cursor:pointer} +.json-view .collapsed{-ms-transform:rotate(-90deg);-moz-transform:rotate(-90deg);-khtml-transform:rotate(-90deg);-webkit-transform:rotate(-90deg);-o-transform:rotate(-90deg);transform:rotate(-90deg)} +.json-view .bl{display:block;padding-left:20px;margin-left:-20px;position:relative} +.json-view{font-family:monospace} +.json-view ul{list-style-type:none;padding-left:2em;border-left:1px dotted;margin:.3em} +.json-view ul li{position:relative} +.json-view .comments,.json-view .dots{display:none;-moz-user-select:none;-ms-user-select:none;-khtml-user-select:none;-webkit-user-select:none;-o-user-select:none;user-select:none} +.json-view .comments{padding-left:.8em;font-style:italic;color:#888} +.json-view .bool,.json-view .null,.json-view .num,.json-view .undef{font-weight:700;color:#1A01CC} +.json-view .str{color:#800} \ No newline at end of file diff --git a/rest_framework/static/rest_framework/docs/img/favicon.ico b/rest_framework/static/rest_framework/docs/img/favicon.ico index e85006a3ce1c6fd81faa6d5a13095519c4a6fc96..17b2c5d983c9b13b29af3fa0f30bc0c6dc1ae44c 100644 GIT binary patch literal 5430 zcmeHK+fBnj5L_b)NC%i7L>b{Tq7gda6KH@s=z@SX*1r( z%x>(<>0;K|g>5#5tG9m?rU#!s^?;(86k(5=-l>lN%BcKy?g z$nRl8h3#F}c`5ypTuDt#pS%$Lo)*r=7*TUE{jesMcdf97+Qd_GG5wGq%df4!&WQPZ z{rUTduD@XZ)cX5C%^l3qb=1c7r+t_7eF;o4-)DN*7RG(%dEA>22(Bf+)4A7r_w?F# zgQfK1R?DBlL*GXjf4ff;wRX@t1bWn+3%%ElGcVkm-{}zaA7k`Ok9p$4c~Zze%&X71 zqSobn<}$z wPoFpZ+Oywy{-xfD7@oiGD`q&JyTSE2c&;nKZ|Bd_b#t!!TmRv(W`6bh1hJ*gHvj+t literal 1150 zcmd6lF-yZh9L1kl>(HSEK`2y^4yB6->f+$wD)=oNY!UheIt03Q=;qj=;8*Bap_4*& za8yAl;wmmx5Yyi^7dXN-WYdJ-{qNqpcez|5t#Fr0qTSYcPTG`I2PBk8r$~4kg^0zN zCJe(rhix3do!L$bZ+IuZ{i08x=JR3=e+M4pv0KsKA??{u_*EFfo|`p&t`Vf=jn{)F z1fKk9hWsmYwqWAP^JO*5u*R;*L&dX3H$%S7oB$f0{ISh{QVXuncnzN67WQH2`lip7 zhX+VI$6x$1+$8gMjh4+1l0N#8_0Fh=N#EwpKk{SeE!)SHFB@xQFX3y+8sF#_@!bDW eIdI-IC`$c%>bk?KbPeN9RHtL<1^)v~#xMt8oB^@` diff --git a/rest_framework/static/rest_framework/docs/js/jquery.json-view.min.js b/rest_framework/static/rest_framework/docs/js/jquery.json-view.min.js new file mode 100755 index 000000000..ce3a60435 --- /dev/null +++ b/rest_framework/static/rest_framework/docs/js/jquery.json-view.min.js @@ -0,0 +1,7 @@ +/** + * jquery.json-view - jQuery collapsible JSON plugin + * @version v1.0.0 + * @link http://github.com/bazh/jquery.json-view + * @license MIT + */ +!function(e){"use strict";var n=function(n){var a=e("",{"class":"collapser",on:{click:function(){var n=e(this);n.toggleClass("collapsed");var a=n.parent().children(".block"),p=a.children("ul");n.hasClass("collapsed")?(p.hide(),a.children(".dots, .comments").show()):(p.show(),a.children(".dots, .comments").hide())}}});return n&&a.addClass("collapsed"),a},a=function(a,p){var t=e.extend({},{nl2br:!0},p),r=function(e){return e.toString()?e.toString().replace(/&/g,"&").replace(/"/g,""").replace(//g,">"):""},s=function(n,a){return e("",{"class":a,html:r(n)})},l=function(a,p){switch(e.type(a)){case"object":p||(p=0);var c=e("",{"class":"block"}),d=Object.keys(a).length;if(!d)return c.append(s("{","b")).append(" ").append(s("}","b"));c.append(s("{","b"));var i=e("