Wiki

Version 244 (Paul Carensac, 03/22/2016 06:08 pm)

1 1 Etienne Pallier
h1. Technical Documentation for the PYROS project (FGFT-CC)
2 1 Etienne Pallier
3 1 Etienne Pallier
4 1 Etienne Pallier
HOWTO Format Redmine Wiki : http://www.redmine.org/projects/redmine/wiki/FrRedmineWikiFormatting
5 1 Etienne Pallier
6 1 Etienne Pallier
{{>toc}}
7 1 Etienne Pallier
8 1 Etienne Pallier
9 121 Etienne Pallier
---
10 1 Etienne Pallier
11 121 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}I - TODO%
12 121 Etienne Pallier
13 126 Etienne Pallier
 * installation sur windows
14 125 Etienne Pallier
15 126 Etienne Pallier
 * gitlab
16 1 Etienne Pallier
17 126 Etienne Pallier
 * séparation des BD Django et Pyros
18 125 Etienne Pallier
19 126 Etienne Pallier
 * intégration dans Eclipse
20 126 Etienne Pallier
21 174 Etienne Pallier
 * Intégration des modules Django déjà développés
22 125 Etienne Pallier
23 121 Etienne Pallier
24 3 Etienne Pallier
---
25 1 Etienne Pallier
26 140 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}I - DATABASE SCHEMA (v0.2.1)%
27 116 Etienne Pallier
28 116 Etienne Pallier
29 117 Etienne Pallier
{{thumbnail(PYROS_PDM_v021.png, size=300, title=Pyros data model)}}
30 121 Etienne Pallier
31 121 Etienne Pallier
32 121 Etienne Pallier
---
33 116 Etienne Pallier
34 141 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}II - Get the project (from gitlab)%
35 141 Etienne Pallier
36 169 Etienne Pallier
h3. Get the project from the terminal
37 1 Etienne Pallier
38 1 Etienne Pallier
<pre>
39 1 Etienne Pallier
git clone https://gitlab.irap.omp.eu/epallier/pyros.git PYROS
40 169 Etienne Pallier
41 174 Etienne Pallier
(or also : git clone git@gitlab.irap.omp.eu:epallier/pyros.git)
42 1 Etienne Pallier
</pre>
43 1 Etienne Pallier
44 197 Etienne Pallier
This creates a PYROS/ folder containing the project (with a .git/ subfolder for synchronization with the git repository)
45 1 Etienne Pallier
46 225 Etienne Pallier
_If you just wanted a static copy of the project (without synchronization) just remove the .git/ folder:_
47 1 Etienne Pallier
<pre>
48 1 Etienne Pallier
$ rm -r .git/
49 1 Etienne Pallier
</pre>
50 226 Etienne Pallier
51 226 Etienne Pallier
You should obtain this structure:
52 226 Etienne Pallier
53 226 Etienne Pallier
<pre>
54 226 Etienne Pallier
55 226 Etienne Pallier
PYROS/
56 226 Etienne Pallier
├── REQUIREMENTS.txt
57 226 Etienne Pallier
├── private/
58 226 Etienne Pallier
│   └── venv_py35_pyros/
59 226 Etienne Pallier
├── public/
60 226 Etienne Pallier
│   └── static/
61 226 Etienne Pallier
├── src/
62 226 Etienne Pallier
│   ├── manage.py
63 226 Etienne Pallier
│   ├── pyros/
64 226 Etienne Pallier
│   │   ├── __init__.py
65 226 Etienne Pallier
│   │   ├── __pycache__
66 226 Etienne Pallier
│   │   ├── settings.py
67 226 Etienne Pallier
│   │   ├── urls.py
68 226 Etienne Pallier
│   │   └── wsgi.py
69 226 Etienne Pallier
│   └── pyrosapp/
70 226 Etienne Pallier
│       ├── __init__.py
71 226 Etienne Pallier
│       ├── admin.py
72 226 Etienne Pallier
│       ├── apps.py
73 226 Etienne Pallier
│       ├── migrations
74 226 Etienne Pallier
│       ├── models.py
75 226 Etienne Pallier
│       ├── tests.py
76 226 Etienne Pallier
│       └── views.py
77 226 Etienne Pallier
78 226 Etienne Pallier
79 226 Etienne Pallier
</pre>
80 226 Etienne Pallier
81 174 Etienne Pallier
82 174 Etienne Pallier
h3. Get the project from Eclipse
83 169 Etienne Pallier
84 197 Etienne Pallier
<pre>
85 169 Etienne Pallier
TODO:
86 197 Etienne Pallier
</pre>
87 169 Etienne Pallier
88 141 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}III - INSTALLATION%
89 2 Etienne Pallier
90 120 Etienne Pallier
91 120 Etienne Pallier
---
92 120 Etienne Pallier
93 184 Etienne Pallier
h3. Install MySql (only if necessary)
94 2 Etienne Pallier
95 49 Etienne Pallier
 * Linux Ubuntu
