Ajout modèle Projet + mini correction modèle user
This commit is contained in:
parent
5632bad4da
commit
9db5cd5232
84
Projects/Model.py
Normal file
84
Projects/Model.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
# -*-coding:utf8 -*
|
||||||
|
|
||||||
|
import DB.dbLink as db
|
||||||
|
|
||||||
|
class Project:
|
||||||
|
"""Modèle projet. Contient un objet projet."""
|
||||||
|
|
||||||
|
def __init__(self, proj_id='', nom='', description='', num_dossier='', budget=0, client=1, statut=1, responsable=1):
|
||||||
|
"""Constructeur initialisant le projet à partir de son ID"""
|
||||||
|
|
||||||
|
#On load le projet depuis la BDD si demandé avec un ID
|
||||||
|
if proj_id != '':
|
||||||
|
self._id_proj = proj_id
|
||||||
|
#On va chercher le projet en base de données
|
||||||
|
link = db.DBLink()
|
||||||
|
query = "SELECT p.Intitulé AS bdd_nom, p.Description AS bdd_description, p.NumDossier AS num_dossier, p.Budget AS budget, \
|
||||||
|
c.IDClie AS client, s.IDStat AS statut, p.IDUtil AS responsable \
|
||||||
|
FROM projet AS p \
|
||||||
|
JOIN client AS c ON p.IDClient = c.IDClie \
|
||||||
|
JOIN statut AS s ON p.IDStat = s.IDStat \
|
||||||
|
WHERE p.IDProj = %s"
|
||||||
|
result = link.query(query, [self._id_proj, ])
|
||||||
|
|
||||||
|
#On hydrate l'objet à partir des éléments récupérés en BDD
|
||||||
|
for bdd_nom, bdd_description, bdd_num_dossier, bdd_budget, bdd_client, bdd_statut, bdd_responsable in result:
|
||||||
|
self.nom = bdd_nom
|
||||||
|
self.description = bdd_description
|
||||||
|
self.num_dossier = bdd_num_dossier
|
||||||
|
self.budget = bdd_budget
|
||||||
|
self.client = bdd_client
|
||||||
|
self.statut = bdd_statut
|
||||||
|
self.responsable = bdd_responsable
|
||||||
|
|
||||||
|
#Sinon, on hydrate à partir des champs renseignés en paramètre
|
||||||
|
else:
|
||||||
|
self.nom = nom
|
||||||
|
self.description = description
|
||||||
|
self.num_dossier = num_dossier
|
||||||
|
self.budget = budget
|
||||||
|
self.client = client
|
||||||
|
self.statut = statut
|
||||||
|
self.responsable = responsable
|
||||||
|
|
||||||
|
def register(self):
|
||||||
|
"""Enregistrement d'un projet"""
|
||||||
|
link = db.DBLink()
|
||||||
|
|
||||||
|
# Vérifier si le projet existe
|
||||||
|
# Si oui, récupérer son ID
|
||||||
|
# Si non, le créer et récupérer son ID
|
||||||
|
|
||||||
|
|
||||||
|
#Enregistrement des données
|
||||||
|
query = "INSERT INTO projet \
|
||||||
|
(Intitulé, Description, NumDossier, Budget, IDStat, IDClient, IDUtil) \
|
||||||
|
VALUES (%s, %s, %s, %s, %s, %s, %s)"
|
||||||
|
link.commit(query, [self.nom, self.description, self.num_dossier, self.budget, self.statut, self.client, self.responsable])
|
||||||
|
#Chargement de l'id ainsi créé
|
||||||
|
|
||||||
|
query = "SELECT IDProj \
|
||||||
|
FROM projet \
|
||||||
|
WHERE IDProj = (SELECT MAX(IDProj) \
|
||||||
|
FROM projet)"
|
||||||
|
result = link.query(query, [])
|
||||||
|
|
||||||
|
for id_proj, in result:
|
||||||
|
self._id_proj = id_proj
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Mise à jour du projet"""
|
||||||
|
link = db.DBLink()
|
||||||
|
query = "UPDATE projet \
|
||||||
|
SET Intitulé = %s, Description = %s, NumDossier = %s, Budget = %s, IDUtil = %s, IDClient = %s, IDStat = %s \
|
||||||
|
WHERE IDProj = %s"
|
||||||
|
link.commit(query, [self.nom, self.description, self.num_dossier, self.budget, self.responsable, self.client, self.statut, self._id_proj])
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""supprimer l'utilisateur"""
|
||||||
|
link = db.DBLink()
|
||||||
|
|
||||||
|
query = "DELETE \
|
||||||
|
FROM projet \
|
||||||
|
WHERE IDProj = %s"
|
||||||
|
link.commit(query, [self._id_proj, ])
|
|
@ -13,7 +13,7 @@ class User:
|
||||||
self._id_table = id
|
self._id_table = id
|
||||||
#On va chercher l'user en base de données
|
#On va chercher l'user en base de données
|
||||||
link = db.DBLink()
|
link = db.DBLink()
|
||||||
query = "SELECT u.IDUtil AS id_bdd, u.Nom AS nom, u.Prénom AS prenom, u.Identifiant AS identifiant, u.MdP AS mdp, u.SalaireBrut AS cout, u.IDFonc AS id_fonc, f.Intitulé AS fonction, p.Libelle AS pole \
|
query = "SELECT u.IDUtil AS id_bdd, u.Nom AS bdd_nom, u.Prénom AS bdd_prenom, u.Identifiant AS bdd_identifiant, u.MdP AS bdd_mdp, u.SalaireBrut AS bdd_cout, u.IDFonc AS bdd_id_fonc, f.Intitulé AS bdd_fonction, p.Libelle AS bdd_pole \
|
||||||
FROM utilisateur AS u \
|
FROM utilisateur AS u \
|
||||||
JOIN fonction AS f ON f.IDFonc = u.IDFonc \
|
JOIN fonction AS f ON f.IDFonc = u.IDFonc \
|
||||||
JOIN pole AS p ON p.IDPole = p.IDPole \
|
JOIN pole AS p ON p.IDPole = p.IDPole \
|
||||||
|
@ -21,16 +21,16 @@ class User:
|
||||||
result = link.query(query, [self._id_table, ])
|
result = link.query(query, [self._id_table, ])
|
||||||
|
|
||||||
#On hydrate l'objet à partir des éléments récupérés en BDD
|
#On hydrate l'objet à partir des éléments récupérés en BDD
|
||||||
for id_bdd, nom, prenom, identifiant, mdp, cout, id_fonc, fonction, pole in result:
|
for id_bdd, bdd_nom, bdd_prenom, bdd_identifiant, bdd_mdp, bdd_cout, bdd_id_fonc, bdd_fonction, bdd_pole in result:
|
||||||
self._id_table = id_bdd
|
self._id_table = id_bdd
|
||||||
self.fonction = fonction
|
self.fonction = bdd_fonction
|
||||||
self.pole = pole
|
self.pole = bdd_pole
|
||||||
self.nom = nom
|
self.nom = bdd_nom
|
||||||
self.prenom = prenom
|
self.prenom = bdd_prenom
|
||||||
self.identifiant = identifiant
|
self.identifiant = bdd_identifiant
|
||||||
self._mdp = mdp
|
self._mdp = bdd_mdp
|
||||||
self.cout = cout
|
self.cout = bdd_cout
|
||||||
self.id_fonc = id_fonc
|
self.id_fonc = bdd_id_fonc
|
||||||
|
|
||||||
#Récupération de la liste des roles
|
#Récupération de la liste des roles
|
||||||
self.roles = dict()
|
self.roles = dict()
|
||||||
|
|
16
main.py
16
main.py
|
@ -1,21 +1,26 @@
|
||||||
# -*-coding:UTF-8 -*
|
# -*-coding:UTF-8 -*
|
||||||
import Auth.authentification as auth
|
import os
|
||||||
|
import Auth.authentication as auth
|
||||||
import Auth.login as log
|
import Auth.login as log
|
||||||
import Menu.barreOutils as barre
|
import Menu.barreOutils as barre
|
||||||
import Users.Model as U
|
import Users.Model as U
|
||||||
import os
|
import Projects.Model as P
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#On appelle le module d'identification - Commenté pour les pahses de test d'autres modules
|
#On appelle le module d'identification - Commenté pour les pahses de test d'autres modules
|
||||||
login = log.Login()
|
login = log.Login()
|
||||||
login.fenetre.mainloop()
|
login.fenetre.mainloop()
|
||||||
|
#auth.Auth.access = True
|
||||||
|
#auth.Auth.current_user_id = 1
|
||||||
|
|
||||||
|
|
||||||
#On lance le programme
|
#On lance le programme
|
||||||
while auth.Auth.access == True:
|
while auth.Auth.access == True:
|
||||||
print("programme en cours")
|
print("programme en cours")
|
||||||
user = U.User(auth.Auth.current_user)
|
user = U.User(auth.Auth.current_user_id)
|
||||||
print("Bonjour", user.nom, user.prenom, "vous êtes dans la boucle")
|
print("Bonjour", user.nom, user.prenom, "vous êtes dans la boucle")
|
||||||
|
|
||||||
# Instanciation d'un objet de la classe BarreOutils
|
# Instanciation d'un objet de la classe BarreOutils
|
||||||
barreOutils = barre.BarreOutils()
|
barreOutils = barre.BarreOutils()
|
||||||
barreOutils.fenetre.mainloop()
|
barreOutils.fenetre.mainloop()
|
||||||
|
@ -23,13 +28,10 @@ while auth.Auth.access == True:
|
||||||
print("fermer = ",barreOutils.fermer)
|
print("fermer = ",barreOutils.fermer)
|
||||||
|
|
||||||
if barreOutils.fermer == True:
|
if barreOutils.fermer == True:
|
||||||
auth.Auth.access = False
|
auth.Auth.access = False
|
||||||
else:
|
else:
|
||||||
os.system("pause")
|
os.system("pause")
|
||||||
# Test de l'attribut access qui détermine si on entre ou pas dans la boucle while
|
# Test de l'attribut access qui détermine si on entre ou pas dans la boucle while
|
||||||
print("access = ", auth.Auth.access)
|
print("access = ", auth.Auth.access)
|
||||||
|
|
||||||
# Fin while
|
# Fin while
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue