Wiki

Version 248 (Paul Carensac, 03/22/2016 06:12 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 245 Paul Carensac
165 245 Paul Carensac
Open cmd (windows + R, cmd) :
166 245 Paul Carensac
 $ python -m pip install --upgrade pip
167 245 Paul Carensac
 $ pip install virtualenv
168 244 Paul Carensac
</pre>
169 1 Etienne Pallier
170 183 Etienne Pallier
 * Windows 10 :
171 183 Etienne Pallier
<pre>
172 187 Etienne Pallier
TODO:
173 183 Etienne Pallier
</pre>
174 3 Etienne Pallier
175 4 Etienne Pallier
---
176 5 Etienne Pallier
177 192 Etienne Pallier
h3. Create a Python3 virtual environment dedicated to the project (inside the project folder)
178 127 Etienne Pallier
179 131 Etienne Pallier
<pre>
180 1 Etienne Pallier
181 193 Etienne Pallier
$ mkdir private/
182 193 Etienne Pallier
183 133 Etienne Pallier
$ cd private/
184 3 Etienne Pallier
185 246 Paul Carensac
$ which python3.5 ("where python" for windows)
186 3 Etienne Pallier
/opt/local/bin/python3.5
187 15 Etienne Pallier
188 127 Etienne Pallier
$ virtualenv-3.5 venv_py35_pyros -p /opt/local/bin/python3.5
189 3 Etienne Pallier
=> creates a venv_py35_pyros/ folder inside PYROS/private/
190 1 Etienne Pallier
191 131 Etienne Pallier
</pre>
192 1 Etienne Pallier
193 7 Etienne Pallier
---
194 3 Etienne Pallier
195 65 Etienne Pallier
h3. Activate the python virtual environment (from inside the project)
196 7 Etienne Pallier
197 55 Etienne Pallier
<pre>
198 1 Etienne Pallier
199 65 Etienne Pallier
$ pwd
200 134 Etienne Pallier
.../PYROS/private
201 1 Etienne Pallier
202 247 Paul Carensac
$ source ./venv_py35_pyros/bin/activate (venv_py35_pyros/Scripts/activate on Windows)
203 247 Paul Carensac
204 65 Etienne Pallier
205 3 Etienne Pallier
$ python -V
206 1 Etienne Pallier
Python 3.5.1
207 3 Etienne Pallier
208 3 Etienne Pallier
$ which pip
209 77 Etienne Pallier
.../PYROS/venv_py35_pyros/bin/pip
210 16 Etienne Pallier
211 194 Etienne Pallier
Upgrade pip to last version available:
212 3 Etienne Pallier
$ pip install --upgrade pip
213 3 Etienne Pallier
Collecting pip
214 3 Etienne Pallier
  Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
215 3 Etienne Pallier
Installing collected packages: pip
216 3 Etienne Pallier
  Found existing installation: pip 7.1.2
217 3 Etienne Pallier
    Uninstalling pip-7.1.2:
218 3 Etienne Pallier
      Successfully uninstalled pip-7.1.2
219 1 Etienne Pallier
Successfully installed pip-8.1.1
220 194 Etienne Pallier
221 194 Etienne Pallier
Upgrade wheel to last version available:
222 194 Etienne Pallier
$ pip install --upgrade wheel
223 194 Etienne Pallier
Collecting wheel
224 194 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
225 194 Etienne Pallier
Installing collected packages: wheel
226 194 Etienne Pallier
  Found existing installation: wheel 0.24.0
227 194 Etienne Pallier
    Uninstalling wheel-0.24.0:
228 194 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
229 194 Etienne Pallier
Successfully installed wheel-0.29.0
230 194 Etienne Pallier
231 55 Etienne Pallier
232 55 Etienne Pallier
</pre>
233 18 Etienne Pallier
234 212 Etienne Pallier
h3. Install the needed Python packages (from within the virtual environment)
235 18 Etienne Pallier
236 66 Etienne Pallier
First, be sure that the virtual environment is activated:
237 66 Etienne Pallier
<pre>
238 66 Etienne Pallier
$ python -V
239 66 Etienne Pallier
Python 3.5.1
240 66 Etienne Pallier
</pre>
241 66 Etienne Pallier
242 62 Etienne Pallier
 * *Automatic Installation of all packages*
243 62 Etienne Pallier
<pre>
244 90 Etienne Pallier
$ pip install -r REQUIREMENTS.txt
245 62 Etienne Pallier
</pre>
246 62 Etienne Pallier
247 93 Etienne Pallier
 * *Or, manual installation of each package*
248 62 Etienne Pallier
249 62 Etienne Pallier
  * *Install Django* :
250 32 Etienne Pallier
<pre>
251 3 Etienne Pallier
$ pip install django
252 3 Etienne Pallier
Collecting django
253 3 Etienne Pallier
  Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
254 3 Etienne Pallier
Installing collected packages: django
255 3 Etienne Pallier
Successfully installed django-1.9.4
256 3 Etienne Pallier
257 3 Etienne Pallier
$ pip install django-admin-tools
258 3 Etienne Pallier
Collecting django-admin-tools
259 3 Etienne Pallier
  Downloading django_admin_tools-0.7.2-py2.py3-none-any.whl (289kB)
260 3 Etienne Pallier
Installing collected packages: django-admin-tools
261 3 Etienne Pallier
Successfully installed django-admin-tools-0.7.2
262 3 Etienne Pallier
263 21 Etienne Pallier
$ pip install django-debug-toolbar
264 21 Etienne Pallier
Collecting django-debug-toolbar
265 21 Etienne Pallier
  Downloading django_debug_toolbar-1.4-py2.py3-none-any.whl (212kB)
266 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)
267 21 Etienne Pallier
Collecting sqlparse (from django-debug-toolbar)
268 21 Etienne Pallier
  Downloading sqlparse-0.1.19.tar.gz (58kB)
