Debian Codegraph @

docs/index.html

raw
1 <!DOCTYPE html>
2 <!--
3 Backdoc is a tool for backbone-like documentation generation.
4 Backdoc main goal is to help to generate one page documentation from one markdown source file.
5
6 https://github.com/chibisov/backdoc
7 -->
8 <html lang="ru">
9 <head>
10 <meta charset="UTF-8"/>
11 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
12 <meta name="HandheldFriendly" content="true" />
13 <title>Django Rest Framework extensions documentation</title>
14
15 <!-- Bootstrap -->
16 <style type="text/css">
17 /*!
18 * Bootstrap v3.0.0
19 *
20 * Copyright 2013 Twitter, Inc
21 * Licensed under the Apache License v2.0
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Designed and built with all the love in the world by @mdo and @fat.
25 *//*! normalize.css v2.1.0 | MIT License | git.io/normalize */
26 article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,video{display:inline-block}audio:not([controls]){display:none;height:0}[hidden]{display:none}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}a:focus{outline:thin dotted}a:active,a:hover{outline:0}h1{margin:.67em 0;font-size:2em}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}hr{height:0;-moz-box-sizing:content-box;box-sizing:content-box}mark{color:#000;background:#ff0}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em}pre{white-space:pre-wrap}q{quotes:"C" "D" "8" "9"}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:0}fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid #c0c0c0}legend{padding:0;border:0}button,input,select,textarea{margin:0;font-family:inherit;font-size:100%}button,input{line-height:normal}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;-webkit-appearance:button}button[disabled],html input[disabled]{cursor:default}input[type="checkbox"],input[type="radio"]{padding:0;box-sizing:border-box}input[type="search"]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}textarea{overflow:auto;vertical-align:top}table{border-collapse:collapse;border-spacing:0}@media print{*{color:#000!important;text-shadow:none!important;background:transparent!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100%!important}@page{margin:2cm .5cm}p,h2,h3{orphans:3;widows:3}h2,h3{page-break-after:avoid}.navbar{display:none}.table td,.table th{background-color:#fff!important}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table{border-collapse:collapse!important}.table-bordered th,.table-bordered td{border:1px solid #ddd!important}}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}html{font-size:62.5%;-webkit-tap-highlight-color:rgba(0,0,0,0)}body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.428571429;color:#333;background-color:#fff}input,button,select,textarea{font-family:inherit;font-size:inherit;line-height:inherit}a{color:#428bca;text-decoration:none}a:hover,a:focus{color:#2a6496;text-decoration:underline}a:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}img{vertical-align:middle}.img-responsive{display:inline-block;height:auto;max-width:100%}.img-rounded{border-radius:6px}.img-circle{border-radius:500px}hr{margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:16.099999999999998px;font-weight:200;line-height:1.4}@media(min-width:768px){.lead{font-size:21px}}small{font-size:85%}cite{font-style:normal}.text-muted{color:#999}.text-primary{color:#428bca}.text-warning{color:#c09853}.text-danger{color:#b94a48}.text-success{color:#468847}.text-info{color:#3a87ad}.text-left{text-align:left}.text-right{text-align:right}.text-center{text-align:center}h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:500;line-height:1.1}h1 small,h2 small,h3 small,h4 small,h5 small,h6 small,.h1 small,.h2 small,.h3 small,.h4 small,.h5 small,.h6 small{font-weight:normal;line-height:1;color:#999}h1,h2,h3{margin-top:20px;margin-bottom:10px}h4,h5,h6{margin-top:10px;margin-bottom:10px}h1,.h1{font-size:38px}h2,.h2{font-size:32px}h3,.h3{font-size:24px}h4,.h4{font-size:18px}h5,.h5{font-size:14px}h6,.h6{font-size:12px}h1 small,.h1 small{font-size:24px}h2 small,.h2 small{font-size:18px}h3 small,.h3 small,h4 small,.h4 small{font-size:14px}.page-header{padding-bottom:9px;margin:40px 0 20px;border-bottom:1px solid #eee}ul,ol{margin-top:0;margin-bottom:10px}ul ul,ol ul,ul ol,ol ol{margin-bottom:0}.list-unstyled{padding-left:0;list-style:none}.list-inline{padding-left:0;list-style:none}.list-inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt,dd{line-height:1.428571429}dt{font-weight:bold}dd{margin-left:0}.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}.dl-horizontal dd:before,.dl-horizontal dd:after{display:table;content:" "}.dl-horizontal dd:after{clear:both}.dl-horizontal dd:before,.dl-horizontal dd:after{display:table;content:" "}.dl-horizontal dd:after{clear:both}abbr[title],abbr[data-original-title]{cursor:help;border-bottom:1px dotted #999}abbr.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:10px 20px;margin:0 0 20px;border-left:5px solid #eee}blockquote p{font-size:17.5px;font-weight:300;line-height:1.25}blockquote p:last-child{margin-bottom:0}blockquote small{display:block;line-height:1.428571429;color:#999}blockquote small:before{content:'4 A0'}blockquote.pull-right{float:right;padding-right:15px;padding-left:0;border-right:5px solid #eee;border-left:0}blockquote.pull-right p,blockquote.pull-right small{text-align:right}blockquote.pull-right small:before{content:''}blockquote.pull-right small:after{content:'A0 4'}q:before,q:after,blockquote:before,blockquote:after{content:""}address{display:block;margin-bottom:20px;font-style:normal;line-height:1.428571429}code,pre{font-family:Monaco,Menlo,Consolas,"Courier New",monospace}code{padding:2px 4px;font-size:90%;color:#c7254e;white-space:nowrap;background-color:#f9f2f4;border-radius:4px}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:1.428571429;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;border-radius:4px}pre.prettyprint{margin-bottom:20px}pre code{padding:0;color:inherit;white-space:pre-wrap;background-color:transparent;border:0}.pre-scrollable{max-height:340px;overflow-y:scroll}.container{margin-right:auto;margin-left:auto}.container:before,.container:after{display:table;content:" "}.container:after{clear:both}.container:before,.container:after{display:table;content:" "}.container:after{clear:both}.row:before,.row:after{display:table;content:" "}.row:after{clear:both}.row:before,.row:after{display:table;content:" "}.row:after{clear:both}@media(min-width:768px){.row{margin-right:-15px;margin-left:-15px}}.row .row{margin-right:-15px;margin-left:-15px}.col-1,.col-2,.col-3,.col-4,.col-5,.col-6,.col-7,.col-8,.col-9,.col-10,.col-11,.col-12,.col-sm-1,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-sm-10,.col-sm-11,.col-sm-12,.col-lg-1,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-lg-10,.col-lg-11,.col-lg-12{position:relative;min-height:1px;padding-right:15px;padding-left:15px}.col-1,.col-2,.col-3,.col-4,.col-5,.col-6,.col-7,.col-8,.col-9,.col-10,.col-11,.col-12{float:left}.col-1{width:8.333333333333332%}.col-2{width:16.666666666666664%}.col-3{width:25%}.col-4{width:33.33333333333333%}.col-5{width:41.66666666666667%}.col-6{width:50%}.col-7{width:58.333333333333336%}.col-8{width:66.66666666666666%}.col-9{width:75%}.col-10{width:83.33333333333334%}.col-11{width:91.66666666666666%}.col-12{width:100%}@media(min-width:768px){.container{max-width:728px}.col-sm-1,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-sm-10,.col-sm-11,.col-sm-12{float:left}.col-sm-1{width:8.333333333333332%}.col-sm-2{width:16.666666666666664%}.col-sm-3{width:25%}.col-sm-4{width:33.33333333333333%}.col-sm-5{width:41.66666666666667%}.col-sm-6{width:50%}.col-sm-7{width:58.333333333333336%}.col-sm-8{width:66.66666666666666%}.col-sm-9{width:75%}.col-sm-10{width:83.33333333333334%}.col-sm-11{width:91.66666666666666%}.col-sm-12{width:100%}.col-push-1{left:8.333333333333332%}.col-push-2{left:16.666666666666664%}.col-push-3{left:25%}.col-push-4{left:33.33333333333333%}.col-push-5{left:41.66666666666667%}.col-push-6{left:50%}.col-push-7{left:58.333333333333336%}.col-push-8{left:66.66666666666666%}.col-push-9{left:75%}.col-push-10{left:83.33333333333334%}.col-push-11{left:91.66666666666666%}.col-pull-1{right:8.333333333333332%}.col-pull-2{right:16.666666666666664%}.col-pull-3{right:25%}.col-pull-4{right:33.33333333333333%}.col-pull-5{right:41.66666666666667%}.col-pull-6{right:50%}.col-pull-7{right:58.333333333333336%}.col-pull-8{right:66.66666666666666%}.col-pull-9{right:75%}.col-pull-10{right:83.33333333333334%}.col-pull-11{right:91.66666666666666%}}@media(min-width:992px){.container{max-width:940px}.col-lg-1,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-lg-10,.col-lg-11,.col-lg-12{float:left}.col-lg-1{width:8.333333333333332%}.col-lg-2{width:16.666666666666664%}.col-lg-3{width:25%}.col-lg-4{width:33.33333333333333%}.col-lg-5{width:41.66666666666667%}.col-lg-6{width:50%}.col-lg-7{width:58.333333333333336%}.col-lg-8{width:66.66666666666666%}.col-lg-9{width:75%}.col-lg-10{width:83.33333333333334%}.col-lg-11{width:91.66666666666666%}.col-lg-12{width:100%}.col-offset-1{margin-left:8.333333333333332%}.col-offset-2{margin-left:16.666666666666664%}.col-offset-3{margin-left:25%}.col-offset-4{margin-left:33.33333333333333%}.col-offset-5{margin-left:41.66666666666667%}.col-offset-6{margin-left:50%}.col-offset-7{margin-left:58.333333333333336%}.col-offset-8{margin-left:66.66666666666666%}.col-offset-9{margin-left:75%}.col-offset-10{margin-left:83.33333333333334%}.col-offset-11{margin-left:91.66666666666666%}}@media(min-width:1200px){.container{max-width:1170px}}table{max-width:100%;background-color:transparent}th{text-align:left}.table{width:100%;margin-bottom:20px}.table thead>tr>th,.table tbody>tr>th,.table tfoot>tr>th,.table thead>tr>td,.table tbody>tr>td,.table tfoot>tr>td{padding:8px;line-height:1.428571429;vertical-align:top;border-top:1px solid #ddd}.table thead>tr>th{vertical-align:bottom}.table caption+thead tr:first-child th,.table colgroup+thead tr:first-child th,.table thead:first-child tr:first-child th,.table caption+thead tr:first-child td,.table colgroup+thead tr:first-child td,.table thead:first-child tr:first-child td{border-top:0}.table tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed thead>tr>th,.table-condensed tbody>tr>th,.table-condensed tfoot>tr>th,.table-condensed thead>tr>td,.table-condensed tbody>tr>td,.table-condensed tfoot>tr>td{padding:5px}.table-bordered{border:1px solid #ddd}.table-bordered>thead>tr>th,.table-bordered>tbody>tr>th,.table-bordered>tfoot>tr>th,.table-bordered>thead>tr>td,.table-bordered>tbody>tr>td,.table-bordered>tfoot>tr>td{border:1px solid #ddd}.table-striped>tbody>tr:nth-child(odd)>td,.table-striped>tbody>tr:nth-child(odd)>th{background-color:#f9f9f9}.table-hover>tbody>tr:hover>td,.table-hover>tbody>tr:hover>th{background-color:#f5f5f5}table col[class^="col-"]{display:table-column;float:none}table td[class^="col-"],table th[class^="col-"]{display:table-cell;float:none}.table>thead>tr>td.active,.table>tbody>tr>td.active,.table>tfoot>tr>td.active,.table>thead>tr>th.active,.table>tbody>tr>th.active,.table>tfoot>tr>th.active,.table>thead>tr.active>td,.table>tbody>tr.active>td,.table>tfoot>tr.active>td,.table>thead>tr.active>th,.table>tbody>tr.active>th,.table>tfoot>tr.active>th{background-color:#f5f5f5}.table>thead>tr>td.success,.table>tbody>tr>td.success,.table>tfoot>tr>td.success,.table>thead>tr>th.success,.table>tbody>tr>th.success,.table>tfoot>tr>th.success,.table>thead>tr.success>td,.table>tbody>tr.success>td,.table>tfoot>tr.success>td,.table>thead>tr.success>th,.table>tbody>tr.success>th,.table>tfoot>tr.success>th{background-color:#dff0d8;border-color:#d6e9c6}.table>thead>tr>td.danger,.table>tbody>tr>td.danger,.table>tfoot>tr>td.danger,.table>thead>tr>th.danger,.table>tbody>tr>th.danger,.table>tfoot>tr>th.danger,.table>thead>tr.danger>td,.table>tbody>tr.danger>td,.table>tfoot>tr.danger>td,.table>thead>tr.danger>th,.table>tbody>tr.danger>th,.table>tfoot>tr.danger>th{background-color:#f2dede;border-color:#eed3d7}.table>thead>tr>td.warning,.table>tbody>tr>td.warning,.table>tfoot>tr>td.warning,.table>thead>tr>th.warning,.table>tbody>tr>th.warning,.table>tfoot>tr>th.warning,.table>thead>tr.warning>td,.table>tbody>tr.warning>td,.table>tfoot>tr.warning>td,.table>thead>tr.warning>th,.table>tbody>tr.warning>th,.table>tfoot>tr.warning>th{background-color:#fcf8e3;border-color:#fbeed5}.table-hover>tbody>tr>td.success:hover,.table-hover>tbody>tr>th.success:hover,.table-hover>tbody>tr.success:hover>td{background-color:#d0e9c6;border-color:#c9e2b3}.table-hover>tbody>tr>td.danger:hover,.table-hover>tbody>tr>th.danger:hover,.table-hover>tbody>tr.danger:hover>td{background-color:#ebcccc;border-color:#e6c1c7}.table-hover>tbody>tr>td.warning:hover,.table-hover>tbody>tr>th.warning:hover,.table-hover>tbody>tr.warning:hover>td{background-color:#faf2cc;border-color:#f8e5be}fieldset{padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:inherit;color:#333;border:0;border-bottom:1px solid #e5e5e5}label{display:inline-block;margin-bottom:5px;font-weight:bold}input[type="search"]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}input[type="radio"],input[type="checkbox"]{margin:4px 0 0;margin-top:1px \9;line-height:normal}input[type="file"]{display:block}select[multiple],select[size]{height:auto}select optgroup{font-family:inherit;font-size:inherit;font-style:inherit}input[type="file"]:focus,input[type="radio"]:focus,input[type="checkbox"]:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}input[type="number"]::-webkit-outer-spin-button,input[type="number"]::-webkit-inner-spin-button{height:auto}.form-control:-moz-placeholder{color:#999}.form-control::-moz-placeholder{color:#999}.form-control:-ms-input-placeholder{color:#999}.form-control::-webkit-input-placeholder{color:#999}.form-control{display:block;width:100%;height:38px;padding:8px 12px;font-size:14px;line-height:1.428571429;color:#555;vertical-align:middle;background-color:#fff;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.form-control:focus{border-color:rgba(82,168,236,0.8);outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(82,168,236,0.6)}.form-control[disabled],.form-control[readonly],fieldset[disabled] .form-control{cursor:not-allowed;background-color:#eee}textarea.form-control{height:auto}.form-group{margin-bottom:15px}.radio,.checkbox{display:block;min-height:20px;padding-left:20px;margin-top:10px;margin-bottom:10px;vertical-align:middle}.radio label,.checkbox label{display:inline;margin-bottom:0;font-weight:normal;cursor:pointer}.radio input[type="radio"],.radio-inline input[type="radio"],.checkbox input[type="checkbox"],.checkbox-inline input[type="checkbox"]{float:left;margin-left:-20px}.radio+.radio,.checkbox+.checkbox{margin-top:-5px}.radio-inline,.checkbox-inline{display:inline-block;padding-left:20px;margin-bottom:0;font-weight:normal;vertical-align:middle;cursor:pointer}.radio-inline+.radio-inline,.checkbox-inline+.checkbox-inline{margin-top:0;margin-left:10px}.form-control.input-large{height:56px;padding:14px 16px;font-size:18px;border-radius:6px}.form-control.input-small{height:30px;padding:5px 10px;font-size:12px;border-radius:3px}select.input-large{height:56px;line-height:56px}select.input-small{height:30px;line-height:30px}.has-warning .help-block,.has-warning .control-label{color:#c09853}.has-warning .form-control{padding-right:32px;border-color:#c09853;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.has-warning .form-control:focus{border-color:#a47e3c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #dbc59e}.has-warning .input-group-addon{color:#c09853;background-color:#fcf8e3;border-color:#c09853}.has-error .help-block,.has-error .control-label{color:#b94a48}.has-error .form-control{padding-right:32px;border-color:#b94a48;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.has-error .form-control:focus{border-color:#953b39;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #d59392}.has-error .input-group-addon{color:#b94a48;background-color:#f2dede;border-color:#b94a48}.has-success .help-block,.has-success .control-label{color:#468847}.has-success .form-control{padding-right:32px;border-color:#468847;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);box-shadow:inset 0 1px 1px rgba(0,0,0,0.075)}.has-success .form-control:focus{border-color:#356635;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075),0 0 6px #7aba7b}.has-success .input-group-addon{color:#468847;background-color:#dff0d8;border-color:#468847}.help-block{display:block;margin-top:5px;margin-bottom:10px;color:#737373}.input-group{display:table;border-collapse:separate}.input-group.col{float:none;padding-right:0;padding-left:0}.input-group .form-control{width:100%;margin-bottom:0}.input-group-addon,.input-group-btn,.input-group .form-control{display:table-cell}.input-group-addon:not(:first-child):not(:last-child),.input-group-btn:not(:first-child):not(:last-child),.input-group .form-control:not(:first-child):not(:last-child){border-radius:0}.input-group-addon,.input-group-btn{width:1%;white-space:nowrap;vertical-align:middle}.input-group-addon{padding:8px 12px;font-size:14px;font-weight:normal;line-height:1.428571429;text-align:center;background-color:#eee;border:1px solid #ccc;border-radius:4px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.input-group-addon.input-small{padding:5px 10px;font-size:12px;border-radius:3px}.input-group-addon.input-large{padding:14px 16px;font-size:18px;border-radius:6px}.input-group .form-control:first-child,.input-group-addon:first-child,.input-group-btn:first-child>.btn,.input-group-btn:first-child>.dropdown-toggle,.input-group-btn:last-child>.btn:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.input-group-addon:first-child{border-right:0}.input-group .form-control:last-child,.input-group-addon:last-child,.input-group-btn:last-child>.btn,.input-group-btn:last-child>.dropdown-toggle,.input-group-btn:first-child>.btn:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.input-group-addon:last-child{border-left:0}.input-group-btn{position:relative;white-space:nowrap}.input-group-btn>.btn{position:relative}.input-group-btn>.btn+.btn{margin-left:-4px}.input-group-btn>.btn:hover,.input-group-btn>.btn:active{z-index:2}.form-inline .form-control,.form-inline .radio,.form-inline .checkbox{display:inline-block}.form-inline .radio,.form-inline .checkbox{margin-top:0;margin-bottom:0}.form-horizontal .control-label{padding-top:6px}.form-horizontal .form-group:before,.form-horizontal .form-group:after{display:table;content:" "}.form-horizontal .form-group:after{clear:both}.form-horizontal .form-group:before,.form-horizontal .form-group:after{display:table;content:" "}.form-horizontal .form-group:after{clear:both}@media(min-width:768px){.form-horizontal .form-group{margin-right:-15px;margin-left:-15px}}.form-horizontal .form-group .row{margin-right:-15px;margin-left:-15px}@media(min-width:768px){.form-horizontal .control-label{text-align:right}}.btn{display:inline-block;padding:8px 12px;margin-bottom:0;font-size:14px;font-weight:500;line-height:1.428571429;text-align:center;white-space:nowrap;vertical-align:middle;cursor:pointer;border:1px solid transparent;border-radius:4px}.btn:focus{outline:thin dotted #333;outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn:hover,.btn:focus{color:#fff;text-decoration:none}.btn:active,.btn.active{outline:0;-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}.btn.disabled,.btn[disabled],fieldset[disabled] .btn{pointer-events:none;cursor:default;opacity:.65;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none}.btn-default{color:#fff;background-color:#474949;border-color:#474949}.btn-default:hover,.btn-default:focus,.btn-default:active,.btn-default.active{background-color:#3a3c3c;border-color:#2e2f2f}.btn-default.disabled,.btn-default[disabled],fieldset[disabled] .btn-default,.btn-default.disabled:hover,.btn-default[disabled]:hover,fieldset[disabled] .btn-default:hover,.btn-default.disabled:focus,.btn-default[disabled]:focus,fieldset[disabled] .btn-default:focus,.btn-default.disabled:active,.btn-default[disabled]:active,fieldset[disabled] .btn-default:active,.btn-default.disabled.active,.btn-default[disabled].active,fieldset[disabled] .btn-default.active{background-color:#474949;border-color:#474949}.btn-primary{color:#fff;background-color:#428bca;border-color:#428bca}.btn-primary:hover,.btn-primary:focus,.btn-primary:active,.btn-primary.active{background-color:#357ebd;border-color:#3071a9}.btn-primary.disabled,.btn-primary[disabled],fieldset[disabled] .btn-primary,.btn-primary.disabled:hover,.btn-primary[disabled]:hover,fieldset[disabled] .btn-primary:hover,.btn-primary.disabled:focus,.btn-primary[disabled]:focus,fieldset[disabled] .btn-primary:focus,.btn-primary.disabled:active,.btn-primary[disabled]:active,fieldset[disabled] .btn-primary:active,.btn-primary.disabled.active,.btn-primary[disabled].active,fieldset[disabled] .btn-primary.active{background-color:#428bca;border-color:#428bca}.btn-warning{color:#fff;background-color:#f0ad4e;border-color:#f0ad4e}.btn-warning:hover,.btn-warning:focus,.btn-warning:active,.btn-warning.active{background-color:#eea236;border-color:#ec971f}.btn-warning.disabled,.btn-warning[disabled],fieldset[disabled] .btn-warning,.btn-warning.disabled:hover,.btn-warning[disabled]:hover,fieldset[disabled] .btn-warning:hover,.btn-warning.disabled:focus,.btn-warning[disabled]:focus,fieldset[disabled] .btn-warning:focus,.btn-warning.disabled:active,.btn-warning[disabled]:active,fieldset[disabled] .btn-warning:active,.btn-warning.disabled.active,.btn-warning[disabled].active,fieldset[disabled] .btn-warning.active{background-color:#f0ad4e;border-color:#f0ad4e}.btn-danger{color:#fff;background-color:#d9534f;border-color:#d9534f}.btn-danger:hover,.btn-danger:focus,.btn-danger:active,.btn-danger.active{background-color:#d43f3a;border-color:#c9302c}.btn-danger.disabled,.btn-danger[disabled],fieldset[disabled] .btn-danger,.btn-danger.disabled:hover,.btn-danger[disabled]:hover,fieldset[disabled] .btn-danger:hover,.btn-danger.disabled:focus,.btn-danger[disabled]:focus,fieldset[disabled] .btn-danger:focus,.btn-danger.disabled:active,.btn-danger[disabled]:active,fieldset[disabled] .btn-danger:active,.btn-danger.disabled.active,.btn-danger[disabled].active,fieldset[disabled] .btn-danger.active{background-color:#d9534f;border-color:#d9534f}.btn-success{color:#fff;background-color:#5cb85c;border-color:#5cb85c}.btn-success:hover,.btn-success:focus,.btn-success:active,.btn-success.active{background-color:#4cae4c;border-color:#449d44}.btn-success.disabled,.btn-success[disabled],fieldset[disabled] .btn-success,.btn-success.disabled:hover,.btn-success[disabled]:hover,fieldset[disabled] .btn-success:hover,.btn-success.disabled:focus,.btn-success[disabled]:focus,fieldset[disabled] .btn-success:focus,.btn-success.disabled:active,.btn-success[disabled]:active,fieldset[disabled] .btn-success:active,.btn-success.disabled.active,.btn-success[disabled].active,fieldset[disabled] .btn-success.active{background-color:#5cb85c;border-color:#5cb85c}.btn-info{color:#fff;background-color:#5bc0de;border-color:#5bc0de}.btn-info:hover,.btn-info:focus,.btn-info:active,.btn-info.active{background-color:#46b8da;border-color:#31b0d5}.btn-info.disabled,.btn-info[disabled],fieldset[disabled] .btn-info,.btn-info.disabled:hover,.btn-info[disabled]:hover,fieldset[disabled] .btn-info:hover,.btn-info.disabled:focus,.btn-info[disabled]:focus,fieldset[disabled] .btn-info:focus,.btn-info.disabled:active,.btn-info[disabled]:active,fieldset[disabled] .btn-info:active,.btn-info.disabled.active,.btn-info[disabled].active,fieldset[disabled] .btn-info.active{background-color:#5bc0de;border-color:#5bc0de}.btn-link{font-weight:normal;color:#428bca;cursor:pointer;border-radius:0}.btn-link,.btn-link:active,.btn-link[disabled],fieldset[disabled] .btn-link{background-color:transparent;-webkit-box-shadow:none;box-shadow:none}.btn-link,.btn-link:hover,.btn-link:focus,.btn-link:active{border-color:transparent}.btn-link:hover,.btn-link:focus{color:#2a6496;text-decoration:underline;background-color:transparent}.btn-link[disabled]:hover,fieldset[disabled] .btn-link:hover,.btn-link[disabled]:focus,fieldset[disabled] .btn-link:focus{color:#333;text-decoration:none}.btn-large{padding:14px 16px;font-size:18px;border-radius:6px}.btn-small{padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.btn-block{display:block;width:100%;padding-right:0;padding-left:0}.btn-block+.btn-block{margin-top:5px}input[type="submit"].btn-block,input[type="reset"].btn-block,input[type="button"].btn-block{width:100%}.fade{opacity:0;-webkit-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{display:none}.collapse.in{display:block}.collapsing{position:relative;height:0;overflow:hidden;-webkit-transition:height .35s ease;transition:height .35s ease}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px solid #000;border-right:4px solid transparent;border-left:4px solid transparent;content:""}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.15);border-radius:4px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,0.175);box-shadow:0 6px 12px rgba(0,0,0,0.175);background-clip:padding-box}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:normal;line-height:1.428571429;color:#333;white-space:nowrap}.dropdown-menu>li>a:hover,.dropdown-menu>li>a:focus{color:#fff;text-decoration:none;background-color:#357ebd;background-image:-webkit-gradient(linear,left 0,left 100%,from(#428bca),to(#357ebd));background-image:-webkit-linear-gradient(top,#428bca,0%,#357ebd,100%);background-image:-moz-linear-gradient(top,#428bca 0,#357ebd 100%);background-image:linear-gradient(to bottom,#428bca 0,#357ebd 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca',endColorstr='#ff357ebd',GradientType=0)}.dropdown-menu>.active>a,.dropdown-menu>.active>a:hover,.dropdown-menu>.active>a:focus{color:#fff;text-decoration:none;background-color:#357ebd;background-image:-webkit-gradient(linear,left 0,left 100%,from(#428bca),to(#357ebd));background-image:-webkit-linear-gradient(top,#428bca,0%,#357ebd,100%);background-image:-moz-linear-gradient(top,#428bca 0,#357ebd 100%);background-image:linear-gradient(to bottom,#428bca 0,#357ebd 100%);background-repeat:repeat-x;outline:0;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca',endColorstr='#ff357ebd',GradientType=0)}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{color:#999}.dropdown-menu>.disabled>a:hover,.dropdown-menu>.disabled>a:focus{text-decoration:none;cursor:not-allowed;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.428571429;color:#999}.dropdown-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{border-top:0;border-bottom:4px solid #000;content:""}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:1px}.list-group{padding-left:0;margin-bottom:20px;background-color:#fff}.list-group-item{position:relative;display:block;padding:10px 30px 10px 15px;margin-bottom:-1px;border:1px solid #ddd}.list-group-item:first-child{border-top-right-radius:4px;border-top-left-radius:4px}.list-group-item:last-child{margin-bottom:0;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.list-group-item>.badge{float:right;margin-right:-15px}.list-group-item-heading{margin-top:0;margin-bottom:5px}.list-group-item-text{margin-bottom:0;line-height:1.3}a.list-group-item .list-group-item-heading{color:#333}a.list-group-item .list-group-item-text{color:#555}a.list-group-item:hover,a.list-group-item:focus{text-decoration:none;background-color:#f5f5f5}a.list-group-item.active{z-index:2;color:#fff;background-color:#428bca;border-color:#428bca}a.list-group-item.active .list-group-item-heading{color:inherit}a.list-group-item.active .list-group-item-text{color:#e1edf7}.panel{padding:15px;margin-bottom:20px;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,0.05);box-shadow:0 1px 1px rgba(0,0,0,0.05)}.panel-heading{padding:10px 15px;margin:-15px -15px 15px;background-color:#f5f5f5;border-bottom:1px solid #ddd;border-top-right-radius:3px;border-top-left-radius:3px}.panel-title{margin-top:0;margin-bottom:0;font-size:17.5px;font-weight:500}.panel-footer{padding:10px 15px;margin:15px -15px -15px;background-color:#f5f5f5;border-top:1px solid #ddd;border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel-primary{border-color:#428bca}.panel-primary .panel-heading{color:#fff;background-color:#428bca;border-color:#428bca}.panel-success{border-color:#d6e9c6}.panel-success .panel-heading{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.panel-warning{border-color:#fbeed5}.panel-warning .panel-heading{color:#c09853;background-color:#fcf8e3;border-color:#fbeed5}.panel-danger{border-color:#eed3d7}.panel-danger .panel-heading{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.panel-info{border-color:#bce8f1}.panel-info .panel-heading{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.list-group-flush{margin:15px -15px -15px}.list-group-flush .list-group-item{border-width:1px 0}.list-group-flush .list-group-item:first-child{border-top-right-radius:0;border-top-left-radius:0}.list-group-flush .list-group-item:last-child{border-bottom:0}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,0.05);box-shadow:inset 0 1px 1px rgba(0,0,0,0.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,0.15)}.well-large{padding:24px;border-radius:6px}.well-small{padding:9px;border-radius:3px}.close{float:right;font-size:21px;font-weight:bold;line-height:1;color:#000;text-shadow:0 1px 0 #fff;opacity:.2;filter:alpha(opacity=20)}.close:hover,.close:focus{color:#000;text-decoration:none;cursor:pointer;opacity:.5;filter:alpha(opacity=50)}button.close{padding:0;cursor:pointer;background:transparent;border:0;-webkit-appearance:none}.nav{padding-left:0;margin-bottom:0;list-style:none}.nav:before,.nav:after{display:table;content:" "}.nav:after{clear:both}.nav:before,.nav:after{display:table;content:" "}.nav:after{clear:both}.nav>li{position:relative;display:block}.nav>li>a{position:relative;display:block;padding:10px 15px}.nav>li>a:hover,.nav>li>a:focus{text-decoration:none;background-color:#eee}.nav>li.disabled>a{color:#999}.nav>li.disabled>a:hover,.nav>li.disabled>a:focus{color:#999;text-decoration:none;cursor:not-allowed;background-color:transparent}.nav>li+.nav-header{margin-top:9px}.nav.open>a,.nav.open>a:hover,.nav.open>a:focus{color:#fff;background-color:#428bca;border-color:#428bca}.nav.open>a .caret,.nav.open>a:hover .caret,.nav.open>a:focus .caret{border-top-color:#fff;border-bottom-color:#fff}.nav>.pull-right{float:right}.nav .nav-divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{float:left;margin-bottom:-1px}.nav-tabs>li>a{margin-right:2px;line-height:1.428571429;border:1px solid transparent;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee}.nav-tabs>li.active>a,.nav-tabs>li.active>a:hover,.nav-tabs>li.active>a:focus{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-tabs.nav-justified{width:100%;border-bottom:0}.nav-tabs.nav-justified>li{display:table-cell;float:none;width:1%}.nav-tabs.nav-justified>li>a{text-align:center}.nav-tabs.nav-justified>li>a{margin-right:0;border-bottom:1px solid #ddd}.nav-tabs.nav-justified>.active>a{border-bottom-color:#fff}.nav-pills>li{float:left}.nav-pills>li>a{border-radius:5px}.nav-pills>li+li{margin-left:2px}.nav-pills>li.active>a,.nav-pills>li.active>a:hover,.nav-pills>li.active>a:focus{color:#fff;background-color:#428bca}.nav-stacked>li{float:none}.nav-stacked>li+li>a{margin-top:2px;margin-left:0}.nav-justified{width:100%}.nav-justified>li{display:table-cell;float:none;width:1%}.nav-justified>li>a{text-align:center}.nav-tabs-justified{border-bottom:0}.nav-tabs-justified>li>a{margin-right:0;border-bottom:1px solid #ddd}.nav-tabs-justified>.active>a{border-bottom-color:#fff}.tabbable:before,.tabbable:after{display:table;content:" "}.tabbable:after{clear:both}.tabbable:before,.tabbable:after{display:table;content:" "}.tabbable:after{clear:both}.tab-content>.tab-pane,.pill-content>.pill-pane{display:none}.tab-content>.active,.pill-content>.active{display:block}.nav .caret{border-top-color:#428bca;border-bottom-color:#428bca}.nav a:hover .caret{border-top-color:#2a6496;border-bottom-color:#2a6496}.nav-tabs .dropdown-menu{margin-top:-1px;border-top-right-radius:0;border-top-left-radius:0}.navbar{position:relative;min-height:50px;padding-right:15px;padding-left:15px;margin-bottom:20px;background-color:#eee;border-radius:4px}.navbar:before,.navbar:after{display:table;content:" "}.navbar:after{clear:both}.navbar:before,.navbar:after{display:table;content:" "}.navbar:after{clear:both}.navbar-nav{margin-top:10px;margin-bottom:15px}.navbar-nav>li>a{padding-top:15px;padding-bottom:15px;line-height:20px;color:#777;border-radius:4px}.navbar-nav>li>a:hover,.navbar-nav>li>a:focus{color:#333;background-color:transparent}.navbar-nav>.active>a,.navbar-nav>.active>a:hover,.navbar-nav>.active>a:focus{color:#555;background-color:#d5d5d5}.navbar-nav>.disabled>a,.navbar-nav>.disabled>a:hover,.navbar-nav>.disabled>a:focus{color:#ccc;background-color:transparent}.navbar-nav.pull-right{width:100%}.navbar-static-top{border-radius:0}.navbar-fixed-top,.navbar-fixed-bottom{position:fixed;right:0;left:0;z-index:1030;border-radius:0}.navbar-fixed-top{top:0}.navbar-fixed-bottom{bottom:0;margin-bottom:0}.navbar-brand{display:block;max-width:200px;padding:15px 15px;margin-right:auto;margin-left:auto;font-size:18px;font-weight:500;line-height:20px;color:#777;text-align:center}.navbar-brand:hover,.navbar-brand:focus{color:#5e5e5e;text-decoration:none;background-color:transparent}.navbar-toggle{position:absolute;top:9px;right:10px;width:48px;height:32px;padding:8px 12px;background-color:transparent;border:1px solid #ddd;border-radius:4px}.navbar-toggle:hover,.navbar-toggle:focus{background-color:#ddd}.navbar-toggle .icon-bar{display:block;width:22px;height:2px;background-color:#ccc;border-radius:1px}.navbar-toggle .icon-bar+.icon-bar{margin-top:4px}.navbar-form{margin-top:6px;margin-bottom:6px}.navbar-form .form-control,.navbar-form .radio,.navbar-form .checkbox{display:inline-block}.navbar-form .radio,.navbar-form .checkbox{margin-top:0;margin-bottom:0}.navbar-nav>li>.dropdown-menu{margin-top:0;border-top-right-radius:0;border-top-left-radius:0}.navbar-fixed-bottom .navbar-nav>li>.dropdown-menu{border-bottom-right-radius:0;border-bottom-left-radius:0}.navbar-nav>.dropdown>a:hover .caret,.navbar-nav>.dropdown>a:focus .caret{border-top-color:#333;border-bottom-color:#333}.navbar-nav>.open>a,.navbar-nav>.open>a:hover,.navbar-nav>.open>a:focus{color:#555;background-color:#d5d5d5}.navbar-nav>.open>a .caret,.navbar-nav>.open>a:hover .caret,.navbar-nav>.open>a:focus .caret{border-top-color:#555;border-bottom-color:#555}.navbar-nav>.dropdown>a .caret{border-top-color:#777;border-bottom-color:#777}.navbar-nav.pull-right>li>.dropdown-menu,.navbar-nav>li>.dropdown-menu.pull-right{right:0;left:auto}.navbar-inverse{background-color:#222}.navbar-inverse .navbar-brand{color:#999}.navbar-inverse .navbar-brand:hover,.navbar-inverse .navbar-brand:focus{color:#fff;background-color:transparent}.navbar-inverse .navbar-text{color:#999}.navbar-inverse .navbar-nav>li>a{color:#999}.navbar-inverse .navbar-nav>li>a:hover,.navbar-inverse .navbar-nav>li>a:focus{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.active>a:hover,.navbar-inverse .navbar-nav>.active>a:focus{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav>.disabled>a,.navbar-inverse .navbar-nav>.disabled>a:hover,.navbar-inverse .navbar-nav>.disabled>a:focus{color:#444;background-color:transparent}.navbar-inverse .navbar-toggle{border-color:#333}.navbar-inverse .navbar-toggle:hover,.navbar-inverse .navbar-toggle:focus{background-color:#333}.navbar-inverse .navbar-toggle .icon-bar{background-color:#fff}.navbar-inverse .navbar-nav>.open>a,.navbar-inverse .navbar-nav>.open>a:hover,.navbar-inverse .navbar-nav>.open>a:focus{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav>.dropdown>a:hover .caret{border-top-color:#fff;border-bottom-color:#fff}.navbar-inverse .navbar-nav>.dropdown>a .caret{border-top-color:#999;border-bottom-color:#999}.navbar-inverse .navbar-nav>.open>a .caret,.navbar-inverse .navbar-nav>.open>a:hover .caret,.navbar-inverse .navbar-nav>.open>a:focus .caret{border-top-color:#fff;border-bottom-color:#fff}@media screen and (min-width:768px){.navbar-brand{float:left;margin-right:5px;margin-left:-15px}.navbar-nav{float:left;margin-top:0;margin-bottom:0}.navbar-nav>li{float:left}.navbar-nav>li>a{border-radius:0}.navbar-nav.pull-right{float:right;width:auto}.navbar-toggle{position:relative;top:auto;left:auto;display:none}.nav-collapse.collapse{display:block!important;height:auto!important;overflow:visible!important}}.navbar-btn{margin-top:6px}.navbar-text{margin-top:15px;margin-bottom:15px}.navbar-link{color:#777}.navbar-link:hover{color:#333}.navbar-inverse .navbar-link{color:#999}.navbar-inverse .navbar-link:hover{color:#fff}.btn .caret{border-top-color:#fff}.dropup .btn .caret{border-bottom-color:#fff}.btn-group,.btn-group-vertical{position:relative;display:inline-block;vertical-align:middle}.btn-group>.btn,.btn-group-vertical>.btn{position:relative;float:left}.btn-group>.btn:hover,.btn-group-vertical>.btn:hover,.btn-group>.btn:active,.btn-group-vertical>.btn:active{z-index:2}.btn-group .btn+.btn{margin-left:-1px}.btn-toolbar:before,.btn-toolbar:after{display:table;content:" "}.btn-toolbar:after{clear:both}.btn-toolbar:before,.btn-toolbar:after{display:table;content:" "}.btn-toolbar:after{clear:both}.btn-toolbar .btn-group{float:left}.btn-toolbar>.btn+.btn,.btn-toolbar>.btn-group+.btn,.btn-toolbar>.btn+.btn-group,.btn-toolbar>.btn-group+.btn-group{margin-left:5px}.btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle){border-radius:0}.btn-group>.btn:first-child{margin-left:0}.btn-group>.btn:first-child:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn:last-child:not(:first-child),.btn-group>.dropdown-toggle:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0}.btn-group>.btn-group{float:left}.btn-group>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group>.btn-group:first-child>.btn:last-child,.btn-group>.btn-group:first-child>.dropdown-toggle{border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn-group:last-child>.btn:first-child{border-bottom-left-radius:0;border-top-left-radius:0}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group>.btn+.dropdown-toggle{padding-right:8px;padding-left:8px}.btn-group>.btn-large+.dropdown-toggle{padding-right:12px;padding-left:12px}.btn-group.open .dropdown-toggle{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,0.125);box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}.btn .caret{margin-left:0}.btn-large .caret{border-width:5px}.dropup .btn-large .caret{border-bottom-width:5px}.btn-group-vertical>.btn{display:block;float:none;width:100%;max-width:100%}.btn-group-vertical>.btn+.btn{margin-top:-1px}.btn-group-vertical .btn:not(:first-child):not(:last-child){border-radius:0}.btn-group-vertical .btn:first-child{border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical .btn:last-child{border-top-right-radius:0;border-top-left-radius:0}.btn-group-justified{display:table;width:100%}.btn-group-justified .btn{display:table-cell;float:none;width:1%}.btn-group[data-toggle="buttons"]>.btn>input[type="radio"],.btn-group[data-toggle="buttons"]>.btn>input[type="checkbox"]{display:none}.breadcrumb{padding:8px 15px;margin-bottom:20px;list-style:none;background-color:#f5f5f5;border-radius:4px}.breadcrumb>li{display:inline-block}.breadcrumb>li+li:before{padding:0 5px;color:#ccc;content:"/a0"}.breadcrumb>.active{color:#999}.pagination{display:inline-block;padding-left:0;margin:20px 0;border-radius:4px}.pagination>li{display:inline}.pagination>li>a,.pagination>li>span{float:left;padding:4px 12px;line-height:1.428571429;text-decoration:none;background-color:#fff;border:1px solid #ddd;border-left-width:0}.pagination>li:first-child>a,.pagination>li:first-child>span{border-left-width:1px;border-bottom-left-radius:4px;border-top-left-radius:4px}.pagination>li:last-child>a,.pagination>li:last-child>span{border-top-right-radius:4px;border-bottom-right-radius:4px}.pagination>li>a:hover,.pagination>li>a:focus,.pagination>.active>a,.pagination>.active>span{background-color:#f5f5f5}.pagination>.active>a,.pagination>.active>span{color:#999;cursor:default}.pagination>.disabled>span,.pagination>.disabled>a,.pagination>.disabled>a:hover,.pagination>.disabled>a:focus{color:#999;cursor:not-allowed;background-color:#fff}.pagination-large>li>a,.pagination-large>li>span{padding:14px 16px;font-size:18px}.pagination-large>li:first-child>a,.pagination-large>li:first-child>span{border-bottom-left-radius:6px;border-top-left-radius:6px}.pagination-large>li:last-child>a,.pagination-large>li:last-child>span{border-top-right-radius:6px;border-bottom-right-radius:6px}.pagination-small>li>a,.pagination-small>li>span{padding:5px 10px;font-size:12px}.pagination-small>li:first-child>a,.pagination-small>li:first-child>span{border-bottom-left-radius:3px;border-top-left-radius:3px}.pagination-small>li:last-child>a,.pagination-small>li:last-child>span{border-top-right-radius:3px;border-bottom-right-radius:3px}.pager{padding-left:0;margin:20px 0;text-align:center;list-style:none}.pager:before,.pager:after{display:table;content:" "}.pager:after{clear:both}.pager:before,.pager:after{display:table;content:" "}.pager:after{clear:both}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;border-radius:15px}.pager li>a:hover,.pager li>a:focus{text-decoration:none;background-color:#f5f5f5}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:hover,.pager .disabled>a:focus,.pager .disabled>span{color:#999;cursor:not-allowed;background-color:#fff}.modal-open{overflow:hidden}.modal{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;display:none;overflow:auto;overflow-y:scroll}.modal.fade .modal-dialog{-webkit-transform:translate(0,-25%);-ms-transform:translate(0,-25%);transform:translate(0,-25%);-webkit-transition:-webkit-transform .3s ease-out;-moz-transition:-moz-transform .3s ease-out;-o-transition:-o-transform .3s ease-out;transition:transform .3s ease-out}.modal.fade.in .modal-dialog{-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0)}.modal-dialog{position:relative;top:0;right:0;left:0;z-index:1050;width:auto;padding:10px}.modal-content{position:relative;background-color:#fff;border:1px solid #999;border:1px solid rgba(0,0,0,0.2);border-radius:6px;outline:0;-webkit-box-shadow:0 3px 9px rgba(0,0,0,0.5);box-shadow:0 3px 9px rgba(0,0,0,0.5);background-clip:padding-box}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1030;background-color:#000}.modal-backdrop.fade{opacity:0;filter:alpha(opacity=0)}.modal-backdrop.fade.in{opacity:.5;filter:alpha(opacity=50)}.modal-header{min-height:16.428571429px;padding:15px;border-bottom:1px solid #e5e5e5}.modal-header .close{margin-top:-2px}.modal-title{margin:0;line-height:1.428571429}.modal-body{position:relative;padding:20px}.modal-footer{padding:19px 20px 20px;margin-top:15px;text-align:right;border-top:1px solid #e5e5e5}.modal-footer:before,.modal-footer:after{display:table;content:" "}.modal-footer:after{clear:both}.modal-footer:before,.modal-footer:after{display:table;content:" "}.modal-footer:after{clear:both}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}@media screen and (min-width:768px){.modal-dialog{right:auto;left:50%;width:560px;padding-top:30px;padding-bottom:30px;margin-left:-280px}.modal-content{-webkit-box-shadow:0 5px 15px rgba(0,0,0,0.5);box-shadow:0 5px 15px rgba(0,0,0,0.5)}}.tooltip{position:absolute;z-index:1030;display:block;font-size:12px;line-height:1.4;opacity:0;filter:alpha(opacity=0);visibility:visible}.tooltip.in{opacity:1;filter:alpha(opacity=100)}.tooltip.top{padding:5px 0;margin-top:-3px}.tooltip.right{padding:0 5px;margin-left:3px}.tooltip.bottom{padding:5px 0;margin-top:3px}.tooltip.left{padding:0 5px;margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;text-decoration:none;background-color:rgba(0,0,0,0.9);border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-top-color:rgba(0,0,0,0.9);border-width:5px 5px 0}.tooltip.top-left .tooltip-arrow{bottom:0;left:5px;border-top-color:rgba(0,0,0,0.9);border-width:5px 5px 0}.tooltip.top-right .tooltip-arrow{right:5px;bottom:0;border-top-color:rgba(0,0,0,0.9);border-width:5px 5px 0}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-right-color:rgba(0,0,0,0.9);border-width:5px 5px 5px 0}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-left-color:rgba(0,0,0,0.9);border-width:5px 0 5px 5px}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-bottom-color:rgba(0,0,0,0.9);border-width:0 5px 5px}.tooltip.bottom-left .tooltip-arrow{top:0;left:5px;border-bottom-color:rgba(0,0,0,0.9);border-width:0 5px 5px}.tooltip.bottom-right .tooltip-arrow{top:0;right:5px;border-bottom-color:rgba(0,0,0,0.9);border-width:0 5px 5px}.popover{position:absolute;top:0;left:0;z-index:1010;display:none;max-width:276px;padding:1px;text-align:left;white-space:normal;background-color:#fff;border:1px solid #ccc;border:1px solid rgba(0,0,0,0.2);border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,0.2);box-shadow:0 5px 10px rgba(0,0,0,0.2);background-clip:padding-box;-webkit-bg-clip:padding-box;-moz-bg-clip:padding}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;font-weight:normal;line-height:18px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover .arrow,.popover .arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover .arrow{border-width:11px}.popover .arrow:after{border-width:10px;content:""}.popover.top .arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,0.25);border-bottom-width:0}.popover.top .arrow:after{bottom:1px;margin-left:-10px;border-top-color:#fff;border-bottom-width:0;content:" "}.popover.right .arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,0.25);border-left-width:0}.popover.right .arrow:after{bottom:-10px;left:1px;border-right-color:#fff;border-left-width:0;content:" "}.popover.bottom .arrow{top:-11px;left:50%;margin-left:-11px;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,0.25);border-top-width:0}.popover.bottom .arrow:after{top:1px;margin-left:-10px;border-bottom-color:#fff;border-top-width:0;content:" "}.popover.left .arrow{top:50%;right:-11px;margin-top:-11px;border-left-color:#999;border-left-color:rgba(0,0,0,0.25);border-right-width:0}.popover.left .arrow:after{right:1px;bottom:-10px;border-left-color:#fff;border-right-width:0;content:" "}.alert{padding:10px 35px 10px 15px;margin-bottom:20px;color:#c09853;background-color:#fcf8e3;border:1px solid #fbeed5;border-radius:4px}.alert h4{margin-top:0;color:inherit}.alert hr{border-top-color:#f8e5be}.alert .alert-link{font-weight:500;color:#a47e3c}.alert .close{position:relative;top:-2px;right:-21px;color:inherit}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-success hr{border-top-color:#c9e2b3}.alert-success .alert-link{color:#356635}.alert-danger{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-danger hr{border-top-color:#e6c1c7}.alert-danger .alert-link{color:#953b39}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.alert-info hr{border-top-color:#a6e1ec}.alert-info .alert-link{color:#2d6987}.alert-block{padding-top:15px;padding-bottom:15px}.alert-block>p,.alert-block>ul{margin-bottom:0}.alert-block p+p{margin-top:5px}.thumbnail,.img-thumbnail{padding:4px;line-height:1.428571429;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.thumbnail{display:block}.thumbnail>img,.img-thumbnail{display:inline-block;height:auto;max-width:100%}a.thumbnail:hover,a.thumbnail:focus{border-color:#428bca}.thumbnail>img{margin-right:auto;margin-left:auto}.thumbnail .caption{padding:9px;color:#333}.media,.media-body{overflow:hidden;zoom:1}.media,.media .media{margin-top:15px}.media:first-child{margin-top:0}.media-object{display:block}.media-heading{margin:0 0 5px}.media>.pull-left{margin-right:10px}.media>.pull-right{margin-left:10px}.media-list{padding-left:0;list-style:none}.label{display:inline;padding:.25em .6em;font-size:75%;font-weight:500;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:middle;background-color:#999;border-radius:.25em}.label[href]:hover,.label[href]:focus{color:#fff;text-decoration:none;cursor:pointer;background-color:#808080}.label-danger{background-color:#d9534f}.label-danger[href]:hover,.label-danger[href]:focus{background-color:#c9302c}.label-success{background-color:#5cb85c}.label-success[href]:hover,.label-success[href]:focus{background-color:#449d44}.label-warning{background-color:#f0ad4e}.label-warning[href]:hover,.label-warning[href]:focus{background-color:#ec971f}.label-info{background-color:#5bc0de}.label-info[href]:hover,.label-info[href]:focus{background-color:#31b0d5}.badge{display:inline-block;min-width:10px;padding:3px 7px;font-size:12px;font-weight:bold;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:middle;background-color:#999;border-radius:10px}.badge:empty{display:none}a.badge:hover,a.badge:focus{color:#fff;text-decoration:none;cursor:pointer}.btn .badge{position:relative;top:-1px}a.list-group-item.active>.badge,.nav-pills>.active>a>.badge{color:#428bca;background-color:#fff}.nav-pills>li>a>.badge{margin-left:3px}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-moz-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-ms-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:0 0}to{background-position:40px 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f5f5f5;border-radius:4px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);box-shadow:inset 0 1px 2px rgba(0,0,0,0.1)}.progress-bar{float:left;width:0;height:100%;font-size:12px;color:#fff;text-align:center;background-color:#428bca;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,0.15);-webkit-transition:width .6s ease;transition:width .6s ease}.progress-striped .progress-bar{background-color:#428bca;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-size:40px 40px}.progress.active .progress-bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-moz-animation:progress-bar-stripes 2s linear infinite;-ms-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-bar-danger{background-color:#d9534f}.progress-striped .progress-bar-danger{background-color:#d9534f;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-bar-success{background-color:#5cb85c}.progress-striped .progress-bar-success{background-color:#5cb85c;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-bar-warning{background-color:#f0ad4e}.progress-striped .progress-bar-warning{background-color:#f0ad4e;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.progress-bar-info{background-color:#5bc0de}.progress-striped .progress-bar-info{background-color:#5bc0de;background-image:-webkit-gradient(linear,0 100%,100% 0,color-stop(0.25,rgba(255,255,255,0.15)),color-stop(0.25,transparent),color-stop(0.5,transparent),color-stop(0.5,rgba(255,255,255,0.15)),color-stop(0.75,rgba(255,255,255,0.15)),color-stop(0.75,transparent),to(transparent));background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:-moz-linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent)}.accordion{margin-bottom:20px}.accordion-group{margin-bottom:2px;border:1px solid #e5e5e5;border-radius:4px}.accordion-heading{border-bottom:0}.accordion-heading .accordion-toggle{display:block;padding:8px 15px;cursor:pointer}.accordion-inner{padding:9px 15px;border-top:1px solid #e5e5e5}.carousel{position:relative}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>img,.carousel-inner>.item>a>img{display:inline-block;height:auto;max-width:100%;line-height:1}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:0;bottom:0;left:0;width:15%;font-size:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,0.6);opacity:.5;filter:alpha(opacity=50)}.carousel-control.left{background-color:rgba(0,0,0,0.0001);background-color:transparent;background-image:-webkit-gradient(linear,0 top,100% top,from(rgba(0,0,0,0.5)),to(rgba(0,0,0,0.0001)));background-image:-webkit-linear-gradient(left,color-stop(rgba(0,0,0,0.5) 0),color-stop(rgba(0,0,0,0.0001) 100%));background-image:-moz-linear-gradient(left,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.0001) 100%);background-image:linear-gradient(to right,rgba(0,0,0,0.5) 0,rgba(0,0,0,0.0001) 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000',endColorstr='#00000000',GradientType=1)}.carousel-control.right{right:0;left:auto;background-color:rgba(0,0,0,0.5);background-color:transparent;background-image:-webkit-gradient(linear,0 top,100% top,from(rgba(0,0,0,0.0001)),to(rgba(0,0,0,0.5)));background-image:-webkit-linear-gradient(left,color-stop(rgba(0,0,0,0.0001) 0),color-stop(rgba(0,0,0,0.5) 100%));background-image:-moz-linear-gradient(left,rgba(0,0,0,0.0001) 0,rgba(0,0,0,0.5) 100%);background-image:linear-gradient(to right,rgba(0,0,0,0.0001) 0,rgba(0,0,0,0.5) 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000',endColorstr='#80000000',GradientType=1)}.carousel-control:hover,.carousel-control:focus{color:#fff;text-decoration:none;opacity:.9;filter:alpha(opacity=90)}.carousel-control .glyphicon,.carousel-control .icon-prev,.carousel-control .icon-next{position:absolute;top:50%;left:50%;z-index:5;display:inline-block;width:20px;height:20px;margin-top:-10px;margin-left:-10px;font-family:serif}.carousel-control .icon-prev:before{content:'ƒ9'}.carousel-control .icon-next:before{content:'ƒa'}.carousel-indicators{position:absolute;bottom:10px;left:50%;z-index:15;width:120px;padding-left:0;margin-left:-60px;text-align:center;list-style:none}.carousel-indicators li{display:inline-block;width:10px;height:10px;margin:1px;text-indent:-999px;cursor:pointer;border:1px solid #fff;border-radius:10px}.carousel-indicators .active{width:12px;height:12px;margin:0;background-color:#fff}.carousel-caption{position:absolute;right:15%;bottom:20px;left:15%;z-index:10;padding-top:20px;padding-bottom:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,0.6)}.carousel-caption .btn{text-shadow:none}@media screen and (min-width:768px){.carousel-control .glyphicon,.carousel-control .icon-prev,.carousel-control .icon-next{width:30px;height:30px;margin-top:-15px;margin-left:-15px;font-size:30px}.carousel-caption{right:20%;left:20%;padding-bottom:30px}.carousel-indicators{bottom:20px}}.jumbotron{padding:30px;margin-bottom:30px;font-size:21px;font-weight:200;line-height:2.1428571435;color:inherit;background-color:#eee}.jumbotron h1{line-height:1;color:inherit}.jumbotron p{line-height:1.4}@media screen and (min-width:768px){.jumbotron{padding:50px 60px;border-radius:6px}.jumbotron h1{font-size:63px}}.clearfix:before,.clearfix:after{display:table;content:" "}.clearfix:after{clear:both}.pull-right{float:right}.pull-left{float:left}.hide{display:none!important}.show{display:block!important}.invisible{visibility:hidden}.text-hide{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.affix{position:fixed}@-ms-viewport{width:device-width}@media screen and (max-width:400px){@-ms-viewport{width:320px}}.hidden{display:none!important;visibility:hidden!important}.visible-sm{display:block!important}tr.visible-sm{display:table-row!important}th.visible-sm,td.visible-sm{display:table-cell!important}.visible-md{display:none!important}tr.visible-md{display:none!important}th.visible-md,td.visible-md{display:none!important}.visible-lg{display:none!important}tr.visible-lg{display:none!important}th.visible-lg,td.visible-lg{display:none!important}.hidden-sm{display:none!important}tr.hidden-sm{display:none!important}th.hidden-sm,td.hidden-sm{display:none!important}.hidden-md{display:block!important}tr.hidden-md{display:table-row!important}th.hidden-md,td.hidden-md{display:table-cell!important}.hidden-lg{display:block!important}tr.hidden-lg{display:table-row!important}th.hidden-lg,td.hidden-lg{display:table-cell!important}@media(min-width:768px) and (max-width:991px){.visible-sm{display:none!important}tr.visible-sm{display:none!important}th.visible-sm,td.visible-sm{display:none!important}.visible-md{display:block!important}tr.visible-md{display:table-row!important}th.visible-md,td.visible-md{display:table-cell!important}.visible-lg{display:none!important}tr.visible-lg{display:none!important}th.visible-lg,td.visible-lg{display:none!important}.hidden-sm{display:block!important}tr.hidden-sm{display:table-row!important}th.hidden-sm,td.hidden-sm{display:table-cell!important}.hidden-md{display:none!important}tr.hidden-md{display:none!important}th.hidden-md,td.hidden-md{display:none!important}.hidden-lg{display:block!important}tr.hidden-lg{display:table-row!important}th.hidden-lg,td.hidden-lg{display:table-cell!important}}@media(min-width:992px){.visible-sm{display:none!important}tr.visible-sm{display:none!important}th.visible-sm,td.visible-sm{display:none!important}.visible-md{display:none!important}tr.visible-md{display:none!important}th.visible-md,td.visible-md{display:none!important}.visible-lg{display:block!important}tr.visible-lg{display:table-row!important}th.visible-lg,td.visible-lg{display:table-cell!important}.hidden-sm{display:block!important}tr.hidden-sm{display:table-row!important}th.hidden-sm,td.hidden-sm{display:table-cell!important}.hidden-md{display:block!important}tr.hidden-md{display:table-row!important}th.hidden-md,td.hidden-md{display:table-cell!important}.hidden-lg{display:none!important}tr.hidden-lg{display:none!important}th.hidden-lg,td.hidden-lg{display:none!important}}.visible-print{display:none!important}tr.visible-print{display:none!important}th.visible-print,td.visible-print{display:none!important}@media print{.visible-print{display:block!important}tr.visible-print{display:table-row!important}th.visible-print,td.visible-print{display:table-cell!important}.hidden-print{display:none!important}tr.hidden-print{display:none!important}th.hidden-print,td.hidden-print{display:none!important}}
27 </style>
28
29 <!-- zepto -->
30 <script type="text/javascript">
31 /* Zepto v1.1.2 - zepto event ajax form ie - zeptojs.com/license */
32 var Zepto=function(){function G(a){return a==null?String(a):z[A.call(a)]||"object"}function H(a){return G(a)=="function"}function I(a){return a!=null&&a==a.window}function J(a){return a!=null&&a.nodeType==a.DOCUMENT_NODE}function K(a){return G(a)=="object"}function L(a){return K(a)&&!I(a)&&Object.getPrototypeOf(a)==Object.prototype}function M(a){return a instanceof Array}function N(a){return typeof a.length=="number"}function O(a){return g.call(a,function(a){return a!=null})}function P(a){return a.length>0?c.fn.concat.apply([],a):a}function Q(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()}function R(a){return a in j?j[a]:j[a]=new RegExp("(^|\s)"+a+"(\s|$)")}function S(a,b){return typeof b=="number"&&!k[Q(a)]?b+"px":b}function T(a){var b,c;return i[a]||(b=h.createElement(a),h.body.appendChild(b),c=getComputedStyle(b,"").getPropertyValue("display"),b.parentNode.removeChild(b),c=="none"&&(c="block"),i[a]=c),i[a]}function U(a){return"children"in a?f.call(a.children):c.map(a.childNodes,function(a){if(a.nodeType==1)return a})}function V(c,d,e){for(b in d)e&&(L(d[b])||M(d[b]))?(L(d[b])&&!L(c[b])&&(c[b]={}),M(d[b])&&!M(c[b])&&(c[b]=[]),V(c[b],d[b],e)):d[b]!==a&&(c[b]=d[b])}function W(a,b){return b==null?c(a):c(a).filter(b)}function X(a,b,c,d){return H(b)?b.call(a,c,d):b}function Y(a,b,c){c==null?a.removeAttribute(b):a.setAttribute(b,c)}function Z(b,c){var d=b.className,e=d&&d.baseVal!==a;if(c===a)return e?d.baseVal:d;e?d.baseVal=c:b.className=c}function $(a){var b;try{return a?a=="true"||(a=="false"?!1:a=="null"?null:!/^0/.test(a)&&!isNaN(b=Number(a))?b:/^[\[\{]/.test(a)?c.parseJSON(a):a):a}catch(d){return a}}function _(a,b){b(a);for(var c in a.childNodes)_(a.childNodes[c],b)}var a,b,c,d,e=[],f=e.slice,g=e.filter,h=window.document,i={},j={},k={"column-count":1,columns:1,"font-weight":1,"line-height":1,opacity:1,"z-index":1,zoom:1},l=/^\s*<(\w+|!)[^>]*>/,m=/^<(\w+)\s*\/?>(?:<\/>|)$/,n=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,o=/^(?:body|html)$/i,p=/([A-Z])/g,q=["val","css","html","text","data","width","height","offset"],r=["after","prepend","before","append"],s=h.createElement("table"),t=h.createElement("tr"),u={tr:h.createElement("tbody"),tbody:s,thead:s,tfoot:s,td:t,th:t,"*":h.createElement("div")},v=/complete|loaded|interactive/,w=/^\.([\w-]+)$/,x=/^#([\w-]*)$/,y=/^[\w-]*$/,z={},A=z.toString,B={},C,D,E=h.createElement("div"),F={tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"};return B.matches=function(a,b){if(!b||!a||a.nodeType!==1)return!1;var c=a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.matchesSelector;if(c)return c.call(a,b);var d,e=a.parentNode,f=!e;return f&&(e=E).appendChild(a),d=~B.qsa(e,b).indexOf(a),f&&E.removeChild(a),d},C=function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},D=function(a){return g.call(a,function(b,c){return a.indexOf(b)==c})},B.fragment=function(b,d,e){var g,i,j;return m.test(b)&&(g=c(h.createElement(RegExp.$1))),g||(b.replace&&(b=b.replace(n,"<$1></$2>")),d===a&&(d=l.test(b)&&RegExp.$1),d in u||(d="*"),j=u[d],j.innerHTML=""+b,g=c.each(f.call(j.childNodes),function(){j.removeChild(this)})),L(e)&&(i=c(g),c.each(e,function(a,b){q.indexOf(a)>-1?i[a](b):i.attr(a,b)})),g},B.Z=function(a,b){return a=a||[],a.__proto__=c.fn,a.selector=b||"",a},B.isZ=function(a){return a instanceof B.Z},B.init=function(b,d){var e;if(!b)return B.Z();if(typeof b=="string"){b=b.trim();if(b[0]=="<"&&l.test(b))e=B.fragment(b,RegExp.$1,d),b=null;else{if(d!==a)return c(d).find(b);e=B.qsa(h,b)}}else{if(H(b))return c(h).ready(b);if(B.isZ(b))return b;if(M(b))e=O(b);else if(K(b))e=[b],b=null;else if(l.test(b))e=B.fragment(b.trim(),RegExp.$1,d),b=null;else{if(d!==a)return c(d).find(b);e=B.qsa(h,b)}}return B.Z(e,b)},c=function(a,b){return B.init(a,b)},c.extend=function(a){var b,c=f.call(arguments,1);return typeof a=="boolean"&&(b=a,a=c.shift()),c.forEach(function(c){V(a,c,b)}),a},B.qsa=function(a,b){var c,d=b[0]=="#",e=!d&&b[0]==".",g=d||e?b.slice(1):b,h=y.test(g);return J(a)&&h&&d?(c=a.getElementById(g))?[c]:[]:a.nodeType!==1&&a.nodeType!==9?[]:f.call(h&&!d?e?a.getElementsByClassName(g):a.getElementsByTagName(b):a.querySelectorAll(b))},c.contains=function(a,b){return a!==b&&a.contains(b)},c.type=G,c.isFunction=H,c.isWindow=I,c.isArray=M,c.isPlainObject=L,c.isEmptyObject=function(a){var b;for(b in a)return!1;return!0},c.inArray=function(a,b,c){return e.indexOf.call(b,a,c)},c.camelCase=C,c.trim=function(a){return a==null?"":String.prototype.trim.call(a)},c.uuid=0,c.support={},c.expr={},c.map=function(a,b){var c,d=[],e,f;if(N(a))for(e=0;e<a.length;e++)c=b(a[e],e),c!=null&&d.push(c);else for(f in a)c=b(a[f],f),c!=null&&d.push(c);return P(d)},c.each=function(a,b){var c,d;if(N(a)){for(c=0;c<a.length;c++)if(b.call(a[c],c,a[c])===!1)return a}else for(d in a)if(b.call(a[d],d,a[d])===!1)return a;return a},c.grep=function(a,b){return g.call(a,b)},window.JSON&&(c.parseJSON=JSON.parse),c.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){z["[object "+b+"]"]=b.toLowerCase()}),c.fn={forEach:e.forEach,reduce:e.reduce,push:e.push,sort:e.sort,indexOf:e.indexOf,concat:e.concat,map:function(a){return c(c.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return c(f.apply(this,arguments))},ready:function(a){return v.test(h.readyState)&&h.body?a(c):h.addEventListener("DOMContentLoaded",function(){a(c)},!1),this},get:function(b){return b===a?f.call(this):this[b>=0?b:b+this.length]},toArray:function(){return this.get()},size:function(){return this.length},remove:function(){return this.each(function(){this.parentNode!=null&&this.parentNode.removeChild(this)})},each:function(a){return e.every.call(this,function(b,c){return a.call(b,c,b)!==!1}),this},filter:function(a){return H(a)?this.not(this.not(a)):c(g.call(this,function(b){return B.matches(b,a)}))},add:function(a,b){return c(D(this.concat(c(a,b))))},is:function(a){return this.length>0&&B.matches(this[0],a)},not:function(b){var d=[];if(H(b)&&b.call!==a)this.each(function(a){b.call(this,a)||d.push(this)});else{var e=typeof b=="string"?this.filter(b):N(b)&&H(b.item)?f.call(b):c(b);this.forEach(function(a){e.indexOf(a)<0&&d.push(a)})}return c(d)},has:function(a){return this.filter(function(){return K(a)?c.contains(this,a):c(this).find(a).size()})},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){var a=this[0];return a&&!K(a)?a:c(a)},last:function(){var a=this[this.length-1];return a&&!K(a)?a:c(a)},find:function(a){var b,d=this;return typeof a=="object"?b=c(a).filter(function(){var a=this;return e.some.call(d,function(b){return c.contains(b,a)})}):this.length==1?b=c(B.qsa(this[0],a)):b=this.map(function(){return B.qsa(this,a)}),b},closest:function(a,b){var d=this[0],e=!1;typeof a=="object"&&(e=c(a));while(d&&!(e?e.indexOf(d)>=0:B.matches(d,a)))d=d!==b&&!J(d)&&d.parentNode;return c(d)},parents:function(a){var b=[],d=this;while(d.length>0)d=c.map(d,function(a){if((a=a.parentNode)&&!J(a)&&b.indexOf(a)<0)return b.push(a),a});return W(b,a)},parent:function(a){return W(D(this.pluck("parentNode")),a)},children:function(a){return W(this.map(function(){return U(this)}),a)},contents:function(){return this.map(function(){return f.call(this.childNodes)})},siblings:function(a){return W(this.map(function(a,b){return g.call(U(b.parentNode),function(a){return a!==b})}),a)},empty:function(){return this.each(function(){this.innerHTML=""})},pluck:function(a){return c.map(this,function(b){return b[a]})},show:function(){return this.each(function(){this.style.display=="none"&&(this.style.display=""),getComputedStyle(this,"").getPropertyValue("display")=="none"&&(this.style.display=T(this.nodeName))})},replaceWith:function(a){return this.before(a).remove()},wrap:function(a){var b=H(a);if(this[0]&&!b)var d=c(a).get(0),e=d.parentNode||this.length>1;return this.each(function(f){c(this).wrapAll(b?a.call(this,f):e?d.cloneNode(!0):d)})},wrapAll:function(a){if(this[0]){c(this[0]).before(a=c(a));var b;while((b=a.children()).length)a=b.first();c(a).append(this)}return this},wrapInner:function(a){var b=H(a);return this.each(function(d){var e=c(this),f=e.contents(),g=b?a.call(this,d):a;f.length?f.wrapAll(g):e.append(g)})},unwrap:function(){return this.parent().each(function(){c(this).replaceWith(c(this).children())}),this},clone:function(){return this.map(function(){return this.cloneNode(!0)})},hide:function(){return this.css("display","none")},toggle:function(b){return this.each(function(){var d=c(this);(b===a?d.css("display")=="none":b)?d.show():d.hide()})},prev:function(a){return c(this.pluck("previousElementSibling")).filter(a||"*")},next:function(a){return c(this.pluck("nextElementSibling")).filter(a||"*")},html:function(a){return arguments.length===0?this.length>0?this[0].innerHTML:null:this.each(function(b){var d=this.innerHTML;c(this).empty().append(X(this,a,b,d))})},text:function(b){return arguments.length===0?this.length>0?this[0].textContent:null:this.each(function(){this.textContent=b===a?"":""+b})},attr:function(c,d){var e;return typeof c=="string"&&d===a?this.length==0||this[0].nodeType!==1?a:c=="value"&&this[0].nodeName=="INPUT"?this.val():!(e=this[0].getAttribute(c))&&c in this[0]?this[0][c]:e:this.each(function(a){if(this.nodeType!==1)return;if(K(c))for(b in c)Y(this,b,c[b]);else Y(this,c,X(this,d,a,this.getAttribute(c)))})},removeAttr:function(a){return this.each(function(){this.nodeType===1&&Y(this,a)})},prop:function(b,c){return b=F[b]||b,c===a?this[0]&&this[0][b]:this.each(function(a){this[b]=X(this,c,a,this[b])})},data:function(b,c){var d=this.attr("data-"+b.replace(p,"-$1").toLowerCase(),c);return d!==null?$(d):a},val:function(a){return arguments.length===0?this[0]&&(this[0].multiple?c(this[0]).find("option").filter(function(){return this.selected}).pluck("value"):this[0].value):this.each(function(b){this.value=X(this,a,b,this.value)})},offset:function(a){if(a)return this.each(function(b){var d=c(this),e=X(this,a,b,d.offset()),f=d.offsetParent().offset(),g={top:e.top-f.top,left:e.left-f.left};d.css("position")=="static"&&(g.position="relative"),d.css(g)});if(this.length==0)return null;var b=this[0].getBoundingClientRect();return{left:b.left+window.pageXOffset,top:b.top+window.pageYOffset,width:Math.round(b.width),height:Math.round(b.height)}},css:function(a,d){if(arguments.length<2){var e=this[0],f=getComputedStyle(e,"");if(!e)return;if(typeof a=="string")return e.style[C(a)]||f.getPropertyValue(a);if(M(a)){var g={};return c.each(M(a)?a:[a],function(a,b){g[b]=e.style[C(b)]||f.getPropertyValue(b)}),g}}var h="";if(G(a)=="string")!d&&d!==0?this.each(function(){this.style.removeProperty(Q(a))}):h=Q(a)+":"+S(a,d);else for(b in a)!a[b]&&a[b]!==0?this.each(function(){this.style.removeProperty(Q(b))}):h+=Q(b)+":"+S(b,a[b])+";";return this.each(function(){this.style.cssText+=";"+h})},index:function(a){return a?this.indexOf(c(a)[0]):this.parent().children().indexOf(this[0])},hasClass:function(a){return a?e.some.call(this,function(a){return this.test(Z(a))},R(a)):!1},addClass:function(a){return a?this.each(function(b){d=[];var e=Z(this),f=X(this,a,b,e);f.split(/\s+/g).forEach(function(a){c(this).hasClass(a)||d.push(a)},this),d.length&&Z(this,e+(e?" ":"")+d.join(" "))}):this},removeClass:function(b){return this.each(function(c){if(b===a)return Z(this,"");d=Z(this),X(this,b,c,d).split(/\s+/g).forEach(function(a){d=d.replace(R(a)," ")}),Z(this,d.trim())})},toggleClass:function(b,d){return b?this.each(function(e){var f=c(this),g=X(this,b,e,Z(this));g.split(/\s+/g).forEach(function(b){(d===a?!f.hasClass(b):d)?f.addClass(b):f.removeClass(b)})}):this},scrollTop:function(b){if(!this.length)return;var c="scrollTop"in this[0];return b===a?c?this[0].scrollTop:this[0].pageYOffset:this.each(c?function(){this.scrollTop=b}:function(){this.scrollTo(this.scrollX,b)})},scrollLeft:function(b){if(!this.length)return;var c="scrollLeft"in this[0];return b===a?c?this[0].scrollLeft:this[0].pageXOffset:this.each(c?function(){this.scrollLeft=b}:function(){this.scrollTo(b,this.scrollY)})},position:function(){if(!this.length)return;var a=this[0],b=this.offsetParent(),d=this.offset(),e=o.test(b[0].nodeName)?{top:0,left:0}:b.offset();return d.top-=parseFloat(c(a).css("margin-top"))||0,d.left-=parseFloat(c(a).css("margin-left"))||0,e.top+=parseFloat(c(b[0]).css("border-top-width"))||0,e.left+=parseFloat(c(b[0]).css("border-left-width"))||0,{top:d.top-e.top,left:d.left-e.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||h.body;while(a&&!o.test(a.nodeName)&&c(a).css("position")=="static")a=a.offsetParent;return a})}},c.fn.detach=c.fn.remove,["width","height"].forEach(function(b){var d=b.replace(/./,function(a){return a[0].toUpperCase()});c.fn[b]=function(e){var f,g=this[0];return e===a?I(g)?g["inner"+d]:J(g)?g.documentElement["scroll"+d]:(f=this.offset())&&f[b]:this.each(function(a){g=c(this),g.css(b,X(this,e,a,g[b]()))})}}),r.forEach(function(a,b){var d=b%2;c.fn[a]=function(){var a,e=c.map(arguments,function(b){return a=G(b),a=="object"||a=="array"||b==null?b:B.fragment(b)}),f,g=this.length>1;return e.length<1?this:this.each(function(a,h){f=d?h:h.parentNode,h=b==0?h.nextSibling:b==1?h.firstChild:b==2?h:null,e.forEach(function(a){if(g)a=a.cloneNode(!0);else if(!f)return c(a).remove();_(f.insertBefore(a,h),function(a){a.nodeName!=null&&a.nodeName.toUpperCase()==="SCRIPT"&&(!a.type||a.type==="text/javascript")&&!a.src&&window.eval.call(window,a.innerHTML)})})})},c.fn[d?a+"To":"insert"+(b?"Before":"After")]=function(b){return c(b)[a](this),this}}),B.Z.prototype=c.fn,B.uniq=D,B.deserializeValue=$,c.zepto=B,c}();window.Zepto=Zepto,window.$===undefined&&(window.$=Zepto),function(a){function m(a){return a._zid||(a._zid=c++)}function n(a,b,c,d){b=o(b);if(b.ns)var e=p(b.ns);return(h[m(a)]||[]).filter(function(a){return a&&(!b.e||a.e==b.e)&&(!b.ns||e.test(a.ns))&&(!c||m(a.fn)===m(c))&&(!d||a.sel==d)})}function o(a){var b=(""+a).split(".");return{e:b[0],ns:b.slice(1).sort().join(" ")}}function p(a){return new RegExp("(?:^| )"+a.replace(" "," .* ?")+"(?: |$)")}function q(a,b){return a.del&&!j&&a.e in k||!!b}function r(a){return l[a]||j&&k[a]||a}function s(b,c,e,f,g,i,j){var k=m(b),n=h[k]||(h[k]=[]);c.split(/\s/).forEach(function(c){if(c=="ready")return a(document).ready(e);var h=o(c);h.fn=e,h.sel=g,h.e in l&&(e=function(b){var c=b.relatedTarget;if(!c||c!==this&&!a.contains(this,c))return h.fn.apply(this,arguments)}),h.del=i;var k=i||e;h.proxy=function(a){a=y(a);if(a.isImmediatePropagationStopped())return;a.data=f;var c=k.apply(b,a._args==d?[a]:[a].concat(a._args));return c===!1&&(a.preventDefault(),a.stopPropagation()),c},h.i=n.length,n.push(h),"addEventListener"in b&&b.addEventListener(r(h.e),h.proxy,q(h,j))})}function t(a,b,c,d,e){var f=m(a);(b||"").split(/\s/).forEach(function(b){n(a,b,c,d).forEach(function(b){delete h[f][b.i],"removeEventListener"in a&&a.removeEventListener(r(b.e),b.proxy,q(b,e))})})}function y(b,c){if(c||!b.isDefaultPrevented){c||(c=b),a.each(x,function(a,d){var e=c[a];b[a]=function(){return this[d]=u,e&&e.apply(c,arguments)},b[d]=v});if(c.defaultPrevented!==d?c.defaultPrevented:"returnValue"in c?c.returnValue===!1:c.getPreventDefault&&c.getPreventDefault())b.isDefaultPrevented=u}return b}function z(a){var b,c={originalEvent:a};for(b in a)!w.test(b)&&a[b]!==d&&(c[b]=a[b]);return y(c,a)}var b=a.zepto.qsa,c=1,d,e=Array.prototype.slice,f=a.isFunction,g=function(a){return typeof a=="string"},h={},i={},j="onfocusin"in window,k={focus:"focusin",blur:"focusout"},l={mouseenter:"mouseover",mouseleave:"mouseout"};i.click=i.mousedown=i.mouseup=i.mousemove="MouseEvents",a.event={add:s,remove:t},a.proxy=function(b,c){if(f(b)){var d=function(){return b.apply(c,arguments)};return d._zid=m(b),d}if(g(c))return a.proxy(b[c],b);throw new TypeError("expected function")},a.fn.bind=function(a,b,c){return this.on(a,b,c)},a.fn.unbind=function(a,b){return this.off(a,b)},a.fn.one=function(a,b,c,d){return this.on(a,b,c,d,1)};var u=function(){return!0},v=function(){return!1},w=/^([A-Z]|returnValue$|layer[XY]$)/,x={preventDefault:"isDefaultPrevented",stopImmediatePropagation:"isImmediatePropagationStopped",stopPropagation:"isPropagationStopped"};a.fn.delegate=function(a,b,c){return this.on(b,a,c)},a.fn.undelegate=function(a,b,c){return this.off(b,a,c)},a.fn.live=function(b,c){return a(document.body).delegate(this.selector,b,c),this},a.fn.die=function(b,c){return a(document.body).undelegate(this.selector,b,c),this},a.fn.on=function(b,c,h,i,j){var k,l,m=this;if(b&&!g(b))return a.each(b,function(a,b){m.on(a,c,h,b,j)}),m;!g(c)&&!f(i)&&i!==!1&&(i=h,h=c,c=d);if(f(h)||h===!1)i=h,h=d;return i===!1&&(i=v),m.each(function(d,f){j&&(k=function(a){return t(f,a.type,i),i.apply(this,arguments)}),c&&(l=function(b){var d,g=a(b.target).closest(c,f).get(0);if(g&&g!==f)return d=a.extend(z(b),{currentTarget:g,liveFired:f}),(k||i).apply(g,[d].concat(e.call(arguments,1)))}),s(f,b,i,h,c,l||k)})},a.fn.off=function(b,c,e){var h=this;return b&&!g(b)?(a.each(b,function(a,b){h.off(a,c,b)}),h):(!g(c)&&!f(e)&&e!==!1&&(e=c,c=d),e===!1&&(e=v),h.each(function(){t(this,b,e,c)}))},a.fn.trigger=function(b,c){return b=g(b)||a.isPlainObject(b)?a.Event(b):y(b),b._args=c,this.each(function(){"dispatchEvent"in this?this.dispatchEvent(b):a(this).triggerHandler(b,c)})},a.fn.triggerHandler=function(b,c){var d,e;return this.each(function(f,h){d=z(g(b)?a.Event(b):b),d._args=c,d.target=h,a.each(n(h,b.type||b),function(a,b){e=b.proxy(d);if(d.isImmediatePropagationStopped())return!1})}),e},"focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(b){a.fn[b]=function(a){return a?this.bind(b,a):this.trigger(b)}}),["focus","blur"].forEach(function(b){a.fn[b]=function(a){return a?this.bind(b,a):this.each(function(){try{this[b]()}catch(a){}}),this}}),a.Event=function(a,b){g(a)||(b=a,a=b.type);var c=document.createEvent(i[a]||"Events"),d=!0;if(b)for(var e in b)e=="bubbles"?d=!!b[e]:c[e]=b[e];return c.initEvent(a,d,!0),y(c)}}(Zepto),function($){function triggerAndReturn(a,b,c){var d=$.Event(b);return $(a).trigger(d,c),!d.isDefaultPrevented()}function triggerGlobal(a,b,c,d){if(a.global)return triggerAndReturn(b||document,c,d)}function ajaxStart(a){a.global&&$.active++===0&&triggerGlobal(a,null,"ajaxStart")}function ajaxStop(a){a.global&&!--$.active&&triggerGlobal(a,null,"ajaxStop")}function ajaxBeforeSend(a,b){var c=b.context;if(b.beforeSend.call(c,a,b)===!1||triggerGlobal(b,c,"ajaxBeforeSend",[a,b])===!1)return!1;triggerGlobal(b,c,"ajaxSend",[a,b])}function ajaxSuccess(a,b,c,d){var e=c.context,f="success";c.success.call(e,a,f,b),d&&d.resolveWith(e,[a,f,b]),triggerGlobal(c,e,"ajaxSuccess",[b,c,a]),ajaxComplete(f,b,c)}function ajaxError(a,b,c,d,e){var f=d.context;d.error.call(f,c,b,a),e&&e.rejectWith(f,[c,b,a]),triggerGlobal(d,f,"ajaxError",[c,d,a||b]),ajaxComplete(b,c,d)}function ajaxComplete(a,b,c){var d=c.context;c.complete.call(d,b,a),triggerGlobal(c,d,"ajaxComplete",[b,c]),ajaxStop(c)}function empty(){}function mimeToDataType(a){return a&&(a=a.split(";",2)[0]),a&&(a==htmlType?"html":a==jsonType?"json":scriptTypeRE.test(a)?"script":xmlTypeRE.test(a)&&"xml")||"text"}function appendQuery(a,b){return b==""?a:(a+"&"+b).replace(/[&?]{1,2}/,"?")}function serializeData(a){a.processData&&a.data&&$.type(a.data)!="string"&&(a.data=$.param(a.data,a.traditional)),a.data&&(!a.type||a.type.toUpperCase()=="GET")&&(a.url=appendQuery(a.url,a.data),a.data=undefined)}function parseArguments(a,b,c,d){var e=!$.isFunction(b);return{url:a,data:e?b:undefined,success:e?$.isFunction(c)?c:undefined:b,dataType:e?d||c:c}}function serialize(a,b,c,d){var e,f=$.isArray(b),g=$.isPlainObject(b);$.each(b,function(b,h){e=$.type(h),d&&(b=c?d:d+"["+(g||e=="object"||e=="array"?b:"")+"]"),!d&&f?a.add(h.name,h.value):e=="array"||!c&&e=="object"?serialize(a,h,c,b):a.add(b,h)})}var jsonpID=0,document=window.document,key,name,rscript=/<script[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,scriptTypeRE=/^(?:text|application)\/javascript/i,xmlTypeRE=/^(?:text|application)\/xml/i,jsonType="application/json",htmlType="text/html",blankRE=/^\s*$/;$.active=0,$.ajaxJSONP=function(a,b){if("type"in a){var c=a.jsonpCallback,d=($.isFunction(c)?c():c)||"jsonp"+ ++jsonpID,e=document.createElement("script"),f=window[d],g,h=function(a){$(e).triggerHandler("error",a||"abort")},i={abort:h},j;return b&&b.promise(i),$(e).on("load error",function(c,h){clearTimeout(j),$(e).off().remove(),c.type=="error"||!g?ajaxError(null,h||"error",i,a,b):ajaxSuccess(g[0],i,a,b),window[d]=f,g&&$.isFunction(f)&&f(g[0]),f=g=undefined}),ajaxBeforeSend(i,a)===!1?(h("abort"),i):(window[d]=function(){g=arguments},e.src=a.url.replace(/=\?/,"="+d),document.head.appendChild(e),a.timeout>0&&(j=setTimeout(function(){h("timeout")},a.timeout)),i)}return $.ajax(a)},$.ajaxSettings={type:"GET",beforeSend:empty,success:empty,error:empty,complete:empty,context:null,global:!0,xhr:function(){return new window.XMLHttpRequest},accepts:{script:"text/javascript, application/javascript, application/x-javascript",json:jsonType,xml:"application/xml, text/xml",html:htmlType,text:"text/plain"},crossDomain:!1,timeout:0,processData:!0,cache:!0},$.ajax=function(options){var settings=$.extend({},options||{}),deferred=$.Deferred&&$.Deferred();for(key in $.ajaxSettings)settings[key]===undefined&&(settings[key]=$.ajaxSettings[key]);ajaxStart(settings),settings.crossDomain||(settings.crossDomain=/^([\w-]+:)?\/\/([^\/]+)/.test(settings.url)&&RegExp.$2!=window.location.host),settings.url||(settings.url=window.location.toString()),serializeData(settings),settings.cache===!1&&(settings.url=appendQuery(settings.url,"_="+Date.now()));var dataType=settings.dataType,hasPlaceholder=/=\?/.test(settings.url);if(dataType=="jsonp"||hasPlaceholder)return hasPlaceholder||(settings.url=appendQuery(settings.url,settings.jsonp?settings.jsonp+"=?":settings.jsonp===!1?"":"callback=?")),$.ajaxJSONP(settings,deferred);var mime=settings.accepts[dataType],headers={},setHeader=function(a,b){headers[a.toLowerCase()]=[a,b]},protocol=/^([\w-]+:)\/\//.test(settings.url)?RegExp.$1:window.location.protocol,xhr=settings.xhr(),nativeSetHeader=xhr.setRequestHeader,abortTimeout;deferred&&deferred.promise(xhr),settings.crossDomain||setHeader("X-Requested-With","XMLHttpRequest"),setHeader("Accept",mime||"*/*");if(mime=settings.mimeType||mime)mime.indexOf(",")>-1&&(mime=mime.split(",",2)[0]),xhr.overrideMimeType&&xhr.overrideMimeType(mime);(settings.contentType||settings.contentType!==!1&&settings.data&&settings.type.toUpperCase()!="GET")&&setHeader("Content-Type",settings.contentType||"application/x-www-form-urlencoded");if(settings.headers)for(name in settings.headers)setHeader(name,settings.headers[name]);xhr.setRequestHeader=setHeader,xhr.onreadystatechange=function(){if(xhr.readyState==4){xhr.onreadystatechange=empty,clearTimeout(abortTimeout);var result,error=!1;if(xhr.status>=200&&xhr.status<300||xhr.status==304||xhr.status==0&&protocol=="file:"){dataType=dataType||mimeToDataType(settings.mimeType||xhr.getResponseHeader("content-type")),result=xhr.responseText;try{dataType=="script"?(1,eval)(result):dataType=="xml"?result=xhr.responseXML:dataType=="json"&&(result=blankRE.test(result)?null:$.parseJSON(result))}catch(e){error=e}error?ajaxError(error,"parsererror",xhr,settings,deferred):ajaxSuccess(result,xhr,settings,deferred)}else ajaxError(xhr.statusText||null,xhr.status?"error":"abort",xhr,settings,deferred)}};if(ajaxBeforeSend(xhr,settings)===!1)return xhr.abort(),ajaxError(null,"abort",xhr,settings,deferred),xhr;if(settings.xhrFields)for(name in settings.xhrFields)xhr[name]=settings.xhrFields[name];var async="async"in settings?settings.async:!0;xhr.open(settings.type,settings.url,async,settings.username,settings.password);for(name in headers)nativeSetHeader.apply(xhr,headers[name]);return settings.timeout>0&&(abortTimeout=setTimeout(function(){xhr.onreadystatechange=empty,xhr.abort(),ajaxError(null,"timeout",xhr,settings,deferred)},settings.timeout)),xhr.send(settings.data?settings.data:null),xhr},$.get=function(a,b,c,d){return $.ajax(parseArguments.apply(null,arguments))},$.post=function(a,b,c,d){var e=parseArguments.apply(null,arguments);return e.type="POST",$.ajax(e)},$.getJSON=function(a,b,c){var d=parseArguments.apply(null,arguments);return d.dataType="json",$.ajax(d)},$.fn.load=function(a,b,c){if(!this.length)return this;var d=this,e=a.split(/\s/),f,g=parseArguments(a,b,c),h=g.success;return e.length>1&&(g.url=e[0],f=e[1]),g.success=function(a){d.html(f?$("<div>").html(a.replace(rscript,"")).find(f):a),h&&h.apply(d,arguments)},$.ajax(g),this};var escape=encodeURIComponent;$.param=function(a,b){var c=[];return c.add=function(a,b){this.push(escape(a)+"="+escape(b))},serialize(c,a,b),c.join("&").replace(/%20/g,"+")}}(Zepto),function(a){a.fn.serializeArray=function(){var b=[],c;return a([].slice.call(this.get(0).elements)).each(function(){c=a(this);var d=c.attr("type");this.nodeName.toLowerCase()!="fieldset"&&!this.disabled&&d!="submit"&&d!="reset"&&d!="button"&&(d!="radio"&&d!="checkbox"||this.checked)&&b.push({name:c.attr("name"),value:c.val()})}),b},a.fn.serialize=function(){var a=[];return this.serializeArray().forEach(function(b){a.push(encodeURIComponent(b.name)+"="+encodeURIComponent(b.value))}),a.join("&")},a.fn.submit=function(b){if(b)this.bind("submit",b);else if(this.length){var c=a.Event("submit");this.eq(0).trigger(c),c.isDefaultPrevented()||this.get(0).submit()}return this}}(Zepto),function(a){"__proto__"in{}||a.extend(a.zepto,{Z:function(b,c){return b=b||[],a.extend(b,a.fn),b.selector=c||"",b.__Z=!0,b},isZ:function(b){return a.type(b)==="array"&&"__Z"in b}});try{getComputedStyle(undefined)}catch(b){var c=getComputedStyle;window.getComputedStyle=function(a){try{return c(a)}catch(b){return null}}}}(Zepto)
33 </script>
34
35 <style type="text/css">
36 body {
37 background: #F9F9F9;
38 font-size: 14px;
39 line-height: 22px;
40 font-family: Helvetica Neue, Helvetica, Arial;
41 }
42
43 a {
44 color: #000;
45 text-decoration: underline;
46 }
47
48 li ul, li ol{
49 margin: 0;
50 }
51
52 .anchor {
53 cursor: pointer;
54 }
55 .anchor .anchor_char{
56 visibility: hidden;
57 padding-left: 0.2em;
58 font-size: 0.9em;
59 opacity: 0.5;
60 }
61 .anchor:hover .anchor_char{
62 visibility: visible;
63 }
64
65 .sidebar{
66 background: #FFF;
67 position: fixed;
68 z-index: 10;
69 top: 0;
70 left: 0;
71 bottom: 0;
72 width: 230px;
73 overflow-y: auto;
74 overflow-x: hidden;
75 padding: 15px 0 30px 30px;
76 border-right: 1px solid #bbb;
77 font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif !important;
78 }
79
80 .sidebar ul{
81 margin: 0;
82 list-style: none;
83 padding: 0;
84 }
85
86 .sidebar ul a:hover {
87 text-decoration: underline;
88 color: #333;
89 }
90
91 .sidebar > ul > li {
92 margin-top: 15px;
93 }
94
95 .sidebar > ul > li > a {
96 font-weight: bold;
97 }
98
99 .sidebar ul ul {
100 margin-top: 5px;
101 font-size: 11px;
102 line-height: 14px;
103 }
104
105 .sidebar ul ul li:before {
106 content: "- ";
107 }
108 .sidebar ul ul li {
109 margin-bottom: 3px;
110 }
111 .sidebar ul ul li a {
112 text-decoration: none;
113 }
114
115 .toggle_sidebar_button{
116 display: none;
117 position: fixed;
118 z-index: 11;
119 top: 0;
120 width: 44px;
121 height: 44px;
122 background: #000;
123 background: rgba(0,0,0,0.7);
124 margin-left: 230px;
125 }
126 .toggle_sidebar_button:hover {
127 background: rgba(0,0,0,1);
128 cursor: pointer;
129 }
130 .toggle_sidebar_button .line{
131 height: 2px;
132 width: 21px;
133 margin-left: 11px;
134 margin-top: 5px;
135 background: #FFF;
136 }
137 .toggle_sidebar_button .line:first-child {
138 margin-top: 15px;
139 }
140
141 .main_container {
142 width: 100%;
143 padding-left: 260px;
144 margin: 30px;
145 margin-left: 0px;
146 padding-right: 30px;
147 }
148
149 .main_container p, ul{
150 margin: 25px 0;
151 }
152
153 .main_container ul {
154 list-style: circle;
155 font-size: 13px;
156 line-height: 18px;
157 padding-left: 15px;
158 }
159
160 pre {
161 font-size: 12px;
162 border: 4px solid #bbb;
163 border-top: 0;
164 border-bottom: 0;
165 margin: 0px 0 25px;
166 padding-top: 0px;
167 padding-bottom: 0px;
168
169 font-family: Monaco, Consolas, "Lucida Console", monospace;
170 line-height: 18px;
171 font-style: normal;
172 background: none;
173 border-radius: 0px;
174 overflow-x: scroll;
175
176 word-wrap: normal;
177 white-space: pre;
178 }
179
180 .main_container {
181 width: 840px;
182 }
183
184 .main_container p, ul, pre {
185 width: 100%;
186 }
187
188 code {
189 padding: 0px 3px;
190 color: #333;
191 background: #fff;
192 border: 1px solid #ddd;
193 zoom: 1;
194 white-space: nowrap;
195 border-radius: 0;
196 font-family: Monaco, Consolas, "Lucida Console", monospace;
197 font-size: 12px;
198 line-height: 18px;
199 font-style: normal;
200 }
201
202 em {
203 font-size: 12px;
204 line-height: 18px;
205 }
206
207 @media (max-width: 820px) {
208 .sidebar {
209 display: none;
210 }
211
212 .main_container {
213 padding: 0px;
214 width: 100%;
215 }
216
217 .main_container > *{
218 padding-left: 10px;
219 padding-right: 10px;
220 }
221 .main_container > ul,
222 .main_container > ol {
223 padding-left: 27px;
224 }
225 .force_show_sidebar .main_container {
226 display: none;
227 }
228 .force_show_sidebar .sidebar {
229 width: 100%;
230 }
231 .force_show_sidebar .sidebar a{
232 font-size: 1.5em;
233 line-height: 1.5em;
234 }
235 .force_show_sidebar .toggle_sidebar_button {
236 right: 0;
237 }
238 .force_show_sidebar .toggle_sidebar_button .line:first-child,
239 .force_show_sidebar .toggle_sidebar_button .line:last-child {
240 visibility: hidden;
241 }
242
243 .toggle_sidebar_button {
244 margin-left: 0px;
245 display: block;
246 }
247
248 pre {
249 font-size: 12px;
250 border: 1px solid #bbb;
251 border-left: 0;
252 border-right: 0;
253 padding: 9px;
254 background: #FFF;
255 }
256
257 code {
258 word-wrap: break-word;
259 white-space: normal;
260 }
261 }
262
263 .force_show_sidebar .sidebar {
264 display: block;
265 }
266
267 .force_show_sidebar .main_container {
268 padding-left: 260px;
269 }
270
271 .force_show_sidebar .toggle_sidebar_button{
272 margin-left: 230px;
273 }
274 </style>
275
276 <script type="text/javascript">
277 $(function(){
278 $('.toggle_sidebar_button').on('click', function(){
279 $('body').toggleClass('force_show_sidebar');
280 });
281
282 // hide sidebar on every click in menu (if small screen)
283 $('.sidebar').find('a').on('click', function(){
284 $('body').removeClass('force_show_sidebar');
285 });
286
287 // add anchors
288 $.each($('.main_container').find('h1,h2,h3,h4,h5,h6'), function(key, item){
289 if ($(item).attr('id')) {
290 $(item).addClass('anchor');
291 $(item).append($('<span class="anchor_char">¶</span>'))
292 $(item).on('click', function(){
293 window.location = '#' + $(item).attr('id');
294 })
295 }
296 });
297
298 // remove <code> tag inside of <pre>
299 $.each($('pre > code'), function(key, item){
300 $(item).parent().html($(item).html())
301 })
302 })
303 </script>
304 </head>
305 <body>
306 <a class="toggle_sidebar_button">
307 <div class="line"></div>
308 <div class="line"></div>
309 <div class="line"></div>
310 </a>
311 <div class="sidebar">
312 <ul>
313 <li><a href="#drf-extensions">DRF-extensions</a></li>
314 <li><a href="#viewsets">Viewsets</a>
315 <ul>
316 <li><a href="#detailserializermixin">DetailSerializerMixin</a></li>
317 <li><a href="#paginatebymaxmixin">PaginateByMaxMixin</a></li>
318 <li><a href="#cache-etag-mixins">Cache/ETAG mixins</a></li>
319 </ul></li>
320 <li><a href="#routers">Routers</a>
321 <ul>
322 <li><a href="#pluggable-router-mixins">Pluggable router mixins</a></li>
323 </ul></li>
324 <li><a href="#nested-routes">Nested routes</a>
325 <ul>
326 <li><a href="#nested-router-mixin">Nested router mixin</a></li>
327 <li><a href="#usage-with-generic-relations">Usage with generic relations</a></li>
328 </ul></li>
329 <li><a href="#serializers">Serializers</a>
330 <ul>
331 <li><a href="#partialupdateserializermixin">PartialUpdateSerializerMixin</a></li>
332 </ul></li>
333 <li><a href="#fields">Fields</a>
334 <ul>
335 <li><a href="#resourceurifield">ResourceUriField</a></li>
336 </ul></li>
337 <li><a href="#permissions">Permissions</a>
338 <ul>
339 <li><a href="#object-permissions">Object permissions</a></li>
340 </ul></li>
341 <li><a href="#caching">Caching</a>
342 <ul>
343 <li><a href="#cache-response">Cache response</a></li>
344 <li><a href="#timeout">Timeout</a></li>
345 <li><a href="#usage-of-the-specific-cache">Usage of the specific cache</a></li>
346 <li><a href="#cache-key">Cache key</a></li>
347 <li><a href="#default-key-function">Default key function</a></li>
348 <li><a href="#caching-errors">Caching errors</a></li>
349 <li><a href="#cacheresponsemixin">CacheResponseMixin</a></li>
350 </ul></li>
351 <li><a href="#key-constructors">Key constructors</a>
352 <ul>
353 <li><a href="#default-key-constructor">Default key constructor</a></li>
354 <li><a href="#how-key-constructor-works">How key constructor works</a></li>
355 <li><a href="#custom-key-bit">Custom key bit</a></li>
356 <li><a href="#key-constructor-params">Key constructor params</a></li>
357 <li><a href="#constructor-s-bits-list">Constructor's bits list</a></li>
358 </ul></li>
359 <li><a href="#default-key-bits">Default key bits</a>
360 <ul>
361 <li><a href="#formatkeybit">FormatKeyBit</a></li>
362 <li><a href="#languagekeybit">LanguageKeyBit</a></li>
363 <li><a href="#userkeybit">UserKeyBit</a></li>
364 <li><a href="#requestmetakeybit">RequestMetaKeyBit</a></li>
365 <li><a href="#headerskeybit">HeadersKeyBit</a></li>
366 <li><a href="#argskeybit">ArgsKeyBit</a></li>
367 <li><a href="#kwargskeybit">KwargsKeyBit</a></li>
368 <li><a href="#queryparamskeybit">QueryParamsKeyBit</a></li>
369 <li><a href="#paginationkeybit">PaginationKeyBit</a></li>
370 <li><a href="#listsqlquerykeybit">ListSqlQueryKeyBit</a></li>
371 <li><a href="#retrievesqlquerykeybit">RetrieveSqlQueryKeyBit</a></li>
372 <li><a href="#uniqueviewidkeybit">UniqueViewIdKeyBit</a></li>
373 <li><a href="#uniquemethodidkeybit">UniqueMethodIdKeyBit</a></li>
374 <li><a href="#listmodelkeybit">ListModelKeyBit</a></li>
375 <li><a href="#retrievemodelkeybit">RetrieveModelKeyBit</a></li>
376 </ul></li>
377 <li><a href="#conditional-requests">Conditional requests</a></li>
378 <li><a href="#bulk-operations">Bulk operations</a>
379 <ul>
380 <li><a href="#safety">Safety</a></li>
381 <li><a href="#bulk-destroy">Bulk destroy</a></li>
382 <li><a href="#bulk-update">Bulk update</a></li>
383 </ul></li>
384 <li><a href="#settings">Settings</a>
385 <ul>
386 <li><a href="#accessing-settings">Accessing settings</a></li>
387 </ul></li>
388 <li><a href="#release-notes">Release notes</a>
389 <ul>
390 <li><a href="#0-8-0">0.8.0</a></li>
391 <li><a href="#0-7-1">0.7.1</a></li>
392 <li><a href="#0-7-0">0.7.0</a></li>
393 <li><a href="#0-6-0">0.6.0</a></li>
394 <li><a href="#0-5-0">0.5.0</a></li>
395 <li><a href="#0-4-0">0.4.0</a></li>
396 <li><a href="#0-3-2">0.3.2</a></li>
397 <li><a href="#0-3-1">0.3.1</a></li>
398 <li><a href="#0-2-8">0.2.8</a></li>
399 <li><a href="#0-2-7">0.2.7</a></li>
400 <li><a href="#0-2-6">0.2.6</a></li>
401 <li><a href="#0-2-5">0.2.5</a></li>
402 <li><a href="#0-2-4">0.2.4</a></li>
403 <li><a href="#0-2-3">0.2.3</a></li>
404 <li><a href="#0-2-2">0.2.2</a></li>
405 <li><a href="#0-2-1">0.2.1</a></li>
406 <li><a href="#0-2">0.2</a></li>
407 </ul></li>
408 </ul>
409
410 </div>
411 <div class="main_container">
412 <h3 id="drf-extensions">DRF-extensions</h3>
413
414 <p>DRF-extensions is a collection of custom extensions for <a href="https://github.com/tomchristie/django-rest-framework">Django REST Framework</a>.
415 Source repository is available at <a href="https://github.com/chibisov/drf-extensions">https://github.com/chibisov/drf-extensions</a>.</p>
416
417 <h3 id="viewsets">Viewsets</h3>
418
419 <p>Extensions for <a href="https://www.django-rest-framework.org/api-guide/viewsets/">viewsets</a>.</p>
420
421 <h4 id="detailserializermixin">DetailSerializerMixin</h4>
422
423 <p>This mixin lets add custom serializer for detail view. Just add mixin and specify <code>serializer_detail_class</code> attribute:</p>
424
425 <pre><code>from django.contrib.auth.models import User
426 from myapps.serializers import UserSerializer, UserDetailSerializer
427 from rest_framework_extensions.mixins import DetailSerializerMixin
428
429 class UserViewSet(DetailSerializerMixin, viewsets.ReadOnlyModelViewSet):
430 serializer_class = UserSerializer
431 serializer_detail_class = UserDetailSerializer
432 queryset = User.objects.all()
433 </code></pre>
434
435 <p>Sometimes you need to set custom QuerySet for detail view. For example, in detail view you want to show user groups and permissions for these groups. You can make it by specifying <code>queryset_detail</code> attribute:</p>
436
437 <pre><code>from django.contrib.auth.models import User
438 from myapps.serializers import UserSerializer, UserDetailSerializer
439 from rest_framework_extensions.mixins import DetailSerializerMixin
440
441 class UserViewSet(DetailSerializerMixin, viewsets.ReadOnlyModelViewSet):
442 serializer_class = UserSerializer
443 serializer_detail_class = UserDetailSerializer
444 queryset = User.objects.all()
445 queryset_detail = queryset.prefetch_related('groups__permissions')
446 </code></pre>
447
448 <p>If you use <code>DetailSerializerMixin</code> and don't specify <code>serializer_detail_class</code> attribute, then <code>serializer_class</code> will be used.</p>
449
450 <p>If you use <code>DetailSerializerMixin</code> and don't specify <code>queryset_detail</code> attribute, then <code>queryset</code> will be used.</p>
451
452 <h4 id="paginatebymaxmixin">PaginateByMaxMixin</h4>
453
454 <p><em>New in DRF-extensions 0.2.2</em></p>
455
456 <p>This mixin allows to paginate results by <a href="https://www.django-rest-framework.org/api-guide/pagination#pagination-in-the-generic-views">max_paginate_by</a>
457 value. This approach is useful when clients want to take as much paginated data as possible,
458 but don't want to bother about backend limitations.</p>
459
460 <pre><code>from myapps.serializers import UserSerializer
461 from rest_framework_extensions.mixins import PaginateByMaxMixin
462
463 class UserViewSet(PaginateByMaxMixin,
464 viewsets.ReadOnlyModelViewSet):
465 max_paginate_by = 100
466 serializer_class = UserSerializer
467 </code></pre>
468
469 <p>And now you can send requests with <code>?page_size=max</code> argument:</p>
470
471 <pre><code># Request
472 GET /users/?page_size=max HTTP/1.1
473 Accept: application/json
474
475 # Response
476 HTTP/1.1 200 OK
477 Content-Type: application/json; charset=UTF-8
478
479 {
480 count: 1000,
481 next: "https://localhost:8000/v1/users/?page=2&amp;page_size=max",
482 previous: null,
483 results: [
484 ...100 items...
485 ]
486 }
487 </code></pre>
488
489 <p>This mixin could be used only with Django Rest Framework &gt;= 2.3.8, because
490 <a href="https://www.django-rest-framework.org/community/release-notes/#382">max_paginate_by</a>
491 was introduced in 2.3.8 version.</p>
492
493 <h4 id="cache-etag-mixins">Cache/ETAG mixins</h4>
494
495 <!--**ReadOnlyCacheResponseAndETAGMixin**-->
496
497 <p><!--This mixin combines <code>ReadOnlyETAGMixin</code> and <code>CacheResponseMixin</code>. It could be used with-->
498 <!--<a href="http://www.django-rest-framework.org/api-guide/viewsets.html#readonlymodelviewset">ReadOnlyModelViewSet</a> and helps-->
499 <!--to process caching + etag calculation for <code>retrieve</code> and <code>list</code> methods:--></p>
500
501 <p><!-- from myapps.serializers import UserSerializer-->
502 <!-- from rest_framework_extensions.mixins import (-->
503 <!-- ReadOnlyCacheResponseAndETAGMixin-->
504 <!-- )--></p>
505
506 <p><!-- class UserViewSet(ReadOnlyCacheResponseAndETAGMixin,-->
507 <!-- viewsets.ReadOnlyModelViewSet):-->
508 <!-- serializer_class = UserSerializer--></p>
509
510 <p><!--**CacheResponseAndETAGMixin**--></p>
511
512 <p><!--This mixin combines <code>ETAGMixin</code> and <code>CacheResponseMixin</code>. It could be used with-->
513 <!--<a href="https://www.django-rest-framework.org/api-guide/viewsets/#modelviewset">ModelViewSet</a> and helps-->
514 <!--to process:--></p>
515
516 <p><!--* Caching for <code>retrieve</code> and <code>list</code> methods-->
517 <!--* Etag for <code>retrieve</code>, <code>list</code>, <code>update</code> and <code>destroy</code> methods--></p>
518
519 <p><!--Usage:--></p>
520
521 <p><!-- from myapps.serializers import UserSerializer-->
522 <!-- from rest_framework_extensions.mixins import CacheResponseAndETAGMixin--></p>
523
524 <p><!-- class UserViewSet(CacheResponseAndETAGMixin,-->
525 <!-- viewsets.ModelViewSet):-->
526 <!-- serializer_class = UserSerializer--></p>
527
528 <p><!--Please, read more about <a href="#caching">caching</a>, <a href="#key-constructor">key construction</a> and <a href="#conditional-requests">conditional requests</a>.-->
529 The etag functionality is pending an overhaul has been temporarily removed since 0.4.0. </p>
530
531 <p>ReadOnlyCacheResponseAndETAGMixin and CacheResponseAndETAGMixin are no longer available to use.</p>
532
533 <p>See discussion in <a href="https://github.com/chibisov/drf-extensions/issues/177">Issue #177</a></p>
534
535 <h3 id="routers">Routers</h3>
536
537 <p>Extensions for <a href="https://www.django-rest-framework.org/api-guide/routers/">routers</a>.</p>
538
539 <p>You will need to use custom <code>ExtendedDefaultRouter</code> or <code>ExtendedSimpleRouter</code> for routing if you want to take advantages of described extensions. For example you have standard implementation:</p>
540
541 <pre><code>from rest_framework.routers import DefaultRouter
542 router = DefaultRouter()
543 </code></pre>
544
545 <p>You should replace <code>DefaultRouter</code> with <code>ExtendedDefaultRouter</code>:</p>
546
547 <pre><code>from rest_framework_extensions.routers import (
548 ExtendedDefaultRouter as DefaultRouter
549 )
550 router = DefaultRouter()
551 </code></pre>
552
553 <p>Or <code>SimpleRouter</code> with <code>ExtendedSimpleRouter</code>:</p>
554
555 <pre><code>from rest_framework_extensions.routers import (
556 ExtendedSimpleRouter as SimpleRouter
557 )
558 router = SimpleRouter()
559 </code></pre>
560
561 <h4 id="pluggable-router-mixins">Pluggable router mixins</h4>
562
563 <p><em>New in DRF-extensions 0.2.4</em></p>
564
565 <p>Every feature in extended routers has it's own mixin. That means that you can use the only features you need in your custom
566 routers. <code>ExtendedRouterMixin</code> has all set of drf-extensions features. For example you can use it with third-party routes:</p>
567
568 <pre><code>from rest_framework_extensions.routers import ExtendedRouterMixin
569 from third_party_app.routers import SomeRouter
570
571 class ExtendedSomeRouter(ExtendedRouterMixin, SomeRouter):
572 pass
573 </code></pre>
574
575 <h3 id="nested-routes">Nested routes</h3>
576
577 <p><em>New in DRF-extensions 0.2.4</em></p>
578
579 <p>Nested routes allows you create nested resources with <a href="https://www.django-rest-framework.org/api-guide/viewsets/">viewsets</a>.</p>
580
581 <p>For example:</p>
582
583 <pre><code>from rest_framework_extensions.routers import ExtendedSimpleRouter
584 from yourapp.views import (
585 UserViewSet,
586 GroupViewSet,
587 PermissionViewSet,
588 )
589
590 router = ExtendedSimpleRouter()
591 (
592 router.register(r'users', UserViewSet, basename='user')
593 .register(r'groups',
594 GroupViewSet,
595 basename='users-group',
596 parents_query_lookups=['user_groups'])
597 .register(r'permissions',
598 PermissionViewSet,
599 basename='users-groups-permission',
600 parents_query_lookups=['group__user', 'group'])
601 )
602 urlpatterns = router.urls
603 </code></pre>
604
605 <p>There is one requirement for viewsets which used in nested routers. They should add mixin <code>NestedViewSetMixin</code>. That mixin
606 adds automatic filtering by parent lookups:</p>
607
608 <pre><code># yourapp.views
609 from rest_framework_extensions.mixins import NestedViewSetMixin
610
611 class UserViewSet(NestedViewSetMixin, ModelViewSet):
612 model = UserModel
613
614 class GroupViewSet(NestedViewSetMixin, ModelViewSet):
615 model = GroupModel
616
617 class PermissionViewSet(NestedViewSetMixin, ModelViewSet):
618 model = PermissionModel
619 </code></pre>
620
621 <p>With such kind of router we have next resources:</p>
622
623 <ul>
624 <li><code>/users/</code> - list of all users. Resolve name is <strong>user-list</strong></li>
625 <li><code>/users/&lt;pk&gt;/</code> - user detail. Resolve name is <strong>user-detail</strong></li>
626 <li><code>/users/&lt;parent_lookup_user_groups&gt;/groups/</code> - list of groups for exact user.
627 Resolve name is <strong>users-group-list</strong></li>
628 <li><code>/users/&lt;parent_lookup_user_groups&gt;/groups/&lt;pk&gt;/</code> - user group detail. If user doesn't have group then resource will
629 be not found. Resolve name is <strong>users-group-detail</strong></li>
630 <li><code>/users/&lt;parent_lookup_group__user&gt;/groups/&lt;parent_lookup_group&gt;/permissions/</code> - list of permissions for user group.
631 Resolve name is <strong>users-groups-permission-list</strong></li>
632 <li><code>/users/&lt;parent_lookup_group__user&gt;/groups/&lt;parent_lookup_group&gt;/permissions/&lt;pk&gt;/</code> - user group permission detail.
633 If user doesn't have group or group doesn't have permission then resource will be not found.
634 Resolve name is <strong>users-groups-permission-detail</strong></li>
635 </ul>
636
637 <p>Every resource is automatically filtered by parent lookups.</p>
638
639 <pre><code># Request
640 GET /users/1/groups/2/permissions/ HTTP/1.1
641 Accept: application/json
642
643 # Response
644 HTTP/1.1 200 OK
645 Content-Type: application/json; charset=UTF-8
646
647
648 [
649 {
650 id: 3,
651 name: "read"
652 },
653 {
654 id: 4,
655 name: "update"
656 },
657 {
658 id: 5,
659 name: "delete"
660 }
661 ]
662 </code></pre>
663
664 <p>For request above permissions will be filtered by user with pk <code>1</code> and group with pk <code>2</code>:</p>
665
666 <pre><code>Permission.objects.filter(group__user=1, group=2)
667 </code></pre>
668
669 <p>Example with registering more then one nested resource in one depth:</p>
670
671 <pre><code>permissions_routes = router.register(
672 r'permissions',
673 PermissionViewSet,
674 basename='permission'
675 )
676 permissions_routes.register(
677 r'groups',
678 GroupViewSet,
679 basename='permissions-group',
680 parents_query_lookups=['permissions']
681 )
682 permissions_routes.register(
683 r'users',
684 UserViewSet,
685 basename='permissions-user',
686 parents_query_lookups=['groups__permissions']
687 )
688 </code></pre>
689
690 <p>With such kind of router we have next resources:</p>
691
692 <ul>
693 <li><code>/permissions/</code> - list of all permissions. Resolve name is <strong>permission-list</strong></li>
694 <li><code>/permissions/&lt;pk&gt;/</code> - permission detail. Resolve name is <strong>permission-detail</strong></li>
695 <li><code>/permissions/&lt;parent_lookup_permissions&gt;/groups/</code> - list of groups for exact permission.
696 Resolve name is <strong>permissions-group-list</strong></li>
697 <li><code>/permissions/&lt;parent_lookup_permissions&gt;/groups/&lt;pk&gt;/</code> - permission group detail. If group doesn't have
698 permission then resource will be not found. Resolve name is <strong>permissions-group-detail</strong></li>
699 <li><code>/permissions/&lt;parent_lookup_groups__permissions&gt;/users/</code> - list of users for exact permission.
700 Resolve name is <strong>permissions-user-list</strong></li>
701 <li><code>/permissions/&lt;parent_lookup_groups__permissions&gt;/user/&lt;pk&gt;/</code> - permission user detail. If user doesn't have
702 permission then resource will be not found. Resolve name is <strong>permissions-user-detail</strong></li>
703 </ul>
704
705 <h4 id="nested-router-mixin">Nested router mixin</h4>
706
707 <p>You can use <code>rest_framework_extensions.routers.NestedRouterMixin</code> for adding nesting feature into your routers:</p>
708
709 <pre><code>from rest_framework_extensions.routers import NestedRouterMixin
710 from rest_framework.routers import SimpleRouter
711
712 class SimpleRouterWithNesting(NestedRouterMixin, SimpleRouter):
713 pass
714 </code></pre>
715
716 <h4 id="usage-with-generic-relations">Usage with generic relations</h4>
717
718 <p>If you want to use nested router for <a href="https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations">generic relation</a>
719 fields, you should explicitly filter <code>QuerySet</code> by content type.</p>
720
721 <p>For example if you have such kind of models:</p>
722
723 <pre><code>class Task(models.Model):
724 title = models.CharField(max_length=30)
725
726 class Book(models.Model):
727 title = models.CharField(max_length=30)
728
729 class Comment(models.Model):
730 content_type = models.ForeignKey(ContentType)
731 object_id = models.PositiveIntegerField()
732 content_object = generic.GenericForeignKey()
733 text = models.CharField(max_length=30)
734 </code></pre>
735
736 <p>Lets create viewsets for that models:</p>
737
738 <pre><code>class TaskViewSet(NestedViewSetMixin, ModelViewSet):
739 model = TaskModel
740
741 class BookViewSet(NestedViewSetMixin, ModelViewSet):
742 model = BookModel
743
744 class CommentViewSet(NestedViewSetMixin, ModelViewSet):
745 queryset = CommentModel.objects.all()
746 </code></pre>
747
748 <p>And router like this:</p>
749
750 <pre><code>router = ExtendedSimpleRouter()
751 # tasks route
752 (
753 router.register(r'tasks', TaskViewSet)
754 .register(r'comments',
755 CommentViewSet,
756 'tasks-comment',
757 parents_query_lookups=['object_id'])
758 )
759 # books route
760 (
761 router.register(r'books', BookViewSet)
762 .register(r'comments',
763 CommentViewSet,
764 'books-comment',
765 parents_query_lookups=['object_id'])
766 )
767 </code></pre>
768
769 <p>As you can see we've added to <code>parents_query_lookups</code> only one <code>object_id</code> value. But when you make requests to <code>comments</code>
770 endpoint for both tasks and books routes there is no context for current content type.</p>
771
772 <pre><code># Request
773 GET /tasks/123/comments/ HTTP/1.1
774 Accept: application/json
775
776 # Response
777 HTTP/1.1 200 OK
778 Content-Type: application/json; charset=UTF-8
779
780 [
781 {
782 id: 1,
783 content_type: 1,
784 object_id: 123,
785 text: "Good task!"
786 },
787 {
788 id: 2,
789 content_type: 2, // oops. Wrong content type (for book)
790 object_id: 123, // task and book has the same id
791 text: "Good book!"
792 },
793 ]
794 </code></pre>
795
796 <p>For such kind of cases you should explicitly filter <code>QuerySets</code> of nested viewsets by content type:</p>
797
798 <pre><code>from django.contrib.contenttypes.models import ContentType
799
800 class CommentViewSet(NestedViewSetMixin, ModelViewSet):
801 queryset = CommentModel.objects.all()
802
803 class TaskCommentViewSet(CommentViewSet):
804 def get_queryset(self):
805 return super(TaskCommentViewSet, self).get_queryset().filter(
806 content_type=ContentType.objects.get_for_model(TaskModel)
807 )
808
809 class BookCommentViewSet(CommentViewSet):
810 def get_queryset(self):
811 return super(BookCommentViewSet, self).get_queryset().filter(
812 content_type=ContentType.objects.get_for_model(BookModel)
813 )
814 </code></pre>
815
816 <p>Lets use new viewsets in router:</p>
817
818 <pre><code>router = ExtendedSimpleRouter()
819 # tasks route
820 (
821 router.register(r'tasks', TaskViewSet)
822 .register(r'comments',
823 TaskCommentViewSet,
824 'tasks-comment',
825 parents_query_lookups=['object_id'])
826 )
827 # books route
828 (
829 router.register(r'books', BookViewSet)
830 .register(r'comments',
831 BookCommentViewSet,
832 'books-comment',
833 parents_query_lookups=['object_id'])
834 )
835 </code></pre>
836
837 <h3 id="serializers">Serializers</h3>
838
839 <p>Extensions for <a href="https://www.django-rest-framework.org/api-guide/serializers/">serializers</a> functionality.</p>
840
841 <h4 id="partialupdateserializermixin">PartialUpdateSerializerMixin</h4>
842
843 <p><em>New in DRF-extensions 0.2.3</em></p>
844
845 <p>By default every saving of <a href="https://www.django-rest-framework.org/api-guide/serializers#modelserializer">ModelSerializer</a>
846 saves the whole object. Even partial update just patches model instance. For example:</p>
847
848 <pre><code>from myapps.models import City
849 from myapps.serializers import CitySerializer
850
851 moscow = City.objects.get(pk=10)
852 city_serializer = CitySerializer(
853 instance=moscow,
854 data={'country': 'USA'},
855 partial=True
856 )
857 if city_serializer.is_valid():
858 city_serializer.save()
859
860 # equivalent to
861 moscow.country = 'USA'
862 moscow.save()
863 </code></pre>
864
865 <p>SQL representation for previous example will be:</p>
866
867 <pre><code>UPDATE city SET name='Moscow', country='USA' WHERE id=1;
868 </code></pre>
869
870 <p>Django's <code>save</code> method has keyword argument <a href="https://docs.djangoproject.com/en/dev/ref/models/instances/#specifying-which-fields-to-save">update_fields</a>.
871 Only the fields named in that list will be updated:</p>
872
873 <pre><code>moscow.country = 'USA'
874 moscow.save(update_fields=['country'])
875 </code></pre>
876
877 <p>SQL representation for example with <code>update_fields</code> usage will be:</p>
878
879 <pre><code>UPDATE city SET country='USA' WHERE id=1;
880 </code></pre>
881
882 <p>To use <code>update_fields</code> for every partial update you should mixin <code>PartialUpdateSerializerMixin</code> to your serializer:</p>
883
884 <pre><code>from rest_framework_extensions.serializers import (
885 PartialUpdateSerializerMixin
886 )
887
888 class CitySerializer(PartialUpdateSerializerMixin,
889 serializers.ModelSerializer):
890 class Meta:
891 model = City
892 </code></pre>
893
894 <h3 id="fields">Fields</h3>
895
896 <p>Set of serializer fields that extends <a href="https://www.django-rest-framework.org/api-guide/fields/">default fields</a> functionality.</p>
897
898 <h4 id="resourceurifield">ResourceUriField</h4>
899
900 <p>Represents a hyperlinking uri that points to the detail view for that object.</p>
901
902 <pre><code>from rest_framework_extensions.fields import ResourceUriField
903
904 class CitySerializer(serializers.ModelSerializer):
905 resource_uri = ResourceUriField(view_name='city-detail')
906
907 class Meta:
908 model = City
909 </code></pre>
910
911 <p>Request example:</p>
912
913 <pre><code># Request
914 GET /cities/268/ HTTP/1.1
915 Accept: application/json
916
917 # Response
918 HTTP/1.1 200 OK
919 Content-Type: application/json; charset=UTF-8
920
921 {
922 id: 268,
923 resource_uri: "http://localhost:8000/v1/cities/268/",
924 name: "Serpuhov"
925 }
926 </code></pre>
927
928 <h3 id="permissions">Permissions</h3>
929
930 <p>Extensions for <a href="http://www.django-rest-framework.org/api-guide/permissions.html">permissions</a>.</p>
931
932 <h4 id="object-permissions">Object permissions</h4>
933
934 <p><em>New in DRF-extensions 0.2.2</em></p>
935
936 <p>Django Rest Framework allows you to use <a href="http://www.django-rest-framework.org/api-guide/permissions#djangoobjectpermissions">DjangoObjectPermissions</a> out of the box. But it has one limitation - if user has no permissions for viewing resource he will get <code>404</code> as response code. In most cases it's good approach because it solves security issues by default. But what if you wanted to return <code>401</code> or <code>403</code>? What if you wanted to say to user - "You need to be logged in for viewing current resource" or "You don't have permissions for viewing current resource"?</p>
937
938 <p><code>ExtenedDjangoObjectPermissions</code> will help you to be more flexible. By default it behaves as standard <a href="http://www.django-rest-framework.org/api-guide/permissions#djangoobjectpermissions">DjangoObjectPermissions</a>. For example, it is safe to replace <code>DjangoObjectPermissions</code> with extended permissions class:</p>
939
940 <pre><code>from rest_framework_extensions.permissions import (
941 ExtendedDjangoObjectPermissions as DjangoObjectPermissions
942 )
943
944 class CommentView(viewsets.ModelViewSet):
945 permission_classes = (DjangoObjectPermissions,)
946 </code></pre>
947
948 <p>Now every request from unauthorized user will get <code>404</code> response:</p>
949
950 <pre><code># Request
951 GET /comments/1/ HTTP/1.1
952 Accept: application/json
953
954 # Response
955 HTTP/1.1 404 NOT FOUND
956 Content-Type: application/json; charset=UTF-8
957
958 {"detail": "Not found"}
959 </code></pre>
960
961 <p>With <code>ExtenedDjangoObjectPermissions</code> you can disable hiding forbidden for read objects by changing <code>hide_forbidden_for_read_objects</code> attribute:</p>
962
963 <pre><code>from rest_framework_extensions.permissions import (
964 ExtendedDjangoObjectPermissions
965 )
966
967 class CommentViewObjectPermissions(ExtendedDjangoObjectPermissions):
968 hide_forbidden_for_read_objects = False
969
970 class CommentView(viewsets.ModelViewSet):
971 permission_classes = (CommentViewObjectPermissions,)
972 </code></pre>
973
974 <p>Now lets see request response for user that has no permissions for viewing <code>CommentView</code> object:</p>
975
976 <pre><code># Request
977 GET /comments/1/ HTTP/1.1
978 Accept: application/json
979
980 # Response
981 HTTP/1.1 403 FORBIDDEN
982 Content-Type: application/json; charset=UTF-8
983
984 {u'detail': u'You do not have permission to perform this action.'}
985 </code></pre>
986
987 <p><code>ExtenedDjangoObjectPermissions</code> could be used only with Django Rest Framework &gt;= 2.3.8, because <a href="https://www.django-rest-framework.org/topics/release-notes#238">DjangoObjectPermissions</a> was introduced in 2.3.8 version.</p>
988
989 <h3 id="caching">Caching</h3>
990
991 <p>To cache something is to save the result of an expensive calculation so that you don't have to perform the calculation next time. Here's some pseudocode explaining how this would work for a dynamically generated api response:</p>
992
993 <pre><code>given a URL, try finding that API response in the cache
994 if the response is in the cache:
995 return the cached response
996 else:
997 generate the response
998 save the generated response in the cache (for next time)
999 return the generated response
1000 </code></pre>
1001
1002 <h4 id="cache-response">Cache response</h4>
1003
1004 <p>DRF-extensions allows you to cache api responses with simple <code>@cache_response</code> decorator.
1005 There are two requirements for decorated method:</p>
1006
1007 <ul>
1008 <li>It should be method of class which is inherited from <code>rest_framework.views.APIView</code></li>
1009 <li>It should return <code>rest_framework.response.Response</code> instance.</li>
1010 </ul>
1011
1012 <p>Usage example:</p>
1013
1014 <pre><code>from rest_framework.response import Response
1015 from rest_framework import views
1016 from rest_framework_extensions.cache.decorators import (
1017 cache_response
1018 )
1019 from myapp.models import City
1020
1021 class CityView(views.APIView):
1022 @cache_response()
1023 def get(self, request, *args, **kwargs):
1024 cities = City.objects.all().values_list('name', flat=True)
1025 return Response(cities)
1026 </code></pre>
1027
1028 <p>If you request view first time you'll get it from processed SQL query. (~60ms response time):</p>
1029
1030 <pre><code># Request
1031 GET /cities/ HTTP/1.1
1032 Accept: application/json
1033
1034 # Response
1035 HTTP/1.1 200 OK
1036 Content-Type: application/json; charset=UTF-8
1037
1038 ['Moscow', 'London', 'Paris']
1039 </code></pre>
1040
1041 <p>Second request will hit the cache. No sql evaluation, no database query. (~30 ms response time):</p>
1042
1043 <pre><code># Request
1044 GET /cities/ HTTP/1.1
1045 Accept: application/json
1046
1047 # Response
1048 HTTP/1.1 200 OK
1049 Content-Type: application/json; charset=UTF-8
1050
1051 ['Moscow', 'London', 'Paris']
1052 </code></pre>
1053
1054 <p>Reduction in response time depends on calculation complexity inside your API method. Sometimes it reduces from 1 second to 10ms, sometimes you win just 10ms.</p>
1055
1056 <p><em>New in DRF-extensions 0.4.0</em></p>
1057
1058 <p>The decorator will render and discard the original DRF response in favor of Django's <code>HttpResponse</code>. This allows the cache to retain a smaller memory footprint and eliminates the need to re-render responses on each request. Furthermore it eliminates the risk for users to unknowingly cache whole Serializers and QuerySets.</p>
1059
1060 <p>You can disable this behavior in your test suite by using <a href="https://docs.djangoproject.com/en/stable/topics/cache/#dummy-caching-for-development">dummy caching</a> for the DRF-extensions cache (set via <code>DEFAULT_USE_CACHE</code>). </p>
1061
1062 <h4 id="timeout">Timeout</h4>
1063
1064 <p>You can specify cache timeout in seconds, providing first argument:</p>
1065
1066 <pre><code>class CityView(views.APIView):
1067 @cache_response(60 * 15)
1068 def get(self, request, *args, **kwargs):
1069 ...
1070 </code></pre>
1071
1072 <p>In the above example, the result of the <code>get()</code> view will be cached for 15 minutes.</p>
1073
1074 <p>If you don't specify <code>timeout</code> argument then value from <code>REST_FRAMEWORK_EXTENSIONS</code> settings will be used. By default it's <code>None</code>, which means "cache forever". You can change this default in settings:</p>
1075
1076 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
1077 'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60 * 15
1078 }
1079 </code></pre>
1080
1081 <h4 id="usage-of-the-specific-cache">Usage of the specific cache</h4>
1082
1083 <p><em>New in DRF-extensions 0.2.3</em></p>
1084
1085 <p><code>@cache_response</code> can also take an optional keyword argument, <code>cache</code>, which directs the decorator
1086 to use a specific cache (from your <a href="https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-CACHES">CACHES</a> setting) when caching results.
1087 By default, the <code>default</code> cache will be used, but you can specify any cache you want:</p>
1088
1089 <pre><code>class CityView(views.APIView):
1090 @cache_response(60 * 15, cache='special_cache')
1091 def get(self, request, *args, **kwargs):
1092 ...
1093 </code></pre>
1094
1095 <p>You can specify what cache to use by default in settings:</p>
1096
1097 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
1098 'DEFAULT_USE_CACHE': 'special_cache'
1099 }
1100 </code></pre>
1101
1102 <h4 id="cache-key">Cache key</h4>
1103
1104 <p>By default every cached data from <code>@cache_response</code> decorator stored by key, which calculated
1105 with <a href="#default-key-constructor">DefaultKeyConstructor</a>.</p>
1106
1107 <p>You can change cache key by providing <code>key_func</code> argument, which must be callable:</p>
1108
1109 <pre><code>def calculate_cache_key(view_instance, view_method,
1110 request, args, kwargs):
1111 return '.'.join([
1112 len(args),
1113 len(kwargs)
1114 ])
1115
1116 class CityView(views.APIView):
1117 @cache_response(60 * 15, key_func=calculate_cache_key)
1118 def get(self, request, *args, **kwargs):
1119 ...
1120 </code></pre>
1121
1122 <p>You can implement view method and use it for cache key calculation by specifying <code>key_func</code> argument as string:</p>
1123
1124 <pre><code>class CityView(views.APIView):
1125 @cache_response(60 * 15, key_func='calculate_cache_key')
1126 def get(self, request, *args, **kwargs):
1127 ...
1128
1129 def calculate_cache_key(self, view_instance, view_method,
1130 request, args, kwargs):
1131 return '.'.join([
1132 len(args),
1133 len(kwargs)
1134 ])
1135 </code></pre>
1136
1137 <p>Key calculation function will be called with next parameters:</p>
1138
1139 <ul>
1140 <li><strong>view_instance</strong> - view instance of decorated method</li>
1141 <li><strong>view_method</strong> - decorated method</li>
1142 <li><strong>request</strong> - decorated method request</li>
1143 <li><strong>args</strong> - decorated method positional arguments</li>
1144 <li><strong>kwargs</strong> - decorated method keyword arguments</li>
1145 </ul>
1146
1147 <h4 id="default-key-function">Default key function</h4>
1148
1149 <p>If <code>@cache_response</code> decorator used without key argument then default key function will be used. You can change this function in
1150 settings:</p>
1151
1152 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
1153 'DEFAULT_CACHE_KEY_FUNC':
1154 'rest_framework_extensions.utils.default_cache_key_func'
1155 }
1156 </code></pre>
1157
1158 <p><code>default_cache_key_func</code> uses <a href="#default-key-constructor">DefaultKeyConstructor</a> as a base for key calculation.</p>
1159
1160 <h4 id="caching-errors">Caching errors</h4>
1161
1162 <p><em>New in DRF-extensions 0.2.7</em></p>
1163
1164 <p>By default every response is cached, even failed. For example:</p>
1165
1166 <pre><code>class CityView(views.APIView):
1167 @cache_response()
1168 def get(self, request, *args, **kwargs):
1169 raise Exception("500 error comes from here")
1170 </code></pre>
1171
1172 <p>First request to <code>CityView.get</code> will fail with <code>500</code> status code error and next requests to this endpoint will
1173 return <code>500</code> error from cache.</p>
1174
1175 <p>You can change this behaviour by turning off caching error responses:</p>
1176
1177 <pre><code>class CityView(views.APIView):
1178 @cache_response(cache_errors=False)
1179 def get(self, request, *args, **kwargs):
1180 raise Exception("500 error comes from here")
1181 </code></pre>
1182
1183 <p>You can change default behaviour by changing <code>DEFAULT_CACHE_ERRORS</code> setting:</p>
1184
1185 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
1186 'DEFAULT_CACHE_ERRORS': False
1187 }
1188 </code></pre>
1189
1190 <h4 id="cacheresponsemixin">CacheResponseMixin</h4>
1191
1192 <p>It is common to cache standard <a href="https://www.django-rest-framework.org/api-guide/viewsets/">viewset</a> <code>retrieve</code> and <code>list</code>
1193 methods. That is why <code>CacheResponseMixin</code> exists. Just mix it into viewset implementation and those methods will
1194 use functions, defined in <code>REST_FRAMEWORK_EXTENSIONS</code> <a href="#settings">settings</a>:</p>
1195
1196 <ul>
1197 <li><em>"DEFAULT_OBJECT_CACHE_KEY_FUNC"</em> for <code>retrieve</code> method</li>
1198 <li><em>"DEFAULT_LIST_CACHE_KEY_FUNC"</em> for <code>list</code> method</li>
1199 </ul>
1200
1201 <p>By default those functions are using <a href="#default-key-constructor">DefaultKeyConstructor</a> and extends it:</p>
1202
1203 <ul>
1204 <li>With <code>RetrieveSqlQueryKeyBit</code> for <em>"DEFAULT_OBJECT_CACHE_KEY_FUNC"</em></li>
1205 <li>With <code>ListSqlQueryKeyBit</code> and <code>PaginationKeyBit</code> for <em>"DEFAULT_LIST_CACHE_KEY_FUNC"</em></li>
1206 </ul>
1207
1208 <p>You can change those settings for custom cache key generation:</p>
1209
1210 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
1211 'DEFAULT_OBJECT_CACHE_KEY_FUNC':
1212 'rest_framework_extensions.utils.default_object_cache_key_func',
1213 'DEFAULT_LIST_CACHE_KEY_FUNC':
1214 'rest_framework_extensions.utils.default_list_cache_key_func',
1215 'DEFAULT_CACHE_RESPONSE_TIMEOUT': None,
1216 }
1217 </code></pre>
1218
1219 <p>Mixin example usage:</p>
1220
1221 <pre><code>from myapps.serializers import UserSerializer
1222 from rest_framework_extensions.cache.mixins import CacheResponseMixin
1223
1224 class UserViewSet(CacheResponseMixin, viewsets.ModelViewSet):
1225 serializer_class = UserSerializer
1226 </code></pre>
1227
1228 <p>You can change cache key function by providing <code>object_cache_key_func</code> or
1229 <code>list_cache_key_func</code> methods in view class:</p>
1230
1231 <pre><code>class UserViewSet(CacheResponseMixin, viewsets.ModelViewSet):
1232 serializer_class = UserSerializer
1233
1234 def object_cache_key_func(self, **kwargs):
1235 return 'some key for object'
1236
1237 def list_cache_key_func(self, **kwargs):
1238 return 'some key for list'
1239 </code></pre>
1240
1241 <p>Of course you can use custom <a href="#key-constructor">key constructor</a>:</p>
1242
1243 <pre><code>from yourapp.key_constructors import (
1244 CustomObjectKeyConstructor,
1245 CustomListKeyConstructor,
1246 )
1247
1248 class UserViewSet(CacheResponseMixin, viewsets.ModelViewSet):
1249 serializer_class = UserSerializer
1250 object_cache_key_func = CustomObjectKeyConstructor()
1251 list_cache_key_func = CustomListKeyConstructor()
1252 </code></pre>
1253
1254 <p><em>New in DRF-extensions development</em></p>
1255
1256 <p>You can change cache timeout by providing <code>object_cache_timeout</code> or
1257 <code>list_cache_timeout</code> properties in view class:</p>
1258
1259 <pre><code>class UserViewSet(CacheResponseMixin, viewsets.ModelViewSet):
1260 serializer_class = UserSerializer
1261 object_cache_timeout = 3600 # one hours (in seconds)
1262 list_cache_timeout = 60 # one minute (in seconds)
1263 </code></pre>
1264
1265 <p>If you want to cache only <code>retrieve</code> method then you could use <code>rest_framework_extensions.cache.mixins.RetrieveCacheResponseMixin</code>.</p>
1266
1267 <p>If you want to cache only <code>list</code> method then you could use <code>rest_framework_extensions.cache.mixins.ListCacheResponseMixin</code>.</p>
1268
1269 <h3 id="key-constructors">Key constructors</h3>
1270
1271 <p>As you could see from previous section cache key calculation might seem fairly simple operation. But let's see next example. We make ordinary HTTP request to cities resource:</p>
1272
1273 <pre><code># Request
1274 GET /cities/ HTTP/1.1
1275 Accept: application/json
1276
1277 # Response
1278 HTTP/1.1 200 OK
1279 Content-Type: application/json; charset=UTF-8
1280
1281 ['Moscow', 'London', 'Paris']
1282 </code></pre>
1283
1284 <p>By the moment all goes fine - response returned and cached. Let's make the same request requiring XML response:</p>
1285
1286 <pre><code># Request
1287 GET /cities/ HTTP/1.1
1288 Accept: application/xml
1289
1290 # Response
1291 HTTP/1.1 200 OK
1292 Content-Type: application/json; charset=UTF-8
1293
1294 ['Moscow', 'London', 'Paris']
1295 </code></pre>
1296
1297 <p>What is that? Oh, we forgot about format negotiations. We can add format to key bits:</p>
1298
1299 <pre><code>def calculate_cache_key(view_instance, view_method,
1300 request, args, kwargs):
1301 return '.'.join([
1302 len(args),
1303 len(kwargs),
1304 request.accepted_renderer.format # here it is
1305 ])
1306
1307 # Request
1308 GET /cities/ HTTP/1.1
1309 Accept: application/xml
1310
1311 # Response
1312 HTTP/1.1 200 OK
1313 Content-Type: application/xml; charset=UTF-8
1314
1315 &lt;?xml version="1.0" encoding="utf-8"?&gt;
1316 &lt;root&gt;
1317 &lt;list-item&gt;Moscow&lt;/list-item&gt;
1318 &lt;list-item&gt;London&lt;/list-item&gt;
1319 &lt;list-item&gt;Paris&lt;/list-item&gt;
1320 &lt;/root&gt;
1321 </code></pre>
1322
1323 <p>That's cool now - we have different responses for different formats with different cache keys. But there are many cases, where key should be different for different requests:</p>
1324
1325 <ul>
1326 <li>Response format (json, xml);</li>
1327 <li>User (exact authorized user or anonymous);</li>
1328 <li>Different request meta data (request.META['REMOTE_ADDR']);</li>
1329 <li>Language (ru, en);</li>
1330 <li>Headers;</li>
1331 <li>Query params. For example, <code>jsonp</code> resources need <code>callback</code> param, which rendered in response;</li>
1332 <li>Pagination. We should show different data for different pages;</li>
1333 <li>Etc...</li>
1334 </ul>
1335
1336 <p>Of course we can use custom <code>calculate_cache_key</code> methods and reuse them for different API methods, but we can't reuse just parts of them. For example, one method depends on user id and language, but another only on user id. How to be more DRYish? Let's see some magic:</p>
1337
1338 <pre><code>from rest_framework_extensions.key_constructor.constructors import (
1339 KeyConstructor
1340 )
1341 from rest_framework_extensions.key_constructor import bits
1342 from your_app.utils import get_city_by_ip
1343
1344 class CityGetKeyConstructor(KeyConstructor):
1345 unique_method_id = bits.UniqueMethodIdKeyBit()
1346 format = bits.FormatKeyBit()
1347 language = bits.LanguageKeyBit()
1348
1349 class CityHeadKeyConstructor(CityGetKeyConstructor):
1350 user = bits.UserKeyBit()
1351 request_meta = bits.RequestMetaKeyBit(params=['REMOTE_ADDR'])
1352
1353 class CityView(views.APIView):
1354 @cache_response(key_func=CityGetKeyConstructor())
1355 def get(self, request, *args, **kwargs):
1356 cities = City.objects.all().values_list('name', flat=True)
1357 return Response(cities)
1358
1359 @cache_response(key_func=CityHeadKeyConstructor())
1360 def head(self, request, *args, **kwargs):
1361 city = ''
1362 user = self.request.user
1363 if user.is_authenticated and user.city:
1364 city = Response(user.city.name)
1365 if not city:
1366 city = get_city_by_ip(request.META['REMOTE_ADDR'])
1367 return Response(city)
1368 </code></pre>
1369
1370 <p>Firstly, let's revise <code>CityView.get</code> method cache key calculation. It constructs from 3 bits:</p>
1371
1372 <ul>
1373 <li><strong>unique_method_id</strong> - remember our <a href="#cache-key">default key calculation</a>? Here it is. Just one of the cache key bits. <code>head</code> method has different set of bits and they can't collide with <code>get</code> method bits. But there could be another view class with the same bits.</li>
1374 <li><strong>format</strong> - key would be different for different formats.</li>
1375 <li><strong>language</strong> - key would be different for different languages.</li>
1376 </ul>
1377
1378 <p>The second method <code>head</code> has the same <code>unique_method_id</code>, <code>format</code> and <code>language</code> bits, buts extends with 2 more:</p>
1379
1380 <ul>
1381 <li><strong>user</strong> - key would be different for different users. As you can see in response calculation we use <code>request.user</code> instance. For different users we need different responses.</li>
1382 <li><strong>request_meta</strong> - key would be different for different ip addresses. As you can see in response calculation we are falling back to getting city from ip address if couldn't get it from authorized user model.</li>
1383 </ul>
1384
1385 <p>All default key bits are listed in <a href="#default-key-bits">this section</a>.</p>
1386
1387 <h4 id="default-key-constructor">Default key constructor</h4>
1388
1389 <p><code>DefaultKeyConstructor</code> is located in <code>rest_framework_extensions.key_constructor.constructors</code> module and constructs a key
1390 from unique <em>method</em> id, request format and request language. It has the following implementation:</p>
1391
1392 <pre><code>class DefaultKeyConstructor(KeyConstructor):
1393 unique_method_id = bits.UniqueMethodIdKeyBit()
1394 format = bits.FormatKeyBit()
1395 language = bits.LanguageKeyBit()
1396 </code></pre>
1397
1398 <h4 id="how-key-constructor-works">How key constructor works</h4>
1399
1400 <p>Key constructor class works in the same manner as the standard <a href="https://docs.djangoproject.com/en/dev/topics/forms/">django forms</a> and
1401 key bits used like form fields. Lets go through key construction steps for <a href="#default-key-constructor">DefaultKeyConstructor</a>.</p>
1402
1403 <p>Firstly, constructor starts iteration over every key bit:</p>
1404
1405 <ul>
1406 <li><strong>unique_method_id</strong></li>
1407 <li><strong>format</strong></li>
1408 <li><strong>language</strong></li>
1409 </ul>
1410
1411 <p>Then constructor gets data from every key bit calling method <code>get_data</code>:</p>
1412
1413 <ul>
1414 <li><strong>unique_method_id</strong> - <code>u'your_app.views.SometView.get'</code></li>
1415 <li><strong>format</strong> - <code>u'json'</code></li>
1416 <li><strong>language</strong> - <code>u'en'</code></li>
1417 </ul>
1418
1419 <p>Every key bit <code>get_data</code> method is called with next arguments:</p>
1420
1421 <ul>
1422 <li><strong>view_instance</strong> - view instance of decorated method</li>
1423 <li><strong>view_method</strong> - decorated method</li>
1424 <li><strong>request</strong> - decorated method request</li>
1425 <li><strong>args</strong> - decorated method positional arguments</li>
1426 <li><strong>kwargs</strong> - decorated method keyword arguments</li>
1427 </ul>
1428
1429 <p>After this it combines every key bit data to one dict, which keys are a key bits names in constructor, and values are returned data:</p>
1430
1431 <pre><code>{
1432 'unique_method_id': u'your_app.views.SometView.get',
1433 'format': u'json',
1434 'language': u'en'
1435 }
1436 </code></pre>
1437
1438 <p>Then constructor dumps resulting dict to json:</p>
1439
1440 <pre><code>'{"unique_method_id": "your_app.views.SometView.get", "language": "en", "format": "json"}'
1441 </code></pre>
1442
1443 <p>And finally compresses json with <strong>md5</strong> and returns hash value:</p>
1444
1445 <pre><code>'b04f8f03c89df824e0ecd25230a90f0e0ebe184cf8c0114342e9471dd2275baa'
1446 </code></pre>
1447
1448 <h4 id="custom-key-bit">Custom key bit</h4>
1449
1450 <p>We are going to create a simple key bit which could be used in real applications with next properties:</p>
1451
1452 <ul>
1453 <li>High read rate</li>
1454 <li>Low write rate</li>
1455 </ul>
1456
1457 <p>The task is - cache every read request and invalidate all cache data after write to any model, which used in API. This approach
1458 let us don't think about granular cache invalidation - just flush it after any model instance change/creation/deletion.</p>
1459
1460 <p>Lets create models:</p>
1461
1462 <pre><code># models.py
1463 from django.db import models
1464
1465 class Group(models.Model):
1466 title = models.CharField()
1467
1468 class Profile(models.Model):
1469 name = models.CharField()
1470 group = models.ForeignKey(Group)
1471 </code></pre>
1472
1473 <p>Define serializers:</p>
1474
1475 <pre><code># serializers.py
1476 from yourapp.models import Group, Profile
1477 from rest_framework import serializers
1478
1479 class GroupSerializer(serializers.ModelSerializer):
1480 class Meta:
1481 model = Group
1482
1483 class ProfileSerializer(serializers.ModelSerializer):
1484 group = GroupSerializer()
1485
1486 class Meta:
1487 model = Profile
1488 </code></pre>
1489
1490 <p>Create views:</p>
1491
1492 <pre><code># views.py
1493 from yourapp.serializers import GroupSerializer, ProfileSerializer
1494 from yourapp.models import Group, Profile
1495
1496 class GroupViewSet(viewsets.ReadOnlyModelViewSet):
1497 serializer_class = GroupSerializer
1498 queryset = Group.objects.all()
1499
1500 class ProfileViewSet(viewsets.ReadOnlyModelViewSet):
1501 serializer_class = ProfileSerializer
1502 queryset = Profile.objects.all()
1503 </code></pre>
1504
1505 <p>And finally register views in router:</p>
1506
1507 <pre><code># urls.py
1508 from yourapp.views import GroupViewSet,ProfileViewSet
1509
1510 router = DefaultRouter()
1511 router.register(r'groups', GroupViewSet)
1512 router.register(r'profiles', ProfileViewSet)
1513 urlpatterns = router.urls
1514 </code></pre>
1515
1516 <p>At the moment we have API, but it's not cached. Lets cache it and create our custom key bit:</p>
1517
1518 <pre><code># views.py
1519 import datetime
1520 from django.core.cache import cache
1521 from django.utils.encoding import force_str
1522 from yourapp.serializers import GroupSerializer, ProfileSerializer
1523 from rest_framework_extensions.cache.decorators import cache_response
1524 from rest_framework_extensions.key_constructor.constructors import (
1525 DefaultKeyConstructor
1526 )
1527 from rest_framework_extensions.key_constructor.bits import (
1528 KeyBitBase,
1529 RetrieveSqlQueryKeyBit,
1530 ListSqlQueryKeyBit,
1531 PaginationKeyBit
1532 )
1533
1534 class UpdatedAtKeyBit(KeyBitBase):
1535 def get_data(self, **kwargs):
1536 key = 'api_updated_at_timestamp'
1537 value = cache.get(key, None)
1538 if not value:
1539 value = datetime.datetime.utcnow()
1540 cache.set(key, value=value)
1541 return force_str(value)
1542
1543 class CustomObjectKeyConstructor(DefaultKeyConstructor):
1544 retrieve_sql = RetrieveSqlQueryKeyBit()
1545 updated_at = UpdatedAtKeyBit()
1546
1547 class CustomListKeyConstructor(DefaultKeyConstructor):
1548 list_sql = ListSqlQueryKeyBit()
1549 pagination = PaginationKeyBit()
1550 updated_at = UpdatedAtKeyBit()
1551
1552 class GroupViewSet(viewsets.ReadOnlyModelViewSet):
1553 serializer_class = GroupSerializer
1554
1555 @cache_response(key_func=CustomObjectKeyConstructor())
1556 def retrieve(self, *args, **kwargs):
1557 return super(GroupViewSet, self).retrieve(*args, **kwargs)
1558
1559 @cache_response(key_func=CustomListKeyConstructor())
1560 def list(self, *args, **kwargs):
1561 return super(GroupViewSet, self).list(*args, **kwargs)
1562
1563 class ProfileViewSet(viewsets.ReadOnlyModelViewSet):
1564 serializer_class = ProfileSerializer
1565
1566 @cache_response(key_func=CustomObjectKeyConstructor())
1567 def retrieve(self, *args, **kwargs):
1568 return super(ProfileViewSet, self).retrieve(*args, **kwargs)
1569
1570 @cache_response(key_func=CustomListKeyConstructor())
1571 def list(self, *args, **kwargs):
1572 return super(ProfileViewSet, self).list(*args, **kwargs)
1573 </code></pre>
1574
1575 <p>As you can see <code>UpdatedAtKeyBit</code> just adds to key information when API models has been update last time. If there is no
1576 information about it then new datetime will be used for key bit data.</p>
1577
1578 <p>Lets write cache invalidation. We just connect models to standard signals and change value in cache by key <code>api_updated_at_timestamp</code>:</p>
1579
1580 <pre><code># models.py
1581 import datetime
1582 from django.db import models
1583 from django.db.models.signals import post_save, post_delete
1584
1585 def change_api_updated_at(sender=None, instance=None, *args, **kwargs):
1586 cache.set('api_updated_at_timestamp', datetime.datetime.utcnow())
1587
1588 class Group(models.Model):
1589 title = models.CharField()
1590
1591 class Profile(models.Model):
1592 name = models.CharField()
1593 group = models.ForeignKey(Group)
1594
1595 for model in [Group, Profile]:
1596 post_save.connect(receiver=change_api_updated_at, sender=model)
1597 post_delete.connect(receiver=change_api_updated_at, sender=model)
1598 </code></pre>
1599
1600 <p>And that's it. When any model changes then value in cache by key <code>api_updated_at_timestamp</code> will be changed too. After this every
1601 key constructor, that used <code>UpdatedAtKeyBit</code>, will construct new keys and <code>@cache_response</code> decorator will
1602 cache data in new places.</p>
1603
1604 <h4 id="key-constructor-params">Key constructor params</h4>
1605
1606 <p><em>New in DRF-extensions 0.2.3</em></p>
1607
1608 <p>You can change <code>params</code> attribute for specific key bit by providing <code>params</code> dict for key constructor initialization
1609 function. For example, here is custom key constructor, which inherits from <a href="#default-key-constructor">DefaultKeyConstructor</a>
1610 and adds geoip key bit:</p>
1611
1612 <pre><code>class CityKeyConstructor(DefaultKeyConstructor):
1613 geoip = bits.RequestMetaKeyBit(params=['GEOIP_CITY'])
1614 </code></pre>
1615
1616 <p>If you wanted to use <code>GEOIP_COUNTRY</code>, you could create new key constructor:</p>
1617
1618 <pre><code>class CountryKeyConstructor(DefaultKeyConstructor):
1619 geoip = bits.RequestMetaKeyBit(params=['GEOIP_COUNTRY'])
1620 </code></pre>
1621
1622 <p>But there is another way. You can send <code>params</code> in key constructor initialization method. This is the dict attribute, where
1623 keys are bit names and values are bit <code>params</code> attribute value (look at <code>CountryView</code>):</p>
1624
1625 <pre><code>class CityKeyConstructor(DefaultKeyConstructor):
1626 geoip = bits.RequestMetaKeyBit(params=['GEOIP_CITY'])
1627
1628 class CityView(views.APIView):
1629 @cache_response(key_func=CityKeyConstructor())
1630 def get(self, request, *args, **kwargs):
1631 ...
1632
1633 class CountryView(views.APIView):
1634 @cache_response(key_func=CityKeyConstructor(
1635 params={'geoip': ['GEOIP_COUNTRY']}
1636 ))
1637 def get(self, request, *args, **kwargs):
1638 ...
1639 </code></pre>
1640
1641 <p>If there is no item provided for key bit then default key bit <code>params</code> value will be used.</p>
1642
1643 <h4 id="constructor-s-bits-list">Constructor's bits list</h4>
1644
1645 <p>You can dynamically change key constructor's bits list in initialization method by altering <code>bits</code> attribute:</p>
1646
1647 <pre><code>class CustomKeyConstructor(DefaultKeyConstructor):
1648 def __init__(self, *args, **kwargs):
1649 super(CustomKeyConstructor, self).__init__(*args, **kwargs)
1650 self.bits['geoip'] = bits.RequestMetaKeyBit(
1651 params=['GEOIP_CITY']
1652 )
1653 </code></pre>
1654
1655 <h3 id="default-key-bits">Default key bits</h3>
1656
1657 <p>Out of the box DRF-extensions has some basic key bits. They are all located in <code>rest_framework_extensions.key_constructor.bits</code> module.</p>
1658
1659 <h4 id="formatkeybit">FormatKeyBit</h4>
1660
1661 <p>Retrieves format info from request. Usage example:</p>
1662
1663 <pre><code>class MyKeyConstructor(KeyConstructor):
1664 format = FormatKeyBit()
1665 </code></pre>
1666
1667 <h4 id="languagekeybit">LanguageKeyBit</h4>
1668
1669 <p>Retrieves active language for request. Usage example:</p>
1670
1671 <pre><code>class MyKeyConstructor(KeyConstructor):
1672 language = LanguageKeyBit()
1673 </code></pre>
1674
1675 <h4 id="userkeybit">UserKeyBit</h4>
1676
1677 <p>Retrieves user id from request. If it is anonymous then returns <em>"anonymous"</em> string. Usage example:</p>
1678
1679 <pre><code>class MyKeyConstructor(KeyConstructor):
1680 user = UserKeyBit()
1681 </code></pre>
1682
1683 <h4 id="requestmetakeybit">RequestMetaKeyBit</h4>
1684
1685 <p>Retrieves data from <a href="https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META">request.META</a> dict.
1686 Usage example:</p>
1687
1688 <pre><code>class MyKeyConstructor(KeyConstructor):
1689 ip_address_and_user_agent = bits.RequestMetaKeyBit(
1690 ['REMOTE_ADDR', 'HTTP_USER_AGENT']
1691 )
1692 </code></pre>
1693
1694 <p>You can use <code>*</code> for retrieving all meta data to key bit:</p>
1695
1696 <p><em>New in DRF-extensions 0.2.7</em></p>
1697
1698 <pre><code>class MyKeyConstructor(KeyConstructor):
1699 all_request_meta = bits.RequestMetaKeyBit('*')
1700 </code></pre>
1701
1702 <h4 id="headerskeybit">HeadersKeyBit</h4>
1703
1704 <p>Same as <code>RequestMetaKeyBit</code> retrieves data from <a href="https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META">request.META</a> dict.
1705 The difference is that <code>HeadersKeyBit</code> allows to use normal header names:</p>
1706
1707 <pre><code>class MyKeyConstructor(KeyConstructor):
1708 user_agent_and_geobase_id = bits.HeadersKeyBit(
1709 ['user-agent', 'x-geobase-id']
1710 )
1711 # will process request.META['HTTP_USER_AGENT'] and
1712 # request.META['HTTP_X_GEOBASE_ID']
1713 </code></pre>
1714
1715 <p>You can use <code>*</code> for retrieving all headers to key bit:</p>
1716
1717 <p><em>New in DRF-extensions 0.2.7</em></p>
1718
1719 <pre><code>class MyKeyConstructor(KeyConstructor):
1720 all_headers = bits.HeadersKeyBit('*')
1721 </code></pre>
1722
1723 <h4 id="argskeybit">ArgsKeyBit</h4>
1724
1725 <p><em>New in DRF-extensions 0.2.7</em></p>
1726
1727 <p>Retrieves data from the view's positional arguments.
1728 A list of position indices can be passed to indicate which arguments to use. For retrieving all arguments you can use <code>*</code> which is also the default value:</p>
1729
1730 <pre><code>class MyKeyConstructor(KeyConstructor):
1731 args = bits.ArgsKeyBit() # will use all positional arguments
1732
1733 class MyKeyConstructor(KeyConstructor):
1734 args = bits.ArgsKeyBit('*') # same as above
1735
1736 class MyKeyConstructor(KeyConstructor):
1737 args = bits.ArgsKeyBit([0, 2])
1738 </code></pre>
1739
1740 <h4 id="kwargskeybit">KwargsKeyBit</h4>
1741
1742 <p><em>New in DRF-extensions 0.2.7</em></p>
1743
1744 <p>Retrieves data from the views's keyword arguments.
1745 A list of keyword argument names can be passed to indicate which kwargs to use. For retrieving all kwargs you can use <code>*</code> which is also the default value:</p>
1746
1747 <pre><code>class MyKeyConstructor(KeyConstructor):
1748 kwargs = bits.KwargsKeyBit() # will use all keyword arguments
1749
1750 class MyKeyConstructor(KeyConstructor):
1751 kwargs = bits.KwargsKeyBit('*') # same as above
1752
1753 class MyKeyConstructor(KeyConstructor):
1754 kwargs = bits.KwargsKeyBit(['user_id', 'city'])
1755 </code></pre>
1756
1757 <h4 id="queryparamskeybit">QueryParamsKeyBit</h4>
1758
1759 <p>Retrieves data from <a href="https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.GET">request.GET</a> dict.
1760 Usage example:</p>
1761
1762 <pre><code>class MyKeyConstructor(KeyConstructor):
1763 part_and_callback = bits.QueryParamsKeyBit(
1764 ['part', 'callback']
1765 )
1766 </code></pre>
1767
1768 <p>You can use <code>*</code> for retrieving all query params to key bit which is also the default value:</p>
1769
1770 <p><em>New in DRF-extensions 0.2.7</em></p>
1771
1772 <pre><code>class MyKeyConstructor(KeyConstructor):
1773 all_query_params = bits.QueryParamsKeyBit('*') # all qs parameters
1774
1775 class MyKeyConstructor(KeyConstructor):
1776 all_query_params = bits.QueryParamsKeyBit() # same as above
1777 </code></pre>
1778
1779 <h4 id="paginationkeybit">PaginationKeyBit</h4>
1780
1781 <p>Inherits from <code>QueryParamsKeyBit</code> and returns data from used pagination params.</p>
1782
1783 <pre><code>class MyKeyConstructor(KeyConstructor):
1784 pagination = bits.PaginationKeyBit()
1785 </code></pre>
1786
1787 <h4 id="listsqlquerykeybit">ListSqlQueryKeyBit</h4>
1788
1789 <p>Retrieves sql query for <code>view.filter_queryset(view.get_queryset())</code> filtering.</p>
1790
1791 <pre><code>class MyKeyConstructor(KeyConstructor):
1792 list_sql_query = bits.ListSqlQueryKeyBit()
1793 </code></pre>
1794
1795 <h4 id="retrievesqlquerykeybit">RetrieveSqlQueryKeyBit</h4>
1796
1797 <p>Retrieves sql query for retrieving exact object.</p>
1798
1799 <pre><code>class MyKeyConstructor(KeyConstructor):
1800 retrieve_sql_query = bits.RetrieveSqlQueryKeyBit()
1801 </code></pre>
1802
1803 <h4 id="uniqueviewidkeybit">UniqueViewIdKeyBit</h4>
1804
1805 <p>Combines data about view module and view class name.</p>
1806
1807 <pre><code>class MyKeyConstructor(KeyConstructor):
1808 unique_view_id = bits.UniqueViewIdKeyBit()
1809 </code></pre>
1810
1811 <h4 id="uniquemethodidkeybit">UniqueMethodIdKeyBit</h4>
1812
1813 <p>Combines data about view module, view class name and view method name.</p>
1814
1815 <pre><code>class MyKeyConstructor(KeyConstructor):
1816 unique_view_id = bits.UniqueMethodIdKeyBit()
1817 </code></pre>
1818
1819 <h4 id="listmodelkeybit">ListModelKeyBit</h4>
1820
1821 <p><em>New in DRF-extensions 0.3.2</em></p>
1822
1823 <p>Computes the semantic fingerprint of a list of objects returned by <code>view.filter_queryset(view.get_queryset())</code>
1824 using a flat representation of all objects' values.</p>
1825
1826 <pre><code>class MyKeyConstructor(KeyConstructor):
1827 list_model_values = bits.ListModelKeyBit()
1828 </code></pre>
1829
1830 <h4 id="retrievemodelkeybit">RetrieveModelKeyBit</h4>
1831
1832 <p><em>New in DRF-extensions 0.3.2</em></p>
1833
1834 <p>Computes the semantic fingerprint of a particular objects returned by <code>view.get_object()</code>.</p>
1835
1836 <pre><code>class MyKeyConstructor(KeyConstructor):
1837 retrieve_model_values = bits.RetrieveModelKeyBit()
1838 </code></pre>
1839
1840 <h3 id="conditional-requests">Conditional requests</h3>
1841
1842 <p>The etag functionality is pending an overhaul has been temporarily removed since 0.4.0. </p>
1843
1844 <p>See discussion in <a href="https://github.com/chibisov/drf-extensions/issues/177">Issue #177</a></p>
1845
1846 <p><!--*This documentation section uses information from <a href="http://shop.oreilly.com/product/9780596801694.do">RESTful Web Services Cookbook</a> 10-th chapter.*--></p>
1847
1848 <p><!--Conditional HTTP requests allow API clients to accomplish 2 goals:--></p>
1849
1850 <p><!--1. Conditional HTTP GET saves client and server <a href="#saving-time-and-bandwidth">time and bandwidth</a>.-->
1851 <!--* For unsafe requests such as PUT, POST, and DELETE, conditional requests provide <a href="#concurrency-control">concurrency control</a>.--></p>
1852
1853 <p><!--The second goal addresses the lost update problem, where a resource is altered and saved by user B while user A is still editing.-->
1854 <!--In both cases, the 'condition' included in the request needs to be a unique identifier (e.g. unique semantic fingerprint) of the requested resource in order to detect changes.-->
1855 <!--This fingerprint can be transient (i.e. using the cache as with <code>UpdatedAtKeyBit</code>), or persistent, i.e. computed from the model instance attribute values from the database. -->
1856 <!--While the <code>UpdatedAtKeyBit</code> approach requires to add triggers to your models, the semantic fingerprint option is designed to be pluggable and does not require to alter your model code. --></p>
1857
1858 <p><!--#### HTTP ETag--></p>
1859
1860 <p><!--*An ETag or entity tag, is part of HTTP, the protocol for the World Wide Web. -->
1861 <!--It is one of several mechanisms that HTTP provides for web cache validation, and which allows a client to make conditional requests.* - <a href="http://en.wikipedia.org/wiki/HTTP_ETag">Wikipedia</a>--></p>
1862
1863 <p><!--For ETag calculation and conditional request processing you should use the decorators from <code>rest_framework_extensions.etag.decorators</code>.-->
1864 <!--The <code>@etag</code> decorator works similar to the native <a href="https://docs.djangoproject.com/en/dev/topics/conditional-view-processing/">django decorator</a>.--></p>
1865
1866 <p><!--<!-- THIS REFERS TO THE DEFAULT_OBJ_ETAG_FUNC -->
1867 <!--The <a href="#default-etag-function">default ETag function</a> used by the <code>@etag</code> decorator computes the value with respect to the particular view and HTTP method in the request and therefore *cannot detect changes in individual model instances*.-->
1868 <!--If you need to compute the *semantic* fingerprint of a model independent of a particular view and method, implement your custom <code>etag_func</code>.-->
1869 <!--Alternatively you could use the <code>@api_etag</code> decorator and specify the <code>viewset</code> in the view.--></p>
1870
1871 <p><!-- from rest_framework_extensions.etag.decorators import etag--></p>
1872
1873 <p><!-- class CityView(views.APIView):-->
1874 <!-- @etag()-->
1875 <!-- def get(self, request, *args, **kwargs):-->
1876 <!-- cities = City.objects.all().values_list('name', flat=True)-->
1877 <!-- return Response(cities)--></p>
1878
1879 <p><!--By default <code>@etag</code> would calculate the ETag header value with the same algorithm as <a href="#cache-key">cache key</a> default calculation performs.--></p>
1880
1881 <p><!-- # Request-->
1882 <!-- GET /cities/ HTTP/1.1-->
1883 <!-- Accept: application/json--></p>
1884
1885 <p><!-- # Response-->
1886 <!-- HTTP/1.1 200 OK-->
1887 <!-- Content-Type: application/json; charset=UTF-8-->
1888 <!-- ETag: "e7b50490dc546d116635a14cfa58110306dd6c5434146b6740ec08bf0a78f9a2"--></p>
1889
1890 <p><!-- ['Moscow', 'London', 'Paris']--></p>
1891
1892 <p><!--You can define a custom function for Etag value calculation with <code>etag_func</code> argument:--></p>
1893
1894 <p><!-- from rest_framework_extensions.etag.decorators import etag--></p>
1895
1896 <p><!-- def calculate_etag(view_instance, view_method,-->
1897 <!-- request, args, kwargs):-->
1898 <!-- return '.'.join([-->
1899 <!-- len(args),-->
1900 <!-- len(kwargs)-->
1901 <!-- ])--></p>
1902
1903 <p><!-- class CityView(views.APIView):-->
1904 <!-- @etag(etag_func=calculate_etag)-->
1905 <!-- def get(self, request, *args, **kwargs):-->
1906 <!-- cities = City.objects.all().values_list('name', flat=True)-->
1907 <!-- return Response(cities)--></p>
1908
1909 <p><!--You can implement a view method and use it for Etag calculation by specifying <code>etag_func</code> argument as string:--></p>
1910
1911 <p><!-- from rest_framework_extensions.etag.decorators import etag--></p>
1912
1913 <p><!-- class CityView(views.APIView):-->
1914 <!-- @etag(etag_func='calculate_etag_from_method')-->
1915 <!-- def get(self, request, *args, **kwargs):-->
1916 <!-- cities = City.objects.all().values_list('name', flat=True)-->
1917 <!-- return Response(cities)--></p>
1918
1919 <p><!-- def calculate_etag_from_method(self, view_instance, view_method,-->
1920 <!-- request, args, kwargs):-->
1921 <!-- return '.'.join([-->
1922 <!-- len(args),-->
1923 <!-- len(kwargs)-->
1924 <!-- ])--></p>
1925
1926 <p><!--ETag calculation function will be called with following parameters:--></p>
1927
1928 <p><!--* **view_instance** - view instance of decorated method-->
1929 <!--* **view_method** - decorated method-->
1930 <!--* **request** - decorated method request-->
1931 <!--* **args** - decorated method positional arguments-->
1932 <!--* **kwargs** - decorated method keyword arguments--></p>
1933
1934 <p><!--#### Default ETag function--></p>
1935
1936 <p><!--If <code>@etag</code> decorator used without <code>etag_func</code> argument then default etag function will be used. You can change this function in-->
1937 <!--settings:--></p>
1938
1939 <p><!-- REST_FRAMEWORK_EXTENSIONS = {-->
1940 <!-- 'DEFAULT_ETAG_FUNC':-->
1941 <!-- 'rest_framework_extensions.utils.default_etag_func'-->
1942 <!-- }--></p>
1943
1944 <p><!--<code>default_etag_func</code> uses <a href="#default-key-constructor">DefaultKeyConstructor</a> as a base for etag calculation.--></p>
1945
1946 <p><!--#### API ETag function-->
1947 <!--<!-- This refers to the APIETagProcessor and @api_etag decorator --></p>
1948
1949 <p><!--*New in DRF-extensions 0.3.2*--></p>
1950
1951 <p><!--In addition, <code>APIETAGProcessor</code> explicitly requires a function that (ideally) creates an ETag value from model instances.-->
1952 <!--If the <code>@api_etag</code> decorator is used without <code>etag_func</code> the framework will raise an <code>AssertionError</code>. -->
1953 <!--Hence, the following snipped would not work:--></p>
1954
1955 <p><!-- # BEGIN BAD CODE:-->
1956 <!-- class View(views.APIView):-->
1957 <!-- @api_etag() -->
1958 <!-- def get(self, request, *args, **kwargs):-->
1959 <!-- return super(View, self).get(request, *args, **kwargs)-->
1960 <!-- # END BAD CODE--></p>
1961
1962 <p><!--**Why's that?**-->
1963 <!--It does not make sense to compute a default ETag here, because the processor would lock us out from the API by always issuing a <code>304</code> -->
1964 <!--response on conditional requests, even if the resource was modified meanwhile.-->
1965 <!--Therefore the <code>APIETAGProcessor</code> cannot be used without specifying an <code>etag_func</code> as keyword argument and there exists convenient -->
1966 <!--<a href="#apietagmixin">mixin classes</a>.--></p>
1967
1968 <p><!--You can use the decorator in regular <code>APIView</code>, and subclasses from the <code>rest_framework.generics</code> module, -->
1969 <!--but ensure to include a <code>queryset</code> attribute or override <code>get_queryset()</code>:--></p>
1970
1971 <p><!-- from rest_framework import generics-->
1972 <!-- from rest_framework.response import Response-->
1973 <!-- from rest_framework_extensions.utils import default_api_object_etag_func-->
1974 <!-- from my_app.models import Book--></p>
1975
1976 <p><!-- class BookCustomDestroyView(generics.DestroyAPIView): -->
1977 <!-- # include the queryset here to enable the object lookup -->
1978 <!-- queryset = Book.objects.all()--></p>
1979
1980 <p><!-- @api_etag(etag_func=default_api_object_etag_func)-->
1981 <!-- def delete(self, request, *args, **kwargs):-->
1982 <!-- obj = Book.objects.get(id=kwargs['pk'])-->
1983 <!-- # ... perform some custom operations here ...-->
1984 <!-- obj.delete()-->
1985 <!-- return Response(status=status.HTTP_204_NO_CONTENT)--></p>
1986
1987 <p><!--The next difference to the <code>@etag</code> decorator is that it defines an explicit map of -->
1988 <!--required headers for each HTTP request verb, using the following default values for unsafe methods:--></p>
1989
1990 <p><!-- precondition_map = {'PUT': ['If-Match'],-->
1991 <!-- 'PATCH': ['If-Match'],-->
1992 <!-- 'DELETE': ['If-Match']}--></p>
1993
1994 <p><!--You can specify a custom set of headers in the decorator by passing the <code>precondition_map</code> keyword argument.-->
1995 <!--For instance, this statement-->
1996 <!-- @api_etag(etag_func=default_api_object_etag_func, precondition_map={'PUT': ['X-mycorp-custom']})-->
1997 <!-- def put(self, request, *args, **kwargs):-->
1998 <!-- obj = Book.objects.get(id=kwargs['pk'])-->
1999 <!-- # ... perform some custom operations here ...-->
2000 <!-- obj.save()-->
2001 <!-- return Response(status=status.HTTP_200_OK)--></p>
2002
2003 <p><!--checks for the presence of a custom header <code>X-mycorp-custom</code> in the request and permits the request, if it is present, -->
2004 <!--or returns a <code>428 PRECONDITION REQUIRED</code> response.--></p>
2005
2006 <p><!--Similarly, to disable all checks for a particular method simply pass an empty dict:--></p>
2007
2008 <p><!-- @api_etag(etag_func=default_api_object_etag_func, precondition_map={})-->
2009 <!-- def put(self, request, *args, **kwargs):-->
2010 <!-- obj = Book.objects.get(id=kwargs['pk'])-->
2011 <!-- # ... perform some custom operations here ...-->
2012 <!-- obj.save()-->
2013 <!-- return Response(status=status.HTTP_200_OK)--></p>
2014
2015 <p><!--Please note that passing <code>None</code> in the <code>precondition_map</code> argument falls back to using the default map.--></p>
2016
2017 <p><!--#### Usage ETag with caching--></p>
2018
2019 <p><!--As you can see <code>@etag</code> and <code>@cache_response</code> decorators has similar key calculation approaches. -->
2020 <!--They both can take key from simple callable function. And more than this - in many cases they share the same calculation logic. -->
2021 <!--In the next example we use both decorators, which share one calculation function:--></p>
2022
2023 <p><!-- from rest_framework_extensions.etag.decorators import etag-->
2024 <!-- from rest_framework_extensions.cache.decorators import cache_response-->
2025 <!-- from rest_framework_extensions.key_constructor import bits-->
2026 <!-- from rest_framework_extensions.key_constructor.constructors import (-->
2027 <!-- KeyConstructor-->
2028 <!-- )--></p>
2029
2030 <p><!-- class CityGetKeyConstructor(KeyConstructor):-->
2031 <!-- format = bits.FormatKeyBit()-->
2032 <!-- language = bits.LanguageKeyBit()--></p>
2033
2034 <p><!-- class CityView(views.APIView):-->
2035 <!-- key_constructor_func = CityGetKeyConstructor()--></p>
2036
2037 <p><!-- @etag(key_constructor_func)-->
2038 <!-- @cache_response(key_func=key_constructor_func)-->
2039 <!-- def get(self, request, *args, **kwargs):-->
2040 <!-- cities = City.objects.all().values_list('name', flat=True)-->
2041 <!-- return Response(cities)--></p>
2042
2043 <p><!--Note the decorators order. First goes <code>@etag</code> and then goes <code>@cache_response</code>. We want firstly perform conditional processing and after it response processing.--></p>
2044
2045 <p><!--There is one more point for it. If conditional processing didn't fail then <code>key_constructor_func</code> would be called again in <code>@cache_response</code>.-->
2046 <!--But in most cases first calculation is enough. To accomplish this goal you could use <code>KeyConstructor</code> initial argument <code>memoize_for_request</code>:--></p>
2047
2048 <p><!-- &gt;&gt;&gt; key_constructor_func = CityGetKeyConstructor(memoize_for_request=True)-->
2049 <!-- &gt;&gt;&gt; request1, request1 = 'request1', 'request2'-->
2050 <!-- &gt;&gt;&gt; print key_constructor_func(request=request1) # full calculation-->
2051 <!-- request1-key-->
2052 <!-- &gt;&gt;&gt; print key_constructor_func(request=request1) # data from cache-->
2053 <!-- request1-key-->
2054 <!-- &gt;&gt;&gt; print key_constructor_func(request=request2) # full calculation-->
2055 <!-- request2-key-->
2056 <!-- &gt;&gt;&gt; print key_constructor_func(request=request2) # data from cache-->
2057 <!-- request2-key--></p>
2058
2059 <p><!--By default <code>memoize_for_request</code> is <code>False</code>, but you can change it in settings:--></p>
2060
2061 <p><!-- REST_FRAMEWORK_EXTENSIONS = {-->
2062 <!-- 'DEFAULT_KEY_CONSTRUCTOR_MEMOIZE_FOR_REQUEST': True-->
2063 <!-- }--></p>
2064
2065 <p><!--It's important to note that this memoization is thread safe.--></p>
2066
2067 <p><!--#### Saving time and bandwidth--></p>
2068
2069 <p><!--When a server returns <code>ETag</code> header, you should store it along with the representation data on the client.-->
2070 <!--When making GET and HEAD requests for the same resource in the future, include the <code>If-None-Match</code> header-->
2071 <!--to make these requests "conditional". --></p>
2072
2073 <p><!--For example, retrieve all cities:--></p>
2074
2075 <p><!-- # Request-->
2076 <!-- GET /cities/ HTTP/1.1-->
2077 <!-- Accept: application/json--></p>
2078
2079 <p><!-- # Response-->
2080 <!-- HTTP/1.1 200 OK-->
2081 <!-- Content-Type: application/json; charset=UTF-8-->
2082 <!-- ETag: "some_etag_value"--></p>
2083
2084 <p><!-- ['Moscow', 'London', 'Paris']--></p>
2085
2086 <p><!--If you make same request with <code>If-None-Match</code> and there exists a cached value for this request,-->
2087 <!--then server will respond with <code>304</code> status code without body data.--></p>
2088
2089 <p><!-- # Request-->
2090 <!-- GET /cities/ HTTP/1.1-->
2091 <!-- Accept: application/json-->
2092 <!-- If-None-Match: some_etag_value--></p>
2093
2094 <p><!-- # Response-->
2095 <!-- HTTP/1.1 304 NOT MODIFIED-->
2096 <!-- Content-Type: application/json; charset=UTF-8-->
2097 <!-- Etag: "some_etag_value"--></p>
2098
2099 <p><!--After this response you can use existing cities data on the client. --></p>
2100
2101 <p><!--#### Concurrency control--></p>
2102
2103 <p><!--Concurrency control ensures the correct processing of data under concurrent operations by clients.-->
2104 <!--There are two ways to implement concurrency control:--></p>
2105
2106 <p><!--* **Pessimistic concurrency control**. In this model, the client gets a lock, obtains-->
2107 <!--the current state of the resource, makes modifications, and then releases the lock.-->
2108 <!--During this process, the server prevents other clients from acquiring a lock on the same resource.-->
2109 <!--Relational databases operate in this manner.-->
2110 <!--* **Optimistic concurrency control**. In this model, the client first gets a token.-->
2111 <!--Instead of obtaining a lock, the client attempts a write operation with the token included in the request.-->
2112 <!--The operation succeeds if the token is still valid and fails otherwise.--></p>
2113
2114 <p><!--HTTP, being a stateless application control, is designed for optimistic concurrency control.-->
2115 <!--According to <a href="https://tools.ietf.org/html/rfc6585">RFC 6585</a>, the server can optionally require -->
2116 <!--a condition for a request. This library returns a <code>428</code> status, if no ETag is supplied, but would be mandatory -->
2117 <!--for a request to succeed.--></p>
2118
2119 <p><!--Update:--></p>
2120
2121 <p><!-- PUT/PATCH-->
2122 <!-- +-->
2123 <!-- +-----------+------------+-->
2124 <!-- | ETag |-->
2125 <!-- | supplied? |-->
2126 <!-- ++-----------------+-----+-->
2127 <!-- | |-->
2128 <!-- Yes No-->
2129 <!-- | |-->
2130 <!-- +---------------------++ ++-------------+-->
2131 <!-- | Do preconditions | | Precondition |-->
2132 <!-- | match? | | required? |-->
2133 <!-- +---+-----------------++ ++------------++-->
2134 <!-- | | | |-->
2135 <!-- Yes No No Yes-->
2136 <!-- | | | |-->
2137 <!-- +----------+------+ +-------+----------+ +---+-----+ |-->
2138 <!-- | Does resource | | 412 Precondition | | 200 OK | |-->
2139 <!-- | exist? | | failed | | Update | |-->
2140 <!-- ++---------------++ +------------------+ +---------+ |-->
2141 <!-- | | +-----------+------+-->
2142 <!-- Yes No | 428 Precondition |-->
2143 <!-- | | | required |-->
2144 <!-- +----+----+ +----+----+ +------------------+-->
2145 <!-- | 200 OK | | 404 Not |-->
2146 <!-- | Update | | found |-->
2147 <!-- +---------+ +---------+--></p>
2148
2149 <p><!--Delete:--></p>
2150
2151 <p><!-- DELETE-->
2152 <!-- +-->
2153 <!-- +-----------+------------+-->
2154 <!-- | ETag |-->
2155 <!-- | supplied? |-->
2156 <!-- ++-----------------+-----+-->
2157 <!-- | |-->
2158 <!-- Yes No-->
2159 <!-- | |-->
2160 <!-- +---------------------++ ++-------------+-->
2161 <!-- | Do preconditions | | Precondition |-->
2162 <!-- | match? | | required? |-->
2163 <!-- +---+-----------------++ ++------------++-->
2164 <!-- | | | |-->
2165 <!-- Yes No No Yes-->
2166 <!-- | | | |-->
2167 <!-- +----------+------+ +-------+----------+ +---+-----+ |-->
2168 <!-- | Does resource | | 412 Precondition | | 204 No | |-->
2169 <!-- | exist? | | failed | | content | |-->
2170 <!-- ++---------------++ +------------------+ +---------+ |-->
2171 <!-- | | +-----------+------+-->
2172 <!-- Yes No | 428 Precondition |-->
2173 <!-- | | | required |-->
2174 <!-- +----+----+ +----+----+ +------------------+-->
2175 <!-- | 204 No | | 404 Not |-->
2176 <!-- | content | | found |-->
2177 <!-- +---------+ +---------+--></p>
2178
2179 <p><!--**Example: transient key construction**--></p>
2180
2181 <p><!--Here is an example implementation for all (C)RUD methods (except create, because it doesn't need concurrency control)-->
2182 <!--wrapped with the default <code>etag</code> decorator. We use our <a href="#custom-key-bit">previous implementation</a> of the <code>UpdatedAtKeyBit</code> that looks up the cache -->
2183 <!--for the last timestamp the particular object was updated on the server. This required us to add <code>post_save</code> and <code>post_delete</code> signals-->
2184 <!--to our models explicitly. See <a href="#apietagmixin">below</a> for an example using <code>@api_etag</code> and mixins that computes the key from persistent data.--></p>
2185
2186 <p><!-- from rest_framework.viewsets import ModelViewSet-->
2187 <!-- from rest_framework_extensions.key_constructor import bits-->
2188 <!-- from rest_framework_extensions.key_constructor.constructors import (-->
2189 <!-- KeyConstructor-->
2190 <!-- )--></p>
2191
2192 <p><!-- from your_app.models import City-->
2193 <!-- # use our own implementation that detects an update timestamp in the cache -->
2194 <!-- from your_app.key_bits import UpdatedAtKeyBit--></p>
2195
2196 <p><!-- class CityListKeyConstructor(KeyConstructor):-->
2197 <!-- format = bits.FormatKeyBit()-->
2198 <!-- language = bits.LanguageKeyBit()-->
2199 <!-- pagination = bits.PaginationKeyBit()-->
2200 <!-- list_sql_query = bits.ListSqlQueryKeyBit()-->
2201 <!-- unique_view_id = bits.UniqueViewIdKeyBit()--></p>
2202
2203 <p><!-- class CityDetailKeyConstructor(KeyConstructor):-->
2204 <!-- format = bits.FormatKeyBit()-->
2205 <!-- language = bits.LanguageKeyBit()-->
2206 <!-- retrieve_sql_query = bits.RetrieveSqlQueryKeyBit()-->
2207 <!-- unique_view_id = bits.UniqueViewIdKeyBit()-->
2208 <!-- updated_at = UpdatedAtKeyBit()--></p>
2209
2210 <p><!-- class CityViewSet(ModelViewSet):-->
2211 <!-- list_key_func = CityListKeyConstructor(-->
2212 <!-- memoize_for_request=True-->
2213 <!-- )-->
2214 <!-- obj_key_func = CityDetailKeyConstructor(-->
2215 <!-- memoize_for_request=True-->
2216 <!-- )--></p>
2217
2218 <p><!-- @etag(list_key_func)-->
2219 <!-- @cache_response(key_func=list_key_func)-->
2220 <!-- def list(self, request, *args, **kwargs):-->
2221 <!-- return super(CityViewSet, self).list(request, *args, **kwargs)--></p>
2222
2223 <p><!-- @etag(obj_key_func)-->
2224 <!-- @cache_response(key_func=obj_key_func)-->
2225 <!-- def retrieve(self, request, *args, **kwargs):-->
2226 <!-- return super(CityViewSet, self).retrieve(request, *args, **kwargs)--></p>
2227
2228 <p><!-- @etag(obj_key_func)-->
2229 <!-- def update(self, request, *args, **kwargs):-->
2230 <!-- return super(CityViewSet, self).update(request, *args, **kwargs)--></p>
2231
2232 <p><!-- @etag(obj_key_func)-->
2233 <!-- def destroy(self, request, *args, **kwargs):-->
2234 <!-- return super(CityViewSet, self).destroy(request, *args, **kwargs)--></p>
2235
2236 <p><!--#### ETag for unsafe methods--></p>
2237
2238 <p><!--From previous section you could see that unsafe methods, such <code>update</code> (PUT, PATCH) or <code>destroy</code> (DELETE), have the same <code>@etag</code>-->
2239 <!--decorator wrapping manner as the safe methods.--></p>
2240
2241 <p><!--But every unsafe method has one distinction from safe method - it changes the data-->
2242 <!--which could be used for Etag calculation. In our case it is <code>UpdatedAtKeyBit</code>. It means that we should calculate Etag:--></p>
2243
2244 <p><!--* Before building response - for <code>If-Match</code> and <code>If-None-Match</code> conditions validation-->
2245 <!--* After building response (if necessary) - for clients--></p>
2246
2247 <p><!--<code>@etag</code> decorator has special attribute <code>rebuild_after_method_evaluation</code>, which by default is <code>False</code>.--></p>
2248
2249 <p><!--If you specify <code>rebuild_after_method_evaluation</code> as <code>True</code> then Etag will be rebuilt after method evaluation:--></p>
2250
2251 <p><!-- class CityViewSet(ModelViewSet):-->
2252 <!-- ...-->
2253 <!-- @etag(obj_key_func, rebuild_after_method_evaluation=True)-->
2254 <!-- def update(self, request, *args, **kwargs):-->
2255 <!-- return super(CityViewSet, self).update(request, *args, **kwargs)--></p>
2256
2257 <p><!-- @etag(obj_key_func)-->
2258 <!-- def destroy(self, request, *args, **kwargs):-->
2259 <!-- return super(CityViewSet, self).destroy(request, *args, **kwargs)--></p>
2260
2261 <p><!-- # Request-->
2262 <!-- PUT /cities/1/ HTTP/1.1-->
2263 <!-- Accept: application/json--></p>
2264
2265 <p><!-- {"name": "London"}--></p>
2266
2267 <p><!-- # Response-->
2268 <!-- HTTP/1.1 200 OK-->
2269 <!-- Content-Type: application/json; charset=UTF-8-->
2270 <!-- ETag: "4e63ef056f47270272b96523f51ad938b5ea141024b767880eac047d10a0b339"--></p>
2271
2272 <p><!-- {-->
2273 <!-- id: 1,-->
2274 <!-- name: "London"-->
2275 <!-- }--></p>
2276
2277 <p><!--As you can see we didn't specify <code>rebuild_after_method_evaluation</code> for <code>destroy</code> method. That is because there is no-->
2278 <!--sense to use returned ETag value on clients if object deletion already performed.--></p>
2279
2280 <p><!--With <code>rebuild_after_method_evaluation</code> parameter Etag calculation for <code>PUT</code>/<code>PATCH</code> method would look like:--></p>
2281
2282 <p><!-- +--------------+-->
2283 <!-- | Request |-->
2284 <!-- +--------------+-->
2285 <!-- |-->
2286 <!-- +--------------------------+-->
2287 <!-- | Calculate Etag |-->
2288 <!-- | for condition matching |-->
2289 <!-- +--------------------------+-->
2290 <!-- |-->
2291 <!-- +--------------------+-->
2292 <!-- | Do preconditions |-->
2293 <!-- | match? |-->
2294 <!-- +--------------------+-->
2295 <!-- | |-->
2296 <!-- Yes No-->
2297 <!-- | |-->
2298 <!-- +--------------+ +--------------------+-->
2299 <!-- | Update the | | 412 Precondition |-->
2300 <!-- | resource | | failed |-->
2301 <!-- +--------------+ +--------------------+-->
2302 <!-- |-->
2303 <!-- +--------------------+-->
2304 <!-- | Calculate Etag |-->
2305 <!-- | again and add it |-->
2306 <!-- | to response |-->
2307 <!-- +--------------------+-->
2308 <!-- |-->
2309 <!-- +------------+-->
2310 <!-- | Return |-->
2311 <!-- | response |-->
2312 <!-- +------------+--></p>
2313
2314 <p><!--<code>If-None-Match</code> example for <code>DELETE</code> method:--></p>
2315
2316 <p><!-- # Request-->
2317 <!-- DELETE /cities/1/ HTTP/1.1-->
2318 <!-- Accept: application/json-->
2319 <!-- If-None-Match: some_etag_value--></p>
2320
2321 <p><!-- # Response-->
2322 <!-- HTTP/1.1 304 NOT MODIFIED-->
2323 <!-- Content-Type: application/json; charset=UTF-8-->
2324 <!-- Etag: "some_etag_value"--></p>
2325
2326 <p><!--<code>If-Match</code> example for <code>DELETE</code> method:--></p>
2327
2328 <p><!-- # Request-->
2329 <!-- DELETE /cities/1/ HTTP/1.1-->
2330 <!-- Accept: application/json-->
2331 <!-- If-Match: another_etag_value--></p>
2332
2333 <p><!-- # Response-->
2334 <!-- HTTP/1.1 412 PRECONDITION FAILED-->
2335 <!-- Content-Type: application/json; charset=UTF-8-->
2336 <!-- Etag: "some_etag_value"--></p>
2337
2338 <p><!--#### ETAGMixin--></p>
2339
2340 <p><!--It is common to process etags for standard <a href="http://www.django-rest-framework.org/api-guide/viewsets">viewset</a>-->
2341 <!--<code>retrieve</code>, <code>list</code>, <code>update</code> and <code>destroy</code> methods.-->
2342 <!--That is why <code>ETAGMixin</code> exists. Just mix it into viewset-->
2343 <!--implementation and those methods will use functions, defined in <code>REST_FRAMEWORK_EXTENSIONS</code> <a href="#settings">settings</a>:--></p>
2344
2345 <p><!--* *"DEFAULT\_OBJECT\_ETAG\_FUNC"* for <code>retrieve</code>, <code>update</code> and <code>destroy</code> methods-->
2346 <!--* *"DEFAULT\_LIST\_ETAG\_FUNC"* for <code>list</code> method--></p>
2347
2348 <p><!--By default those functions are using <a href="#default-key-constructor">DefaultKeyConstructor</a> and extends it:--></p>
2349
2350 <p><!--* With <code>RetrieveSqlQueryKeyBit</code> for *"DEFAULT\_OBJECT\_ETAG\_FUNC"*-->
2351 <!--* With <code>ListSqlQueryKeyBit</code> and <code>PaginationKeyBit</code> for *"DEFAULT\_LIST\_ETAG\_FUNC"*--></p>
2352
2353 <p><!--You can change those settings for custom ETag generation:--></p>
2354
2355 <p><!-- REST_FRAMEWORK_EXTENSIONS = {-->
2356 <!-- 'DEFAULT_OBJECT_ETAG_FUNC':-->
2357 <!-- 'rest_framework_extensions.utils.default_object_etag_func',-->
2358 <!-- 'DEFAULT_LIST_ETAG_FUNC':-->
2359 <!-- 'rest_framework_extensions.utils.default_list_etag_func',-->
2360 <!-- }--></p>
2361
2362 <p><!--Mixin example usage:--></p>
2363
2364 <p><!-- from myapps.serializers import UserSerializer-->
2365 <!-- from rest_framework_extensions.etag.mixins import ETAGMixin--></p>
2366
2367 <p><!-- class UserViewSet(ETAGMixin, viewsets.ModelViewSet):-->
2368 <!-- serializer_class = UserSerializer--></p>
2369
2370 <p><!--You can change etag function by providing <code>object_etag_func</code> or-->
2371 <!--<code>list_etag_func</code> methods in view class:--></p>
2372
2373 <p><!-- class UserViewSet(ETAGMixin, viewsets.ModelViewSet):-->
2374 <!-- serializer_class = UserSerializer--></p>
2375
2376 <p><!-- def object_etag_func(self, **kwargs):-->
2377 <!-- return 'some key for object'--></p>
2378
2379 <p><!-- def list_etag_func(self, **kwargs):-->
2380 <!-- return 'some key for list'--></p>
2381
2382 <p><!--Of course you can use custom <a href="#key-constructor">key constructor</a>:--></p>
2383
2384 <p><!-- from yourapp.key_constructors import (-->
2385 <!-- CustomObjectKeyConstructor,-->
2386 <!-- CustomListKeyConstructor,-->
2387 <!-- )--></p>
2388
2389 <p><!-- class UserViewSet(ETAGMixin, viewsets.ModelViewSet):-->
2390 <!-- serializer_class = UserSerializer-->
2391 <!-- object_etag_func = CustomObjectKeyConstructor()-->
2392 <!-- list_etag_func = CustomListKeyConstructor()--></p>
2393
2394 <p><!--It is important to note that ETags for unsafe method <code>update</code> is processed with parameter-->
2395 <!--<code>rebuild_after_method_evaluation</code> equals <code>True</code>. You can read why from <a href="#etag-for-unsafe-methods">this</a> section.--></p>
2396
2397 <p><!--There are other mixins for more granular Etag calculation in <code>rest_framework_extensions.etag.mixins</code> module:--></p>
2398
2399 <p><!--* **ReadOnlyETAGMixin** - only for <code>retrieve</code> and <code>list</code> methods-->
2400 <!--* **RetrieveETAGMixin** - only for <code>retrieve</code> method-->
2401 <!--* **ListETAGMixin** - only for <code>list</code> method-->
2402 <!--* **DestroyETAGMixin** - only for <code>destroy</code> method-->
2403 <!--* **UpdateETAGMixin** - only for <code>update</code> method--></p>
2404
2405 <p><!--#### APIETagMixin--></p>
2406
2407 <p><!--*New in DRF-extensions 0.3.2*--></p>
2408
2409 <p><!--In analogy to <code>ETAGMixin</code> the <code>APIETAGMixin</code> exists. Just mix it into DRF viewsets or <code>APIViews</code> -->
2410 <!--and those methods will use the ETag functions, defined in <code>REST_FRAMEWORK_EXTENSIONS</code> <a href="#settings">settings</a>:--></p>
2411
2412 <p><!--* *"DEFAULT\_API\_OBJECT\_ETAG\_FUNC"* for <code>retrieve</code>, <code>update</code> and <code>destroy</code> methods-->
2413 <!--* *"DEFAULT\_API\_LIST\_ETAG\_FUNC"* for <code>list</code> method--></p>
2414
2415 <p><!--By default those functions are using custom key constructors that create the key from **persisted model attributes**:--></p>
2416
2417 <p><!--* <code>RetrieveModelKeyBit</code> (see <a href="#retrievemodelkeybit">definition</a>) for *"DEFAULT\_API\_OBJECT\_ETAG\_FUNC"*-->
2418 <!--* <code>ListModelKeyBit</code> (see <a href="#listmodelkeybit">definition</a>) for *"DEFAULT\_API\_LIST\_ETAG\_FUNC"*--></p>
2419
2420 <p><!--You can change those settings globally for your custom ETag generation, or use the default values, which should cover -->
2421 <!--the most common use cases:--></p>
2422
2423 <p><!-- REST_FRAMEWORK_EXTENSIONS = {-->
2424 <!-- 'DEFAULT_API_OBJECT_ETAG_FUNC': -->
2425 <!-- 'rest_framework_extensions.utils.default_api_object_etag_func',-->
2426 <!-- 'DEFAULT_API_LIST_ETAG_FUNC': -->
2427 <!-- 'rest_framework_extensions.utils.default_api_list_etag_func',-->
2428 <!-- }--></p>
2429
2430 <p><!--Mixin example usage:--></p>
2431
2432 <p><!-- from myapps.serializers import UserSerializer-->
2433 <!-- from rest_framework_extensions.etag.mixins import APIETAGMixin--></p>
2434
2435 <p><!-- class UserViewSet(APIETAGMixin, viewsets.ModelViewSet):-->
2436 <!-- serializer_class = UserSerializer--></p>
2437
2438 <p><!--You can change etag function by providing <code>api_object_etag_func</code> or-->
2439 <!--<code>api_list_etag_func</code> methods in view class:--></p>
2440
2441 <p><!-- class UserViewSet(APIETAGMixin, viewsets.ModelViewSet):-->
2442 <!-- serializer_class = UserSerializer--></p>
2443
2444 <p><!-- def api_object_etag_func(self, **kwargs):-->
2445 <!-- return 'some key for object'--></p>
2446
2447 <p><!-- def api_list_etag_func(self, **kwargs):-->
2448 <!-- return 'some key for list'--></p>
2449
2450 <p><!--Of course you can use custom <a href="#key-constructor">key constructors</a>:--></p>
2451
2452 <p><!-- from yourapp.key_constructors import (-->
2453 <!-- CustomObjectKeyConstructor,-->
2454 <!-- CustomListKeyConstructor,-->
2455 <!-- )--></p>
2456
2457 <p><!-- class UserViewSet(APIETAGMixin, viewsets.ModelViewSet):-->
2458 <!-- serializer_class = UserSerializer-->
2459 <!-- api_object_etag_func = CustomObjectKeyConstructor()-->
2460 <!-- api_list_etag_func = CustomListKeyConstructor()--></p>
2461
2462 <p><!--There are other mixins for more granular ETag calculation in <code>rest_framework_extensions.etag.mixins</code> module:--></p>
2463
2464 <p><!--* **APIReadOnlyETAGMixin** - only for <code>retrieve</code> and <code>list</code> methods-->
2465 <!--* **APIRetrieveETAGMixin** - only for <code>retrieve</code> method-->
2466 <!--* **APIListETAGMixin** - only for <code>list</code> method-->
2467 <!--* **APIDestroyETAGMixin** - only for <code>destroy</code> method-->
2468 <!--* **APIUpdateETAGMixin** - only for <code>update</code> method--></p>
2469
2470 <p><!--By default, all mixins require the conditional requests, i.e. they use the default <code>precondition_map</code> from the -->
2471 <!--<code>APIETAGProcessor</code> class.--></p>
2472
2473 <p><!--#### Gzipped ETags--></p>
2474
2475 <p><!--If you use <a href="https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip">GZipMiddleware</a>-->
2476 <!--and your client accepts Gzipped response, then you should return different ETags for compressed and not compressed responses.-->
2477 <!--That's what <code>GZipMiddleware</code> does by default while processing response --->
2478 <!--it adds <code>;gzip</code> postfix to ETag response header if client requests compressed response.-->
2479 <!--Lets see it in example. First request without compression:--></p>
2480
2481 <p><!-- # Request-->
2482 <!-- GET /cities/ HTTP/1.1-->
2483 <!-- Accept: application/json--></p>
2484
2485 <p><!-- # Response-->
2486 <!-- HTTP/1.1 200 OK-->
2487 <!-- Content-Type: application/json; charset=UTF-8-->
2488 <!-- ETag: "e7b50490dc"--></p>
2489
2490 <p><!-- ['Moscow', 'London', 'Paris']--></p>
2491
2492 <p><!--Second request with compression:--></p>
2493
2494 <p><!-- # Request-->
2495 <!-- GET /cities/ HTTP/1.1-->
2496 <!-- Accept: application/json-->
2497 <!-- Accept-Encoding: gzip--></p>
2498
2499 <p><!-- # Response-->
2500 <!-- HTTP/1.1 200 OK-->
2501 <!-- Content-Type: application/json-->
2502 <!-- Content-Length: 675-->
2503 <!-- Content-Encoding: gzip-->
2504 <!-- ETag: "e7b50490dc;gzip"--></p>
2505
2506 <p><!-- wS?n?0?_%o?cc?Ҫ?Eʒ?Cժʻ?a\1?a?^T*7q&lt;&gt;[Nvh?[?^9?x:/Ms?79?Fd/???ۦjES?ڽ?&amp;??c%^?C[K۲%N?w{?졭2?m?}?Q&amp;Egz??--></p>
2507
2508 <p><!--As you can see there is <code>;gzip</code> postfix in ETag response header.-->
2509 <!--That's ok but there is one caveat - drf-extension doesn't know how you post-processed calculated ETag value.-->
2510 <!--And your clients could have next problem with conditional request:--></p>
2511
2512 <p><!--* Client sends request to retrieve compressed data about cities to <code>/cities/</code>-->
2513 <!--* DRF-extensions decorator calculates ETag header for response equals, for example, <code>123</code>-->
2514 <!--* <code>GZipMiddleware</code> adds <code>;gzip</code> postfix to ETag header response, and now it equals <code>123;gzip</code>-->
2515 <!--* Client retrieves response with ETag equals <code>123;gzip</code>-->
2516 <!--* Client again makes request to retrieve compressed data about cities,-->
2517 <!--but now it's conditional request with <code>If-None-Match</code> header equals <code>123;gzip</code>-->
2518 <!--* DRF-extensions decorator calculates ETag value for processing conditional request.-->
2519 <!--But it doesn't know, that <code>GZipMiddleware</code> added <code>;gzip</code> postfix for previous response.-->
2520 <!--DRF-extensions decorator calculates ETag equals <code>123</code>, compares it with <code>123;gzip</code> and returns-->
2521 <!--response with status code 200, because <code>123</code> != <code>123;gzip</code>--></p>
2522
2523 <p><!--You can solve this problem by stripping <code>;gzip</code> postfix on client side.--></p>
2524
2525 <p><!--But there are so many libraries that just magically uses ETag response header without allowing to-->
2526 <!--pre-process conditional requests (for example, browser). If that's you case then you could add custom middleware which removes <code>;gzip</code>-->
2527 <!--postfix from header:--></p>
2528
2529 <p><!-- # yourapp/middleware.py--></p>
2530
2531 <p><!-- class RemoveEtagGzipPostfix(object):-->
2532 <!-- def process_response(self, request, response):-->
2533 <!-- if response.has_header('ETag') and response['ETag'][-6:] == ';gzip"':-->
2534 <!-- response['ETag'] = response['ETag'][:-6] + '"'-->
2535 <!-- return response--></p>
2536
2537 <p><!--Don't forget to add this middleware in your settings before <code>GZipMiddleware</code>:--></p>
2538
2539 <p><!-- # settings.py-->
2540 <!-- MIDDLEWARE_CLASSES = (-->
2541 <!-- ...-->
2542 <!-- 'yourapp.RemoveEtagGzipPostfix',-->
2543 <!-- 'django.middleware.gzip.GZipMiddleware',-->
2544 <!-- 'django.middleware.common.CommonMiddleware',-->
2545 <!-- ...-->
2546 <!-- )--></p>
2547
2548 <h3 id="bulk-operations">Bulk operations</h3>
2549
2550 <p><em>New in DRF-extensions 0.2.4</em></p>
2551
2552 <p>Bulk operations allows you to perform operations over set of objects with one request. There is third-party package
2553 <a href="django-rest-framework-bulk">django-rest-framework-bulk</a> with support for all CRUD methods, but it iterates over every
2554 instance in bulk operation, serializes it and only after that executes operation.</p>
2555
2556 <p>It plays nice with <code>create</code> or <code>update</code>
2557 operations, but becomes unacceptable with <code>partial update</code> and <code>delete</code> methods over the <code>QuerySet</code>. Such kind of
2558 <code>QuerySet</code> could contain thousands of objects and should be performed as database query over the set at once.</p>
2559
2560 <p>Please note - DRF-extensions bulk operations applies over <code>QuerySet</code>, not over instances. It means that:</p>
2561
2562 <ul>
2563 <li>No serializer's <code>save</code> or <code>delete</code> methods would be called</li>
2564 <li>No viewset's <code>pre_save</code>, <code>post_save</code>, <code>pre_delete</code> and <code>post_delete</code> would be called</li>
2565 <li>No model signals would be called</li>
2566 </ul>
2567
2568 <h4 id="safety">Safety</h4>
2569
2570 <p>Bulk operations are very dangerous in case of making stupid mistakes. For example you wanted to delete user instance
2571 with <code>DELETE</code> request from your client application.</p>
2572
2573 <pre><code># Request
2574 DELETE /users/1/ HTTP/1.1
2575 Accept: application/json
2576
2577 # Response
2578 HTTP/1.1 204 NO CONTENT
2579 Content-Type: application/json; charset=UTF-8
2580 </code></pre>
2581
2582 <p>That was example of successful deletion. But there is the common situation when client could not get instance id and sends
2583 request to endpoint without it:</p>
2584
2585 <pre><code># Request
2586 DELETE /users/ HTTP/1.1
2587 Accept: application/json
2588
2589 # Response
2590 HTTP/1.1 204 NO CONTENT
2591 Content-Type: application/json; charset=UTF-8
2592 </code></pre>
2593
2594 <p>If you used <a href="#bulk-destroy">bulk destroy mixin</a> for <code>/users/</code> endpoint, then all your user objects would be deleted.</p>
2595
2596 <p>To protect from such confusions DRF-extensions asks you to send <code>X-BULK-OPERATION</code> header
2597 for every bulk operation request. With this protection previous example would not delete any user instances:</p>
2598
2599 <pre><code># Request
2600 DELETE /users/ HTTP/1.1
2601 Accept: application/json
2602
2603 # Response
2604 HTTP/1.1 400 BAD REQUEST
2605 Content-Type: application/json; charset=UTF-8
2606
2607 {
2608 "detail": "Header 'X-BULK-OPERATION' should be provided for bulk operation."
2609 }
2610 </code></pre>
2611
2612 <p>With <code>X-BULK-OPERATION</code> header it works as expected - deletes all user instances:</p>
2613
2614 <pre><code># Request
2615 DELETE /users/ HTTP/1.1
2616 Accept: application/json
2617 X-BULK-OPERATION: true
2618
2619 # Response
2620 HTTP/1.1 204 NO CONTENT
2621 Content-Type: application/json; charset=UTF-8
2622 </code></pre>
2623
2624 <p>You can change bulk operation header name in settings:</p>
2625
2626 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
2627 'DEFAULT_BULK_OPERATION_HEADER_NAME': 'X-CUSTOM-BULK-OPERATION'
2628 }
2629 </code></pre>
2630
2631 <p>To turn off protection you can set <code>DEFAULT_BULK_OPERATION_HEADER_NAME</code> as <code>None</code>.</p>
2632
2633 <h4 id="bulk-destroy">Bulk destroy</h4>
2634
2635 <p>This mixin allows you to delete many instances with one <code>DELETE</code> request.</p>
2636
2637 <pre><code>from rest_framework_extensions.bulk_operations.mixins import ListDestroyModelMixin
2638
2639 class UserViewSet(ListDestroyModelMixin, viewsets.ModelViewSet):
2640 serializer_class = UserSerializer
2641 </code></pre>
2642
2643 <p>Bulk destroy example - delete all users which emails ends with <code>gmail.com</code>:</p>
2644
2645 <pre><code># Request
2646 DELETE /users/?email__endswith=gmail.com HTTP/1.1
2647 Accept: application/json
2648 X-BULK-OPERATION: true
2649
2650 # Response
2651 HTTP/1.1 204 NO CONTENT
2652 Content-Type: application/json; charset=UTF-8
2653 </code></pre>
2654
2655 <h4 id="bulk-update">Bulk update</h4>
2656
2657 <p>This mixin allows you to update many instances with one <code>PATCH</code> request. Note, that this mixin works only with partial update.</p>
2658
2659 <pre><code>from rest_framework_extensions.mixins import ListUpdateModelMixin
2660
2661 class UserViewSet(ListUpdateModelMixin, viewsets.ModelViewSet):
2662 serializer_class = UserSerializer
2663 </code></pre>
2664
2665 <p>Bulk partial update example - set <code>email_provider</code> of every user as <code>google</code>, if it's email ends with <code>gmail.com</code>:</p>
2666
2667 <pre><code># Request
2668 PATCH /users/?email__endswith=gmail.com HTTP/1.1
2669 Accept: application/json
2670 X-BULK-OPERATION: true
2671
2672 {"email_provider": "google"}
2673
2674 # Response
2675 HTTP/1.1 204 NO CONTENT
2676 Content-Type: application/json; charset=UTF-8
2677 </code></pre>
2678
2679 <h3 id="settings">Settings</h3>
2680
2681 <p>DRF-extensions follows Django Rest Framework approach in settings implementation.</p>
2682
2683 <p><a href="https://www.django-rest-framework.org/api-guide/settings/">In Django Rest Framework</a> you specify custom settings by changing <code>REST_FRAMEWORK</code> variable in settings file:</p>
2684
2685 <pre><code>REST_FRAMEWORK = {
2686 'DEFAULT_RENDERER_CLASSES': (
2687 'rest_framework.renderers.YAMLRenderer',
2688 ),
2689 'DEFAULT_PARSER_CLASSES': (
2690 'rest_framework.parsers.YAMLParser',
2691 )
2692 }
2693 </code></pre>
2694
2695 <p>In DRF-extensions there is a magic variable too called <code>REST_FRAMEWORK_EXTENSIONS</code>:</p>
2696
2697 <pre><code>REST_FRAMEWORK_EXTENSIONS = {
2698 'DEFAULT_CACHE_RESPONSE_TIMEOUT': 60 * 15
2699 }
2700 </code></pre>
2701
2702 <h4 id="accessing-settings">Accessing settings</h4>
2703
2704 <p>If you need to access the values of DRF-extensions API settings in your project, you should use the <code>extensions_api_settings</code> object. For example:</p>
2705
2706 <pre><code>from rest_framework_extensions.settings import extensions_api_settings
2707
2708 print extensions_api_settings.DEFAULT_CACHE_RESPONSE_TIMEOUT
2709 </code></pre>
2710
2711 <h3 id="release-notes">Release notes</h3>
2712
2713 <p>You can read about versioning, deprecation policy and upgrading from
2714 <a href="https://www.django-rest-framework.org/community/release-notes/">Django REST framework documentation</a>.</p>
2715
2716 <h4 id="0-8-0">0.8.0</h4>
2717
2718 <ul>
2719 <li>Added support for Django 4.2 to 5.2</li>
2720 <li>DRF 3.15 support added</li>
2721 <li>Python 3.10 to 3.12 support added</li>
2722 <li>Removed deprecated libs</li>
2723 <li>Added handling for ValidationError while filtering queryset in NestedViewSetMixin</li>
2724 <li>Modified lookup<em>value to use lookup</em>url_kwarg aswell</li>
2725 <li>Migrated CI to Github actions</li>
2726 </ul>
2727
2728 <h4 id="0-7-1">0.7.1</h4>
2729
2730 <ul>
2731 <li>Added support for Django 3.2</li>
2732 <li>Dropped drf 3.11</li>
2733 </ul>
2734
2735 <h4 id="0-7-0">0.7.0</h4>
2736
2737 <ul>
2738 <li>Added support for Django 3.1 </li>
2739 <li>Dropped support below Django 2.2</li>
2740 <li>Added support for DRF 3.12</li>
2741 <li>fix(PartialUpdateSerializerMixin): support nesting on same instance </li>
2742 </ul>
2743
2744 <h4 id="0-6-0">0.6.0</h4>
2745
2746 <p><em>Jan 27, 2020</em></p>
2747
2748 <ul>
2749 <li>Added support for Django 3.0 (#276)</li>
2750 <li>Dropped support for Django 2.0</li>
2751 <li>Added support for DRF 3.10 and 3.11 (#261, #279)</li>
2752 <li>Added support for Python 3.8 (#282)</li>
2753 <li>Added paginate decorator (#266)</li>
2754 <li>Added limit/offset and cursor pagination to PaginationKeyBit (#204)</li>
2755 </ul>
2756
2757 <h4 id="0-5-0">0.5.0</h4>
2758
2759 <p><em>May 10, 2019</em></p>
2760
2761 <ul>
2762 <li>Dropped python 2.7 and 3.4</li>
2763 <li>Fix possible header mutation issue </li>
2764 <li>Added ability to <a href="#cacheresponsemixin">use a specific cache timeouts</a> for <code>CacheResponseMixin</code></li>
2765 <li>Test against Django 2.1, DRF 3.9 and django-filter 2.0.0</li>
2766 <li>Dropped support of older DRF version lower than 3.9</li>
2767 <li>Django 2.2 support added</li>
2768 </ul>
2769
2770 <h4 id="0-4-0">0.4.0</h4>
2771
2772 <p><em>Sep 5, 2018</em></p>
2773
2774 <ul>
2775 <li>Added support for django 1.11 and 2.0</li>
2776 <li>Dropped support for django versions lower then 1.11</li>
2777 <li>Nested routes with over 2 levels now respect <code>lookup_value_regex</code> </li>
2778 <li>Added support for DRF 3.8</li>
2779 <li>Dropped support of older DRF version lower then 3.8</li>
2780 <li>Cache only the renered response instead of rendering whole response object</li>
2781 <li>The etag functionalties are not enabled by default, have to enable it manually</li>
2782 </ul>
2783
2784 <h4 id="0-3-2">0.3.2</h4>
2785
2786 <p><em>Jan 4, 2017</em></p>
2787
2788 <ul>
2789 <li>Added <code>rest_framework_extensions.exceptions.PreconditionRequiredException</code> as subclass of <code>rest_framework.exceptions.APIException</code></li>
2790 <li>Added <code>@api_etag</code> decorator function and <code>APIETAGProcessor</code> that uses <em>semantic</em> ETags per API resource, decoupled from views, such that it can be used in optimistic concurrency control </li>
2791 <li>Added new default key bits <code>RetrieveModelKeyBit</code> and <code>ListModelKeyBit</code> for computing the semantic fingerprint of a django model instance</li>
2792 <li>Added <code>APIETAGMixin</code> to be used in DRF viewsets and views</li>
2793 <li>Added new settings for default implementation of the API ETag functions: <code>DEFAULT_API_OBJECT_ETAG_FUNC</code>, <code>DEFAULT_API_LIST_ETAG_FUNC</code></li>
2794 <li>Added test application for functional tests and demo as <code>tests_app/tests/functional/concurrency/conditional_request</code></li>
2795 <li>Added unit tests for the <code>@api_etag</code> decorator</li>
2796 <li>DRF 3.5.x, Django pre-1.10 compatibility of the key bit construction</li>
2797 <li>(Test-)Code cleanup</li>
2798 </ul>
2799
2800 <h4 id="0-3-1">0.3.1</h4>
2801
2802 <p><em>Sep 29, 2016</em></p>
2803
2804 <ul>
2805 <li>Fix <code>schema_urls</code> <code>ExtendedDefaultRouter</code> compatibility issue introduced by DRF 3.4.0</li>
2806 <li>Removed deprecated @action() and @link() decorators</li>
2807 <li>DRF 3.4.x compatibility</li>
2808 <li>Django 1.9 and 1.10 compatibility</li>
2809 </ul>
2810
2811 <h4 id="0-2-8">0.2.8</h4>
2812
2813 <p><em>Sep 21, 2015</em></p>
2814
2815 <ul>
2816 <li>Fixed <code>ListSqlQueryKeyBit</code> and <code>RetrieveSqlQueryKeyBit</code> <a href="https://github.com/chibisov/drf-extensions/issues/28">problems</a> with <code>EmptyResultSet</code> exception (<a href="https://github.com/chibisov/drf-extensions/pull/75/">pull</a>).</li>
2817 <li>All items are now by default in <a href="#argskeybit">ArgsKeyBit</a>, <a href="#kwargskeybit">KwargsKeyBit</a> and <a href="#queryparamskeybit">QueryParamsKeyBit</a></li>
2818 <li>Respect parent lookup regex value for <a href="#nested-routes">Nested routes</a> (<a href="https://github.com/chibisov/drf-extensions/pull/87">issue</a>).</li>
2819 </ul>
2820
2821 <h4 id="0-2-7">0.2.7</h4>
2822
2823 <p><em>Feb 2, 2015</em></p>
2824
2825 <ul>
2826 <li><a href="https://github.com/chibisov/drf-extensions/issues/39">DRF 3.x compatibility</a></li>
2827 <li><a href="#detailserializermixin">DetailSerializerMixin</a> is now <a href="https://github.com/chibisov/drf-extensions/issues/46">compatible with DRF 3.0</a></li>
2828 <li>Added <a href="#argskeybit">ArgsKeyBit</a></li>
2829 <li>Added <a href="#kwargskeybit">KwargsKeyBit</a></li>
2830 <li>Fixed <a href="#partialupdateserializermixin">PartialUpdateSerializerMixin</a> <a href="https://github.com/chibisov/drf-extensions/issues/66">compatibility issue with DRF 3.x</a></li>
2831 <li>Added <a href="#caching-errors">cache_errors</a> attribute for switching caching for error responses</li>
2832 <li>Added ability to specify usage of all items for <a href="#requestmetakeybit">RequestMetaKeyBit</a>, <a href="#headerskeybit">HeadersKeyBit</a>
2833 and <a href="#queryparamskeybit">QueryParamsKeyBit</a> providing <code>params='*'</code></li>
2834 <li><a href="#collection-level-controllers">Collection level controllers</a> is in pending deprecation</li>
2835 <li><a href="#controller-endpoint-name">Controller endpoint name</a> is in pending deprecation</li>
2836 </ul>
2837
2838 <h4 id="0-2-6">0.2.6</h4>
2839
2840 <p><em>Sep 9, 2014</em></p>
2841
2842 <ul>
2843 <li>Usage of <a href="https://docs.djangoproject.com/en/dev/topics/cache/#django.core.cache.caches">django.core.cache.caches</a> for
2844 django &gt;= 1.7</li>
2845 <li><a href="#gzipped-etags">Documented ETag usage with GZipMiddleware</a></li>
2846 <li>Fixed <code>ListSqlQueryKeyBit</code> and <code>RetrieveSqlQueryKeyBit</code> <a href="https://github.com/chibisov/drf-extensions/issues/28">problems</a>
2847 with <code>EmptyResultSet</code>.</li>
2848 <li>Fixed <a href="#cache-response">cache response</a> compatibility <a href="https://github.com/chibisov/drf-extensions/issues/32">issue</a>
2849 with DRF 2.4.x</li>
2850 </ul>
2851
2852 <h4 id="0-2-5">0.2.5</h4>
2853
2854 <p><em>July 9, 2014</em></p>
2855
2856 <ul>
2857 <li>Fixed <a href="https://github.com/chibisov/drf-extensions/issues/20">setuptools confusion with pyc files</a></li>
2858 </ul>
2859
2860 <h4 id="0-2-4">0.2.4</h4>
2861
2862 <p><em>July 7, 2014</em></p>
2863
2864 <ul>
2865 <li>Added tests for <a href="https://www.django-rest-framework.org/topics/release-notes#2314">Django REST Framework 2.3.14</a></li>
2866 <li>Added <a href="#bulk-operations">Bulk operations</a></li>
2867 <li>Fixed <a href="#routers">extended routers</a> compatibility issue with <a href="http://www.django-rest-framework.org/api-guide/viewsets#marking-extra-methods-for-routing">default controller decorators</a></li>
2868 <li>Documented <a href="#pluggable-router-mixins">pluggable router mixins</a></li>
2869 <li>Added <a href="#nested-routes">nested routes</a></li>
2870 </ul>
2871
2872 <h4 id="0-2-3">0.2.3</h4>
2873
2874 <p><em>Apr. 25, 2014</em></p>
2875
2876 <ul>
2877 <li>Added <a href="#partialupdateserializermixin">PartialUpdateSerializerMixin</a></li>
2878 <li>Added <a href="#key-constructor-params">Key constructor params</a></li>
2879 <li>Documented dynamically <a href="#constructor-s-bits-list">constructor's bits list</a> altering</li>
2880 <li>Added ability to <a href="#usage-of-the-specific-cache">use a specific cache</a> for <code>@cache_response</code> decorator</li>
2881 </ul>
2882
2883 <h4 id="0-2-2">0.2.2</h4>
2884
2885 <p><em>Mar. 23, 2014</em></p>
2886
2887 <ul>
2888 <li>Added <a href="#paginatebymaxmixin">PaginateByMaxMixin</a></li>
2889 <li>Added <a href="#object-permissions">ExtenedDjangoObjectPermissions</a></li>
2890 <li>Added tests for django 1.7</li>
2891 </ul>
2892
2893 <h4 id="0-2-1">0.2.1</h4>
2894
2895 <p><em>Feb. 1, 2014</em></p>
2896
2897 <ul>
2898 <li>Rewritten tests to nose and tox</li>
2899 <li>New tests directory structure</li>
2900 <li>Rewritten HTTP documentation requests examples into more raw manner</li>
2901 <li>Added trailing_slash on extended routers for Django Rest Framework versions<code>&gt;=2.3.6</code> (which supports this feature)</li>
2902 <li>Added <a href="#caching">caching</a></li>
2903 <li>Added <a href="#key-constructor">key constructor</a></li>
2904 <li>Added <a href="#conditional-requests">conditional requests</a> with Etag calculation</li>
2905 <li>Added <a href="#cache-etag-mixins">Cache/ETAG mixins</a></li>
2906 <li>Added <a href="#cacheresponsemixin">CacheResponseMixin</a></li>
2907 <li>Added <a href="#etagmixin">ETAGMixin</a></li>
2908 <li>Documented <a href="#resourceurifield">ResourceUriField</a></li>
2909 <li>Documented <a href="#settings">settings</a> customization</li>
2910 </ul>
2911
2912 <h4 id="0-2">0.2</h4>
2913
2914 <p><em>Nov. 5, 2013</em></p>
2915
2916 <ul>
2917 <li>Moved docs from readme to github pages</li>
2918 <li>Docs generation with <a href="https://github.com/chibisov/backdoc">Backdoc</a></li>
2919 </ul>
2920
2921 </div>
2922 </body>
2923 </html>