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 17, 2024
1 parent eed14f5 commit e0f5c7f
Showing 185 changed files with 421 additions and 666 deletions.
82 changes: 0 additions & 82 deletions _modules/apis_core/utils/DateParser.html
Original file line number Diff line number Diff line change
@@ -359,88 +359,6 @@ <h1>Source code for apis_core.utils.DateParser</h1><div class="highlight"><pre>

<span class="k">return</span> <span class="n">date_single</span><span class="p">,</span> <span class="n">date_ab</span><span class="p">,</span> <span class="n">date_bis</span></div>



<div class="viewcode-block" id="get_date_help_text_from_dates">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.DateParser.get_date_help_text_from_dates">[docs]</a>
<span class="k">def</span> <span class="nf">get_date_help_text_from_dates</span><span class="p">(</span>
<span class="n">single_date</span><span class="p">,</span> <span class="n">single_start_date</span><span class="p">,</span> <span class="n">single_end_date</span><span class="p">,</span> <span class="n">single_date_written</span>
<span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> function for creating string help text from parsed dates, to provide feedback to the user</span>
<span class="sd"> about the parsing status of a given date field.</span>

<span class="sd"> :param single_date: datetime :</span>
<span class="sd"> the individual date point</span>
<span class="sd"> :param single_start_date: datetime :</span>
<span class="sd"> the start range of a date</span>
<span class="sd"> :param single_end_date: datetime :</span>
<span class="sd"> the endrange of a date</span>
<span class="sd"> :param single_date_written: str :</span>
<span class="sd"> the textual user entry of a date field (needed to check if empty or not)</span>
<span class="sd"> :return help_text: str :</span>
<span class="sd"> The text to be displayed underneath a date field, informing the user about the parsing result</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c1"># check which of the dates could be parsed to construct the relevant feedback text</span>
<span class="n">help_text</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">if</span> <span class="n">single_date</span><span class="p">:</span>
<span class="c1"># single date could be parsed</span>
<span class="n">help_text</span> <span class="o">=</span> <span class="s2">&quot;Date interpreted as &quot;</span>
<span class="k">if</span> <span class="n">single_start_date</span> <span class="ow">or</span> <span class="n">single_end_date</span><span class="p">:</span>
<span class="c1"># date has also start or end ranges, then ignore single date</span>
<span class="k">if</span> <span class="n">single_start_date</span><span class="p">:</span>
<span class="c1"># date has start range</span>
<span class="n">help_text</span> <span class="o">+=</span> <span class="p">(</span>
<span class="nb">str</span><span class="p">(</span><span class="n">single_start_date</span><span class="o">.</span><span class="n">year</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot;-&quot;</span>
<span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">single_start_date</span><span class="o">.</span><span class="n">month</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot;-&quot;</span>
<span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">single_start_date</span><span class="o">.</span><span class="n">day</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot; until &quot;</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># date has no start range, then write &quot;undefined&quot;</span>
<span class="n">help_text</span> <span class="o">+=</span> <span class="s2">&quot;undefined start until &quot;</span>
<span class="k">if</span> <span class="n">single_end_date</span><span class="p">:</span>
<span class="c1"># date has end range</span>
<span class="n">help_text</span> <span class="o">+=</span> <span class="p">(</span>
<span class="nb">str</span><span class="p">(</span><span class="n">single_end_date</span><span class="o">.</span><span class="n">year</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot;-&quot;</span>
<span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">single_end_date</span><span class="o">.</span><span class="n">month</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot;-&quot;</span>
<span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">single_end_date</span><span class="o">.</span><span class="n">day</span><span class="p">)</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># date has no start range, then write &quot;undefined&quot;</span>
<span class="n">help_text</span> <span class="o">+=</span> <span class="s2">&quot;undefined end&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># date has no start nor end range. Use single date then.</span>
<span class="n">help_text</span> <span class="o">+=</span> <span class="p">(</span>
<span class="nb">str</span><span class="p">(</span><span class="n">single_date</span><span class="o">.</span><span class="n">year</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot;-&quot;</span>
<span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">single_date</span><span class="o">.</span><span class="n">month</span><span class="p">)</span>
<span class="o">+</span> <span class="s2">&quot;-&quot;</span>
<span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">single_date</span><span class="o">.</span><span class="n">day</span><span class="p">)</span>
<span class="p">)</span>
<span class="k">elif</span> <span class="n">single_date_written</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># date input field is not empty but it could not be parsed either. Show parsing info and help text</span>
<span class="n">help_text</span> <span class="o">=</span> <span class="p">(</span>
<span class="s2">&quot;&lt;b&gt;Date could not be interpreted&lt;/b&gt;&lt;br&gt;&quot;</span> <span class="o">+</span> <span class="n">get_date_help_text_default</span><span class="p">()</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># date field is completely empty. Show help text only</span>
<span class="n">help_text</span> <span class="o">=</span> <span class="n">get_date_help_text_default</span><span class="p">()</span>

<span class="k">return</span> <span class="n">help_text</span></div>



<div class="viewcode-block" id="get_date_help_text_default">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.DateParser.get_date_help_text_default">[docs]</a>
<span class="k">def</span> <span class="nf">get_date_help_text_default</span><span class="p">():</span>
<span class="k">return</span> <span class="s2">&quot;Dates are interpreted by defined rules. If this fails, an iso-date can be explicitly set with &#39;&amp;lt;YYYY-MM-DD&amp;gt;&#39;.&quot;</span></div>

</pre></div>

</div>
19 changes: 4 additions & 15 deletions _modules/apis_core/utils/test_DateParser.html
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ <h1>Source code for apis_core.utils.test_DateParser</h1><div class="highlight"><

<span class="kn">from</span> <span class="nn">django.test</span> <span class="kn">import</span> <span class="n">TestCase</span>

<span class="kn">from</span> <span class="nn">.DateParser</span> <span class="kn">import</span> <span class="n">get_date_help_text_from_dates</span><span class="p">,</span> <span class="n">parse_date</span>
<span class="kn">from</span> <span class="nn">.DateParser</span> <span class="kn">import</span> <span class="n">parse_date</span>

<span class="n">help_text_default</span> <span class="o">=</span> <span class="s2">&quot;Dates are interpreted by defined rules. If this fails, an iso-date can be explicitly set with &#39;&amp;lt;YYYY-MM-DD&amp;gt;&#39;.&quot;</span>

@@ -102,26 +102,23 @@ <h1>Source code for apis_core.utils.test_DateParser</h1><div class="highlight"><


<span class="c1"># a dict of dates with the written date as key</span>
<span class="c1"># followed by a tuple of (single, start, end, help_text)</span>
<span class="c1"># followed by a tuple of (single, start, end)</span>
<span class="n">dates</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;vor dem 23.10.1449 &lt;1449-10-23&gt;&quot;</span><span class="p">:</span> <span class="p">(</span>
<span class="n">fi</span><span class="p">(</span><span class="s2">&quot;1449-10-23&quot;</span><span class="p">),</span>
<span class="kc">None</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="s2">&quot;Date interpreted as 1449-10-23&quot;</span><span class="p">,</span>
<span class="p">),</span>
<span class="s2">&quot;1459-12&quot;</span><span class="p">:</span> <span class="p">(</span>
<span class="n">fi</span><span class="p">(</span><span class="s2">&quot;1459-12-16&quot;</span><span class="p">),</span>
<span class="n">fi</span><span class="p">(</span><span class="s2">&quot;1459-12-01&quot;</span><span class="p">),</span>
<span class="n">fi</span><span class="p">(</span><span class="s2">&quot;1459-12-31&quot;</span><span class="p">),</span>
<span class="s2">&quot;Date interpreted as 1459-12-1 until 1459-12-31&quot;</span><span class="p">,</span>
<span class="p">),</span>
<span class="s2">&quot;1460-03-30&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">fi</span><span class="p">(</span><span class="s2">&quot;1460-03-30&quot;</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;Date interpreted as 1460-3-30&quot;</span><span class="p">),</span>
<span class="s2">&quot;1460-03-30&quot;</span><span class="p">:</span> <span class="p">(</span><span class="n">fi</span><span class="p">(</span><span class="s2">&quot;1460-03-30&quot;</span><span class="p">),</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">),</span>
<span class="s2">&quot;&quot;</span><span class="p">:</span> <span class="p">(</span>
<span class="kc">None</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="kc">None</span><span class="p">,</span>
<span class="s2">&quot;&lt;b&gt;Date could not be interpreted&lt;/b&gt;&lt;br&gt;&quot;</span> <span class="o">+</span> <span class="n">help_text_default</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">}</span>

@@ -132,19 +129,11 @@ <h1>Source code for apis_core.utils.test_DateParser</h1><div class="highlight"><
<div class="viewcode-block" id="DateParserTest.test_dates">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.test_DateParser.DateParserTest.test_dates">[docs]</a>
<span class="k">def</span> <span class="nf">test_dates</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">for</span> <span class="n">datestring</span><span class="p">,</span> <span class="p">(</span><span class="n">expsingle</span><span class="p">,</span> <span class="n">expstart</span><span class="p">,</span> <span class="n">expend</span><span class="p">,</span> <span class="n">help_text</span><span class="p">)</span> <span class="ow">in</span> <span class="n">dates</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">for</span> <span class="n">datestring</span><span class="p">,</span> <span class="p">(</span><span class="n">expsingle</span><span class="p">,</span> <span class="n">expstart</span><span class="p">,</span> <span class="n">expend</span><span class="p">)</span> <span class="ow">in</span> <span class="n">dates</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">single</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span> <span class="o">=</span> <span class="n">parse_date</span><span class="p">(</span><span class="n">datestring</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">expsingle</span><span class="p">,</span> <span class="n">single</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">expstart</span><span class="p">,</span> <span class="n">start</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">expend</span><span class="p">,</span> <span class="n">end</span><span class="p">)</span></div>


<div class="viewcode-block" id="DateParserTest.test_help_text">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.test_DateParser.DateParserTest.test_help_text">[docs]</a>
<span class="k">def</span> <span class="nf">test_help_text</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">for</span> <span class="n">datestring</span><span class="p">,</span> <span class="p">(</span><span class="n">single</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">exp_help_text</span><span class="p">)</span> <span class="ow">in</span> <span class="n">dates</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">help_text</span> <span class="o">=</span> <span class="n">get_date_help_text_from_dates</span><span class="p">(</span><span class="n">single</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">datestring</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">exp_help_text</span><span class="p">,</span> <span class="n">help_text</span><span class="p">)</span></div>
</div>

</pre></div>
10 changes: 2 additions & 8 deletions genindex.html
Original file line number Diff line number Diff line change
@@ -1691,10 +1691,6 @@ <h2 id="G">G</h2>
<li><a href="modules/apis_core.generic.html#apis_core.generic.importers.GenericModelImporter.get_data">get_data() (apis_core.generic.importers.GenericModelImporter method)</a>
</li>
<li><a href="modules/apis_core.history.html#apis_core.history.serializers.ModelChangeSerializer.get_data_for_m2m_field">get_data_for_m2m_field() (apis_core.history.serializers.ModelChangeSerializer method)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.DateParser.get_date_help_text_default">get_date_help_text_default() (in module apis_core.utils.DateParser)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.DateParser.get_date_help_text_from_dates">get_date_help_text_from_dates() (in module apis_core.utils.DateParser)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.rdf.get_definition_and_attributes_from_uri">get_definition_and_attributes_from_uri() (in module apis_core.utils.rdf)</a>
</li>
@@ -1720,10 +1716,10 @@ <h2 id="G">G</h2>
</li>
<li><a href="modules/apis_core.apis_entities.html#apis_core.apis_entities.models.AbstractEntity.get_entity_list_filter">get_entity_list_filter() (apis_core.apis_entities.models.AbstractEntity class method)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="modules/apis_core.utils.html#apis_core.utils.settings.get_entity_settings_by_modelname">get_entity_settings_by_modelname() (in module apis_core.utils.settings)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="modules/apis_core.history.html#apis_core.history.serializers.ModelChangeSerializer.get_field_data">get_field_data() (apis_core.history.serializers.ModelChangeSerializer method)</a>
</li>
<li><a href="modules/apis_core.history.html#apis_core.history.serializers.ModelChangeSerializer.get_field_data_new">get_field_data_new() (apis_core.history.serializers.ModelChangeSerializer method)</a>
@@ -3012,8 +3008,6 @@ <h2 id="T">T</h2>
<li><a href="modules/apis_core.utils.html#apis_core.utils.test_rdf.RdfTest.test_get_definition_from_dict_place_from_dnb">test_get_definition_from_dict_place_from_dnb() (apis_core.utils.test_rdf.RdfTest method)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.test_rdf.RdfTest.test_get_definition_from_dict_place_from_geonames">test_get_definition_from_dict_place_from_geonames() (apis_core.utils.test_rdf.RdfTest method)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.test_DateParser.DateParserTest.test_help_text">test_help_text() (apis_core.utils.test_DateParser.DateParserTest method)</a>
</li>
<li><a href="modules/apis_core.utils.html#apis_core.utils.test_helpers.FilterMethodstest.test_lookup">test_lookup() (apis_core.utils.test_helpers.FilterMethodstest method)</a>
</li>
Loading

0 comments on commit e0f5c7f

Please sign in to comment.