269 21 Etienne Pallier
Building wheels for collected packages: sqlparse
270 21 Etienne Pallier
  Running setup.py bdist_wheel for sqlparse ... done
271 21 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/7b/d4/72/6011bb100dd5fc213164e4bbee13d4e03261dd54ce6a5de6b8
272 21 Etienne Pallier
Successfully built sqlparse
273 21 Etienne Pallier
Installing collected packages: sqlparse, django-debug-toolbar
274 21 Etienne Pallier
Successfully installed django-debug-toolbar-1.4 sqlparse-0.1.19
275 21 Etienne Pallier
276 21 Etienne Pallier
$ pip install django-extensions
277 21 Etienne Pallier
Collecting django-extensions
278 21 Etienne Pallier
  Downloading django_extensions-1.6.1-py2.py3-none-any.whl (202kB)
279 21 Etienne Pallier
Collecting six>=1.2 (from django-extensions)
280 21 Etienne Pallier
  Downloading six-1.10.0-py2.py3-none-any.whl
281 21 Etienne Pallier
Installing collected packages: six, django-extensions
282 21 Etienne Pallier
Successfully installed django-extensions-1.6.1 six-1.10.0
283 21 Etienne Pallier
284 21 Etienne Pallier
$ pip install django-suit
285 21 Etienne Pallier
Collecting django-suit
286 21 Etienne Pallier
  Downloading django-suit-0.2.18.tar.gz (587kB)
287 21 Etienne Pallier
Building wheels for collected packages: django-suit
288 1 Etienne Pallier
  Running setup.py bdist_wheel for django-suit ... done
289 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/12/8b/9a/e02ab0ad9229881638aa040d47d77c8f562999533811927d41
290 1 Etienne Pallier
Successfully built django-suit
291 1 Etienne Pallier
Installing collected packages: django-suit
292 1 Etienne Pallier
Successfully installed django-suit-0.2.18
293 21 Etienne Pallier
294 32 Etienne Pallier
</pre>
295 32 Etienne Pallier
296 63 Etienne Pallier
  * *Install the web application server gunicorn (will be used in production instead of the dev django web server)* :
297 32 Etienne Pallier
<pre>
298 25 Etienne Pallier
$ pip install gunicorn
299 25 Etienne Pallier
Collecting gunicorn
300 25 Etienne Pallier
  Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
301 21 Etienne Pallier
Installing collected packages: gunicorn
302 26 Etienne Pallier
Successfully installed gunicorn-19.4.5
303 1 Etienne Pallier
</pre>
304 1 Etienne Pallier
305 63 Etienne Pallier
  * *Install the python mysql client*:
