Added modif line in writeindb() for member modification
This commit is contained in:
parent
d651a4973a
commit
3dbb48d7fc
29
IFPass.py
29
IFPass.py
@ -214,12 +214,35 @@ def getpic():
|
||||
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="")
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user