Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 11, 2023
1 parent 9ab36fc commit 2b71065
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 4 deletions.
3 changes: 2 additions & 1 deletion _modules/apis_core/urls.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ <h1>Source code for apis_core.urls</h1><div class="highlight"><pre>
<span class="c1"># from apis_core.apis_vocabularies.api_views import UserViewSet</span>
<span class="kn">from</span> <span class="nn">apis_core.utils</span> <span class="kn">import</span> <span class="n">caching</span>
<span class="kn">from</span> <span class="nn">apis_core.apis_metainfo.viewsets</span> <span class="kn">import</span> <span class="n">UriToObjectViewSet</span>
<span class="kn">from</span> <span class="nn">apis_core.core.views</span> <span class="kn">import</span> <span class="n">Dumpdata</span>

<span class="n">app_name</span> <span class="o">=</span> <span class="s2">&quot;apis_core&quot;</span>

Expand Down Expand Up @@ -193,7 +194,6 @@ <h1>Source code for apis_core.urls</h1><div class="highlight"><pre>

<span class="kn">from</span> <span class="nn">apis_core.apis_entities.api_views</span> <span class="kn">import</span> <span class="n">GetEntityGeneric</span>


<span class="n">urlpatterns</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">TemplateView</span><span class="o">.</span><span class="n">as_view</span><span class="p">(</span><span class="n">template_name</span><span class="o">=</span><span class="s2">&quot;base.html&quot;</span><span class="p">),</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;apis_index&quot;</span><span class="p">),</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;admin/&quot;</span><span class="p">,</span> <span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">urls</span><span class="p">),</span>
Expand Down Expand Up @@ -258,6 +258,7 @@ <h1>Source code for apis_core.urls</h1><div class="highlight"><pre>
<span class="n">GetEntityGeneric</span><span class="o">.</span><span class="n">as_view</span><span class="p">(),</span>
<span class="n">name</span><span class="o">=</span><span class="s2">&quot;GetEntityGeneric&quot;</span><span class="p">,</span>
<span class="p">),</span>
<span class="n">path</span><span class="p">(</span><span class="s2">&quot;api/dumpdata&quot;</span><span class="p">,</span> <span class="n">Dumpdata</span><span class="o">.</span><span class="n">as_view</span><span class="p">()),</span>
<span class="p">]</span>

<span class="k">if</span> <span class="s2">&quot;apis_fulltext_download&quot;</span> <span class="ow">in</span> <span class="n">settings</span><span class="o">.</span><span class="n">INSTALLED_APPS</span><span class="p">:</span>
Expand Down
66 changes: 66 additions & 0 deletions _modules/apis_core/utils/helpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ <h1>Source code for apis_core.utils.helpers</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">apis_core.apis_entities.models</span> <span class="kn">import</span> <span class="n">TempEntityClass</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">django.apps</span> <span class="kn">import</span> <span class="n">apps</span>
<span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">DEFAULT_DB_ALIAS</span><span class="p">,</span> <span class="n">router</span>
<span class="kn">from</span> <span class="nn">django.contrib.contenttypes.models</span> <span class="kn">import</span> <span class="n">ContentType</span>
<span class="kn">from</span> <span class="nn">django.core</span> <span class="kn">import</span> <span class="n">serializers</span>


<div class="viewcode-block" id="get_classes_with_allowed_relation_from">
Expand Down Expand Up @@ -170,6 +173,69 @@ <h1>Source code for apis_core.utils.helpers</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">members</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
<span class="k">return</span> <span class="kc">None</span></div>



<div class="viewcode-block" id="datadump_get_objects">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.helpers.datadump_get_objects">[docs]</a>
<span class="k">def</span> <span class="nf">datadump_get_objects</span><span class="p">(</span><span class="n">models</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="p">[],</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">models</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">proxy</span> <span class="ow">and</span> <span class="n">router</span><span class="o">.</span><span class="n">allow_migrate_model</span><span class="p">(</span>
<span class="n">DEFAULT_DB_ALIAS</span><span class="p">,</span> <span class="n">model</span>
<span class="p">):</span>
<span class="n">objects</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">_default_manager</span>
<span class="n">queryset</span> <span class="o">=</span> <span class="n">objects</span><span class="o">.</span><span class="n">using</span><span class="p">(</span><span class="n">DEFAULT_DB_ALIAS</span><span class="p">)</span><span class="o">.</span><span class="n">order_by</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">pk</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">yield from</span> <span class="n">queryset</span><span class="o">.</span><span class="n">iterator</span><span class="p">()</span></div>



<div class="viewcode-block" id="datadump_get_queryset">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.helpers.datadump_get_queryset">[docs]</a>
<span class="k">def</span> <span class="nf">datadump_get_queryset</span><span class="p">(</span><span class="n">additional_app_labels</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="p">[]):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> This method is loosely based on the `dumpdata` admin command.</span>
<span class="sd"> It iterates throug the relevant app models and exports them using</span>
<span class="sd"> a serializer and natural foreign keys.</span>
<span class="sd"> Data exported this way can be reimported into a newly created Django APIS app</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c1"># get all APIS apps and all APIS models</span>
<span class="n">apis_app_labels</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;apis_relations&quot;</span><span class="p">,</span> <span class="s2">&quot;apis_metainfo&quot;</span><span class="p">]</span>
<span class="n">apis_app_models</span> <span class="o">=</span> <span class="p">[</span>
<span class="n">model</span> <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">apps</span><span class="o">.</span><span class="n">get_models</span><span class="p">()</span> <span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">app_label</span> <span class="ow">in</span> <span class="n">apis_app_labels</span>
<span class="p">]</span>

