Ajout fenetre de navigation avec liste des projets + fonction recherche

This commit is contained in:
Matt Marcha 2017-08-24 16:47:11 +02:00
parent 1784a5b461
commit 6956cbb1ac
5 changed files with 220 additions and 12 deletions

View file

@ -0,0 +1,78 @@
# -*-coding:utf8 -*
"""Controleur pour la fenêtre de navigation"""
import sys
import os
DOSSIER_COURRANT = os.path.dirname(os.path.abspath(__file__))
DOSSIER_PARENT = os.path.dirname(DOSSIER_COURRANT)
sys.path.append(DOSSIER_PARENT)
from Controllers.Functions import Functions
from DB.dbLink import DBLink as DB
from Projects.Model import Project
class BrowseController:
"""Classe contenant les fonctions de contrôle utiles à la fenêtre de navigation"""
def __init__(self):
self.link = DB()
def get_projects_list(self):
"""Renvoie la liste des projets ouverts"""
#Requete permettant d'obtenir la liste des ID des projets au statut "ouvert" (1)
##On prépare la liste des ID et la Requete
proj_ids = list()
query = "SELECT IDProj \
FROM projet \
WHERE IDStat = (SELECT IDStat \
FROM statut \
WHERE Statut LIKE('%uvert%'))"
result = self.link.query(query, []).fetchall()
for idproj in result:
proj_ids.append(idproj[0])
#Depuis cette liste, charger chaque projet dans une autre liste
proj_list = list()
for pid in proj_ids:
proj_list.append(Project(pid))
return proj_list
def get_projects_search_results(self, search_query):
"""Renvoie la liste des projets correspondant à une recherche"""
##On prépare la liste des ID et la Requete
proj_ids = list()
query = "SELECT IDProj \
FROM projet \
WHERE Intitulé REGEXP %s \
OR NumDossier REGEXP %s \
AND IDStat = (SELECT IDStat \
FROM statut \
WHERE Statut LIKE('%uvert%')) "
result = self.link.query(query, [search_query, search_query]).fetchall()
for idproj in result:
proj_ids.append(idproj[0])
#Depuis cette liste, charger chaque projet dans une autre liste
proj_list = list()
for pid in proj_ids:
proj_list.append(Project(pid))
return proj_list
############## TESTS #################
test = BrowseController()
liste = test.get_projects_search_results("ou")
for elem in liste:
print(elem.nom)

23
Controllers/Functions.py Normal file
View file

@ -0,0 +1,23 @@
# -*-coding:utf8 -*
"""Fonctions générales au logiciel"""
import sys
import os
DOSSIER_COURRANT = os.path.dirname(os.path.abspath(__file__))
DOSSIER_PARENT = os.path.dirname(DOSSIER_COURRANT)
sys.path.append(DOSSIER_PARENT)
from Auth.authentication import Auth as Auth
from Users.Model import User as User
class Functions:
def __init__(self):
#Initialisation AUTH POUR TESTS - A SUPPRIMER
authy = Auth("test", "test")
############
Functions.current_user = User(Auth.current_user_id)
###### TESTS ########

View file

