def modPersonne(perso, idP, nom=None, prenom=None, login=None, mdp=None, sexe=None, typeP=None, adresse=None, promotion=None, dateDeNaissance=None, lieuDeNaissance=None, numeroDeTel=None, email=None, groupes=None): """ Modify a person in the database :param idP: id of the person to modify :type idP: int :param pers: the user who wants to modify the object :type pers: Personne :param nom: last name of the person :type nom: string :param prenom: first name of the person :type prenom: string :param login: username of the person :type login: string :param mdp: password of the person :type mdp: string :param sexe: sex of the person :type sexe: list of tuple :param typeP: if the person is a student, a teacher etc... :type typeP: list of tuple :param adresse: the address of the person :type adresse: string :param promotion: year of the person promotion :type promotion: int :param dateDeNaissance: date of birth :type dateDeNaissance: python date :param lieuDeNaissance: place of birth :type lieuDeNaissance: string :param numeroDeTel: phone number :type numeroDeTel: string :param email: email of the person :type email: Django email or string :example: >> from BDD.choices import HOMME_STATUT, ELEVE_STATUT >> modPersonne(request.user.personne, sexe=HOMME_STATUT, typeP=ELEVE_STATUT) modify a person in the database """ p = models.Personne.objects.filter(id=idP)[0] su = 0 txt = "Vous avez changé la personne " + p.user.first_name + " " + p.user.last_name txt2 = "Votre profil à été changé :" if (prenom != None and prenom != "" and prenom != p.user.first_name) or (nom != None and nom != "" and nom != p.user.last_name): mod = models.Modification() mod.datemodif = timezone.now() mod.typetable = 'UserChanged : ' mod.typemod = MODIFIER mod.ipmod = p.user.id mod.save() cm = models.ChampsModifie() cm.champs = mod cm.nomchamp = 'Nom changé depuis' if prenom != None and prenom != "" and prenom != p.user.first_name: su = 1 cm.valchamp = p.user.first_name+' '+p.user.last_name cm.save() p.user.first_name = prenom if nom != None and nom != "" and nom != p.user.last_name: su = 1 cm.valchamp = p.user.first_name+' '+p.user.last_name cm.save() p.user.last_name = nom if su == 1: txt2 = txt2 + " vous etes maintenant : " + prenom + " " + nom + ". " txt = txt + " en " + prenom + " " + nom txt = txt + ". " if groupes != None: txt, txt2 = manytomany(groupes, txt, p, models.Groupe, "groupe_set", "groupe", "au", True, attrafiche="nom", txt2=txt2) p.groupe_set = groupes if login != None and login != "" and login != p.user.username: txt = txt + " Son login a changé de " + p.user.username + " à " + login txt2 = txt2 + " Votre login a été changé de " + p.user.username + " à " + login p.user.username = login if mdp != None and mdp != "" and p.user.password != login: txt = txt + " Son mot de passe a été changé " txt2 = txt2 + " Votre mot de passe a été changé " p.user.password = mdp p.filter = "{0} {1}".format(p.user.last_name, p.user.first_name) if email != None and email != "" and p.user.email != email: txt = txt + " Son email a changé de " + p.user.email + " à " + email txt2 = txt2 + " Votre email a été changé de " + p.user.email + " à " + email p.user.email = email p.user.save() if typeP != None and typeP != "" and int(typeP) != int(p.type): txt = txt + " Son statut a changé de " + str(p.get_type_display()) + " à " + findchoice(typeP, TYPE) + ". " txt2 = txt2 + " Votre statut a été changé de " + str(p.get_type_display()) + " à " + findchoice(typeP, TYPE) + ". " if int(typeP) == 3: p.user.is_superuser = True else: p.user.is_superuser = False p.type = typeP if sexe != None and int(sexe) != int(p.sexe): txt = txt + " Vous avez changé son sexe de " + str(p.get_sexe_display()) + " à " + findchoice(sexe, SEXE) + ". " txt2 = txt2 + " Vous sexe a été changé (sur le site) de " + str(p.get_sexe_display()) + " à " + findchoice(sexe, SEXE) + ". " p.sexe = sexe if adresse != None and adresse != "" and p.adresse != adresse: txt = txt + " Vous avez changé son adresse de " + p.adresse + " à " + adresse + ". " txt2 = txt2 + " Votre adresse a été changé de " + p.adresse + " à " + adresse + ". " p.adresse = adresse if promotion != None and promotion != "" and p.promotion != promotion: txt = txt + " Vous avez changé sa promotion de " + str(p.promotion) + " à " + str(promotion) + ". " txt2 = txt2 + " Votre promotion a changé de " + str(p.promotion) + " à " + str(promotion) + ". " p.promotion = promotion if dateDeNaissance != None and dateDeNaissance != "" and p.dateDeNaissance != dateDeNaissance: txt = txt + " Vous avez changé sa date de naissance de " + str(p.dateDeNaissance) + " à " + str(dateDeNaissance) + ". " txt2 = txt2 + " Votre date de naissance a été changé de " + str(p.dateDeNaissance) + " à " + str(dateDeNaissance) + ". " p.dateDeNaissance = dateDeNaissance if lieuDeNaissance != None and lieuDeNaissance != "" and p.lieuDeNaissance != lieuDeNaissance: txt = txt + " Vous avez changé son lieu de naissance de " + str(p.lieuDeNaissance) + " à " + str(lieuDeNaissance) + ". " txt2 = txt2 + " Votre lieu de naissance a été changé de " + str(p.lieuDeNaissance) + " à " + str(lieuDeNaissance) + ". " p.lieuDeNaissance = lieuDeNaissance if numeroDeTel != None and numeroDeTel != "" and p.numeroDeTel != numeroDeTel: txt = txt + " Vous avez changé son numéro de " + str(p.numeroDeTel) + " à " + str(numeroDeTel) + ". " txt2 = txt2 + " Votre numéro a changé de " + str(p.numeroDeTel) + " à " + str(numeroDeTel) + ". " p.numeroDeTel = numeroDeTel p.save() if p != perso: n = models.News() n.txt = txt n.typeG = MODIFIER n.type = PERSONNESTATUT n.uploadDate = timezone.now() n.save() n.personne.add(perso) n2 = models.News() n2.txt = txt2 n2.typeG = MODIFIER n2.type = PERSONNESTATUT n2.uploadDate = timezone.now() n2.save() n2.personne.add(p)
def modCourLive(idP, pers, salles=None, typeCour=None, jour=None, semaineMin=None, semaineMax=None, hmin=None, hmax=None): """ Modify an lesson :param idP: id of the lesson :type idP: int :param pers: the user who wants to modify the object :type pers: Personne :param salles: the lesson classroom(s) :type salles: List of Salle :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 :example: >> from BDD.choices import MARDI >> modCourLive(3, request.user.personne, jour=MARDI) change the day of the lesson which id=3 """ c = models.Cour.objects.get(id=idP) if (typeCour != None and c.typeCour.id != typeCour.id) or (salles != None and c.salles != salles) or (jour != None and jour != "" and c.jour != jour) or (semaineMin != None and semaineMin != "" and c.semaineMin != semaineMin) or (semaineMax != None and semaineMax != "" and c.semaineMax != semaineMax) or (hmin != None and hmin != "" and c.hmin != hmin) or (hmax != None and hmax != "" and c.hmax != hmax): mod = models.Modification() mod.datemodif = timezone.now() mod.typetable = 'TypeCour' mod.typemod = MODIFIER mod.ipmod = c.id mod.save() if typeCour != None and c.typeCour.id != typeCour.id: txt = "Vous avez modifié un cours de " + c.typeCour.nom + " en un cours de " + typeCour.nom + ". " cm1 = models.ChampsModifie() cm1.champs = mod cm1.nomchamp = 'Type de cours changé depuis' cm1.valchamp = c.typeCour cm1.save() c.typeCour = typeCour else: txt = "Vous avez modifié un cours de " + c.typeCour.nom + ". " if salles != None and c.salles != salles: txt = manytomany(salles, txt, c, models.Salle, "salles", "salle", "la", False) cm2 = models.ChampsModifie() cm2.champs = mod cm2.nomchamp = 'Salles changés depuis' cm2.valchamp = c.salles cm2.save() c.salles = salles if jour != None and jour != "" and c.jour != jour: txt = txt + "Vous avez modifié son jour de " + c.get_jour_display() + " à " + str(findchoice(int(jour), SEMAINE)) cm3 = models.ChampsModifie() cm3.champs = mod cm3.nomchamp = 'Jour changé depuis' cm3.valchamp = c.jour cm3.save() c.jour = jour if (semaineMin != None and semaineMin != "" and c.semaineMin != semaineMin) or (semaineMax != None and semaineMax != "" and c.semaineMax != semaineMax): cm4 = models.ChampsModifie() cm4.champs = mod cm4.nomchamp = 'Semaines' if semaineMin != None and c.semaineMin != semaineMin: txt = txt + "Vous avez modifié sa première semaine de " + str(c.semaineMin) + " à " + str(semaineMin) cm4.valchamp = '' cm4.save() c.semaineMin = semaineMin if semaineMax != None and c.semaineMax != semaineMax: txt = txt + "Vous avez modifié sa dernière semaine de " + str(c.semaineMax) + " à " + str(semaineMax) cm4.valchamp = 'De la semaine '+c.semaineMin+' à la semaine '+c.semaineMax cm4.save() c.semaineMax = semaineMax if (hmin != None and hmin != "" and c.hmin != hmin) or (hmax != None and hmax != "" and c.hmax != hmax): cm4 = models.ChampsModifie() cm4.champs = mod cm4.nomchamp = 'Heures' if hmin != None and c.hmin != hmin: txt = txt + "Vous avez modifié sa première heure de " + str(c.hmin) + " à " + str(hmin) cm4.valchamp = 'De l\H'+c.hmin+' à l\H'+c.hmax cm4.save() c.hmin = hmin if hmax != None and c.hmax != hmax: txt = txt + "Vous avez modifié sa dernière heure de " + str(c.hmax) + " à " + str(hmax) cm4.valchamp = 'De l\H'+c.hmin+' à l\H'+c.hmax cm4.save() c.hmax = hmax c.save() n = models.News() n.txt = txt n.typeG = MODIFIER n.type = CALENDRIERSTATUT n.uploadDate = timezone.now() n.save() n.personne.add(pers)
def addPersonne( pers, nom, prenom, login, mdp, sexe, typeP, adresse=None, promotion=None, dateDeNaissance=None, lieuDeNaissance=None, numeroDeTel=None, email=None, ): """ Add a person in the database :param pers: the user who wants to add the object :type pers: Personne :param nom: last name of the person :type nom: string :param prenom: first name of the person :type prenom: string :param login: username of the person :type login: string :param mdp: password of the person :type mdp: string :param sexe: sex of the person :type sexe: list of tuple :param typeP: if the person is a student, a teacher etc... :type typeP: list of tuple :param adresse: the address of the person :type adresse: string :param promotion: year of the person promotion :type promotion: int :param dateDeNaissance: date of birth :type dateDeNaissance: python date :param lieuDeNaissance: place of birth :type lieuDeNaissance: string :param numeroDeTel: phone number :type numeroDeTel: string :param email: email of the person :type email: Django email or string :exemple: >> from BDD.choices import HOMME_STATUT, ELEVE_STATUT >> addPersonne(request.user.personne, "Davis", "Miles", "godofjazz", "123456", HOMME_STATUT, ELEVE_STATUT) save a person in the database """ if models.User.objects.filter(username=login).count() > 0: return "Login already taken" if int(sexe) == INCONNU_STATUT: sexestring = "de sexe inconnu" elif int(sexe) == HOMME_STATUT: sexestring = "un homme" else: sexestring = "une femme" txt = ( "Vous avez ajouté " + prenom + " " + nom + " de login " + login + ", qui est " + sexestring + " et qui est " + findchoice(typeP, TYPE) + "." ) user = User.objects.create_user(username=login, password=mdp) user.first_name = prenom user.last_name = nom if email != "" and email != None: txt = txt + " Son mail est " + str(email) + "." user.email = email #### change### user.has_perm("BDD.add_note") user.has_perm("BDD.change_note") user.has_perm("BDD.delete_note") user.is_staff = True # ## fin ##" if typeP == ADMINISTRATEUR_STATUT: user.is_superuser = True user.save() p = models.Personne() p.user = user p.type = typeP p.sexe = sexe if adresse != "" and adresse != None: p.adresse = adresse txt = txt + " Son adresse est " + adresse + "." if promotion != None: p.promotion = promotion txt = txt + " Sa promotion est " + str(promotion) + "." if dateDeNaissance != "" and dateDeNaissance != None: txt = txt + " Il/Elle est né(e) le " + str(dateDeNaissance) + "." p.dateDeNaissance = dateDeNaissance if lieuDeNaissance != "" and lieuDeNaissance != None: txt = txt + " Il/Elle est né(e) à " + str(lieuDeNaissance) + "." p.lieuDeNaissance = lieuDeNaissance if numeroDeTel != "" and numeroDeTel != None: txt = txt + " Son noméro est le " + str(numeroDeTel) + "." p.numeroDeTel = numeroDeTel stri = "{0} {1}".format(p.user.last_name, p.user.first_name) if Personne.objects.filter(filter=stri).count() > 0 and lieuDeNaissance != None: stri = stri + " de " + lieuDeNaissance + "." if Personne.objects.filter(filter=stri).count() > 0 and dateDeNaissance != None: stri = stri + " du " + p.dateDeNaissance.strftime("%d/%m/%y") + "." i = 1 strbase = stri while Personne.objects.filter(filter=stri).count() > 0: stri = strbase + str(i) i = i + 1 p.filter = stri p.uploadDate = timezone.now() p.save() if typeP == PROF_STATUT: for ii in range(0, 5): h = horaireProf() h.prof = p h.jdelaSemaine = ii h.hminApresMidi = 5 h.hmaxApresMidi = 8 h.hminMatin = 1 h.hmaxMatin = 3 h.save() mod = models.Modification() mod.datemodif = timezone.now() mod.typetable = "Personne" mod.typemod = AJOUT mod.ipmod = p.id mod.save() cm1 = models.ChampsModifie() cm1.champs = mod cm1.nomchamp = "Identité" cm1.valchamp = nom + " " + prenom cm1.save() cm2 = models.ChampsModifie() cm2.champs = mod cm2.nomchamp = "Date d'upload" cm2.valchamp = p.uploadDate cm2.save() n = models.News() n.txt = txt n.typeG = AJOUT n.type = PERSONNESTATUT n.uploadDate = timezone.now() n.save() n.personne.add(pers) return p