306 32 Etienne Pallier
<pre>
307 32 Etienne Pallier
$ pip install mysqlclient
308 72 Etienne Pallier
...
309 72 Etienne Pallier
</pre>
310 33 Etienne Pallier
311 73 Etienne Pallier
   * => Issue under Mac OS X:
312 72 Etienne Pallier
<pre>
313 3 Etienne Pallier
$ pip install mysqlclient
314 3 Etienne Pallier
Collecting mysqlclient
315 1 Etienne Pallier
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
316 22 Etienne Pallier
Building wheels for collected packages: mysqlclient
317 3 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... error
318 3 Etienne Pallier
319 1 Etienne Pallier
  ----------------------------------------
320 1 Etienne Pallier
  Failed building wheel for mysqlclient
321 1 Etienne Pallier
  Running setup.py clean for mysqlclient
322 1 Etienne Pallier
Failed to build mysqlclient
323 1 Etienne Pallier
Installing collected packages: mysqlclient
324 1 Etienne Pallier
  Running setup.py install for mysqlclient ... done
325 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
326 1 Etienne Pallier
327 1 Etienne Pallier
BOUH !!!
328 1 Etienne Pallier
329 1 Etienne Pallier
$ pip install --upgrade wheel
330 1 Etienne Pallier
Collecting wheel
331 1 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
332 1 Etienne Pallier
Installing collected packages: wheel
333 1 Etienne Pallier
  Found existing installation: wheel 0.24.0
334 1 Etienne Pallier
    Uninstalling wheel-0.24.0:
335 1 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
336 1 Etienne Pallier
Successfully installed wheel-0.29.0
337 1 Etienne Pallier
338 1 Etienne Pallier
$ pip uninstall mysqlclient
339 1 Etienne Pallier
340 1 Etienne Pallier
$ pip install mysqlclient
341 1 Etienne Pallier
Collecting mysqlclient
342 1 Etienne Pallier
  Using cached mysqlclient-1.3.7.tar.gz
343 1 Etienne Pallier
Building wheels for collected packages: mysqlclient
344 1 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... done
345 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/9b/06/50/d11418c26cf8f2156b13d4363b5afde8e7e75ebb8540d0228d
346 1 Etienne Pallier
Successfully built mysqlclient
347 1 Etienne Pallier
Installing collected packages: mysqlclient
348 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
349 1 Etienne Pallier
350 1 Etienne Pallier
YES !!!
351 1 Etienne Pallier
352 1 Etienne Pallier
</pre>
353 1 Etienne Pallier
354 107 Paul Carensac
   * => Issues under Ubuntu:
355 107 Paul Carensac
<pre>
356 107 Paul Carensac
$ pip install mysqlclient
357 107 Paul Carensac
Collecting mysqlclient
358 107 Paul Carensac
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
359 107 Paul Carensac
    100% |████████████████████████████████| 81kB 1.5MB/s
360 107 Paul Carensac
    Complete output from command python setup.py egg_info:
361 107 Paul Carensac
    /bin/sh: 1: mysql_config: not found
362 107 Paul Carensac
    Traceback (most recent call last):
363 107 Paul Carensac
      File "<string>", line 1, in <module>
364 107 Paul Carensac
    [...]
365 107 Paul Carensac
    ----------------------------------------
366 107 Paul Carensac
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-q6j4inuz/mysqlclient/
367 1 Etienne Pallier
368 108 Paul Carensac
BOUH !!!
369 108 Paul Carensac
370 107 Paul Carensac
$ sudo apt-get install libmysqlclient-dev
371 108 Paul Carensac
372 107 Paul Carensac
$ pip install mysqlclient
373 107 Paul Carensac
Collecting mysqlclient
374 107 Paul Carensac
  Using cached mysqlclient-1.3.7.tar.gz
375 107 Paul Carensac
Building wheels for collected packages: mysqlclient
376 107 Paul Carensac
  Running setup.py bdist_wheel for mysqlclient ... error
377 107 Paul Carensac
378 107 Paul Carensac
    _mysql.c:40:20: fatal error: Python.h: No such file or directory
379 107 Paul Carensac
     #include "Python.h"
380 107 Paul Carensac
                        ^
381 107 Paul Carensac
    compilation terminated.
382 107 Paul Carensac
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
383 107 Paul Carensac
    
384 107 Paul Carensac
    ----------------------------------------
