From a304f6a97db2e575b93747432add690b157eac05 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Thu, 20 Feb 2020 22:10:10 +0100 Subject: [PATCH 1/4] Some initial data --- apps/member/fixtures/initial.json | 26 ++++ apps/note/fixtures/initial.json | 220 ++++++++++++++++++++++++++++++ apps/note/signals.py | 12 +- 3 files changed, 256 insertions(+), 2 deletions(-) create mode 100644 apps/member/fixtures/initial.json create mode 100644 apps/note/fixtures/initial.json diff --git a/apps/member/fixtures/initial.json b/apps/member/fixtures/initial.json new file mode 100644 index 00000000..7ff10c91 --- /dev/null +++ b/apps/member/fixtures/initial.json @@ -0,0 +1,26 @@ +[ + { + "model": "member.club", + "pk": 1, + "fields": { + "name": "BDE", + "email": "tresorerie.bde@example.com", + "membership_fee": 5, + "membership_duration": "365 00:00:00", + "membership_start": "00:00:00", + "membership_end": "365 00:00:00" + } + }, + { + "model": "member.club", + "pk": 2, + "fields": { + "name": "Kfet", + "email": "tresorerie.bde@example.com", + "membership_fee": 35, + "membership_duration": "365 00:00:00", + "membership_start": "00:00:00", + "membership_end": "365 00:00:00" + } + } +] \ No newline at end of file diff --git a/apps/note/fixtures/initial.json b/apps/note/fixtures/initial.json new file mode 100644 index 00000000..f853d3cb --- /dev/null +++ b/apps/note/fixtures/initial.json @@ -0,0 +1,220 @@ +[ + { + "model": "note.note", + "pk": 1, + "fields": { + "polymorphic_ctype": 22, + "balance": 0, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:02:48.778Z" + } + }, + { + "model": "note.note", + "pk": 2, + "fields": { + "polymorphic_ctype": 22, + "balance": 0, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:06:39.546Z" + } + }, + { + "model": "note.note", + "pk": 3, + "fields": { + "polymorphic_ctype": 22, + "balance": 0, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:06:43.049Z" + } + }, + { + "model": "note.note", + "pk": 4, + "fields": { + "polymorphic_ctype": 22, + "balance": 0, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:06:50.996Z" + } + }, + { + "model": "note.note", + "pk": 5, + "fields": { + "polymorphic_ctype": 21, + "balance": 0, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:09:38.615Z" + } + }, + { + "model": "note.note", + "pk": 6, + "fields": { + "polymorphic_ctype": 21, + "balance": 0, + "is_active": true, + "display_image": "", + "created_at": "2020-02-20T20:16:14.753Z" + } + }, + { + "model": "note.notespecial", + "pk": 1, + "fields": { + "special_type": "Esp\u00e8ces" + } + }, + { + "model": "note.notespecial", + "pk": 2, + "fields": { + "special_type": "Carte bancaire" + } + }, + { + "model": "note.notespecial", + "pk": 3, + "fields": { + "special_type": "Ch\u00e8que" + } + }, + { + "model": "note.notespecial", + "pk": 4, + "fields": { + "special_type": "Virement bancaire" + } + }, + { + "model": "note.noteclub", + "pk": 5, + "fields": { + "club": 1 + } + }, + { + "model": "note.noteclub", + "pk": 6, + "fields": { + "club": 2 + } + }, + { + "model": "note.alias", + "pk": 1, + "fields": { + "name": "Esp\u00e8ces", + "normalized_name": "especes", + "note": 1 + } + }, + { + "model": "note.alias", + "pk": 2, + "fields": { + "name": "Carte bancaire", + "normalized_name": "cartebancaire", + "note": 2 + } + }, + { + "model": "note.alias", + "pk": 3, + "fields": { + "name": "Ch\u00e8que", + "normalized_name": "cheque", + "note": 3 + } + }, + { + "model": "note.alias", + "pk": 4, + "fields": { + "name": "Virement bancaire", + "normalized_name": "virementbancaire", + "note": 4 + } + }, + { + "model": "note.alias", + "pk": 5, + "fields": { + "name": "BDE", + "normalized_name": "bde", + "note": 5 + } + }, + { + "model": "note.alias", + "pk": 6, + "fields": { + "name": "Kfet", + "normalized_name": "kfet", + "note": 6 + } + }, + { + "model": "note.transactioncategory", + "pk": 1, + "fields": { + "name": "Soft" + } + }, + { + "model": "note.transactioncategory", + "pk": 2, + "fields": { + "name": "Pulls" + } + }, + { + "model": "note.transactioncategory", + "pk": 3, + "fields": { + "name": "Gala" + } + }, + { + "model": "note.transactioncategory", + "pk": 4, + "fields": { + "name": "Clubs" + } + }, + { + "model": "note.transactioncategory", + "pk": 5, + "fields": { + "name": "Bouffe" + } + }, + { + "model": "note.transactioncategory", + "pk": 6, + "fields": { + "name": "BDA" + } + }, + { + "model": "note.transactioncategory", + "pk": 7, + "fields": { + "name": "Autre" + } + }, + { + "model": "note.transactioncategory", + "pk": 8, + "fields": { + "name": "Alcool" + } + } +] \ No newline at end of file diff --git a/apps/note/signals.py b/apps/note/signals.py index ad376ee0..e62115b3 100644 --- a/apps/note/signals.py +++ b/apps/note/signals.py @@ -2,20 +2,28 @@ # SPDX-License-Identifier: GPL-3.0-or-later -def save_user_note(instance, created, **_kwargs): +def save_user_note(instance, created, raw, **_kwargs): """ Hook to create and save a note when an user is updated """ + if raw: + # When provisionning data, do not try to autocreate + return + if created: from .models import NoteUser NoteUser.objects.create(user=instance) instance.note.save() -def save_club_note(instance, created, **_kwargs): +def save_club_note(instance, created, raw, **_kwargs): """ Hook to create and save a note when a club is updated """ + if raw: + # When provisionning data, do not try to autocreate + return + if created: from .models import NoteClub NoteClub.objects.create(club=instance) From 362880511d2b4ac9ab2d29b4e1a57dbbb73d6049 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Thu, 20 Feb 2020 22:10:37 +0100 Subject: [PATCH 2/4] [readme] How to load initial data --- README.md | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 6db8e5ed..ad9e62d9 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ On supposera pour la suite que vous utiliser debian/ubuntu sur un serveur tout n $ cp nginx_note.conf_example nginx_note.conf -*** Modifier le fichier pour etre en accord avec le reste de votre config *** +***Modifier le fichier pour être en accord avec le reste de votre config*** On utilise uwsgi et Nginx pour gérer le coté serveu : @@ -107,10 +107,9 @@ On supposera pour la suite que vous utiliser debian/ubuntu sur un serveur tout n 6. Variable d'environnement et Migrations - Ensuite on (re)bascule dans l'environement virtuel et on lance les migrations - + $ source /env/bin/activate (env)$ ./manage.py check # pas de bétise qui traine (env)$ ./manage.py makemigrations @@ -127,7 +126,8 @@ Il est possible de travailler sur une instance Docker. $ git clone git@gitlab.crans.org:bde/nk20.git -2. Dans le fichier `docker_compose.yml`, qu'on suppose déjà configuré, ajouter les lignes suivantes, en les adaptant à la configuration voulue : +2. Dans le fichier `docker_compose.yml`, qu'on suppose déjà configuré, + ajouter les lignes suivantes, en les adaptant à la configuration voulue : nk20: build: /chemin/vers/nk20 @@ -143,38 +143,39 @@ Il est possible de travailler sur une instance Docker. $ docker-compose up -d nk20 -## Installer en local +## Installer un serveur de développement -Il est tout-à-fait possible de travailler en local, vive `./manage.py runserver` ! +Avec `./manage.py runserver` il est très rapide de mettre en place +un serveur de développement par exemple sur son ordinateur. 1. Cloner le dépôt là où vous voulez : - $ git clone git@gitlab.crans.org:bde/nk20.git + $ git clone git@gitlab.crans.org:bde/nk20.git && cd nk20 -2. Initialiser l'environnement Virtuel - - $ cd nk20 - $ virtualenv env - $ source /env/bin/activate +2. Créer un environnement Python isolé + pour ne pas interférer avec les versions de paquets systèmes : + + $ python3 -m venv venv + $ source venv/bin/activate (env)$ pip install -r requirements.txt -3. Migrations: +3. Migrations et chargement des données initiales : (env)$ ./manage.py makemigrations (env)$ ./manage.py migrate + (env)$ ./manage.py loaddata initial -4. Enjoy: - - (env)$ ./manage.py runserver - -## Minimal Setup - -1. Créer un superuser : +4. Créer un super-utilisateur : (env)$ ./manage.py createsuperuser -Avec ce dernier vous pouvez vous connecter à l'interface admin de Django, avoir -accès à la doc auto-générée du projet, jouer avec des models, etc ... +5. Enjoy : + + (env)$ ./manage.py runserver 0.0.0.0:8000 + +En mettant `0.0.0.0:8000` après `runserver`, vous rendez votre instance Django +accessible depuis l'ensemble de votre réseau, pratique pour tester le rendu +de la note sur un téléphone ! ## Cahier des Charges @@ -182,4 +183,5 @@ Il est disponible [ici](https://wiki.crans.org/NoteKfet/NoteKfet2018/CdC). ## Documentation -La documentation est générée par django et son module admindocs. **Commenter votre code !* +La documentation est générée par django et son module admindocs. +**Commenter votre code !** From 20953ff214f02d419f8369abd55acb1b269bf686 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Thu, 20 Feb 2020 22:15:28 +0100 Subject: [PATCH 3/4] Change default site name with project fixture --- note_kfet/fixtures/initial.json | 10 ++++++++++ note_kfet/settings/base.py | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 note_kfet/fixtures/initial.json diff --git a/note_kfet/fixtures/initial.json b/note_kfet/fixtures/initial.json new file mode 100644 index 00000000..08501606 --- /dev/null +++ b/note_kfet/fixtures/initial.json @@ -0,0 +1,10 @@ +[ + { + "model": "sites.site", + "pk": 1, + "fields": { + "domain": "localhost", + "name": "La Note Kfet \ud83c\udf7b" + } + } +] \ No newline at end of file diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index 410f496f..92ed5819 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -160,6 +160,8 @@ USE_TZ = True LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")] +FIXTURE_DIRS = [os.path.join(BASE_DIR, "note_kfet/fixtures")] + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ From f1b442932f2f2f5146f76a18a5850da4f22ec15a Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sat, 22 Feb 2020 21:56:02 +0100 Subject: [PATCH 4/4] Use membership parameters according to BDE status --- apps/member/fixtures/initial.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/member/fixtures/initial.json b/apps/member/fixtures/initial.json index 7ff10c91..769650a0 100644 --- a/apps/member/fixtures/initial.json +++ b/apps/member/fixtures/initial.json @@ -6,9 +6,9 @@ "name": "BDE", "email": "tresorerie.bde@example.com", "membership_fee": 5, - "membership_duration": "365 00:00:00", - "membership_start": "00:00:00", - "membership_end": "365 00:00:00" + "membership_duration": "396 00:00:00", + "membership_start": "213 00:00:00", + "membership_end": "273 00:00:00" } }, { @@ -18,9 +18,9 @@ "name": "Kfet", "email": "tresorerie.bde@example.com", "membership_fee": 35, - "membership_duration": "365 00:00:00", - "membership_start": "00:00:00", - "membership_end": "365 00:00:00" + "membership_duration": "396 00:00:00", + "membership_start": "213 00:00:00", + "membership_end": "273 00:00:00" } } -] \ No newline at end of file +]