96 49 Etienne Pallier
<pre>
97 107 Paul Carensac
98 107 Paul Carensac
$ sudo apt-get install mysql-server
99 107 Paul Carensac
$ sudo apt-get install mysql-client
100 107 Paul Carensac
101 49 Etienne Pallier
</pre>
102 49 Etienne Pallier
103 49 Etienne Pallier
 * Linux CentOS
104 49 Etienne Pallier
<pre>
105 49 Etienne Pallier
TODO:
106 49 Etienne Pallier
$ sudo yum install mysql
107 49 Etienne Pallier
...
108 49 Etienne Pallier
</pre>
109 49 Etienne Pallier
110 49 Etienne Pallier
 * Mac OS X
111 1 Etienne Pallier
Install XAMPP
112 1 Etienne Pallier
(but you could also use the pre-installed Mac OS MySql)
113 177 Etienne Pallier
<pre>
114 177 Etienne Pallier
TODO:
115 49 Etienne Pallier
</pre>
116 1 Etienne Pallier
117 49 Etienne Pallier
 * Windows
118 243 Paul Carensac
119 1 Etienne Pallier
<pre>
120 243 Paul Carensac
Download and install the newest version on https://dev.mysql.com/downloads/installer/
121 243 Paul Carensac
122 243 Paul Carensac
Once installed, launch MySQL Installer. Clic on 'Add...' on the right.
123 243 Paul Carensac
In MySQLServers section, choose the newest, then clic on next.
124 243 Paul Carensac
Install and configure the server (just follow the installation guide).
125 243 Paul Carensac
126 243 Paul Carensac
Then launch mysql (via the Windows menu).
127 49 Etienne Pallier
</pre>
128 49 Etienne Pallier
129 49 Etienne Pallier
130 49 Etienne Pallier
---
131 1 Etienne Pallier
132 185 Etienne Pallier
h3. Install Python3.5 (only if necessary)
133 1 Etienne Pallier
134 11 Etienne Pallier
135 11 Etienne Pallier
 * Mac OS X :
136 1 Etienne Pallier
<pre>
137 183 Etienne Pallier
138 24 Etienne Pallier
1) Installer MacPort
139 24 Etienne Pallier
(TODO: doc)
140 24 Etienne Pallier
141 24 Etienne Pallier
2) Installer le "port" python35
142 1 Etienne Pallier
$ sudo port install python35
143 183 Etienne Pallier
144 1 Etienne Pallier
</pre>
145 1 Etienne Pallier
146 1 Etienne Pallier
 * Linux (Ubuntu) :
147 1 Etienne Pallier
<pre>
148 244 Paul Carensac
$ sudo add-apt-repository ppa:fkrull/deadsnakes
149 244 Paul Carensac
$ sudo apt-get update
150 244 Paul Carensac
$ sudo apt-get install python3.5
151 1 Etienne Pallier
152 244 Paul Carensac
$ sudo pip install virtualenv
153 1 Etienne Pallier
</pre>
154 1 Etienne Pallier
155 244 Paul Carensac
156 244 Paul Carensac
 * Windows 7 :
157 244 Paul Carensac
<pre>
158 244 Paul Carensac
Go to https://www.python.org/downloads/windows/ , choose the wanted version
159 244 Paul Carensac
On the wanted version’s page, download Windows x86 executable installer
160 244 Paul Carensac
161 244 Paul Carensac
Run the executable
162 244 Paul Carensac
    * On the first page, check "Add python3.5 to PATH"
163 244 Paul Carensac
    * Choose "Install now" option
164 244 Paul Carensac
</pre>
165 1 Etienne Pallier
166 183 Etienne Pallier
 * Windows 10 :
