Added modif line in writeindb() for member modification

This commit is contained in:
Jordan ERNST 2019-02-28 15:50:07 +01:00
parent d651a4973a
commit 3dbb48d7fc

View File

@ -214,12 +214,35 @@ def getpic():
sys.exit() sys.exit()
def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp): def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new):
if new is True:
print("Ajout dans la base de données... ", end="") print("Ajout dans la base de données... ", end="")
with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile: with open(clientsfile, 'a', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile, delimiter=';') writer = csv.writer(csvfile, delimiter=';')
writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp]) writer.writerow([titre, firstname, surname, clientID, dateinsc, dateexp])
print(colored('[OK]', 'green')) 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(): def bkpdb():
@ -328,7 +351,7 @@ def newmember():
if version not in ('dev', 'devnocam'): if version not in ('dev', 'devnocam'):
bkpdb() bkpdb()
printcard(cartefilename) printcard(cartefilename)
writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=True)
break break
@ -423,7 +446,7 @@ def memberdo(choix, member):
if version not in ('dev', 'devnocam'): if version not in ('dev', 'devnocam'):
bkpdb() bkpdb()
printcard(cartefilename) printcard(cartefilename)
writeindb(titre, firstname, surname, clientID, dateinsc, dateexp) writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False)
break break
else: else:
# We crop pic from the previous card # We crop pic from the previous card