« Previous - Version 52/177 (diff) - Next » - Current version
Etienne Pallier, 03/25/2016 11:53 pm


Project Development

Project Installation page : Project Installation

HOWTO Format Redmine Wiki : http://www.redmine.org/projects/redmine/wiki/FrRedmineWikiFormatting


TODO

  • Interface admin (http://localhost:8000/admin):
    • Impossible d'ajouter un pays dans Country depuis admin (erreur sur pyrosuser.name)
    • Impossible d'ajouter un telescope (erreur sur device.name)
    • champs booleans: représenter en case à cocher (cf requests.is_alert) : is_alert = models.BooleanField()
    • Fix plurals:
      • Country : plural "countries" and not "countrys"
      • NrtAnalysiss
      • Historys
      • ...
  • Models: bien définir les valeurs par défaut
    • ex: request.is_alert = False par défaut
  • Preload some data for some tables:
    • country => France, Mexico, ...
    • sequencetype => 0=routine, 1=alert, ...
    • userlevel => 0=normal, 1=expert, 2=admin, ...
    • ...
  • updated et created : champs automatiques Django
  • Ecrire quelques premiers petits tests
  • Tester install eclipse from scratch (vérifier qu'on n'a plus besoin de faire "set as pydev" et "set as django" et set DJANGO_MANAGE_LOCATION et set DJANGO_SETTINGS_MODULE)
  • Séparation des BD Django et Pyros
  • Intégration des modules Django déjà développés
  • Intégration continue avec Jenkins (+ run des tests sur une VM Windows)
  • Planifier la suite...
  • Doc pour le meeting de mai
  • pyrossu : pyrossu!

LIENS UTILES

  • Eclipse:
    • Shift-Ctrl-f (ou Shift-Cmd-f) : reformatage du fichier selon PEP8
    • Shift-Ctrl-1 : make doc string ...


I - DATABASE SCHEMA (v0.2.1)

Error executing the thumbnail macro (Attachment PYROS_PDM_v021.png not found)


II - Get the project (from gitlab)

Gitlab management interface

https://gitlab.irap.omp.eu/epallier/pyros

https://gitlab.irap.omp.eu/epallier/pyros/team

Get the project

https://projects.irap.omp.eu/projects/pyros/wiki/Project_Installation#II-Get-the-project-from-gitlab


III - INSTALLATION

https://projects.irap.omp.eu/projects/pyros/wiki/Project_Installation#III-INSTALLATION


IV - CONFIGURATION of the Django Back Office (administration interface)

Configuration of the Django Back office (admin)


V - EVOLUTION OF THE PROJECT

Linking the User model to the django's one

  • Modifications in models.py :
    • Rename User model to PyrosUser
    • Rename user table name to pyros_user
    • Change all occurences (User -> PyrosUser, users -> pyros_users, ...)
    • from django.contrib.auth.models import User <== add at the beginning of the file
    • user = models.OneToOneField(User, on_delete=models.CASCADE) <== add this field in PyrosUser declaration
    • delete fields in PyrosUser : name, firstname, email, login, pass
  • Modifications in admin.py :
    • Change all occurences (User* -> PyrosUser*, users -> pyros_users, ...)
$ python manage.py makemigrations pyrosapp
$ python manage.py migrate

Manage static files (for admin but also for each application)

./manage.py runserver

if DEBUG=False, we have errors, missing static files :

Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/login.css
Not Found: /admin/login
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/login.css
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/login.css
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/dashboard.css
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/base.css
…

=> We have to activate the static files management

(see https://docs.djangoproject.com/en/1.9/howto/static-files)

In pyros/urls.py, add this:


from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

STATIC_ROOT must be defined in settings and says where is the root of all static files

Edit settings.py, add:

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'public', 'static')

./manage.py collectstatic

=> 56 static files copied to '.../PYROS/public/static'

(in fact it is in public/static/admin/)

Cette commande copie tous les fichiers statiques de toutes les applis
dans public/static

Apache viendra lire ce dossier unique

A chq changement d’un fichier statique d’une appli, exécuter « collectstatic » pour mettre à jour le dossier final public/static (auquel on ne doit pas toucher manuellement, c’est un dossier « final »)


DJANGO SHELL (top cool)

cf page 60 for the ORM methods

./manage.py shell
Python 3.5.1 (default, Mar  2 2016, 03:38:02) 
(InteractiveConsole)

>>> import django

>>> from pyrosapp.models import *

>>> country = Country(name='mexico', quota=1)
>>> country.save()
(ajout si pas d’id, modif si id)

>>> country = Country(name='france')
>>> country.save()
>>> country.pk
>>> 2

>>> countries = Country.objects.all()
>>> countries.count
>>> <bound method QuerySet.count of <Country: mexico>, <Country: france>>
>>> countries.count()
>>> 2
>>> print(countries)
>>> <Country: mexico>, <Country: france>
>>> print(countries.query)
>>> SELECT country.id, country.name, country.desc, country.quota FROM country

>>> cs = countries.filter(name__icontains='fran')
>>> print(cs)
>>> <Country: france>

>>> cs = countries.filter(name__startswith='me')
>>> print(cs)
>>> <Country: mexico>


HOWTO (divers)

Many to Many

tache <=> user

tache.user
user.tache_set

Pour relier une appli python pure à un projet django :

=> Ajouter le src/ dans le pythonpath

Séparer le code métier :

=> installer le code métier comme un module via pip
Couches :
  • présentation
  • métier
  • modèle

ORM

(cf page 60)

b = Book(…)
b.save() :
ajout si pas d’id, modif si id

Book.objects.all()

Book.objects.filter(
release__gte=date(2013, 01, 01)
).exclude(
borrowed=True
)

A! La requete est exécutée le plus tard possible, seulement quand django a vraiment besoin de l’exécuter

books = Book.objects.exclude(borrowed=True).order_by('title')
print (books.author)

Book.objects.get(pk=12)

author = Author.objects.get(pk=25)
author.books.filter(borrowed=False)

(books est le related name déclaré dans la relation manytomany)


INSTALLATION FROM THE BEGINNING (for dev only, history of the initial project creation)

Pyros installation from the beginning

PYROS_PDM_v021.png (306 KB) Etienne Pallier, 03/24/2016 12:53 pm

models.py Magnifier (18.7 KB) Paul Carensac, 03/24/2016 03:30 pm

admin.py Magnifier (3.87 KB) Paul Carensac, 03/24/2016 03:30 pm

models.png (603 KB) Etienne Pallier, 04/01/2016 11:42 am

classes_dashboard.png (19.1 KB) Etienne Pallier, 04/01/2016 12:52 pm

classes_pyrosapp.png (2.09 MB) Etienne Pallier, 04/01/2016 12:52 pm

classes_pyrosappadmin.png (433 KB) Etienne Pallier, 04/01/2016 12:52 pm

IRAP-OFT-CC-SP-0007.pdf (630 KB) Etienne Pallier, 04/01/2016 04:25 pm