Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jun 19, 2024
1 parent 576357f commit 4e153a9
Show file tree
Hide file tree
Showing 153 changed files with 536 additions and 485 deletions.
26 changes: 23 additions & 3 deletions _modules/apis_core/apis_entities/filtersets.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@
<h1>Source code for apis_core.apis_entities.filtersets</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">django_filters</span>
<span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
<span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Q</span><span class="p">,</span> <span class="n">Case</span><span class="p">,</span> <span class="n">When</span>
<span class="kn">from</span> <span class="nn">apis_core.generic.filtersets</span> <span class="kn">import</span> <span class="n">GenericFilterSet</span><span class="p">,</span> <span class="n">GenericFilterSetForm</span>
<span class="kn">from</span> <span class="nn">apis_core.apis_relations.models</span> <span class="kn">import</span> <span class="n">Property</span>
<span class="kn">from</span> <span class="nn">apis_core.apis_relations.models</span> <span class="kn">import</span> <span class="n">Property</span><span class="p">,</span> <span class="n">Triple</span>
<span class="kn">from</span> <span class="nn">apis_core.generic.helpers</span> <span class="kn">import</span> <span class="n">generate_search_filter</span>
<span class="kn">from</span> <span class="nn">apis_core.apis_entities.utils</span> <span class="kn">import</span> <span class="n">get_entity_classes</span>
<span class="kn">from</span> <span class="nn">apis_core.apis_metainfo.models</span> <span class="kn">import</span> <span class="n">RootObject</span>

<span class="n">ABSTRACT_ENTITY_FILTERS_EXCLUDE</span> <span class="o">=</span> <span class="p">[</span>
<span class="s2">&quot;rootobject_ptr&quot;</span><span class="p">,</span>
Expand Down Expand Up @@ -127,8 +130,25 @@ <h1>Source code for apis_core.apis_entities.filtersets</h1><div class="highlight
<div class="viewcode-block" id="related_entity">
<a class="viewcode-back" href="../../../modules/apis_core.apis_entities.html#apis_core.apis_entities.filtersets.related_entity">[docs]</a>
<span class="k">def</span> <span class="nf">related_entity</span><span class="p">(</span><span class="n">queryset</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="n">search_filter</span> <span class="o">=</span> <span class="n">generate_search_filter</span><span class="p">(</span><span class="n">queryset</span><span class="o">.</span><span class="n">model</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
<span class="k">return</span> <span class="n">queryset</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">search_filter</span><span class="p">)</span></div>
<span class="n">entities</span> <span class="o">=</span> <span class="n">get_entity_classes</span><span class="p">()</span>
<span class="n">q</span> <span class="o">=</span> <span class="n">Q</span><span class="p">()</span>
<span class="k">for</span> <span class="n">entity</span> <span class="ow">in</span> <span class="n">entities</span><span class="p">:</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">entity</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">model_name</span>
<span class="n">q</span> <span class="o">|=</span> <span class="n">Q</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">__isnull&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">})</span> <span class="o">&amp;</span> <span class="n">generate_search_filter</span><span class="p">(</span>
<span class="n">entity</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">__&quot;</span>
<span class="p">)</span>
<span class="n">all_entities</span> <span class="o">=</span> <span class="n">RootObject</span><span class="o">.</span><span class="n">objects_inheritance</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">q</span><span class="p">)</span><span class="o">.</span><span class="n">values_list</span><span class="p">(</span><span class="s2">&quot;pk&quot;</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">t</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">Triple</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">Q</span><span class="p">(</span><span class="n">subj__in</span><span class="o">=</span><span class="n">all_entities</span><span class="p">)</span> <span class="o">|</span> <span class="n">Q</span><span class="p">(</span><span class="n">obj__in</span><span class="o">=</span><span class="n">all_entities</span><span class="p">))</span>
<span class="o">.</span><span class="n">annotate</span><span class="p">(</span>
<span class="n">related</span><span class="o">=</span><span class="n">Case</span><span class="p">(</span>
<span class="n">When</span><span class="p">(</span><span class="n">subj__in</span><span class="o">=</span><span class="n">all_entities</span><span class="p">,</span> <span class="n">then</span><span class="o">=</span><span class="s2">&quot;obj&quot;</span><span class="p">),</span>
<span class="n">When</span><span class="p">(</span><span class="n">obj__in</span><span class="o">=</span><span class="n">all_entities</span><span class="p">,</span> <span class="n">then</span><span class="o">=</span><span class="s2">&quot;subj&quot;</span><span class="p">),</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="o">.</span><span class="n">values_list</span><span class="p">(</span><span class="s2">&quot;related&quot;</span><span class="p">,</span> <span class="n">flat</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">queryset</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">pk__in</span><span class="o">=</span><span class="n">t</span><span class="p">)</span></div>



Expand Down
8 changes: 6 additions & 2 deletions _modules/apis_core/generic/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ <h1>Source code for apis_core.generic.helpers</h1><div class="highlight"><pre>

<div class="viewcode-block" id="generate_search_filter">
<a class="viewcode-back" href="../../../modules/apis_core.generic.html#apis_core.generic.helpers.generate_search_filter">[docs]</a>
<span class="k">def</span> <span class="nf">generate_search_filter</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">fields_to_search</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">generate_search_filter</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">fields_to_search</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Generate a default search filter that searches for the `query`</span>
<span class="sd"> in all the CharFields and TextFields of a model (case-insensitive)</span>
<span class="sd"> or in the fields listed in the `fields_to_search` argument.</span>
<span class="sd"> This helper can be used by autocomplete querysets if nothing</span>
<span class="sd"> fancier is needed.</span>
<span class="sd"> If the `prefix` is set, the field names will be prefixed with that string -</span>
<span class="sd"> this can be useful if you want to use the `generate_search_filter` in a</span>
<span class="sd"> `Q` combined query while searching over multiple models.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">query</span> <span class="o">=</span> <span class="n">query</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>

Expand All @@ -128,7 +131,8 @@ <h1>Source code for apis_core.generic.helpers</h1><div class="highlight"><pre>

<span class="k">for</span> <span class="n">token</span> <span class="ow">in</span> <span class="n">query</span><span class="p">:</span>
<span class="n">q</span> <span class="o">&amp;=</span> <span class="n">functools</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span>
<span class="k">lambda</span> <span class="n">acc</span><span class="p">,</span> <span class="n">field_name</span><span class="p">:</span> <span class="n">acc</span> <span class="o">|</span> <span class="n">Q</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">field_name</span><span class="si">}</span><span class="s2">__icontains&quot;</span><span class="p">:</span> <span class="n">token</span><span class="p">}),</span>
<span class="k">lambda</span> <span class="n">acc</span><span class="p">,</span> <span class="n">field_name</span><span class="p">:</span> <span class="n">acc</span>
<span class="o">|</span> <span class="n">Q</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">prefix</span><span class="si">}{</span><span class="n">field_name</span><span class="si">}</span><span class="s2">__icontains&quot;</span><span class="p">:</span> <span class="n">token</span><span class="p">}),</span>
<span class="n">fields_to_search</span><span class="p">,</span>
<span class="n">Q</span><span class="p">(),</span>
<span class="p">)</span>
Expand Down
28 changes: 14 additions & 14 deletions htmlcov/class_index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4e153a9

Please sign in to comment.