@ -5,7 +5,7 @@ import DB.dbLink as db
class Project: class Project:
"""Modèle projet. Contient un objet projet.""" """Modèle projet. Contient un objet projet."""
def __init__(self, proj_id='', nom='', description='', num_dossier='', budget=0, client=1, statut=1, responsable=1): def __init__(self, proj_id='', nom='', description='', num_dossier='', budget=0, client="", statut=1, responsable=1):
"""Constructeur initialisant le projet à partir de son ID""" """Constructeur initialisant le projet à partir de son ID"""
#On load le projet depuis la BDD si demandé avec un ID #On load le projet depuis la BDD si demandé avec un ID
@ -14,7 +14,7 @@ class Project:
#On va chercher le projet en base de données #On va chercher le projet en base de données
link = db.DBLink() link = db.DBLink()
query = "SELECT p.Intitulé AS bdd_nom, p.Description AS bdd_description, p.NumDossier AS num_dossier, p.Budget AS budget, \ 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 \ c.RaisonSociale AS client, c.IDClie AS idclient, s.IDStat AS statut, p.IDUtil AS responsable \
FROM projet AS p \ FROM projet AS p \
JOIN client AS c ON p.IDClient = c.IDClie \ JOIN client AS c ON p.IDClient = c.IDClie \
JOIN statut AS s ON p.IDStat = s.IDStat \ JOIN statut AS s ON p.IDStat = s.IDStat \
@ -22,7 +22,7 @@ class Project:
result = link.query(query, [self._id_proj, ]) result = link.query(query, [self._id_proj, ])
#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 bdd_nom, bdd_description, bdd_num_dossier, bdd_budget, bdd_client, bdd_statut, bdd_responsable in result: for bdd_nom, bdd_description, bdd_num_dossier, bdd_budget, bdd_client, bdd_statut, bdd_responsable, bdd_idclient in result:
self.nom = bdd_nom self.nom = bdd_nom
self.description = bdd_description self.description = bdd_description
self.num_dossier = bdd_num_dossier self.num_dossier = bdd_num_dossier
@ -30,6 +30,7 @@ class Project:
self.client = bdd_client self.client = bdd_client
self.statut = bdd_statut self.statut = bdd_statut
self.responsable = bdd_responsable self.responsable = bdd_responsable
self.id_client = bdd_idclient
#Sinon, on hydrate à partir des champs renseignés en paramètre #Sinon, on hydrate à partir des champs renseignés en paramètre
else: else:
@ -45,16 +46,13 @@ class Project:
"""Enregistrement d'un projet""" """Enregistrement d'un projet"""
link = db.DBLink() link = db.DBLink()
# Vérifier si le projet existe #On gère le client
# Si oui, récupérer son ID self.registerClient()
# Si non, le créer et récupérer son ID
#Enregistrement des données #Enregistrement des données
query = "INSERT INTO projet \ query = "INSERT INTO projet \
(Intitulé, Description, NumDossier, Budget, IDStat, IDClient, IDUtil) \ (Intitulé, Description, NumDossier, Budget, IDStat, IDClient, IDUtil) \
VALUES (%s, %s, %s, %s, %s, %s, %s)" 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]) link.commit(query, [self.nom, self.description, self.num_dossier, self.budget, self.statut, self.id_client, self.responsable])
#Chargement de l'id ainsi créé #Chargement de l'id ainsi créé
query = "SELECT IDProj \ query = "SELECT IDProj \
@ -72,7 +70,7 @@ class Project:
query = "UPDATE projet \ query = "UPDATE projet \
SET Intitulé = %s, Description = %s, NumDossier = %s, Budget = %s, IDUtil = %s, IDClient = %s, IDStat = %s \ SET Intitulé = %s, Description = %s, NumDossier = %s, Budget = %s, IDUtil = %s, IDClient = %s, IDStat = %s \
WHERE IDProj = %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]) link.commit(query, [self.nom, self.description, self.num_dossier, self.budget, self.responsable, self.id_client, self.statut, self._id_proj])
def delete(self): def delete(self):
"""supprimer l'utilisateur""" """supprimer l'utilisateur"""
@ -82,3 +80,26 @@ class Project:
FROM projet \ FROM projet \
WHERE IDProj = %s" WHERE IDProj = %s"
link.commit(query, [self._id_proj, ]) link.commit(query, [self._id_proj, ])
def registerClient(self):
"""Enregistrement du client en BDD"""
link = db.DBLink()
#On vérifie si le client existe
query = "SELECT IDClie \
FROM client \
WHERE RaisonSociale = %s "
result = link.query(query, [self.client, ]).fetchone()
#Si oui, on récupère son ID
if result is not None:
for element in result:
self.id_client = element
else:
#Sinon, on enregistre en BDD
link = db.DBLink()
query = "INSERT INTO client \
SET RaisonSociale = (%s)"
result = link.commit(query, [self.client, ])
#Récupération de l'ID
self.id_client = result.lastrowid