385 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/
386 107 Paul Carensac
387 108 Paul Carensac
BOUH !!!
388 108 Paul Carensac
389 107 Paul Carensac
$ sudo apt-get install python3.5-dev
390 108 Paul Carensac
391 107 Paul Carensac
$ pip install mysqlclient
392 107 Paul Carensac
393 107 Paul Carensac
YES !!!
394 107 Paul Carensac
395 107 Paul Carensac
</pre>
396 12 Etienne Pallier
397 12 Etienne Pallier
---
398 28 Etienne Pallier
399 142 Etienne Pallier
h3. Test the project
400 142 Etienne Pallier
401 142 Etienne Pallier
<pre>
402 142 Etienne Pallier
403 150 Etienne Pallier
$ cd src/
404 150 Etienne Pallier
405 1 Etienne Pallier
$ ./manage.py runserver
406 38 Etienne Pallier
(or gunicorn pyros.wsgi)
407 3 Etienne Pallier
==> http://localhost:8000
408 87 Etienne Pallier
...
409 87 Etienne Pallier
...
410 87 Etienne Pallier
Ctrl-c
411 87 Etienne Pallier
412 1 Etienne Pallier
</pre>
413 142 Etienne Pallier
414 142 Etienne Pallier
415 142 Etienne Pallier
416 142 Etienne Pallier
---
417 142 Etienne Pallier
418 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)%
419 155 Paul Carensac
420 155 Paul Carensac
---
421 155 Paul Carensac
422 155 Paul Carensac
h3. Back Office setup
423 155 Paul Carensac
424 155 Paul Carensac
 * Prerequisites in src/pyros/settings.py :
425 155 Paul Carensac
426 155 Paul Carensac
    * INSTALLED_APPS must (at least) contain :
427 155 Paul Carensac
428 155 Paul Carensac
        * django.contrib.admin
429 155 Paul Carensac
        * django.contrib.auth
430 155 Paul Carensac
        * django.contrib.contenttypes
431 155 Paul Carensac
        * django.contrib.sessions
432 155 Paul Carensac
433 155 Paul Carensac
    * MIDDLEWARES must (at least) contain :
434 155 Paul Carensac
435 155 Paul Carensac
        * django.contrib.sessions.middleware.SessionMiddleware
436 155 Paul Carensac
        * django.middleware.common.CommonMiddleware
437 155 Paul Carensac
        * django.contrib.auth.middleware.AuthenticationMiddleware
438 155 Paul Carensac
439 155 Paul Carensac
 * At least one 'python manage.py migrate' must have been executed
440 155 Paul Carensac
441 155 Paul Carensac
 * Create a superuser for the administration :
442 155 Paul Carensac
443 155 Paul Carensac
<pre>
444 155 Paul Carensac
$ python manage.py createsuperuser
445 155 Paul Carensac
</pre>
446 155 Paul Carensac
447 156 Paul Carensac
* For each app of the project, fill the admin.py file :
448 155 Paul Carensac
449 155 Paul Carensac
<pre>
450 155 Paul Carensac
from django.contrib import admin
451 155 Paul Carensac
from app.models import Model1, Model2
452 155 Paul Carensac
453 155 Paul Carensac
admin.site.register(Model1)
454 155 Paul Carensac
admin.site.register(Model2)
455 155 Paul Carensac
</pre>
456 155 Paul Carensac
457 155 Paul Carensac
*Reminder* : each application must be registered in the settings.py INSTALLED_APPS variable.
458 157 Paul Carensac
459 168 Paul Carensac
* For each model in models.py, add a '__str__()' method in order to identify the object on the back office. Example :
460 157 Paul Carensac
461 157 Paul Carensac
<pre>
462 157 Paul Carensac
class UserLevel(models.Model):
463 157 Paul Carensac
    name = models.CharField(max_length=45, blank=True, null=True)
464 157 Paul Carensac
    desc = models.TextField(blank=True, null=True)
465 157 Paul Carensac
    priority = models.IntegerField(blank=True, null=True)
466 157 Paul Carensac
    quota = models.FloatField(blank=True, null=True)
467 157 Paul Carensac
468 157 Paul Carensac
    class Meta:
469 157 Paul Carensac
        managed = True
470 157 Paul Carensac
        db_table = 'userlevel'
471 157 Paul Carensac
472 157 Paul Carensac
    def __str__(self):
473 163 Paul Carensac
        return (str(self.name))
474 157 Paul Carensac
</pre>
475 157 Paul Carensac
476 159 Paul Carensac
*Naming convention* : Use self.name when possible, the creation time/date otherwise. Example :
477 159 Paul Carensac
478 159 Paul Carensac
<pre>
479 159 Paul Carensac
class SiteWatch(models.Model):
480 159 Paul Carensac
    updated = models.DateTimeField(blank=True, null=True)
481 159 Paul Carensac
    lights = models.CharField(max_length=45, blank=True, null=True)
482 159 Paul Carensac
    dome = models.CharField(max_length=45, blank=True, null=True)
483 159 Paul Carensac
    doors = models.CharField(max_length=45, blank=True, null=True)
484 159 Paul Carensac
    temperature = models.FloatField(blank=True, null=True)
485 159 Paul Carensac
486 159 Paul Carensac
    class Meta:
487 159 Paul Carensac
        managed = True
488 159 Paul Carensac
        db_table = 'sitewatch'
489 159 Paul Carensac
490 159 Paul Carensac
    def __str__(self):
491 160 Paul Carensac
        return (str(self.updated))
492 159 Paul Carensac
</pre>
493 173 Etienne Pallier
494 211 Paul Carensac
---
495 211 Paul Carensac
496 211 Paul Carensac
h3. Adaptation of the one-to-many and many-to-many display
497 211 Paul Carensac
498 211 Paul Carensac
* The one-to-many relationships are the following (One.many format) :
499 211 Paul Carensac
500 211 Paul Carensac
    * Schedule.sequences
501 211 Paul Carensac
    * Request.sequences
502 211 Paul Carensac
    * Sequence.albums
503 211 Paul Carensac
    * Album.plans
504 211 Paul Carensac
    * Plan.images
505 211 Paul Carensac
    * Telescope.detectors
506 211 Paul Carensac
    * Detector.filters
507 211 Paul Carensac
    * NrtAnalysis.images
508 211 Paul Carensac
    * Filter.plans
509 211 Paul Carensac
    * Detector.albums
510 211 Paul Carensac
    * UserLevel.users
511 211 Paul Carensac
    * Country.users
512 211 Paul Carensac
    * ScientificProgram.requests
513 211 Paul Carensac
    * User.requests
514 211 Paul Carensac
    * StrategyObs.alerts
515 211 Paul Carensac
    * SequenceType.sequences
516 211 Paul Carensac
517 211 Paul Carensac
* For each "many", create a new class in admin.py just after the imports, following these examples :
518 211 Paul Carensac
519 211 Paul Carensac
<pre>
520 211 Paul Carensac
521 211 Paul Carensac
For Schedule.sequences, Request.sequences and Sequentype.sequences, we will need :
522 211 Paul Carensac
523 211 Paul Carensac
class SequenceInline(admin.TabularInline):
524 211 Paul Carensac
    model = Sequence
525 211 Paul Carensac
    fields = ("name",)
526 211 Paul Carensac
    show_change_link = True
527 211 Paul Carensac
528 211 Paul Carensac
529 211 Paul Carensac
For Sequence.albums and Detector.albums, we will need :
530 211 Paul Carensac
531 211 Paul Carensac
class AlbumInline(admin.TabularInline):
532 211 Paul Carensac
    model = Album
533 211 Paul Carensac
    fields = ("name",)
534 211 Paul Carensac
    show_change_link = True
535 211 Paul Carensac
536 211 Paul Carensac
537 211 Paul Carensac
For StrategyObs.alerts, we will need :
538 211 Paul Carensac
539 211 Paul Carensac
class AlertInline(admin.TabularInline):
540 211 Paul Carensac
    model = Alert
541 211 Paul Carensac
    fields = ("request.name",) # there is no 'name' attribute in the Alert model
542 211 Paul Carensac
    show_change_link = True
543 211 Paul Carensac
544 211 Paul Carensac
</pre>
545 211 Paul Carensac
546 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 :
547 211 Paul Carensac
548 222 Paul Carensac
<pre>
549 222 Paul Carensac
For Request.sequences :
550 222 Paul Carensac
551 222 Paul Carensac
class RequestAdmin(admin.ModelAdmin):
552 222 Paul Carensac
    inlines = [
553 222 Paul Carensac
	SequenceInline,
554 222 Paul Carensac
    ]
