cours4.html 27.3 KB
Newer Older
Bonnegent Sebastien's avatar
Bonnegent Sebastien committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="generator" content="pandoc">
  <meta name="author" content="Sébastien Bonnegent">
  <title>Django par la pratique 4/7</title>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
  <link rel="stylesheet" href="./reveal.js/css/reveal.css">
  <style type="text/css">
      code{white-space: pre-wrap;}
      span.smallcaps{font-variant: small-caps;}
      span.underline{text-decoration: underline;}
      div.column{display: inline-block; vertical-align: top; width: 50%;}
  </style>
  <style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
  { position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
  { content: attr(title);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; pointer-events: all; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
  </style>
  <link rel="stylesheet" href="./reveal.js/css/theme/beige.css" id="theme">
  <!-- Printing and PDF exports -->
  <script>
    var link = document.createElement( 'link' );
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = window.location.search.match( /print-pdf/gi ) ? './reveal.js/css/print/pdf.css' : './reveal.js/css/print/paper.css';
    document.getElementsByTagName( 'head' )[0].appendChild( link );
  </script>
  <!--[if lt IE 9]>
  <script src="./reveal.js/lib/js/html5shiv.js"></script>
  <![endif]-->
</head>
<body>
  <div class="reveal">
    <div class="slides">

<section id="title-slide">
  <h1 class="title">Django par la pratique 4/7</h1>
  <p class="author">Sébastien Bonnegent</p>
</section>

<section><section id="départ" class="title-slide slide level1"><h1>Départ</h1></section><section id="support" class="slide level2">
<h2>Support</h2>
<ul>
<li>cours4.html</li>
</ul>
</section><section id="préparation" class="slide level2">
<h2>Préparation</h2>
<h3 id="lancien">L’ancien</h3>
<pre><code>$ cd fwm3
$ pipenv --rm</code></pre>
<h3 id="le-nouveau">Le nouveau</h3>
<pre><code>$ cd fwm4
$ pipenv install</code></pre>
</section><section id="au-programme" class="slide level2">
<h2>Au programme</h2>
<ul>
<li>rappel sur les fichiers</li>
<li>authentification, limitation d’accès</li>
<li>vue liste générique (Parefeu)</li>
<li>vue détail générique (Parefeu)</li>
<li>envoi de mails</li>
<li>formulaire simple (contact)</li>
<li>messages</li>
</ul>
</section></section>
<section><section id="rappel" class="title-slide slide level1"><h1>Rappel</h1></section><section id="rôle-de-chaque-fichier" class="slide level2">
<h2>Rôle de chaque fichier</h2>
<ul>
<li>./manage.py: contrôles et commandes</li>
<li>./db.sqlite3: base de données</li>
<li>Pipfile: dépendances primaires</li>
<li>Pipfile.lock: toutes les dépendances</li>
</ul>
</section><section id="rôle-de-chaque-fichier-1" class="slide level2">
<h2>Rôle de chaque fichier</h2>
<ul>
<li>conf/settings.py: configuration</li>
<li>conf/urls.py: routage des URI</li>
<li>conf/wsgi.py: pour la production</li>
</ul>
</section><section id="rôle-de-chaque-fichier-2" class="slide level2">
<h2>Rôle de chaque fichier</h2>
<ul>
<li>webui/views.py: manipulations des objets</li>
<li>webui/forms.py: formulaires</li>
<li>webui/admin.py: administration</li>
<li>webui/templates/: préparation de l’affichage</li>
<li>webui/migrations/: évolution de la BD</li>
<li>webui/tests.py: les tests</li>
<li>webui/models.py: les modèles</li>
</ul>
</section></section>
<section><section id="authentification" class="title-slide slide level1"><h1>Authentification</h1></section><section id="à-modifier" class="slide level2">
<h2>à modifier</h2>
<h3 id="webuitemplateswebuihome.html">webui/templates/webui/home.html</h3>
<pre><code>{% if user.is_authenticated %}
...
    {% if user.is_staff %}
    ...
    {% endif %}
{% endif %}</code></pre>
<h3 id="confurls.py">conf/urls.py</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb4-1" title="1"><span class="im">from</span> django.contrib.auth.decorators <span class="im">import</span> login_required</a>
<a class="sourceLine" id="cb4-2" title="2"><span class="co"># ...</span></a>
<a class="sourceLine" id="cb4-3" title="3">path(<span class="st">&#39;accounts/&#39;</span>, include(<span class="st">&#39;django.contrib.auth.urls&#39;</span>)),</a>
<a class="sourceLine" id="cb4-4" title="4"><span class="co"># ...</span></a></code></pre></div>
</section><section id="à-modifier-1" class="slide level2">
<h2>à modifier</h2>
<h3 id="confsettings.py">conf/settings.py</h3>
<div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb5-1" title="1">LOGOUT_REDIRECT_URL <span class="op">=</span> <span class="st">&#39;/&#39;</span></a>
<a class="sourceLine" id="cb5-2" title="2">LOGIN_REDIRECT_URL <span class="op">=</span> <span class="st">&#39;/&#39;</span></a></code></pre></div>
</section><section id="à-modifier-2" class="slide level2">
<h2>à modifier</h2>
<h3 id="webuitemplatesregistrationlogin.html">webui/templates/registration/login.html</h3>
<ul>
<li>le template doit être présent</li>
</ul>
<h3 id="confurls.py-1">conf/urls.py</h3>
<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb6-1" title="1">path(<span class="st">&#39;&#39;</span>, login_required(views.home_v2), name<span class="op">=</span><span class="st">&#39;home&#39;</span>),</a></code></pre></div>
</section></section>
<section><section id="vue-liste-générique" class="title-slide slide level1"><h1>Vue liste générique</h1></section><section id="parefeu" class="slide level2">
<h2>Parefeu</h2>
<h3 id="documentation">Documentation</h3>
<p>https://docs.djangoproject.com/fr/2.2/topics/class-based-views/generic-display/</p>
</section><section id="implémentation" class="slide level2">
<h2>Implémentation</h2>
<h3 id="webuiviews.py">webui/views.py</h3>
<div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb7-1" title="1"><span class="im">from</span> django.views.generic <span class="im">import</span> ListView</a>
<a class="sourceLine" id="cb7-2" title="2"><span class="im">from</span> webui.models <span class="im">import</span> Parefeu</a>
<a class="sourceLine" id="cb7-3" title="3"></a>
<a class="sourceLine" id="cb7-4" title="4"><span class="kw">class</span> ParefeuList(ListView):</a>
<a class="sourceLine" id="cb7-5" title="5">    model <span class="op">=</span> Parefeu</a></code></pre></div>
</section><section id="templates" class="slide level2">
<h2>Templates</h2>
<h3 id="webuitemplateswebuiparefeu_list.html">webui/templates/webui/parefeu_list.html</h3>
<div class="sourceCode" id="cb8"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb8-1" title="1">{<span class="op">%</span> extends <span class="st">&quot;webui/home.html&quot;</span> <span class="op">%</span>}</a>
<a class="sourceLine" id="cb8-2" title="2"></a>
<a class="sourceLine" id="cb8-3" title="3">{<span class="op">%</span> block content <span class="op">%</span>}</a>
<a class="sourceLine" id="cb8-4" title="4">    <span class="op">&lt;</span>h2<span class="op">&gt;</span>Parefeux<span class="op">&lt;/</span>h2<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb8-5" title="5">    <span class="op">&lt;</span>ul<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb8-6" title="6">        {<span class="op">%</span> <span class="cf">for</span> parefeu <span class="kw">in</span> object_list <span class="op">%</span>}</a>
<a class="sourceLine" id="cb8-7" title="7">            <span class="op">&lt;</span>li<span class="op">&gt;</span>{{ parefeu.nom }}<span class="op">&lt;/</span>li<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb8-8" title="8">        {<span class="op">%</span> endfor <span class="op">%</span>}</a>
<a class="sourceLine" id="cb8-9" title="9">    <span class="op">&lt;/</span>ul<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb8-10" title="10">{<span class="op">%</span> endblock <span class="op">%</span>}</a></code></pre></div>
</section><section id="routage" class="slide level2">
<h2>Routage</h2>
<h3 id="confurls.py-2">conf/urls.py</h3>
<div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb9-1" title="1">...</a>
<a class="sourceLine" id="cb9-2" title="2">path(<span class="st">&#39;parefeu/&#39;</span>,</a>
<a class="sourceLine" id="cb9-3" title="3">     login_required(views.ParefeuList.as_view()),</a>
<a class="sourceLine" id="cb9-4" title="4">     name<span class="op">=</span><span class="st">&#39;parefeux&#39;</span>),</a>
<a class="sourceLine" id="cb9-5" title="5">...</a></code></pre></div>
</section><section id="templates-1" class="slide level2">
<h2>Templates</h2>
<h3 id="webuitemplateswebuihome.html-1">webui/templates/webui/home.html</h3>
<div class="sourceCode" id="cb10"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb10-1" title="1"><span class="op">&lt;</span>li <span class="kw">class</span><span class="op">=</span><span class="st">&quot;nav-item active&quot;</span><span class="op">&gt;</span></a>
<a class="sourceLine" id="cb10-2" title="2">    <span class="op">&lt;</span>a <span class="kw">class</span><span class="op">=</span><span class="st">&quot;nav-link&quot;</span> href<span class="op">=</span><span class="st">&quot;{</span><span class="sc">% u</span><span class="st">rl &#39;parefeux&#39; %}&quot;</span><span class="op">&gt;</span>Parefeux<span class="op">&lt;/</span>a<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb10-3" title="3"><span class="op">&lt;/</span>li<span class="op">&gt;</span></a></code></pre></div>
</section><section id="menu-actif" class="slide level2">
<h2>Menu actif</h2>
<h3 id="webuitemplateswebuihome.html-2">webui/templates/webui/home.html</h3>
<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb11-1" title="1">...</a>
<a class="sourceLine" id="cb11-2" title="2"><span class="op">&lt;</span>li <span class="kw">class</span><span class="op">=</span><span class="st">&quot;nav-item active&quot;</span><span class="op">&gt;</span></a>
<a class="sourceLine" id="cb11-3" title="3">... <span class="co"># devient</span></a>
<a class="sourceLine" id="cb11-4" title="4"><span class="op">&lt;</span>li <span class="kw">class</span><span class="op">=</span><span class="st">&quot;nav-item </span><span class="sc">{{</span><span class="st"> menu_parefeu </span><span class="sc">}}</span><span class="st">&quot;</span></a></code></pre></div>
</section><section id="implémentation-1" class="slide level2">
<h2>Implémentation</h2>
<h3 id="webuiviews.py-1">webui/views.py</h3>
<div class="sourceCode" id="cb12"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb12-1" title="1"><span class="kw">class</span> ParefeuList(ListView):</a>
<a class="sourceLine" id="cb12-2" title="2">    model <span class="op">=</span> Parefeu</a>
<a class="sourceLine" id="cb12-3" title="3"></a>
<a class="sourceLine" id="cb12-4" title="4">    <span class="kw">def</span> get_context_data(<span class="va">self</span>, <span class="op">**</span>kwargs):</a>
<a class="sourceLine" id="cb12-5" title="5">        context <span class="op">=</span> <span class="bu">super</span>().get_context_data(<span class="op">**</span>kwargs)</a>
<a class="sourceLine" id="cb12-6" title="6">        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="cb12-7" title="7">        <span class="cf">return</span> context</a></code></pre></div>
</section></section>
<section><section id="vue-détail-générique" class="title-slide slide level1"><h1>Vue détail générique</h1></section><section id="parefeu-1" class="slide level2">
<h2>Parefeu</h2>
<h3 id="webuiviews.py-2">webui/views.py</h3>
<div class="sourceCode" id="cb13"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb13-1" title="1"><span class="im">from</span> django.views.generic <span class="im">import</span> DetailView</a>
<a class="sourceLine" id="cb13-2" title="2"></a>
<a class="sourceLine" id="cb13-3" title="3"><span class="kw">class</span> ParefeuDetail(DetailView):</a>
<a class="sourceLine" id="cb13-4" title="4">    context_object_name <span class="op">=</span> <span class="st">&#39;parefeu&#39;</span></a>
<a class="sourceLine" id="cb13-5" title="5">    model <span class="op">=</span> Parefeu</a>
<a class="sourceLine" id="cb13-6" title="6">    <span class="co"># queryset = Parefeu.objects.all()</span></a></code></pre></div>
</section><section id="routage-1" class="slide level2">
<h2>Routage</h2>
<h3 id="confurls.py-3">conf/urls.py</h3>
<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb14-1" title="1">path(<span class="st">&#39;parefeu/&lt;int:pk&gt;/&#39;</span>,</a>
<a class="sourceLine" id="cb14-2" title="2">     login_required(views.ParefeuDetail.as_view()),</a>
<a class="sourceLine" id="cb14-3" title="3">     name<span class="op">=</span><span class="st">&#39;parefeu-detail&#39;</span>),</a></code></pre></div>
</section><section id="templates-2" class="slide level2">
<h2>Templates</h2>
<h3 id="webuitemplateswebuiparefeu_detail.html">webui/templates/webui/parefeu_detail.html</h3>
<div class="sourceCode" id="cb15"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb15-1" title="1">{<span class="op">%</span> extends <span class="st">&quot;webui/home.html&quot;</span> <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-2" title="2">{<span class="op">%</span> block title <span class="op">%</span>}Parefeu: {{parefeu.nom}}{<span class="op">%</span> endblock <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-3" title="3">{<span class="op">%</span> block content <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-4" title="4"><span class="op">&lt;</span>h2<span class="op">&gt;</span>{{parefeu.nom}}<span class="op">&lt;/</span>h2<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-5" title="5"><span class="op">&lt;</span>table <span class="kw">class</span><span class="op">=</span><span class="st">&quot;table table-striped&quot;</span><span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-6" title="6">    <span class="op">&lt;</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-7" title="7">        <span class="op">&lt;</span>th<span class="op">&gt;</span>Nombre de règles total<span class="op">&lt;/</span>th<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-8" title="8">        <span class="op">&lt;</span>td<span class="op">&gt;</span>{{parefeu.nombre_de_regles}}<span class="op">&lt;/</span>td<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-9" title="9">    <span class="op">&lt;/</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-10" title="10">    <span class="op">&lt;</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-11" title="11">        <span class="op">&lt;</span>th<span class="op">&gt;</span>Administrateur<span class="op">&lt;/</span>th<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-12" title="12">        <span class="op">&lt;</span>td<span class="op">&gt;</span>{{parefeu.admin}}<span class="op">&lt;/</span>td<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-13" title="13">    <span class="op">&lt;/</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-14" title="14">    <span class="op">&lt;</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-15" title="15">        <span class="op">&lt;</span>th<span class="op">&gt;</span>Dernière modification<span class="op">&lt;/</span>th<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-16" title="16">        <span class="op">&lt;</span>td<span class="op">&gt;</span>{{parefeu.modification}}<span class="op">&lt;/</span>td<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-17" title="17">    <span class="op">&lt;/</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-18" title="18">    {<span class="op">%</span> <span class="cf">if</span> parefeu.parefeu_set.count <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-19" title="19">    <span class="op">&lt;</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-20" title="20">        <span class="op">&lt;</span>th<span class="op">&gt;</span>Parefeu(x) utilisant ce parefeu comme modèle<span class="op">&lt;/</span>th<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-21" title="21">        <span class="op">&lt;</span>td<span class="op">&gt;</span>{<span class="op">%</span> <span class="cf">for</span> fw <span class="kw">in</span> parefeu.parefeu_set.<span class="bu">all</span> <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-22" title="22">            <span class="op">&lt;</span>a href<span class="op">=</span><span class="st">&quot;{</span><span class="sc">% u</span><span class="st">rl &#39;parefeu&#39; fw.id %}&quot;</span><span class="op">&gt;</span>{{fw}}<span class="op">&lt;/</span>a<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-23" title="23">            {<span class="op">%</span> endfor <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-24" title="24">        <span class="op">&lt;/</span>td<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-25" title="25">    <span class="op">&lt;/</span>tr<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-26" title="26">    {<span class="op">%</span> endif <span class="op">%</span>}</a>
<a class="sourceLine" id="cb15-27" title="27"><span class="op">&lt;/</span>table<span class="op">&gt;</span></a>
<a class="sourceLine" id="cb15-28" title="28">{<span class="op">%</span> endblock <span class="op">%</span>}</a></code></pre></div>
</section><section id="accés-facile" class="slide level2">
<h2>Accés facile</h2>
<h3 id="webuitemplateswebuiparefeu_list.html-1">webui/templates/webui/parefeu_list.html</h3>
<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb16-1" title="1"><span class="op">&lt;</span>li<span class="op">&gt;&lt;</span>a href<span class="op">=</span><span class="st">&quot;{</span><span class="sc">% u</span><span class="st">rl &#39;parefeu-detail&#39; parefeu.id %}&quot;</span><span class="op">&gt;</span></a>
<a class="sourceLine" id="cb16-2" title="2">    {{ parefeu.nom }}<span class="op">&lt;/</span>a<span class="op">&gt;&lt;/</span>li<span class="op">&gt;</span></a></code></pre></div>
</section><section id="menu-active" class="slide level2">
<h2>Menu active</h2>
<h3 id="webuiviews.py-3">webui/views.py</h3>
<div class="sourceCode" id="cb17"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb17-1" title="1"><span class="kw">def</span> get_context_data(<span class="va">self</span>, <span class="op">**</span>kwargs):</a>
<a class="sourceLine" id="cb17-2" title="2">    context <span class="op">=</span> <span class="bu">super</span>().get_context_data(<span class="op">**</span>kwargs)</a>
<a class="sourceLine" id="cb17-3" title="3">    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="cb17-4" title="4">    <span class="cf">return</span> context</a></code></pre></div>
</section><section id="à-faire" class="slide level2">
<h2>à faire</h2>
<ul>
<li>ServiceList</li>
<li>PortList</li>
</ul>
</section></section>
<section><section id="mail" class="title-slide slide level1"><h1>Mail</h1></section><section id="envoi-de-mails" class="slide level2">
<h2>Envoi de mails</h2>
<h3 id="documentation-1">Documentation</h3>
<ul>
<li>https://docs.djangoproject.com/fr/2.2/topics/email/</li>
<li>en production, envoi des messages d’erreurs</li>
<li>différents des Users ‘superadmins’</li>
</ul>
</section><section id="envoi-de-mails-1" class="slide level2">
<h2>Envoi de mails</h2>
Bonnegent Sebastien's avatar
Bonnegent Sebastien committed
315
316
317
318
319
<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>
Bonnegent Sebastien's avatar
Bonnegent Sebastien committed
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<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>
</section></section>
<section><section id="formulaire-simple" class="title-slide slide level1"><h1>Formulaire simple</h1></section><section id="formulaire-de-contact" class="slide level2">
<h2>Formulaire de contact</h2>
<ul>
<li>contrôler la partie la liste des services</li>
<li>bouton sur les pages listes des services et des ports</li>
<li>pouvoir demander la création de service/port aux admins</li>
<li>https://docs.djangoproject.com/fr/2.2/topics/class-based-views/generic-editing/</li>
</ul>
</section><section id="suivre-la-documentation" class="slide level2">
<h2>Suivre la documentation</h2>
<h3 id="à-modifier-3">à modifier</h3>
<ul>
<li>webui/forms.py</li>
<li>webui/views.py</li>
<li>webui/templates/webui/contact.html</li>
<li>conf/urls.py</li>
</ul>
</section></section>
<section><section id="messages" class="title-slide slide level1"><h1>Messages</h1></section><section id="pourquoi" class="slide level2">
<h2>Pourquoi ?</h2>
<ul>
<li>affichage facile à l’utilisateur</li>
<li>permet un retour sur les opérations</li>
<li>fourni par Django</li>
</ul>
</section><section id="mise-en-place" class="slide level2">
<h2>Mise en place</h2>
<h3 id="webuiviews.py-4">webui/views.py</h3>
Bonnegent Sebastien's avatar
Bonnegent Sebastien committed
352
353
354
355
356
357
358
359
360
361
<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>
Bonnegent Sebastien's avatar
Bonnegent Sebastien committed
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
</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>
<pre><code>{% for message in messages %}
    {% if message.tags == &quot;error&quot; %}
        &lt;div class=&quot;alert alert-danger&quot; role=&quot;alert&quot;&gt;
    {% else %}
        &lt;div class=&quot;alert alert-{{ message.tags }}&quot; role=&quot;alert&quot;&gt;
    {% endif %}
    {{ message }}&lt;/div&gt;
{% endfor %}</code></pre>
</section></section>
<section><section id="fin" class="title-slide slide level1"><h1>FIN !</h1></section></section>
    </div>
  </div>

  <script src="./reveal.js/lib/js/head.min.js"></script>
  <script src="./reveal.js/js/reveal.js"></script>

  <script>

      // Full list of configuration options available at:
      // https://github.com/hakimel/reveal.js#configuration
      Reveal.initialize({
        // Push each slide change to the browser history
        history: true,

        // Optional reveal.js plugins
        dependencies: [
          { src: './reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
          { src: './reveal.js/plugin/zoom-js/zoom.js', async: true },
          { src: './reveal.js/plugin/notes/notes.js', async: true }
        ]
      });
    </script>
    </body>
</html>