2017-01-30 23:13:32 +01:00
|
|
|
"""
|
|
|
|
Charge des données de test dans la BDD
|
|
|
|
- Utilisateurs
|
|
|
|
- Sondage
|
|
|
|
- Événement
|
|
|
|
- Petits cours
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.core.management import call_command
|
2019-01-05 18:14:29 +01:00
|
|
|
|
|
|
|
from gestioncof.management.base import MyBaseCommand
|
2018-11-25 00:37:22 +01:00
|
|
|
from petitscours.models import (
|
2018-10-06 12:35:49 +02:00
|
|
|
LEVELS_CHOICES,
|
|
|
|
PetitCoursAbility,
|
|
|
|
PetitCoursAttributionCounter,
|
|
|
|
PetitCoursSubject,
|
2017-01-30 23:13:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Où sont stockés les fichiers json
|
2018-10-06 12:35:49 +02:00
|
|
|
DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data")
|
2017-01-30 23:13:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Command(MyBaseCommand):
|
|
|
|
help = "Charge des données de test dans la BDD"
|
|
|
|
|
2017-02-03 23:41:33 +01:00
|
|
|
def add_arguments(self, parser):
|
2017-01-30 23:13:32 +01:00
|
|
|
"""
|
|
|
|
Permet de ne pas créer l'utilisateur "root".
|
|
|
|
"""
|
|
|
|
parser.add_argument(
|
2018-10-06 12:35:49 +02:00
|
|
|
"--no-root",
|
|
|
|
action="store_true",
|
|
|
|
dest="no-root",
|
2017-01-30 23:13:32 +01:00
|
|
|
default=False,
|
2018-10-06 12:35:49 +02:00
|
|
|
help='Ne crée pas l\'utilisateur "root"',
|
2017-01-30 23:13:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
# ---
|
|
|
|
# Utilisateurs
|
|
|
|
# ---
|
|
|
|
|
|
|
|
# Gaulois
|
2018-10-06 12:35:49 +02:00
|
|
|
gaulois = self.from_json("gaulois.json", DATA_DIR, User)
|
2017-01-30 23:13:32 +01:00
|
|
|
for user in gaulois:
|
|
|
|
user.profile.is_cof = True
|
|
|
|
user.profile.save()
|
|
|
|
|
|
|
|
# Romains
|
2018-10-06 12:35:49 +02:00
|
|
|
self.from_json("romains.json", DATA_DIR, User)
|
2017-01-30 23:13:32 +01:00
|
|
|
|
|
|
|
# Root
|
2018-10-06 12:35:49 +02:00
|
|
|
no_root = options.get("no-root", False)
|
2017-01-30 23:13:32 +01:00
|
|
|
if not no_root:
|
|
|
|
self.stdout.write("Création de l'utilisateur root")
|
|
|
|
root, _ = User.objects.get_or_create(
|
2018-10-06 12:35:49 +02:00
|
|
|
username="root",
|
|
|
|
first_name="super",
|
|
|
|
last_name="user",
|
|
|
|
email="root@localhost",
|
|
|
|
)
|
|
|
|
root.set_password("root")
|
2017-02-03 17:07:50 +01:00
|
|
|
root.is_staff = True
|
|
|
|
root.is_superuser = True
|
2017-01-30 23:13:32 +01:00
|
|
|
root.profile.is_cof = True
|
|
|
|
root.profile.is_buro = True
|
|
|
|
root.profile.save()
|
|
|
|
root.save()
|
|
|
|
|
|
|
|
# ---
|
|
|
|
# Petits cours
|
|
|
|
# ---
|
|
|
|
|
|
|
|
self.stdout.write("Inscriptions au système des petits cours")
|
|
|
|
levels = [id for (id, verbose) in LEVELS_CHOICES]
|
|
|
|
subjects = list(PetitCoursSubject.objects.all())
|
|
|
|
nb_of_teachers = 0
|
|
|
|
for user in gaulois:
|
|
|
|
if random.randint(0, 1):
|
|
|
|
nb_of_teachers += 1
|
|
|
|
# L'utilisateur reçoit les demandes de petits cours
|
|
|
|
user.profile.petits_cours_accept = True
|
|
|
|
user.save()
|
|
|
|
# L'utilisateur est compétent dans une matière
|
|
|
|
subject = random.choice(subjects)
|
|
|
|
if not PetitCoursAbility.objects.filter(
|
2018-10-06 12:35:49 +02:00
|
|
|
user=user, matiere=subject
|
|
|
|
).exists():
|
2017-01-30 23:13:32 +01:00
|
|
|
PetitCoursAbility.objects.create(
|
|
|
|
user=user,
|
|
|
|
matiere=subject,
|
|
|
|
niveau=random.choice(levels),
|
2018-10-06 12:35:49 +02:00
|
|
|
agrege=bool(random.randint(0, 1)),
|
2017-01-30 23:13:32 +01:00
|
|
|
)
|
|
|
|
# On initialise son compteur d'attributions
|
|
|
|
PetitCoursAttributionCounter.objects.get_or_create(
|
2018-10-06 12:35:49 +02:00
|
|
|
user=user, matiere=subject
|
2017-01-30 23:13:32 +01:00
|
|
|
)
|
|
|
|
self.stdout.write("- {:d} inscriptions".format(nb_of_teachers))
|
|
|
|
|
|
|
|
# ---
|
|
|
|
# Le BdA
|
|
|
|
# ---
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
call_command("loadbdadevdata")
|
2017-02-08 02:22:31 +01:00
|
|
|
|
|
|
|
# ---
|
|
|
|
# La K-Fêt
|
|
|
|
# ---
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
call_command("loadkfetdevdata")
|