Esempio n. 1
0
def generEmploiedutemp():
    grps = Groupe.objects.all()
    
    salles = Salle.objects.all()
    for g in grps:
        
        courtypes = g.typecour_set.all()
        for j in range(0, 5):
            for h in range(0, 6):
                c = Cour()
                c.typeCour = r.choice(courtypes)
                c.jour = j
                
                c.uploadDate = timezone.now()
                c.semaineMin = 0
                c.semaineMax = 52
                c.hmin = h
                c.hmax = h
                c.save()
                c.salles.add(r.choice(salles))
Esempio n. 2
0
def addCalendrier(pers, typeCour, jour, semaineMin, semaineMax, hmin, hmax, salles):
    """
        add a lesson in the database
        
    :param pers: the user who wants to add the object
    :type pers: Personne
    :param typeCour: which type of lesson
    :type typeCour: typeCour
    :param jour: Day of the lesson
    :type jour: list of Tuple
    :param semaineMin: first week of the lesson
    :type semaineMin: int
    :param semaineMax: last week of the lesson
    :type semaineMax: int
    :param hmin: first hour of the lesson
    :type hmin: int 
    :param hmax: last hour of the lesson
    :type hmax: int
    :param salles: the lesson classroom(s)
    :type salles: List of Salle
    
    :exemple:
    
    >> from BDD.choices import MARDI
    >> t = TypeCour.objects.get(id=2)
    >> s = SALLE.objects.filter(id=1) # it must be a list that is why it is a filter and not a get
    >> addCalendrier(request.user.personne, t, MARDI,0,1,0,A, s)
    save a lesson in the database
    
    """
    if hmin > hmax or semaineMin > semaineMax:
        return "entrées non valide"
    c = Cour()
    c.typeCour = typeCour
    c.jour = jour

    c.uploadDate = timezone.now()
    c.semaineMin = semaineMin
    c.semaineMax = semaineMax
    c.hmin = hmin
    c.hmax = hmax
    c.save()
    c.salles = salles

    mod = models.Modification()
    mod.datemodif = timezone.now()
    mod.typetable = "TypeCour"
    mod.typemod = AJOUT
    mod.ipmod = c.id
    mod.save()
    cm1 = models.ChampsModifie()
    cm1.champs = mod
    cm1.nomchamp = "Jour"
    cm1.valchamp = jour
    cm1.save()
    cm2 = models.ChampsModifie()
    cm2.champs = mod
    cm2.nomchamp = "Date d'upload"
    cm2.valchamp = c.uploadDate
    cm2.save()
    cm3 = models.ChampsModifie()
    cm3.champs = mod
    cm3.nomchamp = "Semaines"
    cm3.valchamp = "De la semaine " + str(semaineMin) + " à la semaine " + str(semaineMax)
    cm3.save()
    cm4 = models.ChampsModifie()
    cm4.champs = mod
    cm4.nomchamp = "Heures"
    cm4.valchamp = ""
    cm4.save()
    cm5 = models.ChampsModifie()
    cm5.champs = mod
    cm5.nomchamp = "Salles du cours "
    a = ""
    for p in c.salles.all():
        a = a + str(p) + " "
    cm5.valchamp = a
    cm5.save()
    cm6 = models.ChampsModifie()
    cm6.champs = mod
    cm6.nomchamp = "Type de cour"
    cm6.valchamp = typeCour
    cm6.save()

    d = datetime.datetime.now()
    n = models.News()
    if semaineMin < semaineMax:
        n.txt = (
            "Vous avez ajouté un cours de "
            + typeCour.nom
            + " du "
            + day2(d.year, semaineMin, jour).strftime("%d/%m/%Y")
            + " au "
            + day2(d.year, semaineMax, jour).strftime("%d/%m/%Y")
            + " de l'heure "
            + str(hmin)
            + " jusqu'à "
            + str(hmax)
        )
    else:
        n.txt = (
            "Vous avez ajouté un cours de "
            + typeCour.nom
            + " le "
            + day2(d.year, semaineMin, jour).strftime("%d/%m/%Y")
            + " de l'heure "
            + str(hmin)
            + " jusqu'à "
            + str(hmax)
        )

    n.typeG = AJOUT
    n.type = CALENDRIERSTATUT
    n.uploadDate = timezone.now()
    n.save()
    n.personne.add(pers)
    return c