View file

@ -100,7 +100,7 @@ class User:
result = link.query(query, [self._id_table, ]) result = link.query(query, [self._id_table, ])
for id_role, role in result: for id_role, role in result:
self.roles[role] = id_role self.roles[id_role] = role
def update_roles(self): def update_roles(self):
"""enregistrement/mise à jour des roles de l'uitlisateur""" """enregistrement/mise à jour des roles de l'uitlisateur"""
@ -113,7 +113,7 @@ class User:
link.commit(query, [self._id_table, ]) link.commit(query, [self._id_table, ])
#Puis on enregistre les nouveaux #Puis on enregistre les nouveaux
for rol_id in self.roles.values(): for rol_id in self.roles.keys():
query = "INSERT INTO roleattribution \ query = "INSERT INTO roleattribution \
(IDUtil, IDRole) \ (IDUtil, IDRole) \
VALUES(%s, %s)" VALUES(%s, %s)"

86
Views/browseView.py Normal file
View file

@ -0,0 +1,86 @@
# -*-coding:utf8 -*
"""Fenêtre de navigation"""
from tkinter import *
from tkinter.ttk import *
import sys
import os
DOSSIER_COURRANT = os.path.dirname(os.path.abspath(__file__))
DOSSIER_PARENT = os.path.dirname(DOSSIER_COURRANT)
sys.path.append(DOSSIER_PARENT)
from Controllers.BrowseController import BrowseController
from Users.Model import User
class BrowseView:
def __init__(self):
self.ctrl = BrowseController()
self.search_input = ""
#On lance la fenêtre par rapport à la fenêtre mère
BrowseView.root = Tk()
BrowseView.root.title("Naviguer")
#Initialisation des variables
#self.mother = mother
tabs = Notebook(BrowseView.root, name="projets")
#Création des onglets
##Projets
pr_tab = Frame(tabs)
#recherche
search_frame = Frame(pr_tab)
self.search_input = Entry(search_frame)
self.search_input.pack(side=LEFT)
Button(search_frame, text="Rechercher", command=self.search).pack(side=RIGHT)
search_frame.pack()
###Treeview listant les projets
Label(pr_tab, text="Liste des projets").pack()
####Headers
self.pr_list = Treeview(pr_tab, selectmode="browse", show="headings", columns=("nom", "chef", "client", "num"))
self.pr_list.heading("nom", text="Nom")
self.pr_list.heading("chef", text="Chef de projet")
self.pr_list.heading("client", text="client")
self.pr_list.heading("num", text="N° dossier")
####Insertion du contenu
projects = self.ctrl.get_projects_list()
for proj in projects:
cdp = User(proj.responsable)
self.pr_list.insert("", 1, values=(proj.nom, (cdp.nom, cdp.prenom),
proj.client, proj.num_dossier))
self.pr_list.pack()
Button(pr_tab, text="Voir le projet").pack()
Button(pr_tab, text="Démarrer une tâche rapide pour ce projet").pack()
##Tâches
ta_tab = Frame(tabs)
#Ajout des onglets au notebook et affichage
tabs.add(pr_tab, text="Projets")
tabs.add(ta_tab, text="Tâches")
tabs.pack()
def search(self):
#on récupère les résultats
projects = self.ctrl.get_projects_search_results(self.search_input.get())
#on vide l'arbre
self.pr_list.delete(*self.pr_list.get_children())
#on le rerempli avec les résultats
for proj in projects:
cdp = User(proj.responsable)
self.pr_list.insert("", 1, values=(proj.nom, (cdp.nom, cdp.prenom),
proj.client, proj.num_dossier))
#test
test = BrowseView()
test.root.mainloop()