555 222 Paul Carensac
556 222 Paul Carensac
For Detector.filters and Detector.albums :
557 222 Paul Carensac
558 222 Paul Carensac
class DetectorAdmin(admin.ModelAdmin):
559 222 Paul Carensac
    inlines = [
560 222 Paul Carensac
	FilterInline,
561 222 Paul Carensac
        AlbumInline,
562 222 Paul Carensac
    ]
563 222 Paul Carensac
564 222 Paul Carensac
</pre>
565 222 Paul Carensac
566 232 Paul Carensac
567 222 Paul Carensac
* The many-to-many relationships are the following :
568 232 Paul Carensac
569 222 Paul Carensac
    * ScientificProgram - User
570 222 Paul Carensac
    * ScheduleHistory - Sequence
571 222 Paul Carensac
572 222 Paul Carensac
* For each many-to-many relationship, declare a new "Inline" class in admin.py just after the imports, like this :
573 222 Paul Carensac
574 222 Paul Carensac
<pre>
575 222 Paul Carensac
For ScientificProgram - User :
576 222 Paul Carensac
577 222 Paul Carensac
class UserAndSPInline(admin.TabularInline):
578 222 Paul Carensac
    model = ScientificProgram.users.through
579 222 Paul Carensac
580 222 Paul Carensac
581 222 Paul Carensac
For ScheduleHistory - Sequence
582 222 Paul Carensac
583 222 Paul Carensac
class SequenceAndSHInline(admin.TabularInline):
584 222 Paul Carensac
    model = ScheduleHistory.sequences.through
585 222 Paul Carensac
586 222 Paul Carensac
</pre>
587 222 Paul Carensac
588 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.
589 232 Paul Carensac
590 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 :
591 232 Paul Carensac
592 232 Paul Carensac
<pre>
593 232 Paul Carensac
For the ScheduleHistory - Sequence relationship :
594 232 Paul Carensac
595 232 Paul Carensac
class ScheduleHistoryAdmin(admin.ModelAdmin):
596 232 Paul Carensac
    inlines = [
597 232 Paul Carensac
        SequenceAndSHInline,
598 232 Paul Carensac
    ]
599 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
600 232 Paul Carensac
601 232 Paul Carensac
class SequenceAdmin(admin.ModelAdmin):
602 232 Paul Carensac
    inlines = [
603 232 Paul Carensac
        AlbumInline,        # This is the Inline for the one-to-many relationship Sequence.albums
604 232 Paul Carensac
        SequenceAndSHInline,                                                                
605 232 Paul Carensac
    ]
606 232 Paul Carensac
607 232 Paul Carensac
For the ScientificProgram - User relationship :
608 232 Paul Carensac
609 232 Paul Carensac
class ScientificProgramAdmin(admin.ModelAdmin):
610 232 Paul Carensac
    inlines = [
611 232 Paul Carensac
        RequestInline,
612 232 Paul Carensac
	UserAndSPInline,                                                                         
613 232 Paul Carensac
    ]
614 232 Paul Carensac
    exclude = ('users',) # Same as ScheduleHistory                                                                         
615 232 Paul Carensac
616 232 Paul Carensac
class UserAdmin(admin.ModelAdmin):
617 232 Paul Carensac
    inlines = [
618 232 Paul Carensac
	RequestInline,   # This is the Inline for the one-to-many relationship User.requests
619 232 Paul Carensac
        UserAndSPInline,                                                                    
620 232 Paul Carensac
    ]
621 232 Paul Carensac
622 232 Paul Carensac
</pre>
623 232 Paul Carensac
624 235 Paul Carensac
* For each ModelAdmin class in the admin.py, change the registering line
625 235 Paul Carensac
626 235 Paul Carensac
<pre>
627 235 Paul Carensac
admin.site.register(Album)
628 235 Paul Carensac
</pre>
629 235 Paul Carensac
630 235 Paul Carensac
to
631 235 Paul Carensac
632 235 Paul Carensac
<pre>
633 235 Paul Carensac
admin.site.register(Album, AlbumAdmin)
634 235 Paul Carensac
</pre>
635 211 Paul Carensac
636 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)%
637 1 Etienne Pallier
638 236 Etienne Pallier
639 242 Etienne Pallier
[[pyros_install_from_start|Pyros installation from the beginning]]