mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-03-19 23:00:24 +00:00
286 lines
No EOL
18 KiB
HTML
286 lines
No EOL
18 KiB
HTML
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>Views — Django-Select2 3.1.2 documentation</title>
|
|
|
|
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '',
|
|
VERSION: '3.1.2',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
<link rel="top" title="Django-Select2 3.1.2 documentation" href="index.html" />
|
|
<link rel="up" title="API Reference" href="reference.html" />
|
|
<link rel="next" title="Util" href="ref_util.html" />
|
|
<link rel="prev" title="Fields" href="ref_fields.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li class="right" >
|
|
<a href="ref_util.html" title="Util"
|
|
accesskey="N">next</a> |</li>
|
|
<li class="right" >
|
|
<a href="ref_fields.html" title="Fields"
|
|
accesskey="P">previous</a> |</li>
|
|
<li><a href="index.html">Django-Select2 3.1.2 documentation</a> »</li>
|
|
<li><a href="reference.html" accesskey="U">API Reference</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="views">
|
|
<h1>Views<a class="headerlink" href="#views" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="class-diagram">
|
|
<h2>Class Diagram<a class="headerlink" href="#class-diagram" title="Permalink to this headline">¶</a></h2>
|
|
<p class="graphviz">
|
|
<img src="_images/inheritance-226e89d7da8304ffcc884462a1620b9e4209ee59.png" alt="Inheritance diagram of django_select2.views" usemap="#inheritanceb5a6c91e22" class="inheritance"/>
|
|
<map id="inheritanceb5a6c91e22" name="inheritanceb5a6c91e22">
|
|
<area shape="poly" id="node1" href="#django_select2.views.JSONResponseMixin" title="JSONResponseMixin" alt="" coords="206,23,201,17,187,13,165,9,137,7,105,6,74,7,46,9,24,13,9,17,4,23,9,28,24,33,46,36,74,39,105,40,137,39,165,36,187,33,201,28"/>
|
|
<area shape="poly" id="node2" href="#django_select2.views.Select2View" title="Select2View" alt="" coords="254,105,251,100,241,95,226,92,207,89,185,88,164,89,145,92,130,95,120,100,117,105,120,111,130,115,145,119,164,121,185,122,207,121,226,119,241,115,251,111"/>
|
|
<area shape="poly" id="node6" href="#django_select2.views.AutoResponseView" title="AutoResponseView" alt="" coords="285,188,280,183,266,178,244,174,216,172,185,171,154,172,127,174,104,178,90,183,85,188,90,193,104,198,127,202,154,204,185,205,216,204,244,202,266,198,280,193"/>
|
|
</map>
|
|
</p>
|
|
</div>
|
|
<div class="section" id="module-django_select2.views">
|
|
<span id="reference"></span><h2>Reference<a class="headerlink" href="#module-django_select2.views" title="Permalink to this headline">¶</a></h2>
|
|
<dl class="data">
|
|
<dt id="django_select2.views.NO_ERR_RESP">
|
|
<tt class="descclassname">django_select2.views.</tt><tt class="descname">NO_ERR_RESP</tt><em class="property"> = 'nil'</em><a class="headerlink" href="#django_select2.views.NO_ERR_RESP" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Equals to ‘nil’ constant.</p>
|
|
<p>Use this in <a class="reference internal" href="#django_select2.views.Select2View.get_results" title="django_select2.views.Select2View.get_results"><tt class="xref py py-meth docutils literal"><span class="pre">Select2View.get_results()</span></tt></a> to mean no error, instead of hardcoding ‘nil’ value.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="class">
|
|
<dt id="django_select2.views.JSONResponseMixin">
|
|
<em class="property">class </em><tt class="descclassname">django_select2.views.</tt><tt class="descname">JSONResponseMixin</tt><a class="reference internal" href="_modules/django_select2/views.html#JSONResponseMixin"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.JSONResponseMixin" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
|
|
<p>A mixin that can be used to render a JSON response.</p>
|
|
<dl class="attribute">
|
|
<dt id="django_select2.views.JSONResponseMixin.response_class">
|
|
<tt class="descname">response_class</tt><a class="headerlink" href="#django_select2.views.JSONResponseMixin.response_class" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>alias of <tt class="xref py py-class docutils literal"><span class="pre">HttpResponse</span></tt></p>
|
|
</dd></dl>
|
|
|
|
<dl class="method">
|
|
<dt id="django_select2.views.JSONResponseMixin.render_to_response">
|
|
<tt class="descname">render_to_response</tt><big>(</big><em>context</em>, <em>**response_kwargs</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#JSONResponseMixin.render_to_response"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.JSONResponseMixin.render_to_response" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Returns a JSON response, transforming ‘context’ to make the payload.</p>
|
|
</dd></dl>
|
|
|
|
<dl class="method">
|
|
<dt id="django_select2.views.JSONResponseMixin.convert_context_to_json">
|
|
<tt class="descname">convert_context_to_json</tt><big>(</big><em>context</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#JSONResponseMixin.convert_context_to_json"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.JSONResponseMixin.convert_context_to_json" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Convert the context dictionary into a JSON object</p>
|
|
</dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
<dl class="class">
|
|
<dt id="django_select2.views.Select2View">
|
|
<em class="property">class </em><tt class="descclassname">django_select2.views.</tt><tt class="descname">Select2View</tt><big>(</big><em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#Select2View"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.Select2View" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <a class="reference internal" href="#django_select2.views.JSONResponseMixin" title="django_select2.views.JSONResponseMixin"><tt class="xref py py-class docutils literal"><span class="pre">django_select2.views.JSONResponseMixin</span></tt></a>, <a class="reference external" href="https://docs.djangoproject.com/en/1.4/ref/class-based-views/#django.views.generic.base.View" title="(in Django v1.4.1)"><tt class="xref py py-class docutils literal"><span class="pre">django.views.generic.base.View</span></tt></a></p>
|
|
<p>Base view which is designed to respond with JSON to Ajax queries from heavy widgets/fields.</p>
|
|
<p>Although the widgets won’t enforce the type of data_view it gets, but it is recommended to
|
|
sub-class this view instead of creating a Django view from scratch.</p>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">Only <a class="reference external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3">GET</a> Http requests are supported.</p>
|
|
</div>
|
|
<dl class="method">
|
|
<dt id="django_select2.views.Select2View.respond_with_exception">
|
|
<tt class="descname">respond_with_exception</tt><big>(</big><em>e</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#Select2View.respond_with_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.Select2View.respond_with_exception" title="Permalink to this definition">¶</a></dt>
|
|
<dd><table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>e</strong> (<em>Exception</em>) – Exception object.</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Response with status code of 404 if e is <tt class="docutils literal"><span class="pre">Http404</span></tt> object,
|
|
else 400.</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">HttpResponse</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<dl class="method">
|
|
<dt id="django_select2.views.Select2View.check_all_permissions">
|
|
<tt class="descname">check_all_permissions</tt><big>(</big><em>request</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#Select2View.check_all_permissions"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.Select2View.check_all_permissions" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Sub-classes can use this to raise exception on permission check failures,
|
|
or these checks can be placed in <tt class="docutils literal"><span class="pre">urls.py</span></tt>, e.g. <tt class="docutils literal"><span class="pre">login_required(SelectClass.as_view())</span></tt>.</p>
|
|
<table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
<li><strong>request</strong> (<a class="reference external" href="https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest" title="(in Django v1.4.1)"><tt class="xref py py-class docutils literal"><span class="pre">django.http.HttpRequest</span></tt></a>) – The Ajax request object.</li>
|
|
<li><strong>args</strong> – The <tt class="docutils literal"><span class="pre">*args</span></tt> passed to <tt class="xref py py-meth docutils literal"><span class="pre">django.views.generic.View.dispatch()</span></tt>.</li>
|
|
<li><strong>kwargs</strong> – The <tt class="docutils literal"><span class="pre">**kwargs</span></tt> passed to <tt class="xref py py-meth docutils literal"><span class="pre">django.views.generic.View.dispatch()</span></tt>.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition warning">
|
|
<p class="first admonition-title">Warning</p>
|
|
<p class="last">Sub-classes should override this. You really do not want random people making
|
|
Http reqeusts to your server, be able to get access to sensitive information.</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="method">
|
|
<dt id="django_select2.views.Select2View.get_results">
|
|
<tt class="descname">get_results</tt><big>(</big><em>request</em>, <em>term</em>, <em>page</em>, <em>context</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#Select2View.get_results"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.Select2View.get_results" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Returns the result for the given search <tt class="docutils literal"><span class="pre">term</span></tt>.</p>
|
|
<table class="docutils field-list" frame="void" rules="none">
|
|
<col class="field-name" />
|
|
<col class="field-body" />
|
|
<tbody valign="top">
|
|
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
|
|
<li><strong>request</strong> (<a class="reference external" href="https://docs.djangoproject.com/en/1.4/ref/request-response/#django.http.HttpRequest" title="(in Django v1.4.1)"><tt class="xref py py-class docutils literal"><span class="pre">django.http.HttpRequest</span></tt></a>) – The Ajax request object.</li>
|
|
<li><strong>term</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#str" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">str</span></tt></a>) – The search term.</li>
|
|
<li><strong>page</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">int</span></tt></a>) – The page number. If in your last response you had signalled that there are more results,
|
|
then when user scrolls more a new Ajax request would be sent for the same term but with next page
|
|
number. (Page number starts at 1)</li>
|
|
<li><strong>context</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#str" title="(in Python v2.7)"><tt class="xref py py-obj docutils literal"><span class="pre">str</span></tt></a> or None) – <p>Can be anything which persists across the lifecycle of queries for the same search term.
|
|
It is reset to <tt class="docutils literal"><span class="pre">None</span></tt> when the term changes.</p>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">Currently this is not used by <tt class="docutils literal"><span class="pre">heavy_data.js</span></tt>.</p>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>Expected output is of the form:</p>
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="n">has_more</span><span class="p">,</span> <span class="p">[</span><span class="n">results</span><span class="p">])</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Where <tt class="docutils literal"><span class="pre">results</span> <span class="pre">=</span> <span class="pre">[(id1,</span> <span class="pre">text1),</span> <span class="pre">(id2,</span> <span class="pre">text2),</span> <span class="pre">...]</span></tt></p>
|
|
<p>For example:</p>
|
|
<div class="highlight-python"><div class="highlight"><pre><span class="p">(</span><span class="s">'nil'</span><span class="p">,</span> <span class="bp">False</span><span class="p">,</span>
|
|
<span class="p">[</span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s">'Value label1'</span><span class="p">),</span>
|
|
<span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="s">'Value label2'</span><span class="p">),</span>
|
|
<span class="p">])</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>When everything is fine then the <cite>err</cite> must be ‘nil’.
|
|
<cite>has_more</cite> should be true if there are more rows.</p>
|
|
</dd></dl>
|
|
|
|
</dd></dl>
|
|
|
|
<dl class="class">
|
|
<dt id="django_select2.views.AutoResponseView">
|
|
<em class="property">class </em><tt class="descclassname">django_select2.views.</tt><tt class="descname">AutoResponseView</tt><big>(</big><em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/django_select2/views.html#AutoResponseView"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django_select2.views.AutoResponseView" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Bases: <a class="reference internal" href="#django_select2.views.Select2View" title="django_select2.views.Select2View"><tt class="xref py py-class docutils literal"><span class="pre">django_select2.views.Select2View</span></tt></a></p>
|
|
<p>A central view meant to respond to Ajax queries for all Heavy widgets/fields.
|
|
Although it is not mandatory to use, but is immensely helpful.</p>
|
|
<div class="admonition tip">
|
|
<p class="first admonition-title">Tip</p>
|
|
<p class="last">Fields which want to use this view must sub-class <tt class="xref py py-class docutils literal"><span class="pre">AutoViewFieldMixin</span></tt>.</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<h3><a href="index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">Views</a><ul>
|
|
<li><a class="reference internal" href="#class-diagram">Class Diagram</a></li>
|
|
<li><a class="reference internal" href="#module-django_select2.views">Reference</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<h4>Previous topic</h4>
|
|
<p class="topless"><a href="ref_fields.html"
|
|
title="previous chapter">Fields</a></p>
|
|
<h4>Next topic</h4>
|
|
<p class="topless"><a href="ref_util.html"
|
|
title="next chapter">Util</a></p>
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="_sources/ref_views.txt"
|
|
rel="nofollow">Show Source</a></li>
|
|
</ul>
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="genindex.html" title="General Index"
|
|
>index</a></li>
|
|
<li class="right" >
|
|
<a href="py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li class="right" >
|
|
<a href="ref_util.html" title="Util"
|
|
>next</a> |</li>
|
|
<li class="right" >
|
|
<a href="ref_fields.html" title="Fields"
|
|
>previous</a> |</li>
|
|
<li><a href="index.html">Django-Select2 3.1.2 documentation</a> »</li>
|
|
<li><a href="reference.html" >API Reference</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2012, Nirupam Biswas.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
|
|
</div>
|
|
</body>
|
|
</html> |