Commit 692456a0 authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

cours 4 ok

parent 715d8783
......@@ -310,14 +310,13 @@ $ pipenv install</code></pre>
<li>en production, envoi des messages d’erreurs</li>
<li>différents des Users ‘superadmins’</li>
</ul>
<h3 id="confsettings.py-1">conf/settings.py</h3>
<div class="sourceCode" id="cb18"><pre class="sourceCode numberSource py numberLines"><code class="sourceCode python"><a class="sourceLine" id="cb18-1" title="1">ADMINS <span class="op">=</span> [(<span class="st">&#39;Admin&#39;</span>, <span class="st">&#39;ad@min.fr&#39;</span>), ]</a></code></pre></div>
</section><section id="envoi-de-mails-1" class="slide level2">
<h2>Envoi de mails</h2>
<h3 id="confsettings.py-2">conf/settings.py</h3>
<div class="sourceCode" id="cb19"><pre class="sourceCode numberSource py numberLines"><code class="sourceCode python"><a class="sourceLine" id="cb19-1" title="1">EMAIL_HOST <span class="op">=</span> <span class="st">&quot;127.0.0.1&quot;</span> </a>
<a class="sourceLine" id="cb19-2" title="2">EMAIL_PORT <span class="op">=</span> <span class="dv">2525</span></a>
<a class="sourceLine" id="cb19-3" title="3">SERVER_EMAIL <span class="op">=</span> <span class="st">&#39;noreply@insa-rouen.fr&#39;</span></a></code></pre></div>
<h3 id="confsettings.py-1">conf/settings.py</h3>
<div class="sourceCode" id="cb18"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb18-1" title="1">ADMINS <span class="op">=</span> [(<span class="st">&#39;Admin&#39;</span>, <span class="st">&#39;ad@min.fr&#39;</span>), ]</a>
<a class="sourceLine" id="cb18-2" title="2">EMAIL_HOST <span class="op">=</span> <span class="st">&quot;127.0.0.1&quot;</span> </a>
<a class="sourceLine" id="cb18-3" title="3">EMAIL_PORT <span class="op">=</span> <span class="dv">2525</span></a>
<a class="sourceLine" id="cb18-4" title="4">SERVER_EMAIL <span class="op">=</span> <span class="st">&#39;noreply@insa-rouen.fr&#39;</span></a></code></pre></div>
<h3 id="un-faux-serveur-smtp">un faux serveur smtp</h3>
<pre><code>$ pipenv run ./manage.py help mail_debug
$ pipenv run ./manage.py mail_debug --use-settings</code></pre>
......@@ -350,16 +349,16 @@ $ pipenv run ./manage.py mail_debug --use-settings</code></pre>
</section><section id="mise-en-place" class="slide level2">
<h2>Mise en place</h2>
<h3 id="webuiviews.py-4">webui/views.py</h3>
<div class="sourceCode" id="cb21"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb21-1" title="1"><span class="im">from</span> django.contrib <span class="im">import</span> messages</a>
<a class="sourceLine" id="cb21-2" title="2"></a>
<a class="sourceLine" id="cb21-3" title="3"><span class="kw">class</span> ContactView(FormView):</a>
<a class="sourceLine" id="cb21-4" title="4">...</a>
<a class="sourceLine" id="cb21-5" title="5"> <span class="kw">def</span> form_valid(<span class="va">self</span>, form):</a>
<a class="sourceLine" id="cb21-6" title="6"> <span class="cf">if</span> form.send_email():</a>
<a class="sourceLine" id="cb21-7" title="7"> messages.success(<span class="va">self</span>.request, <span class="st">&quot;La demande a été transmise&quot;</span>)</a>
<a class="sourceLine" id="cb21-8" title="8"> <span class="cf">else</span>:</a>
<a class="sourceLine" id="cb21-9" title="9"> messages.warning(<span class="va">self</span>.request, <span class="st">&quot;La demande n&#39;a pu être transmise&quot;</span>)</a>
<a class="sourceLine" id="cb21-10" title="10"> <span class="cf">return</span> <span class="bu">super</span>().form_valid(form)</a></code></pre></div>
<div class="sourceCode" id="cb20"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb20-1" title="1"><span class="im">from</span> django.contrib <span class="im">import</span> messages</a>
<a class="sourceLine" id="cb20-2" title="2"></a>
<a class="sourceLine" id="cb20-3" title="3"><span class="kw">class</span> ContactView(FormView):</a>
<a class="sourceLine" id="cb20-4" title="4">...</a>
<a class="sourceLine" id="cb20-5" title="5"> <span class="kw">def</span> form_valid(<span class="va">self</span>, form):</a>
<a class="sourceLine" id="cb20-6" title="6"> <span class="cf">if</span> form.send_email():</a>
<a class="sourceLine" id="cb20-7" title="7"> messages.success(<span class="va">self</span>.request, <span class="st">&quot;La demande a été transmise&quot;</span>)</a>
<a class="sourceLine" id="cb20-8" title="8"> <span class="cf">else</span>:</a>
<a class="sourceLine" id="cb20-9" title="9"> messages.warning(<span class="va">self</span>.request, <span class="st">&quot;La demande n&#39;a pu être transmise&quot;</span>)</a>
<a class="sourceLine" id="cb20-10" title="10"> <span class="cf">return</span> <span class="bu">super</span>().form_valid(form)</a></code></pre></div>
</section><section id="mise-en-place-1" class="slide level2">
<h2>Mise en place</h2>
<h3 id="webuitemplateswebuihome.html-3">webui/templates/webui/home.html</h3>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment