Renew membership implementation + Multiple fixes.

This commit is contained in:
Jordan ERNST 2019-03-04 17:36:01 +01:00
parent a1beec5cd1
commit 5d76b1f584

View File

@ -112,7 +112,7 @@ def get_fullname(**kwargs): # **kwargs => Optionnal arguments
if 'surname' in kwargs: if 'surname' in kwargs:
surname = kwargs['surname'] surname = kwargs['surname']
newsurname = input("Prénom (" + surname + "): ").strip() newsurname = input("Nom (" + surname + "): ").strip()
if len(newsurname) != 0: if len(newsurname) != 0:
surname = newsurname surname = newsurname
else: else:
@ -236,6 +236,7 @@ def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new):
changewith = ";".join([titre, firstname, surname, clientID, dateinsc, dateexp]) + '\n' changewith = ";".join([titre, firstname, surname, clientID, dateinsc, dateexp]) + '\n'
content.insert(tochange, changewith) content.insert(tochange, changewith)
content = "".join(content) content = "".join(content)
csvfile.seek(0)
csvfile.truncate(0) csvfile.truncate(0)
csvfile.write(content) csvfile.write(content)
@ -355,7 +356,7 @@ def newmember():
def membersearch(): def membersearch():
with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile: with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile, delimiter=';') reader = csv.reader(csvfile, delimiter=';')
csvlist = list(map(tuple, reader)) csvlist = list(map(list, reader))
del csvlist[0] # We dele the first line (Prénom, Nom...) del csvlist[0] # We dele the first line (Prénom, Nom...)
research = input('Entrez une partie du nom, prénom, ou numéro de carte (ou flashez) : ').lower() research = input('Entrez une partie du nom, prénom, ou numéro de carte (ou flashez) : ').lower()
os.system('cls') os.system('cls')
@ -405,7 +406,13 @@ def membersearch():
print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - Imprimer la carte', '0 - Menu principal', sep='\n') print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - Imprimer la carte', '0 - Menu principal', sep='\n')
choix = input('Choix : ') choix = input('Choix : ')
memberdo(choix, member) if choix == '0':
os.system('cls')
return
# We update values with new (edited) values :
newtitre, newfirstname, newsurname, newdateexp = memberdo(choix, member)
member[0], member[1], member[2], member[5] = newtitre, newfirstname, newsurname, newdateexp
else: else:
print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold'])) print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold']))
os.system("pause") os.system("pause")
@ -424,15 +431,16 @@ def memberdo(choix, member):
while "the informations are incorrect": # Loop Filling informations while "the informations are incorrect": # Loop Filling informations
titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname) titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname)
os.system('cls')
print("Titre : ", colored(titre, 'green')) print("Titre : ", colored(titre, 'green'))
print("Prénom : ", colored(firstname, 'green')) print("Prénom : ", colored(firstname, 'green'))
print("Nom : ", colored(surname, 'green')) print("Nom : ", colored(surname, 'green'))
correct = yes_or_no("Ces informations sont elles correctes ?") correct = yes_or_no("Ces informations sont elles correctes ?")
os.system('cls')
if correct: if correct:
wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?")
os.system('cls')
if wantnewpic: if wantnewpic:
os.system('cls') os.system('cls')
if version != 'devnocam': if version != 'devnocam':
@ -455,17 +463,28 @@ def memberdo(choix, member):
bkpdb() bkpdb()
printcard(cartefilename) printcard(cartefilename)
writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False)
os.system('cls')
break break
elif choix == '2': # Renew subscription elif choix == '2': # Renew subscription
print(2) dateexp = datetime.strptime(dateexp, '%d/%m/%Y').date()
diff = (dateexp - date.today()).days
if diff >= 0:
dateexp = dateexp + timedelta(days=365)
elif diff < 0:
dateexp = date.today() + timedelta(days=365)
dateexp = dateexp.strftime('%d/%m/%Y')
if version not in ('dev', 'devnocam'):
bkpdb()
printcard(cartefilename)
writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False)
print(colored("La date d'expiration a bien été mise à jour !\n", 'blue', attrs=['bold']))
elif choix == '3': # Print card elif choix == '3': # Print card
print('Print card') print('Print card')
elif choix == '0': # Menu
return
else: else:
os.system('cls')
print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) print(colored('Choix incorrect !\n', 'red', attrs=['bold']))
return titre, firstname, surname, dateexp
def main(): def main():