Code reformatting : function newmember()
This commit is contained in:
parent
d5c4ee5997
commit
0ce5ed334c
152
IFPass.py
152
IFPass.py
@ -201,7 +201,7 @@ def getpic():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
def writeindb(clientID):
|
def writeindb(titre, firstname, surname, clientID, dateinsc, dateexp):
|
||||||
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=';')
|
||||||
@ -213,7 +213,7 @@ def bkpdb():
|
|||||||
copyfile(clientsfile, clientsbkpfile)
|
copyfile(clientsfile, clientsbkpfile)
|
||||||
|
|
||||||
|
|
||||||
def fillcard(barcode):
|
def fillcard(clientID, titrename, firstname, dateexp, barcode):
|
||||||
print("Création de la carte avec les informations...", end='')
|
print("Création de la carte avec les informations...", end='')
|
||||||
try:
|
try:
|
||||||
im = Image.open(pngtemplate)
|
im = Image.open(pngtemplate)
|
||||||
@ -248,12 +248,11 @@ def fillcard(barcode):
|
|||||||
# Create PDF :
|
# Create PDF :
|
||||||
im = im.convert("RGB")
|
im = im.convert("RGB")
|
||||||
im.save(imgdir + clientID + '_Front.pdf', 'PDF', resolution=299.0, quality=98)
|
im.save(imgdir + clientID + '_Front.pdf', 'PDF', resolution=299.0, quality=98)
|
||||||
writeindb(clientID)
|
|
||||||
|
|
||||||
print(colored('[OK]', 'green'))
|
print(colored('[OK]', 'green'))
|
||||||
|
|
||||||
|
|
||||||
def mergepdf():
|
def mergepdf(clientID):
|
||||||
cartefilename = os.path.join(imgdir, clientID + '.pdf')
|
cartefilename = os.path.join(imgdir, clientID + '.pdf')
|
||||||
output = PdfFileWriter()
|
output = PdfFileWriter()
|
||||||
|
|
||||||
@ -278,6 +277,49 @@ def printcard(cartefilename):
|
|||||||
subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' ' + printername, shell=False)
|
subprocess.Popen('"' + AcrobatReader + '"' + ' /h /n /t ' + cartefilename + ' ' + printername, shell=False)
|
||||||
|
|
||||||
|
|
||||||
|
def newmember():
|
||||||
|
while "the informations are incorrect": # Loop Filling informations
|
||||||
|
os.system('cls')
|
||||||
|
titre, firstname, surname, titrename = get_fullname()
|
||||||
|
dateinsc = date.today()
|
||||||
|
dateexp = dateinsc + timedelta(days=365)
|
||||||
|
|
||||||
|
dateinsc = dateinsc.strftime('%d/%m/%Y')
|
||||||
|
dateexp = dateexp.strftime('%d/%m/%Y')
|
||||||
|
changeexp = yes_or_no("Voulez-vous choisir la date d'expiration ?")
|
||||||
|
if changeexp:
|
||||||
|
while True:
|
||||||
|
dateexp = input("Quelle date d'expiration voulez-vous mettre (Format : JJ/MM/AAAA)? : ")
|
||||||
|
match = re.fullmatch(r'^(0[1-9]|1[0-9]|2[0-9]|3[0-1])/(0[1-9]|1[0-2])/([0-9]){4}$', dateexp)
|
||||||
|
if match:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print('Mauvais format ! JJ/MM/AAAA, exemple : 01/08/2042')
|
||||||
|
|
||||||
|
os.system('cls')
|
||||||
|
print("Titre : ", colored(titre, 'green'))
|
||||||
|
print("Prénom : ", colored(firstname, 'green'))
|
||||||
|
print("Nom : ", colored(surname, 'green'))
|
||||||
|
print("Date d'inscription :", colored(dateinsc, 'green'))
|
||||||
|
print("Date d'expiration : ", colored(dateexp, 'green'))
|
||||||
|
correct = yes_or_no("Ces informations sont elles correctes ?")
|
||||||
|
|
||||||
|
if correct:
|
||||||
|
os.system('cls')
|
||||||
|
if version != 'devnocam':
|
||||||
|
global picture
|
||||||
|
picture = getpic()
|
||||||
|
clientID = getclientID()
|
||||||
|
barcode = barcode_gen(clientID)
|
||||||
|
fillcard(clientID, titrename, firstname, dateexp, barcode)
|
||||||
|
cartefilename = mergepdf(clientID)
|
||||||
|
if version not in ('dev', 'devnocam'):
|
||||||
|
bkpdb()
|
||||||
|
printcard(cartefilename)
|
||||||
|
writeindb(titre, firstname, surname, clientID, dateinsc, dateexp)
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
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=';')
|
||||||
@ -329,25 +371,59 @@ def membersearch():
|
|||||||
elif diff == 0:
|
elif diff == 0:
|
||||||
print(colored("Il s'agit du dernier jour de l'abonnement, il expirera demain.", 'yellow', attrs=['bold']))
|
print(colored("Il s'agit du dernier jour de l'abonnement, il expirera demain.", 'yellow', attrs=['bold']))
|
||||||
|
|
||||||
print('\n1 - Modifier', "2 - Renouveller l'abonnement", '3 - 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 : ')
|
||||||
if choix == '1':
|
memberdo(choix, member)
|
||||||
print(1)
|
|
||||||
elif choix == '2':
|
|
||||||
print(2)
|
|
||||||
elif choix == '3':
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
os.system('cls')
|
|
||||||
print(colored('Choix incorrect !\n', 'red', attrs=['bold']))
|
|
||||||
|
|
||||||
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")
|
||||||
|
|
||||||
|
|
||||||
|
def memberdo(choix, member):
|
||||||
|
titre = member[0]
|
||||||
|
firstname = member[1]
|
||||||
|
os.system('cls')
|
||||||
|
if choix == '1': # Edit member
|
||||||
|
while "the informations are incorrect": # Loop Filling informations
|
||||||
|
titre, firstname, surname, titrename = get_fullname()
|
||||||
|
|
||||||
|
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 ?")
|
||||||
|
|
||||||
|
if correct:
|
||||||
|
newpic = yes_or_no("Voulez-vous prendre une nouvelle photo ?")
|
||||||
|
if newpic:
|
||||||
|
os.system('cls')
|
||||||
|
if version != 'devnocam':
|
||||||
|
global picture
|
||||||
|
picture = getpic()
|
||||||
|
clientID = member[3]
|
||||||
|
barcode = barcode_gen(clientID)
|
||||||
|
fillcard(barcode)
|
||||||
|
cartefilename = mergepdf()
|
||||||
|
if version not in ('dev', 'devnocam'):
|
||||||
|
bkpdb()
|
||||||
|
printcard(cartefilename)
|
||||||
|
break
|
||||||
|
|
||||||
|
elif choix == '2': # Renew subscription
|
||||||
|
print(2)
|
||||||
|
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']))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global titre, firstname, surname, titrename, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader
|
# global titre, firstname, surname, titrename, dateinsc, dateexp, clientID, clientsfile, IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, picture, pdftemplate, printername, AcrobatReader
|
||||||
|
global IFPassDBdir, clientsfile, imgdir, clientsbkpfile, templatesdir, pngtemplate, fonttemplate, pdftemplate, printername, AcrobatReader
|
||||||
while "The program is running":
|
while "The program is running":
|
||||||
init() # Initialisation of colorama
|
init() # Initialisation of colorama
|
||||||
IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
IFPassDBdir, printername, AcrobatReader, clientsfile, clientsbkpfile, imgdir, templatesdir, pdftemplate, pngtemplate, fonttemplate = initialisation()
|
||||||
@ -360,54 +436,16 @@ def main():
|
|||||||
print(colored("\nATTENTION : Il s'agit d'une version en cours de développement, potentiellement instable !", 'red'))
|
print(colored("\nATTENTION : Il s'agit d'une version en cours de développement, potentiellement instable !", 'red'))
|
||||||
print("\nLe programme IFPass à été écrit par Jordan ERNST Q1 2018 pour l'Institut Français en Hongrie.")
|
print("\nLe programme IFPass à été écrit par Jordan ERNST Q1 2018 pour l'Institut Français en Hongrie.")
|
||||||
print('Pour toute question, problème ou requête contactez-moi à pro.ernst@gmail.com.\n')
|
print('Pour toute question, problème ou requête contactez-moi à pro.ernst@gmail.com.\n')
|
||||||
print('1 - Nouveau membre', '2 - Rechercher un membre', '3 - Quitter', sep='\n')
|
print('1 - Nouveau membre', '2 - Rechercher un membre', '0 - Quitter', sep='\n')
|
||||||
choix = input('Choix : ')
|
choix = input('Choix : ')
|
||||||
if choix == '1':
|
if choix == '1':
|
||||||
while "the informations are incorrect": # Loop Filling informations
|
newmember()
|
||||||
os.system('cls')
|
|
||||||
titre, firstname, surname, titrename = get_fullname()
|
|
||||||
dateinsc = date.today()
|
|
||||||
dateexp = dateinsc + timedelta(days=365)
|
|
||||||
|
|
||||||
dateinsc = dateinsc.strftime('%d/%m/%Y')
|
|
||||||
dateexp = dateexp.strftime('%d/%m/%Y')
|
|
||||||
changeexp = yes_or_no("Voulez-vous choisir la date d'expiration ?")
|
|
||||||
if changeexp:
|
|
||||||
while True:
|
|
||||||
dateexp = input("Quelle date d'expiration voulez-vous mettre (Format : JJ/MM/AAAA)? : ")
|
|
||||||
match = re.fullmatch(r'^(0[1-9]|1[0-9]|2[0-9]|3[0-1])/(0[1-9]|1[0-2])/([0-9]){4}$', dateexp)
|
|
||||||
if match:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('Mauvais format ! JJ/MM/AAAA, exemple : 01/08/2042')
|
|
||||||
|
|
||||||
os.system('cls')
|
|
||||||
print("Titre : ", colored(titre, 'green'))
|
|
||||||
print("Prénom : ", colored(firstname, 'green'))
|
|
||||||
print("Nom : ", colored(surname, 'green'))
|
|
||||||
print("Date d'inscription :", colored(dateinsc, 'green'))
|
|
||||||
print("Date d'expiration : ", colored(dateexp, 'green'))
|
|
||||||
correct = yes_or_no("Ces informations sont elles correctes ?")
|
|
||||||
|
|
||||||
if correct:
|
|
||||||
os.system('cls')
|
|
||||||
if version != 'devnocam':
|
|
||||||
global picture
|
|
||||||
picture = getpic()
|
|
||||||
clientID = getclientID()
|
|
||||||
barcode = barcode_gen(clientID)
|
|
||||||
fillcard(barcode)
|
|
||||||
cartefilename = mergepdf()
|
|
||||||
if version not in ('dev', 'devnocam'):
|
|
||||||
bkpdb()
|
|
||||||
printcard(cartefilename)
|
|
||||||
break
|
|
||||||
|
|
||||||
elif choix == '2':
|
elif choix == '2':
|
||||||
os.system('cls')
|
os.system('cls')
|
||||||
membersearch()
|
membersearch()
|
||||||
|
|
||||||
elif choix == '3':
|
elif choix == '0':
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user