167 183 Etienne Pallier
<pre>
168 187 Etienne Pallier
TODO:
169 183 Etienne Pallier
</pre>
170 3 Etienne Pallier
171 4 Etienne Pallier
---
172 5 Etienne Pallier
173 192 Etienne Pallier
h3. Create a Python3 virtual environment dedicated to the project (inside the project folder)
174 127 Etienne Pallier
175 131 Etienne Pallier
<pre>
176 1 Etienne Pallier
177 193 Etienne Pallier
$ mkdir private/
178 193 Etienne Pallier
179 133 Etienne Pallier
$ cd private/
180 3 Etienne Pallier
181 3 Etienne Pallier
$ which python3.5
182 3 Etienne Pallier
/opt/local/bin/python3.5
183 15 Etienne Pallier
184 127 Etienne Pallier
$ virtualenv-3.5 venv_py35_pyros -p /opt/local/bin/python3.5
185 3 Etienne Pallier
=> creates a venv_py35_pyros/ folder inside PYROS/private/
186 1 Etienne Pallier
187 131 Etienne Pallier
</pre>
188 1 Etienne Pallier
189 7 Etienne Pallier
---
190 3 Etienne Pallier
191 65 Etienne Pallier
h3. Activate the python virtual environment (from inside the project)
192 7 Etienne Pallier
193 55 Etienne Pallier
<pre>
194 1 Etienne Pallier
195 65 Etienne Pallier
$ pwd
196 134 Etienne Pallier
.../PYROS/private
197 1 Etienne Pallier
198 65 Etienne Pallier
$ source ./venv_py35_pyros/bin/activate
199 65 Etienne Pallier
200 3 Etienne Pallier
$ python -V
201 1 Etienne Pallier
Python 3.5.1
202 3 Etienne Pallier
203 3 Etienne Pallier
$ which pip
204 77 Etienne Pallier
.../PYROS/venv_py35_pyros/bin/pip
205 16 Etienne Pallier
206 194 Etienne Pallier
Upgrade pip to last version available:
207 3 Etienne Pallier
$ pip install --upgrade pip
208 3 Etienne Pallier
Collecting pip
209 3 Etienne Pallier
  Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
210 3 Etienne Pallier
Installing collected packages: pip
211 3 Etienne Pallier
  Found existing installation: pip 7.1.2
212 3 Etienne Pallier
    Uninstalling pip-7.1.2:
213 3 Etienne Pallier
      Successfully uninstalled pip-7.1.2
214 1 Etienne Pallier
Successfully installed pip-8.1.1
215 194 Etienne Pallier
216 194 Etienne Pallier
Upgrade wheel to last version available:
217 194 Etienne Pallier
$ pip install --upgrade wheel
218 194 Etienne Pallier
Collecting wheel
219 194 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
220 194 Etienne Pallier
Installing collected packages: wheel
221 194 Etienne Pallier
  Found existing installation: wheel 0.24.0
222 194 Etienne Pallier
    Uninstalling wheel-0.24.0:
223 194 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
224 194 Etienne Pallier
Successfully installed wheel-0.29.0
225 194 Etienne Pallier
226 55 Etienne Pallier
227 55 Etienne Pallier
</pre>
228 18 Etienne Pallier
229 212 Etienne Pallier
h3. Install the needed Python packages (from within the virtual environment)
230 18 Etienne Pallier
231 66 Etienne Pallier
First, be sure that the virtual environment is activated:
232 66 Etienne Pallier
<pre>
233 66 Etienne Pallier
$ python -V
234 66 Etienne Pallier
Python 3.5.1
235 66 Etienne Pallier
</pre>
236 66 Etienne Pallier
237 62 Etienne Pallier
 * *Automatic Installation of all packages*
238 62 Etienne Pallier
<pre>
239 90 Etienne Pallier
$ pip install -r REQUIREMENTS.txt
240 62 Etienne Pallier
</pre>
241 62 Etienne Pallier
242 93 Etienne Pallier
 * *Or, manual installation of each package*
243 62 Etienne Pallier
244 62 Etienne Pallier
  * *Install Django* :
245 32 Etienne Pallier
<pre>
246 3 Etienne Pallier
$ pip install django
247 3 Etienne Pallier
Collecting django
248 3 Etienne Pallier
  Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
249 3 Etienne Pallier
Installing collected packages: django
250 3 Etienne Pallier
Successfully installed django-1.9.4
251 3 Etienne Pallier
252 3 Etienne Pallier
$ pip install django-admin-tools
253 3 Etienne Pallier
Collecting django-admin-tools
254 3 Etienne Pallier
  Downloading django_admin_tools-0.7.2-py2.py3-none-any.whl (289kB)
