From 5d76b1f58481c3679f958bc2988f35c858addbb0 Mon Sep 17 00:00:00 2001 From: Jordan ERNST Date: Mon, 4 Mar 2019 17:36:01 +0100 Subject: [PATCH] Renew membership implementation + Multiple fixes. --- IFPass.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/IFPass.py b/IFPass.py index 53e5c08..90c65ac 100644 --- a/IFPass.py +++ b/IFPass.py @@ -112,7 +112,7 @@ def get_fullname(**kwargs): # **kwargs => Optionnal arguments if 'surname' in kwargs: surname = kwargs['surname'] - newsurname = input("Prénom (" + surname + "): ").strip() + newsurname = input("Nom (" + surname + "): ").strip() if len(newsurname) != 0: surname = newsurname else: @@ -224,7 +224,7 @@ def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): 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="") + 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): @@ -236,6 +236,7 @@ def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new): changewith = ";".join([titre, firstname, surname, clientID, dateinsc, dateexp]) + '\n' content.insert(tochange, changewith) content = "".join(content) + csvfile.seek(0) csvfile.truncate(0) csvfile.write(content) @@ -355,7 +356,7 @@ def newmember(): def membersearch(): with open(clientsfile, 'r', newline='', encoding='utf-8') as csvfile: 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...) research = input('Entrez une partie du nom, prénom, ou numéro de carte (ou flashez) : ').lower() 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') 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: print(colored("Aucun membre n'a été trouvé.", 'red', attrs=['bold'])) os.system("pause") @@ -424,15 +431,16 @@ def memberdo(choix, member): while "the informations are incorrect": # Loop Filling informations titre, firstname, surname, titrename = get_fullname(titre=titre, firstname=firstname, surname=surname) - os.system('cls') print("Titre : ", colored(titre, 'green')) print("Prénom : ", colored(firstname, 'green')) print("Nom : ", colored(surname, 'green')) correct = yes_or_no("Ces informations sont elles correctes ?") + os.system('cls') if correct: wantnewpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?") + os.system('cls') if wantnewpic: os.system('cls') if version != 'devnocam': @@ -455,17 +463,28 @@ def memberdo(choix, member): bkpdb() printcard(cartefilename) writeindb(titre, firstname, surname, clientID, dateinsc, dateexp, new=False) + os.system('cls') break 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 print('Print card') - elif choix == '0': # Menu - return else: - os.system('cls') print(colored('Choix incorrect !\n', 'red', attrs=['bold'])) + return titre, firstname, surname, dateexp def main():