refactored from simpliest models
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
class View:
|
||||
"""Prompt menu, get choices"""
|
||||
def __init__(self):
|
||||
@@ -10,3 +13,22 @@ class View:
|
||||
|
||||
def display_winner(self, participants):
|
||||
pass
|
||||
|
||||
def check_date(self):
|
||||
while True:
|
||||
date = input("Date de naissance (jj/mm/aaaa) ? : ")
|
||||
if datetime.strptime(date, '%d/%m/%Y'):
|
||||
break
|
||||
else:
|
||||
print("La date doit être au format jj/mm/aaaa")
|
||||
|
||||
|
||||
def test_ine(self):
|
||||
ine_pattern = r'[a-zA-Z]{2}\d{5}'
|
||||
while True:
|
||||
ine = input("Identifiant National d'Echecs (ine) ? : ")
|
||||
if re.match(ine_pattern, ine):
|
||||
break
|
||||
else:
|
||||
print("Mauvais format d'ine")
|
||||
|
||||
|
||||
@@ -15,19 +15,22 @@ class Menu:
|
||||
]
|
||||
|
||||
def items(self, value):
|
||||
"""displays menu depending on given value"""
|
||||
menu_type = []
|
||||
if value == 1:
|
||||
menu_type = self.ITEMS
|
||||
if value == 2:
|
||||
menu_type = self.RAPPORTS
|
||||
|
||||
for i in menu_type:
|
||||
print(i)
|
||||
try:
|
||||
demande = input("Choix ? : ")
|
||||
if demande not in range(1, len(menu_type)):
|
||||
demande = input("Choix ? : ")
|
||||
except ValueError:
|
||||
print("Veuillez saisir un chiffre")
|
||||
demande = input("Choix ? : ")
|
||||
return demande
|
||||
while True:
|
||||
try:
|
||||
choice = input("Choix ? : ")
|
||||
if int(choice) not in range(1, len(menu_type) + 1):
|
||||
print("Veuillez saisir un chiffre entre 1 et", len(menu_type))
|
||||
print(int(choice) in range(1, len(menu_type)))
|
||||
else:
|
||||
return choice
|
||||
except ValueError:
|
||||
print("Veuillez entrer un chiffre")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user