From 3dbb48d7fcf554d7a2bc39aaf7329a96ad2819d3 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Thu, 28 Feb 2019 15:50:07 +0100 Subject: [PATCH] Added modif line in writeindb() for member modification --- IFPass.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/IFPass.py b/IFPass.py index 4d79dd7..cfdd26d 100644 --- a/IFPass.py +++ b/IFPass.py @@ -214,12 +214,35 @@ def getpic(): sys.exit() -def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp): - print("Ajout dans la base de données... ", end="") - with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile: - writer = csv.writer(csvfile, delimiter=';') - writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp]) - print(colored('[OK]', 'green')) +def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): + if new is True: + print("Ajout dans la base de données... ", end="") + with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile: + writer = csv.writer(csvfile, delimiter=';') + writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp]) + print(colored('[OK]', 'green')) + elif new is False: + print("Modification de la base de données... ", end="") + with open(clientsfile, 'r+', newline='', encoding='utf-8') as csvfile: + content = csvfile.readlines() + for index, member in enumerate(content): + member = member.split(';') + if member[3] == clientID: + tochange = index + break + content.pop(tochange) + changewith = ";".join([titre, firstname, surname, clientID, dateinsc, dateexp]) + '\n' + content.insert(tochange, changewith) + content = "".join(content) + csvfile.truncate(0) + csvfile.write(content) + + reader = csv.reader(csvfile, delimiter=';') + writer = csv.writer(csvfile, delimiter=';') + for index, member in enumerate(reader): + if member[3] == clientID: + + print(colored('[OK]', 'green')) def bkpdb(): @@ -328,7 +351,7 @@ def newmember(): if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=True) break @@ -423,7 +446,7 @@ def memberdo(choix, member): if version not in ('dev', 'devnocam'): bkpdb() printcard(cartefilename) - writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) + writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) break else: # We crop pic from the previous card