255 3 Etienne Pallier
Installing collected packages: django-admin-tools
256 3 Etienne Pallier
Successfully installed django-admin-tools-0.7.2
257 3 Etienne Pallier
258 21 Etienne Pallier
$ pip install django-debug-toolbar
259 21 Etienne Pallier
Collecting django-debug-toolbar
260 21 Etienne Pallier
  Downloading django_debug_toolbar-1.4-py2.py3-none-any.whl (212kB)
261 21 Etienne Pallier
Requirement already satisfied (use --upgrade to upgrade): Django>=1.7 in ./venv_py35_pyros/lib/python3.5/site-packages (from django-debug-toolbar)
262 21 Etienne Pallier
Collecting sqlparse (from django-debug-toolbar)
263 21 Etienne Pallier
  Downloading sqlparse-0.1.19.tar.gz (58kB)
264 21 Etienne Pallier
Building wheels for collected packages: sqlparse
265 21 Etienne Pallier
  Running setup.py bdist_wheel for sqlparse ... done
266 21 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/7b/d4/72/6011bb100dd5fc213164e4bbee13d4e03261dd54ce6a5de6b8
267 21 Etienne Pallier
Successfully built sqlparse
268 21 Etienne Pallier
Installing collected packages: sqlparse, django-debug-toolbar
269 21 Etienne Pallier
Successfully installed django-debug-toolbar-1.4 sqlparse-0.1.19
270 21 Etienne Pallier
271 21 Etienne Pallier
$ pip install django-extensions
272 21 Etienne Pallier
Collecting django-extensions
273 21 Etienne Pallier
  Downloading django_extensions-1.6.1-py2.py3-none-any.whl (202kB)
274 21 Etienne Pallier
Collecting six>=1.2 (from django-extensions)
275 21 Etienne Pallier
  Downloading six-1.10.0-py2.py3-none-any.whl
276 21 Etienne Pallier
Installing collected packages: six, django-extensions
277 21 Etienne Pallier
Successfully installed django-extensions-1.6.1 six-1.10.0
278 21 Etienne Pallier
279 21 Etienne Pallier
$ pip install django-suit
280 21 Etienne Pallier
Collecting django-suit
281 21 Etienne Pallier
  Downloading django-suit-0.2.18.tar.gz (587kB)
282 21 Etienne Pallier
Building wheels for collected packages: django-suit
283 1 Etienne Pallier
  Running setup.py bdist_wheel for django-suit ... done
284 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/12/8b/9a/e02ab0ad9229881638aa040d47d77c8f562999533811927d41
285 1 Etienne Pallier
Successfully built django-suit
286 1 Etienne Pallier
Installing collected packages: django-suit
287 1 Etienne Pallier
Successfully installed django-suit-0.2.18
288 21 Etienne Pallier
289 32 Etienne Pallier
</pre>
290 32 Etienne Pallier
291 63 Etienne Pallier
  * *Install the web application server gunicorn (will be used in production instead of the dev django web server)* :
292 32 Etienne Pallier
<pre>
293 25 Etienne Pallier
$ pip install gunicorn
294 25 Etienne Pallier
Collecting gunicorn
295 25 Etienne Pallier
  Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
296 21 Etienne Pallier
Installing collected packages: gunicorn
297 26 Etienne Pallier
Successfully installed gunicorn-19.4.5
298 1 Etienne Pallier
</pre>
299 1 Etienne Pallier
300 63 Etienne Pallier
  * *Install the python mysql client*:
301 32 Etienne Pallier
<pre>
302 32 Etienne Pallier
$ pip install mysqlclient
303 72 Etienne Pallier
...
304 72 Etienne Pallier
</pre>
305 33 Etienne Pallier
306 73 Etienne Pallier
   * => Issue under Mac OS X:
307 72 Etienne Pallier
<pre>
308 3 Etienne Pallier
$ pip install mysqlclient
309 3 Etienne Pallier
Collecting mysqlclient
310 1 Etienne Pallier
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
311 22 Etienne Pallier
Building wheels for collected packages: mysqlclient
312 3 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... error
313 3 Etienne Pallier
314 1 Etienne Pallier
  ----------------------------------------
315 1 Etienne Pallier
  Failed building wheel for mysqlclient
316 1 Etienne Pallier
  Running setup.py clean for mysqlclient
