Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Apr 2, 2024
1 parent 660cccc commit ff03512
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions _modules/apis_core/generic/forms/fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
<div itemprop="articleBody">

<h1>Source code for apis_core.generic.forms.fields</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">django.forms</span> <span class="kn">import</span> <span class="n">ModelChoiceField</span>
<span></span><span class="kn">from</span> <span class="nn">django.core.exceptions</span> <span class="kn">import</span> <span class="n">ValidationError</span>
<span class="kn">from</span> <span class="nn">django.forms</span> <span class="kn">import</span> <span class="n">ModelChoiceField</span>
<span class="kn">from</span> <span class="nn">django.utils.translation</span> <span class="kn">import</span> <span class="n">gettext</span> <span class="k">as</span> <span class="n">_</span>
<span class="kn">from</span> <span class="nn">apis_core.utils.helpers</span> <span class="kn">import</span> <span class="n">create_object_from_uri</span>


Expand All @@ -101,10 +103,15 @@ <h1>Source code for apis_core.generic.forms.fields</h1><div class="highlight"><p
<div class="viewcode-block" id="ModelImportChoiceField.to_python">
<a class="viewcode-back" href="../../../../modules/apis_core.generic.forms.html#apis_core.generic.forms.fields.ModelImportChoiceField.to_python">[docs]</a>
<span class="k">def</span> <span class="nf">to_python</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">create_object_from_uri</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">queryset</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
<span class="k">if</span> <span class="n">result</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">result</span>
<span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">to_python</span><span class="p">(</span><span class="n">value</span><span class="p">)</span></div>
<span class="n">result</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">create_object_from_uri</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">queryset</span><span class="o">.</span><span class="n">model</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">ValidationError</span><span class="p">(</span>
<span class="n">_</span><span class="p">(</span><span class="s2">&quot;Could not import </span><span class="si">%(value)s</span><span class="s2">: </span><span class="si">%(exception)s</span><span class="s2">&quot;</span><span class="p">),</span>
<span class="n">params</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;value&quot;</span><span class="p">:</span> <span class="n">value</span><span class="p">,</span> <span class="s2">&quot;exception&quot;</span><span class="p">:</span> <span class="n">e</span><span class="p">},</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">result</span> <span class="ow">or</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">to_python</span><span class="p">(</span><span class="n">value</span><span class="p">)</span></div>
</div>

</pre></div>
Expand Down

0 comments on commit ff03512

Please sign in to comment.