Commit 6610b84e authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

cours 5 ok

parent e6483324
......@@ -127,19 +127,21 @@ $ pipenv install</code></pre>
<section><section id="créer" class="title-slide slide level1"><h1>Créer</h1></section><section id="parefeu" class="slide level2">
<h2>Parefeu</h2>
<h3 id="webuiviews.py">webui/views.py</h3>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb3-1" title="1"><span class="kw">class</span> ParefeuCreate(CreateView):</a>
<a class="sourceLine" id="cb3-2" title="2"> model <span class="op">=</span> Parefeu</a>
<a class="sourceLine" id="cb3-3" title="3"> fields <span class="op">=</span> [<span class="st">&#39;nom&#39;</span>, <span class="st">&#39;modele&#39;</span>]</a>
<a class="sourceLine" id="cb3-4" title="4"> template_name <span class="op">=</span> <span class="st">&quot;webui/object_create.html&quot;</span></a>
<a class="sourceLine" id="cb3-5" title="5"></a>
<a class="sourceLine" id="cb3-6" title="6"> <span class="kw">def</span> get_context_data(<span class="va">self</span>, <span class="op">**</span>kwargs):</a>
<a class="sourceLine" id="cb3-7" title="7"> context <span class="op">=</span> <span class="bu">super</span>().get_context_data(<span class="op">**</span>kwargs)</a>
<a class="sourceLine" id="cb3-8" title="8"> context[<span class="st">&#39;menu_parefeu&#39;</span>] <span class="op">=</span> <span class="st">&#39;active&#39;</span></a>
<a class="sourceLine" id="cb3-9" title="9"> <span class="cf">return</span> context</a>
<a class="sourceLine" id="cb3-10" title="10"></a>
<a class="sourceLine" id="cb3-11" title="11"> <span class="kw">def</span> form_valid(<span class="va">self</span>, form):</a>
<a class="sourceLine" id="cb3-12" title="12"> form.instance.admin <span class="op">=</span> <span class="va">self</span>.request.user</a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="cf">return</span> <span class="bu">super</span>(ParefeuCreate, <span class="va">self</span>).form_valid(form)</a></code></pre></div>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb3-1" title="1"><span class="im">from</span> django.views.generic.edit <span class="im">import</span> CreateView</a>
<a class="sourceLine" id="cb3-2" title="2"></a>
<a class="sourceLine" id="cb3-3" title="3"><span class="kw">class</span> ParefeuCreate(CreateView):</a>
<a class="sourceLine" id="cb3-4" title="4"> model <span class="op">=</span> Parefeu</a>
<a class="sourceLine" id="cb3-5" title="5"> fields <span class="op">=</span> [<span class="st">&#39;nom&#39;</span>, <span class="st">&#39;modele&#39;</span>]</a>
<a class="sourceLine" id="cb3-6" title="6"> template_name <span class="op">=</span> <span class="st">&quot;webui/object_create.html&quot;</span></a>
<a class="sourceLine" id="cb3-7" title="7"></a>
<a class="sourceLine" id="cb3-8" title="8"> <span class="kw">def</span> get_context_data(<span class="va">self</span>, <span class="op">**</span>kwargs):</a>
<a class="sourceLine" id="cb3-9" title="9"> context <span class="op">=</span> <span class="bu">super</span>().get_context_data(<span class="op">**</span>kwargs)</a>
<a class="sourceLine" id="cb3-10" title="10"> context[<span class="st">&#39;menu_parefeu&#39;</span>] <span class="op">=</span> <span class="st">&#39;active&#39;</span></a>
<a class="sourceLine" id="cb3-11" title="11"> <span class="cf">return</span> context</a>
<a class="sourceLine" id="cb3-12" title="12"></a>
<a class="sourceLine" id="cb3-13" title="13"> <span class="kw">def</span> form_valid(<span class="va">self</span>, form):</a>
<a class="sourceLine" id="cb3-14" title="14"> form.instance.admin <span class="op">=</span> <span class="va">self</span>.request.user</a>
<a class="sourceLine" id="cb3-15" title="15"> <span class="cf">return</span> <span class="bu">super</span>(ParefeuCreate, <span class="va">self</span>).form_valid(form)</a></code></pre></div>
</section><section id="parefeu-1" class="slide level2">
<h2>Parefeu</h2>
<h3 id="webuitemplateswebuiobject_create.html">webui/templates/webui/object_create.html</h3>
......
......@@ -32,6 +32,8 @@ $ pipenv install
## Parefeu
### webui/views.py
~~~python
from django.views.generic.edit import CreateView
class ParefeuCreate(CreateView):
model = Parefeu
fields = ['nom', 'modele']
......
No preview for this file type
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