317 1 Etienne Pallier
Failed to build mysqlclient
318 1 Etienne Pallier
Installing collected packages: mysqlclient
319 1 Etienne Pallier
  Running setup.py install for mysqlclient ... done
320 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
321 1 Etienne Pallier
322 1 Etienne Pallier
BOUH !!!
323 1 Etienne Pallier
324 1 Etienne Pallier
$ pip install --upgrade wheel
325 1 Etienne Pallier
Collecting wheel
326 1 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
327 1 Etienne Pallier
Installing collected packages: wheel
328 1 Etienne Pallier
  Found existing installation: wheel 0.24.0
329 1 Etienne Pallier
    Uninstalling wheel-0.24.0:
330 1 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
331 1 Etienne Pallier
Successfully installed wheel-0.29.0
332 1 Etienne Pallier
333 1 Etienne Pallier
$ pip uninstall mysqlclient
334 1 Etienne Pallier
335 1 Etienne Pallier
$ pip install mysqlclient
336 1 Etienne Pallier
Collecting mysqlclient
337 1 Etienne Pallier
  Using cached mysqlclient-1.3.7.tar.gz
338 1 Etienne Pallier
Building wheels for collected packages: mysqlclient
339 1 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... done
340 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/9b/06/50/d11418c26cf8f2156b13d4363b5afde8e7e75ebb8540d0228d
341 1 Etienne Pallier
Successfully built mysqlclient
342 1 Etienne Pallier
Installing collected packages: mysqlclient
343 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
344 1 Etienne Pallier
345 1 Etienne Pallier
YES !!!
346 1 Etienne Pallier
347 1 Etienne Pallier
</pre>
348 1 Etienne Pallier
349 107 Paul Carensac
   * => Issues under Ubuntu:
350 107 Paul Carensac
<pre>
351 107 Paul Carensac
$ pip install mysqlclient
352 107 Paul Carensac
Collecting mysqlclient
353 107 Paul Carensac
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
354 107 Paul Carensac
    100% |████████████████████████████████| 81kB 1.5MB/s
355 107 Paul Carensac
    Complete output from command python setup.py egg_info:
356 107 Paul Carensac
    /bin/sh: 1: mysql_config: not found
357 107 Paul Carensac
    Traceback (most recent call last):
358 107 Paul Carensac
      File "<string>", line 1, in <module>
359 107 Paul Carensac
    [...]
360 107 Paul Carensac
    ----------------------------------------
361 107 Paul Carensac
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-q6j4inuz/mysqlclient/
362 1 Etienne Pallier
363 108 Paul Carensac
BOUH !!!
364 108 Paul Carensac
365 107 Paul Carensac
$ sudo apt-get install libmysqlclient-dev
366 108 Paul Carensac
367 107 Paul Carensac
$ pip install mysqlclient
368 107 Paul Carensac
Collecting mysqlclient
369 107 Paul Carensac
  Using cached mysqlclient-1.3.7.tar.gz
370 107 Paul Carensac
Building wheels for collected packages: mysqlclient
371 107 Paul Carensac
  Running setup.py bdist_wheel for mysqlclient ... error
372 107 Paul Carensac
373 107 Paul Carensac
    _mysql.c:40:20: fatal error: Python.h: No such file or directory
374 107 Paul Carensac
     #include "Python.h"
375 107 Paul Carensac
                        ^
376 107 Paul Carensac
    compilation terminated.
377 107 Paul Carensac
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
378 107 Paul Carensac
    
379 107 Paul Carensac
    ----------------------------------------
