Adds the product list & user input #5
This commit is contained in:
parent
0dc050f23d
commit
f9dd7d4ed6
16
cli.py
16
cli.py
|
@ -16,10 +16,11 @@ You can save this product to get it later.
|
||||||
from os import system
|
from os import system
|
||||||
from db import Db
|
from db import Db
|
||||||
from config import DB_REQUEST, CLI_MSG_DISCLAIMER, CLI_MSG_ASK_CAT, \
|
from config import DB_REQUEST, CLI_MSG_DISCLAIMER, CLI_MSG_ASK_CAT, \
|
||||||
CLI_MSG_ASK_ERR, CLI_MSG_QUIT, CLI_MSG_CHOOSEN_CAT
|
CLI_MSG_ASK_ERR, CLI_MSG_QUIT, CLI_MSG_CHOOSEN_CAT, CLI_MSG_CHOOSEN_PROD, \
|
||||||
|
CLI_MSG_PROD
|
||||||
cli_msg = str()
|
cli_msg = str()
|
||||||
|
|
||||||
|
product_asked = {'valid_item': False}
|
||||||
|
|
||||||
def ask_user(head_msg, foot_msg, item_list, db_obj=None):
|
def ask_user(head_msg, foot_msg, item_list, db_obj=None):
|
||||||
"""
|
"""
|
||||||
|
@ -141,12 +142,21 @@ category_asked = ask_user(CLI_MSG_DISCLAIMER, cli_msg, category_list, LOCAL_DB)
|
||||||
|
|
||||||
# Lists all products
|
# Lists all products
|
||||||
if category_asked['valid_item']:
|
if category_asked['valid_item']:
|
||||||
|
product_list = get_data_list(
|
||||||
|
LOCAL_DB, DB_REQUEST['list_prod'].format(category_asked['item'][1])
|
||||||
|
)
|
||||||
|
CLI_MSG_PROD = CLI_MSG_CHOOSEN_CAT.format(category_asked['item'][1]) \
|
||||||
|
+ CLI_MSG_PROD
|
||||||
|
|
||||||
|
product_asked = ask_user(CLI_MSG_PROD, cli_msg, product_list)
|
||||||
|
|
||||||
|
if product_asked['valid_item']:
|
||||||
cli_msg = CLI_MSG_CHOOSEN_CAT.format(category_asked['item'][1])
|
cli_msg = CLI_MSG_CHOOSEN_CAT.format(category_asked['item'][1])
|
||||||
|
cli_msg += CLI_MSG_CHOOSEN_PROD.format(product_asked['item'][1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cli_msg = CLI_MSG_QUIT
|
cli_msg = CLI_MSG_QUIT
|
||||||
|
|
||||||
|
|
||||||
# Asks the user to enter the index of the selected product
|
# Asks the user to enter the index of the selected product
|
||||||
|
|
||||||
# If index is not valid, re-ask
|
# If index is not valid, re-ask
|
||||||
|
|
|
@ -35,14 +35,17 @@ DB_REQUEST = {
|
||||||
|
|
||||||
CLI_MSG_DISCLAIMER = "\n# # # Bienvenu sur le terminal # # #\n"\
|
CLI_MSG_DISCLAIMER = "\n# # # Bienvenu sur le terminal # # #\n"\
|
||||||
"Voici la liste des catégories disponibles : \n"
|
"Voici la liste des catégories disponibles : \n"
|
||||||
|
CLI_MSG_PROD = "Produits disponibles :\n"
|
||||||
|
|
||||||
CLI_MSG_ASK_CAT = "Saisissez le nombre de la catégorie choisie [0-{}]"\
|
CLI_MSG_ASK_CAT = "Saisissez le nombre de la catégorie choisie [0-{}]"\
|
||||||
"\n(«Q» pour quitter): "
|
"\n(«Q» pour quitter): "
|
||||||
|
|
||||||
CLI_MSG_ASK_ERR = "\nSaisie incorrecte : «{}»"
|
CLI_MSG_ASK_ERR = "\nSaisie incorrecte : «{}»"
|
||||||
CLI_MSG_QUIT = "\nAu revoir!"
|
CLI_MSG_QUIT = "\nAu revoir!"
|
||||||
CLI_MSG_CHOOSEN_CAT = "\n# # Categorie : [ {} ] # #"
|
CLI_MSG_CHOOSEN_CAT = "# # Categorie : [ {} ]\n"
|
||||||
|
CLI_MSG_CHOOSEN_PROD = "\n# Produits : [ {} ]"
|
||||||
|
|
||||||
|
CLI_ITEM_MAX_LEN = 15
|
||||||
|
|
||||||
# DATABASE
|
# DATABASE
|
||||||
DB_CONFIG = {
|
DB_CONFIG = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user