瀏覽代碼

Select a customer instead typing name by hand

Jovian (Netbook) 6 年之前
父節點
當前提交
ef78c90852
共有 2 個文件被更改,包括 29 次插入6 次删除
  1. 8 6
      app_customer.py
  2. 21 0
      cli/select.py

+ 8 - 6
app_customer.py

@@ -1,7 +1,7 @@
 from consumer.connect import DataConsumer
 from consumer.credentials import getCredentials
 from basic_display import BasicDisplay
-from cli.name_asker import NameAsker
+from cli.select import Selecter
 from cli.pass_asker import PassAsker
 from cli.customer_action_asker import CustomerActionAsker
 from cli.book_asker import BookAsker
@@ -11,7 +11,7 @@ print('|Customer application|')
 credentials = getCredentials()
 consumer = DataConsumer(credentials)
 
-nameAsker = NameAsker()
+companyAsker = Selecter('Choose your company')
 passAsker = PassAsker()
 actionAsker = CustomerActionAsker()
 bookAsker = BookAsker()
@@ -19,16 +19,18 @@ bookAsker = BookAsker()
 display = BasicDisplay()
 
 # Login phase
-login = nameAsker.ask()
-pwd = passAsker.ask()
-
 compList = consumer.getCompanyNames()
 compList.append('dev')
 
-if login in compList:
+login = companyAsker.selectInto(compList)
+pwd = passAsker.ask()
+
+# Dummy password check
+if pwd != "":
     print('Successfully logged as', login)
 else:
     print('Name', login, 'not recognized.')
+    print('(dummy password check : enter an non-empty password)')
     exit()
 
 # Action phase

+ 21 - 0
cli/select.py

@@ -0,0 +1,21 @@
+from PyInquirer import prompt 
+
+# Select an item from a list
+
+class Selecter:
+    def __init__(self, choices, question = 'Please select an item :'):
+        self.widget = [
+            {
+                'type':'list',
+                'name':'ans',
+                'message':question,
+                'choices':choices
+            }
+        ]
+
+    def select(self):
+        return prompt(self.widget)['ans']
+
+    def selectInto(self, choices):
+        self.widget[0]['choices'] = choices
+        return self.select()