380 107 Paul Carensac
Command "/home/carens_p/pyros/venv_py35_pyros/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-k3klv92j/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-gz242xxs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/carens_p/pyros/venv_py35_pyros/include/site/python3.5/mysqlclient" failed with error code 1 in /tmp/pip-build-k3klv92j/mysqlclient/
381 107 Paul Carensac
382 108 Paul Carensac
BOUH !!!
383 108 Paul Carensac
384 107 Paul Carensac
$ sudo apt-get install python3.5-dev
385 108 Paul Carensac
386 107 Paul Carensac
$ pip install mysqlclient
387 107 Paul Carensac
388 107 Paul Carensac
YES !!!
389 107 Paul Carensac
390 107 Paul Carensac
</pre>
391 12 Etienne Pallier
392 12 Etienne Pallier
---
393 28 Etienne Pallier
394 142 Etienne Pallier
h3. Test the project
395 142 Etienne Pallier
396 142 Etienne Pallier
<pre>
397 142 Etienne Pallier
398 150 Etienne Pallier
$ cd src/
399 150 Etienne Pallier
400 1 Etienne Pallier
$ ./manage.py runserver
401 38 Etienne Pallier
(or gunicorn pyros.wsgi)
402 3 Etienne Pallier
==> http://localhost:8000
403 87 Etienne Pallier
...
404 87 Etienne Pallier
...
405 87 Etienne Pallier
Ctrl-c
406 87 Etienne Pallier
407 1 Etienne Pallier
</pre>
408 142 Etienne Pallier
409 142 Etienne Pallier
410 142 Etienne Pallier
411 142 Etienne Pallier
---
412 142 Etienne Pallier
413 156 Paul Carensac
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}IV - CONFIGURATION of the Django Back Office (administration interface)%
414 155 Paul Carensac
415 155 Paul Carensac
---
416 155 Paul Carensac
417 155 Paul Carensac
h3. Back Office setup
418 155 Paul Carensac
419 155 Paul Carensac
 * Prerequisites in src/pyros/settings.py :
420 155 Paul Carensac
421 155 Paul Carensac
    * INSTALLED_APPS must (at least) contain :
422 155 Paul Carensac
423 155 Paul Carensac
        * django.contrib.admin
424 155 Paul Carensac
        * django.contrib.auth
425 155 Paul Carensac
        * django.contrib.contenttypes
426 155 Paul Carensac
        * django.contrib.sessions
427 155 Paul Carensac
428 155 Paul Carensac
    * MIDDLEWARES must (at least) contain :
429 155 Paul Carensac
430 155 Paul Carensac
        * django.contrib.sessions.middleware.SessionMiddleware
431 155 Paul Carensac
        * django.middleware.common.CommonMiddleware
432 155 Paul Carensac
        * django.contrib.auth.middleware.AuthenticationMiddleware
433 155 Paul Carensac
434 155 Paul Carensac
 * At least one 'python manage.py migrate' must have been executed
435 155 Paul Carensac
436 155 Paul Carensac
 * Create a superuser for the administration :
437 155 Paul Carensac
438 155 Paul Carensac
<pre>
439 155 Paul Carensac
$ python manage.py createsuperuser
440 155 Paul Carensac
</pre>
441 155 Paul Carensac
442 156 Paul Carensac
* For each app of the project, fill the admin.py file :
443 155 Paul Carensac
444 155 Paul Carensac
<pre>
445 155 Paul Carensac
from django.contrib import admin
446 155 Paul Carensac
from app.models import Model1, Model2
447 155 Paul Carensac
448 155 Paul Carensac
admin.site.register(Model1)
449 155 Paul Carensac
admin.site.register(Model2)
450 155 Paul Carensac
</pre>
451 155 Paul Carensac
452 155 Paul Carensac
*Reminder* : each application must be registered in the settings.py INSTALLED_APPS variable.
453 157 Paul Carensac
454 168 Paul Carensac
* For each model in models.py, add a '__str__()' method in order to identify the object on the back office. Example :
455 157 Paul Carensac
456 157 Paul Carensac
<pre>
457 157 Paul Carensac
class UserLevel(models.Model):
458 157 Paul Carensac
    name = models.CharField(max_length=45, blank=True, null=True)
459 157 Paul Carensac
    desc = models.TextField(blank=True, null=True)
460 157 Paul Carensac
    priority = models.IntegerField(blank=True, null=True)
461 157 Paul Carensac
    quota = models.FloatField(blank=True, null=True)
462 157 Paul Carensac
463 157 Paul Carensac
    class Meta:
464 157 Paul Carensac
        managed = True
465 157 Paul Carensac
        db_table = 'userlevel'
466 157 Paul Carensac
467 157 Paul Carensac
    def __str__(self):
468 163 Paul Carensac
        return (str(self.name))
469 157 Paul Carensac
</pre>
470 157 Paul Carensac
471 159 Paul Carensac
*Naming convention* : Use self.name when possible, the creation time/date otherwise. Example :
472 159 Paul Carensac
473 159 Paul Carensac
<pre>
474 159 Paul Carensac
class SiteWatch(models.Model):
475 159 Paul Carensac
    updated = models.DateTimeField(blank=True, null=True)
476 159 Paul Carensac
    lights = models.CharField(max_length=45, blank=True, null=True)