<span class="c1"># create a list of app labels we want to iterate</span>
<span class="c1"># this allows to extend the apps via the ?app_labels= parameter</span>
<span class="n">app_labels</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">apis_app_labels</span><span class="p">)</span>
<span class="n">app_labels</span> <span class="o">|=</span> <span class="nb">set</span><span class="p">(</span><span class="n">additional_app_labels</span><span class="p">)</span>

<span class="c1"># look for models that inherit from APIS models and add their</span>
<span class="c1"># app label to app_labels</span>
<span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="n">apps</span><span class="o">.</span><span class="n">get_models</span><span class="p">():</span>
<span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">x</span><span class="p">),</span> <span class="n">apis_app_models</span><span class="p">)):</span>
<span class="n">app_labels</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">app_label</span><span class="p">)</span>

<span class="c1"># now go through all app labels</span>
<span class="n">app_list</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">app_label</span> <span class="ow">in</span> <span class="n">app_labels</span><span class="p">:</span>
<span class="n">app_config</span> <span class="o">=</span> <span class="n">apps</span><span class="o">.</span><span class="n">get_app_config</span><span class="p">(</span><span class="n">app_label</span><span class="p">)</span>
<span class="n">app_list</span><span class="p">[</span><span class="n">app_config</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>

<span class="n">models</span> <span class="o">=</span> <span class="n">serializers</span><span class="o">.</span><span class="n">sort_dependencies</span><span class="p">(</span><span class="n">app_list</span><span class="o">.</span><span class="n">items</span><span class="p">(),</span> <span class="n">allow_cycles</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

<span class="k">yield from</span> <span class="n">datadump_get_objects</span><span class="p">(</span><span class="n">models</span><span class="p">)</span></div>



<div class="viewcode-block" id="datadump_serializer">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.helpers.datadump_serializer">[docs]</a>
<span class="k">def</span> <span class="nf">datadump_serializer</span><span class="p">(</span><span class="n">additional_app_labels</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="p">[],</span> <span class="n">serialier_format</span><span class="o">=</span><span class="s2">&quot;json&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="n">serializers</span><span class="o">.</span><span class="n">serialize</span><span class="p">(</span>
<span class="n">serialier_format</span><span class="p">,</span>
<span class="n">datadump_get_queryset</span><span class="p">(</span><span class="n">additional_app_labels</span><span class="p">),</span>
<span class="n">use_natural_foreign_keys</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="p">)</span></div>

</pre></div>

</div>
Expand Down
10 changes: 8 additions & 2 deletions genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,12 @@ <h2 id="C">C</h2>
<h2 id="D">D</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="modules/apis_core.utils.html#apis_core.utils.helpers.datadump_get_objects">datadump_get_objects() (in module apis_core.utils.helpers)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.helpers.datadump_get_queryset">datadump_get_queryset() (in module apis_core.utils.helpers)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.helpers.datadump_serializer">datadump_serializer() (in module apis_core.utils.helpers)</a>
</li>
<li><a href="modules/apis_core.default_settings.html#apis_core.default_settings.NER_settings.date_conversion">date_conversion() (in module apis_core.default_settings.NER_settings)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.test_DateParser.DateParserTest">DateParserTest (class in apis_core.utils.test_DateParser)</a>
Expand Down Expand Up @@ -1064,6 +1070,8 @@ <h2 id="D">D</h2>
</ul></li>
<li><a href="modules/apis_core.html#apis_core.api_routers.deep_get">deep_get() (in module apis_core.api_routers)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="modules/apis_core.apis_labels.html#apis_core.apis_labels.apps.LabelsConfig.default_auto_field">default_auto_field (apis_core.apis_labels.apps.LabelsConfig attribute)</a>

<ul>
Expand All @@ -1074,8 +1082,6 @@ <h2 id="D">D</h2>
<li><a href="modules/apis_core.apis_vocabularies.html#apis_core.apis_vocabularies.apps.VocabulariesConfig.default_auto_field">(apis_core.apis_vocabularies.apps.VocabulariesConfig attribute)</a>
</li>
</ul></li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="modules/apis_core.utils.html#apis_core.utils.settings.default_settings">default_settings() (in module apis_core.utils.settings)</a>
</li>
<li><a href="modules/apis_core.apis_metainfo.html#apis_core.apis_metainfo.models.Collection.description">description (apis_core.apis_metainfo.models.Collection attribute)</a>
Expand Down
3 changes: 3 additions & 0 deletions modules/apis_core.html
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,9 @@ <h2>Subpackages<a class="headerlink" href="#subpackages" title="Link to this hea
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="apis_core.utils.html#module-apis_core.utils.helpers">apis_core.utils.helpers module</a><ul>
<li class="toctree-l3"><a class="reference internal" href="apis_core.utils.html#apis_core.utils.helpers.datadump_get_objects"><code class="docutils literal notranslate"><span class="pre">datadump_get_objects()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="apis_core.utils.html#apis_core.utils.helpers.datadump_get_queryset"><code class="docutils literal notranslate"><span class="pre">datadump_get_queryset()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="apis_core.utils.html#apis_core.utils.helpers.datadump_serializer"><code class="docutils literal notranslate"><span class="pre">datadump_serializer()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="apis_core.utils.html#apis_core.utils.helpers.get_classes_with_allowed_relation_from"><code class="docutils literal notranslate"><span class="pre">get_classes_with_allowed_relation_from()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="apis_core.utils.html#apis_core.utils.helpers.get_member_for_entity"><code class="docutils literal notranslate"><span class="pre">get_member_for_entity()</span></code></a></li>
</ul>
Expand Down
Loading

0 comments on commit 2b71065

Please sign in to comment.