477 159 Paul Carensac
    dome = models.CharField(max_length=45, blank=True, null=True)
478 159 Paul Carensac
    doors = models.CharField(max_length=45, blank=True, null=True)
479 159 Paul Carensac
    temperature = models.FloatField(blank=True, null=True)
480 159 Paul Carensac
481 159 Paul Carensac
    class Meta:
482 159 Paul Carensac
        managed = True
483 159 Paul Carensac
        db_table = 'sitewatch'
484 159 Paul Carensac
485 159 Paul Carensac
    def __str__(self):
486 160 Paul Carensac
        return (str(self.updated))
487 159 Paul Carensac
</pre>
488 173 Etienne Pallier
489 211 Paul Carensac
---
490 211 Paul Carensac
491 211 Paul Carensac
h3. Adaptation of the one-to-many and many-to-many display
492 211 Paul Carensac
493 211 Paul Carensac
* The one-to-many relationships are the following (One.many format) :
494 211 Paul Carensac
495 211 Paul Carensac
    * Schedule.sequences
496 211 Paul Carensac
    * Request.sequences
497 211 Paul Carensac
    * Sequence.albums
498 211 Paul Carensac
    * Album.plans
499 211 Paul Carensac
    * Plan.images
500 211 Paul Carensac
    * Telescope.detectors
501 211 Paul Carensac
    * Detector.filters
502 211 Paul Carensac
    * NrtAnalysis.images
503 211 Paul Carensac
    * Filter.plans
504 211 Paul Carensac
    * Detector.albums
505 211 Paul Carensac
    * UserLevel.users
506 211 Paul Carensac
    * Country.users
507 211 Paul Carensac
    * ScientificProgram.requests
508 211 Paul Carensac
    * User.requests
509 211 Paul Carensac
    * StrategyObs.alerts
510 211 Paul Carensac
    * SequenceType.sequences
511 211 Paul Carensac
512 211 Paul Carensac
* For each "many", create a new class in admin.py just after the imports, following these examples :
513 211 Paul Carensac
514 211 Paul Carensac
<pre>
515 211 Paul Carensac
516 211 Paul Carensac
For Schedule.sequences, Request.sequences and Sequentype.sequences, we will need :
517 211 Paul Carensac
518 211 Paul Carensac
class SequenceInline(admin.TabularInline):
519 211 Paul Carensac
    model = Sequence
520 211 Paul Carensac
    fields = ("name",)
521 211 Paul Carensac
    show_change_link = True
522 211 Paul Carensac
523 211 Paul Carensac
524 211 Paul Carensac
For Sequence.albums and Detector.albums, we will need :
525 211 Paul Carensac
526 211 Paul Carensac
class AlbumInline(admin.TabularInline):
527 211 Paul Carensac
    model = Album
528 211 Paul Carensac
    fields = ("name",)
529 211 Paul Carensac
    show_change_link = True
530 211 Paul Carensac
531 211 Paul Carensac
532 211 Paul Carensac
For StrategyObs.alerts, we will need :
533 211 Paul Carensac
534 211 Paul Carensac
class AlertInline(admin.TabularInline):
535 211 Paul Carensac
    model = Alert
536 211 Paul Carensac
    fields = ("request.name",) # there is no 'name' attribute in the Alert model
537 211 Paul Carensac
    show_change_link = True
538 211 Paul Carensac
539 211 Paul Carensac
</pre>
540 211 Paul Carensac
541 222 Paul Carensac
* For each "One", declare a new class in admin.py, just after the "Inlines" class declaration, as done in the following examples :
542 211 Paul Carensac
543 222 Paul Carensac
<pre>
544 222 Paul Carensac
For Request.sequences :
545 222 Paul Carensac
546 222 Paul Carensac
class RequestAdmin(admin.ModelAdmin):
547 222 Paul Carensac
    inlines = [
548 222 Paul Carensac
	SequenceInline,
549 222 Paul Carensac
    ]
550 222 Paul Carensac
551 222 Paul Carensac
For Detector.filters and Detector.albums :
552 222 Paul Carensac
553 222 Paul Carensac
class DetectorAdmin(admin.ModelAdmin):
554 222 Paul Carensac
    inlines = [
555 222 Paul Carensac
	FilterInline,
556 222 Paul Carensac
        AlbumInline,
557 222 Paul Carensac
    ]
558 222 Paul Carensac
559 222 Paul Carensac
</pre>
560 222 Paul Carensac
561 232 Paul Carensac
562 222 Paul Carensac
* The many-to-many relationships are the following :
563 232 Paul Carensac
564 222 Paul Carensac
    * ScientificProgram - User
565 222 Paul Carensac
    * ScheduleHistory - Sequence
566 222 Paul Carensac
567 222 Paul Carensac
* For each many-to-many relationship, declare a new "Inline" class in admin.py just after the imports, like this :
568 222 Paul Carensac
569 222 Paul Carensac
<pre>
570 222 Paul Carensac
For ScientificProgram - User :
571 222 Paul Carensac
572 222 Paul Carensac
class UserAndSPInline(admin.TabularInline):
573 222 Paul Carensac
    model = ScientificProgram.users.through
574 222 Paul Carensac
575 222 Paul Carensac
576 222 Paul Carensac
For ScheduleHistory - Sequence
577 222 Paul Carensac
578 222 Paul Carensac
class SequenceAndSHInline(admin.TabularInline):
579 222 Paul Carensac
    model = ScheduleHistory.sequences.through
580 222 Paul Carensac
581 222 Paul Carensac
</pre>
582 222 Paul Carensac
583 222 Paul Carensac
+Note :+ The order in the line "model = ScientificProgram.users.through" is very important : the first model (ScientificProgram) is the one in which is declared the ManyToManyField relationship.
584 232 Paul Carensac
585 232 Paul Carensac
* For each many-to-many relationship, declare two new classes in admin.py, just after the inlines, like in the following examples :
586 232 Paul Carensac
587 232 Paul Carensac
<pre>
588 232 Paul Carensac
For the ScheduleHistory - Sequence relationship :
589 232 Paul Carensac
590 232 Paul Carensac
class ScheduleHistoryAdmin(admin.ModelAdmin):
591 232 Paul Carensac
    inlines = [
592 232 Paul Carensac
        SequenceAndSHInline,
593 232 Paul Carensac
    ]
594 232 Paul Carensac
    exclude = ('sequences',) # ScheduleHistory declares the ManyToManyField, and we want to replace its display in the back office, so we won't display the default field
595 232 Paul Carensac
596 232 Paul Carensac
class SequenceAdmin(admin.ModelAdmin):
597 232 Paul Carensac
    inlines = [
598 232 Paul Carensac
        AlbumInline,        # This is the Inline for the one-to-many relationship Sequence.albums
599 232 Paul Carensac
        SequenceAndSHInline,                                                                
600 232 Paul Carensac
    ]
601 232 Paul Carensac
602 232 Paul Carensac
For the ScientificProgram - User relationship :
603 232 Paul Carensac
604 232 Paul Carensac
class ScientificProgramAdmin(admin.ModelAdmin):
605 232 Paul Carensac
    inlines = [
606 232 Paul Carensac
        RequestInline,
607 232 Paul Carensac
	UserAndSPInline,                                                                         
608 232 Paul Carensac
    ]
609 232 Paul Carensac
    exclude = ('users',) # Same as ScheduleHistory                                                                         
610 232 Paul Carensac
611 232 Paul Carensac
class UserAdmin(admin.ModelAdmin):
612 232 Paul Carensac
    inlines = [
613 232 Paul Carensac
	RequestInline,   # This is the Inline for the one-to-many relationship User.requests
614 232 Paul Carensac
        UserAndSPInline,                                                                    
615 232 Paul Carensac
    ]
616 232 Paul Carensac
617 232 Paul Carensac
</pre>
618 232 Paul Carensac
619 235 Paul Carensac
* For each ModelAdmin class in the admin.py, change the registering line
620 235 Paul Carensac
621 235 Paul Carensac
<pre>
622 235 Paul Carensac
admin.site.register(Album)
623 235 Paul Carensac
</pre>
624 235 Paul Carensac
625 235 Paul Carensac
to
626 235 Paul Carensac
627 235 Paul Carensac
<pre>
628 235 Paul Carensac
admin.site.register(Album, AlbumAdmin)
629 235 Paul Carensac
</pre>
630 211 Paul Carensac
631 229 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}V - INSTALLATION FROM THE BEGINNING (for dev only, history of the initial project creation)%
632 1 Etienne Pallier
633 236 Etienne Pallier
634 242 Etienne Pallier
[[pyros_install_from_start|Pyros installation from the beginning]]